ãã®èšäºã¯KDããªãŒã«å®å šã«å°å¿µããŠããŸããKDããªãŒã®æ§ç¯ã®è€éããKDããªãŒã§ã®ãé£æ¥ãæ€çŽ¢æ©èœã®å®è£ ã®åŸ®åŠããããã³ã¢ã«ãŽãªãºã ã®ç¹å®ã®ãµãã¿ã¹ã¯ã解決ããããã»ã¹ã§çºçããå¯èœæ§ã®ãããèœãšãç©Žãã«ã€ããŠèª¬æããŸãã èªè ãå°éçšèªïŒé£è¡æ©ãè¶ é£è¡æ©ãªã©ïŒãšæ··åããªãããã«ããããããããŠå®éã«äŸ¿å®äžãäž»ãªã¢ã¯ã·ã§ã³ã¯3次å 空éã§è¡ããããšæ³å®ãããŠããŸãã ãã ããå¿ èŠã«å¿ããŠãç°ãªã次å ã®ç©ºéã§äœæ¥ããããšã«æ³šæããŠãã ããã ç§ã®æèŠã§ã¯ããã®èšäºã¯ããã°ã©ããŒãšã¢ã«ãŽãªãºã ã®åŠç¿ã«èå³ããããã¹ãŠã®äººã«ãšã£ãŠæçšã§ãã誰ããèªåèªèº«ã®ããã«æ°ããäœããèŠã€ãã誰ããåã«è³æãç¹°ãè¿ããã³ã¡ã³ãã®èšäºãè£è¶³ãããããããŸããã ãããã«ãããç§ã¯ç«ã®äžã®ãã¹ãŠã®äººã«å°ããŸãã
ã¯ããã«
KDããªãŒ ïŒK次å ããªãŒïŒãç¹å¥ãªã幟äœåŠçãªãããŒã¿æ§é ã§ããã®ç©ºéãè¶ å¹³é¢ïŒ K> 3 ïŒãå¹³é¢ïŒ K = 3 ïŒãçŽç·ã§åºåãããšã«ãããK次å 空éããããå°ããéšåãã«åå²ã§ããŸãïŒ K = 2 ïŒããã1次å 空éã®å Žåããã€ã³ãïŒãã®ãããªããªãŒã§æ€çŽ¢ããããšã«ããã ãã€ããªæ€çŽ¢ã«äŒŒããã®ãåŸãããŸã ïŒã
ãã®ãããªããŒãã£ã·ã§ã³ã¯éåžžãK次å 空éã®æ€çŽ¢ç¯å²ãçããããã«äœ¿çšãããã®ãè«ççã§ãã ããšãã°ããã€ã³ãã«è¿ããªããžã§ã¯ãïŒé ç¹ãçãäžè§åœ¢ãªã©ïŒã®æ€çŽ¢ããã€ã³ãã®3Dã°ãªãããžã®æ圱ãã¬ã€ãã¬ãŒã·ã³ã°ïŒã¬ã€ãã¬ãŒã·ã³ã°ã§ã¢ã¯ãã£ãã«äœ¿çšïŒãªã©ã åæã«ã空éãªããžã§ã¯ãã¯ç¹å¥ãªå¹³è¡å é¢äœ- ããŠã³ãã£ã³ã°ããã¯ã¹ã«é 眮ãããŸãïŒããŠã³ãã£ã³ã°ããã¯ã¹ã®ã¿ãäœæããå Žåããªããžã§ã¯ãã®å ã®ã»ãããŸãã¯ãªããžã§ã¯ãèªäœãèšè¿°ããå¹³è¡å é¢äœã®ãããªããŠã³ãã£ã³ã°ããã¯ã¹ãåŒã³åºããŸãããã€ã³ãã®å ŽåãããŠã³ãã£ã³ã°ããã¯ã¹ã¯ããŠã³ãã£ã³ã°ããã¯ã¹ãšããŠååŸãããŸããè¡šé¢ç©ãšäœç©ããŒãã®ããã¯ã¹ïŒããã®èŸºã¯åº§æšè»žã«å¹³è¡ã§ãã
ããŒãåå²ããã»ã¹
ãããã£ãŠãKD-Treeã䜿çšããåã«ãæ§ç¯ããå¿ èŠããããŸãã ãã¹ãŠã®ãªããžã§ã¯ãã¯ãå ã®ã»ããã®ãªããžã§ã¯ããèšè¿°ãã1ã€ã®å€§ããªããŠã³ãã£ã³ã°ããã¯ã¹ã«é 眮ããïŒåãªããžã§ã¯ãã¯ããŠã³ãã£ã³ã°ããã¯ã¹ã«ãã£ãŠå¶éãããŸãïŒããã®åŸããã®åŽé¢ã®1ã€ã«å¹³è¡ãªå¹³é¢ã§2ã€ã«åå²ïŒåå²ïŒãããŸãã 2ã€ã®æ°ããããŒããããªãŒã«è¿œå ãããŸãã åæ§ã«ãçµæã®å¹³è¡å é¢äœã¯ãããã2ã€ã«åå²ãããŸãã ããã»ã¹ã¯ãç¹å¥ãªåºæºïŒ SAHãåç §ïŒã«ãã£ãŠããŸãã¯ããªãŒã®ç¹å®ã®æ·±ãã«å°éãããšãããŸãã¯ããªãŒããŒãå ã§ç¹å®ã®æ°ã®èŠçŽ ã«å°éãããšãã«çµäºããŸãã äžéšã®èŠçŽ ã¯ãå·Šå³ã®ããŒãã®äž¡æ¹ã«åæã«å ¥åã§ããŸãïŒããšãã°ãäžè§åœ¢ãããªãŒèŠçŽ ãšèŠãªãããå ŽåïŒã
ãã®ããã»ã¹ã2Dã®å€ãã®äžè§åœ¢ã®äŸã§èª¬æããŸãã
å³1ã¯ãäžè§åœ¢ã®åæã»ããã瀺ããŠããŸãã åäžè§åœ¢ã¯ç¬èªã®å¢çããã¯ã¹ã«é 眮ãããäžè§åœ¢ã®ã»ããå šäœã1ã€ã®å€§ããªã«ãŒãå¢çããã¯ã¹ã«å æ¥ããŸãã
å³2ã§ã¯ ãã«ãŒãããŒãã2ã€ã®ããŒãïŒOXïŒ ã«åå²ããŸããäžè§åœ¢1ã2ã5ã¯å·ŠããŒãã«ã3ã4ã5ã¯å³ããŒãã«åé¡ãããŸãã
å³3ã§ã¯ãçµæã®ããŒããåã³2ã€ã«åå²ãããããããã«äžè§åœ¢5ãå«ãŸããŠããŸãã ããã»ã¹ãçµäºãããšã4ã€ã®ãªãŒãããŒããååŸãããŸãã
ããªãŒããŒããåé¢ããå¹³é¢ãéžæããããšãéåžžã«éèŠã§ãã ãããè¡ãã«ã¯éåžžã«å€ãã®æ¹æ³ããããŸãããå®éã«ã¯æãäžè¬çãªæ¹æ³ã®äžéšã®ã¿ã瀺ããŸãïŒåæãªããžã§ã¯ãã¯1ã€ã®å€§ããªå¢çããã¯ã¹ã«é 眮ããã座æšè»žã®1ã€ã«å¹³è¡ã«åé¢ãè¡ããããšæ³å®ãããŠããŸãïŒïŒ
⊠æ¹æ³1 ïŒå¢çããã¯ã¹ã®æ倧ã®åŽé¢ãéžæããŸãã 次ã«ãå²ç·å¹³é¢ãéžæãã蟺ã®äžå€®ãééããŸãã
⊠æ¹æ³2 ïŒäžå€®å€ã§åæïŒåº§æšã®1ã€ã§ãã¹ãŠã®ããªããã£ãã䞊ã¹æ¿ãã䞊ã¹æ¿ãããããªã¹ãã®äžå€®ã«ããèŠçŽ ïŒãŸãã¯èŠçŽ ã®äžå¿ïŒãäžå€®å€ãšåŒã³ãŸãã å²ç·å¹³é¢ã¯äžå€®å€ãééãããããå·Šå³ã®èŠçŽ ã®æ°ã¯ã»ãŒçãããªããŸãã
⊠æ¹æ³3 ïŒåå²æã«äº€äºã®èŸºã䜿çšïŒæ·±ã0ã§ãOXã«å¹³è¡ãªèŸºã®äžå€®ãããŒããOYã«å¹³è¡ãªèŸºã®äžå€®ã次ã®æ·±ãã¬ãã«ã次ã«OZã«æ²¿ã£ãŠããŒããªã© ããã¹ãŠã®è»žã«æ²¿ã£ãŠæ©ãããå Žåãããã»ã¹ãåã³éå§ããŸãã çµäºåºæºã¯äžèšã§èª¬æãããŠããŸãã
⊠æ¹æ³4 ïŒæããã¹ããŒãããªãªãã·ã§ã³ã¯ã SAHïŒSurface Area HeuristicïŒããŠã³ãã£ã³ã°ããã¯ã¹ããŒãã£ã·ã§ã³è©äŸ¡é¢æ°ã䜿çšããããšã§ãã ïŒããã«ã€ããŠã¯ä»¥äžã§è©³ãã説æããŸãïŒã SAHã¯ãããŒãåå²ãåæ¢ããããã®æ®éçãªåºæºãæäŸããŸãã
æ¹æ³1ãš3ã¯ãããªãŒã®æ§ç¯ã®é床ã«é¢ããŠã¯åªããŠããŸãïŒåŽé¢ã®äžå€®ãèŠã€ããŠå¹³é¢ãæããããå ã®ã»ãããå·Šããšãå³ãã®èŠçŽ ããµããåããã®ã¯ç°¡åã§ãïŒã åæã«ããããã¯ãã°ãã°ç©ºéã®ããŒãã£ã·ã§ã³ã®å€§ãŸããªãã¥ãŒãæäŸããKDããªãŒã®åºæ¬çãªæäœã«æªåœ±é¿ãäžããå¯èœæ§ããããŸãïŒç¹ã«ããªãŒå ã®å ç·ã远跡ããå ŽåïŒã
æ¹æ³2ã§ã¯ãè¯ãçµæãåŸãããšãã§ããŸãããããŒãã®èŠçŽ ã®ãœãŒãã«è²»ããããããªãã®æéãå¿ èŠã§ãã ã¡ãœãã1ã3ãšåæ§ãå®è£ ã¯éåžžã«ç°¡åã§ãã
æãèå³æ·±ãã®ã¯ããã¹ããŒããSAHãã¥ãŒãªã¹ãã£ãã¯ã䜿çšããæ¹æ³ïŒæ¹æ³4ïŒã§ãã
ããªãŒããŒãã®ããŠã³ãã£ã³ã°ããã¯ã¹ã¯ãNïŒè»žã«å¹³è¡ãªïŒå¹³é¢ã§ååŽã§N + 1éšåïŒéåžžã¯çããïŒã«åå²ãããŸãïŒå®éãååŽé¢ã®å¹³é¢ã®æ°ã¯ä»»æã§ãããåçŽããšå¹çã®ããã«äžå®ã§ãïŒ ã ããã«ãå¹³é¢ãšå¢çããã¯ã¹ã®å¯èœãªäº€å·®ç¹ã§ãç¹æ®é¢æ°ã®å€SAHãèšç®ãããŸãã åå²ã¯ãæå°ã®SAHé¢æ°å€ãæã€ãã¬ãŒã³ã«ãã£ãŠå®è¡ãããŸãïŒæ¬¡ã®å³ã§ã¯ãSAH [7]ã§æå°å€ã«éãããšæ³å®ããããããã®ãã¬ãŒã³ã«ãã£ãŠåå²ãå®è¡ãããŸãïŒãã ãã2D空éã¯éåžžã«çŽæ¥ã§ãïŒïŒã
çŸåšã®å¹³é¢ã®é¢æ°ã®SAHå€ã¯ã次ã®ããã«èšç®ãããŸãã
KD-Treeã®å®è£ ã§ã¯ãåé¢ã32ã®ãã¬ãŒã³ã䜿çšããŠ33ã®çããéšåã«åå²ããŸãã ãããã£ãŠããã¹ãçµæã«ãããšãããªãŒã®åºæ¬æ©èœã®ãé»éã®ãäžéé床/ããªãŒã®æ§ç¯é床ãèŠã€ããããšãã§ããŸããã
SAHãã¥ãŒãªã¹ãã£ãã¯ãšããŠãäžå³ã«ç€ºãããŠããé¢æ°ã䜿çšããŸãã
決å®ãäžãã«ã¯ããã¹ãŠã®å²ç·é¢ã§ãã®é¢æ°ã®æå°å€ã®ã¿ãå¿ èŠã§ããããšã¯æ³šç®ã«å€ããŸãã ãããã£ãŠãäžçåŒã®æãåçŽãªæ°åŠçç¹æ§ã䜿çšããããŒãè¡šé¢ç©ïŒ3DïŒïŒ SARãSALãSA ïŒãèšç®ãããšãã«2ã®ä¹ç®ãç Žæ£ããã ãã§ãªãããã®åŒãå€§å¹ ã«ç°¡çŽ åã§ããŸãã å®å šã«ãèšç®ã¯ããŒãããšã«1åã®ã¿å®è¡ãããŸãïŒé€ç®é¢æ°ãçµäºããããã®åºæºãè©äŸ¡ãããšãã ãã®ãããªåçŽãªæé©åã«ãããããªãŒã®æ§ç¯é床ãå€§å¹ ã«åäžããŸãïŒ x2.5 ïŒã
SAHé¢æ°ã®å€ãå¹æçã«èšç®ããã«ã¯ããã®å¹³é¢ã®å³åŽã«ããç¯ç¹èŠçŽ ã®æ°ãšå·ŠåŽã«ããç¯ç¹èŠçŽ ã®æ°ããã°ãã決å®ã§ããå¿ èŠããããŸãã ã¢ã«ãŽãªãºã ãšããŠ2次挞è¿ç·ã䜿çšããç²ãããããããã«ãŒããã©ãŒã¹ã¢ãããŒãã䜿çšãããšãçµæã¯äžååã«ãªããŸãã ãã ãã ãbinnedãã¡ãœããã䜿çšãããšãç¶æ³ã¯å€§å¹ ã«æ¹åãããŸãã ãã®æ¹æ³ã®èª¬æã以äžã«ç€ºããŸãã
ããŠã³ãã£ã³ã°ããã¯ã¹åŽãNåã®çããéšåã«åå²ãïŒãã¬ãŒã³ã®æ°ã¯ïŒN-1ïŒïŒã1çµã®åº§æšïŒpointMinãpointMax- å³1ãåç §ïŒã§ããŠã³ãã£ã³ã°ããã¯ã¹ãæ ŒçŽããããŒãã®ãã¹ãŠã®èŠçŽ ã1åãã¹ãããšä»®å®ããŸããåãã¬ãŒã³ã«ã€ããŠãå³åŽã«ããèŠçŽ ã®æ°ãšãå·ŠåŽã«ããèŠçŽ ã®æ°ãæ£ç¢ºã«æ±ºå®ã§ããŸãã ããããã«NèŠçŽ ã®2ã€ã®é åãäœæãããŒãã§åæåããŸãã aHighããã³aLowãšããååã®é åãšããŸãã ããŒãã®ãã¹ãŠã®èŠçŽ ãé£ç¶ããŠå®è¡ããŸãã çŸåšã®èŠçŽ ã§ã¯ãã©ã®éšåãå¢çããã¯ã¹ã®pointMinãšpointMaxãååŸãããã確èªããŸãã ãããã£ãŠãã»ããã®èŠçŽ ããšã«2ã€ã®ã€ã³ããã¯ã¹ãååŸããŸãã iHigh ïŒpointMaxã®å ŽåïŒããã³iLow ïŒpointMinã®å ŽåïŒãšããååã®ã€ã³ããã¯ã¹ãšããŸãã ãã®åŸã以äžãå®è¡ããŸããaHigh[iHigh] + = 1ãaLow [iLow] + = 1ã
ãã¹ãŠã®èŠçŽ ãééããåŸãå¡ãã€ã¶ãããé åaHighããã³aLowãååŸããŸãã aHighé åã®å Žåãéšåæ¥å°ŸèŸïŒæ¥å°ŸèŸïŒã®éãèšç®ããaLowã®å Žåãéšåæ¥é èŸïŒæ¥é èŸïŒã®éãèšç®ããŸãïŒå³ãåç §ïŒã å³åŽã®èŠçŽ ã®æ°ïŒ ãããŠå³åŽã®ã¿ïŒ ïŒã€ã³ããã¯ã¹iã®å¹³é¢ã®aLow [i + 1]ãå·ŠåŽã«ããèŠçŽ ã®æ°ïŒ ãããŠå·ŠåŽã®ã¿ïŒ ïŒã«çããããšãããããŸã ïŒAHigh [i]ããšããŠå ¥åããèŠçŽ ã®æ°å·Šå³ã®ããŒãïŒAllElements-aLow [i + 1] -aHigh [i]ã
ãã®åé¡ã¯è§£æ±ºããããã®ç°¡åãªããã»ã¹ã®äŸã以äžã«ç€ºããŸãã
ãããŒãããã¬ãŒã³ã®å·Šå³ã«æå®ã®æ°ã®èŠçŽ ãååŸãããšãå¿ èŠãªã¡ã¢ãªéãäºåã«å²ãåœãŠãããšãã§ããŸãïŒçµå±ãæå°SAHãåãåã£ãåŸããã¹ãŠã®èŠçŽ ãããäžåºŠèª¿ã¹ãŠããããããåžæã®é åã«é 眮ããå¿ èŠããããŸãïŒ ãïŒããã³éåžžã®push_backã䜿çšãããšïŒäºçŽãåŒã³åºãããªãã£ãå ŽåïŒäžå®ã®ã¡ã¢ãªå²ãåœãŠãéåžžã«é«äŸ¡ãªæäœã«ãªããŸãïŒãããªãŒæ§ç¯ã¢ã«ãŽãªãºã ïŒx3.3ïŒã®é床ã«ãã©ã¹ã®åœ±é¿ãäžããŸãã
ããã§ãSAHèšç®åŒã§äœ¿çšãããå®æ°ã®ç®çãããã«è©³ãã説æãããã®ããŒãã®åå²ãåæ¢ããããã®åºæºã«ã€ããŠã説æããŸãã
å®æ°cIããã³cTã調ã¹ããšãããå¯ãªããªãŒæ§é ïŒãŸãã¯ãã®éïŒãéæã§ããã¢ã«ãŽãªãºã ã®æéãç ç²ã«ããŸãã äž»ã«ã¬ã€ãã¬ãŒã·ã³ã°ã¬ã³ããªã³ã°çšã®KDããªãŒã®æ§ç¯ã«é¢ããèšäºã§ã¯ãèè ã¯å€cI = 1ãcT = [1; 2] ïŒcTå€ãé«ãã»ã©ãããªãŒã®æ§ç¯ãéããªãããã®ãããªããªãŒã§ã®ã¬ã€ãã¬ãŒã·ã³ã°ã®çµæãæªåããŸãã
ç§ã®å®è£ ã§ã¯ãããªãŒã䜿çšããŠãé£æ¥ããæ€çŽ¢ããå¿ èŠãªä¿æ°ã®ãã¹ããšæ€çŽ¢ã®çµæã«åå泚æãæã£ãŠããŸããcTã®å€ãé«ããšãèŠçŽ ã§å®å šã«æºããããŠããªãããŒããåŸãããããšãããããŸãã ãã®ç¶æ³ãåé¿ããããã«ãcTå€ã1ã«èšå®ããç°ãªã倧ããªããŒã¿åäœã§cIå€ããã¹ãããããšã«ããŸããã ãã®çµæã建èšäžã«ããªãã®æéãè²»ãããŠãããªãå¯ãªããªãŒæ§é ãåŸãããšãã§ããŸããã ãé£äººãã®æ€çŽ¢çµæã§ã¯ããã®ã¢ã¯ã·ã§ã³ãç©æ¥µçã«åæ ãããæ€çŽ¢é床ãåäžããŸããã
ããŒãã®åå²ãåæ¢ããããã®åºæºã¯éåžžã«ç°¡åã§ãã
ã€ãŸããåããŒãã®ãã¬ãŒã¹ã®ã³ã¹ãã芪ããŒãã®ãã¬ãŒã¹ã®ã³ã¹ãããã倧ããå Žåãåå²ãåæ¢ããå¿ èŠããããŸãã
KDããªãŒããŒããåå²ããæ¹æ³ãåŠç¿ããã®ã§ãããŒãå ã®èŠçŽ ã®æ°ãéåžžã«å€ããèŠçŽ ã®æ°ã«ããåæ¢åºæºã«ãã£ãŠã¢ã«ãŽãªãºã ãç¡éã«ãªã£ãåæã®ã±ãŒã¹ã«ã€ããŠèª¬æããŸãã å®éã«ã¯ãç»åãžã®ãã¹ãŠã®æ³šæïŒããšãã°ã2Dã®äžè§åœ¢ïŒïŒ
ç§ã¯ãã®ãããªç¶æ³ããæ圢ããšåŒãã§ããŸãïŒå ±éã®æ¥ç¹ããããäžèŽãããªããžã§ã¯ããããããã®ã«ããŽãªã«ãé¢é£ããŠããŸãïŒã å²ç·é¢ãã©ã®ããã«æç»ããŠããäžå¿ç¹ã¯äœããã®æ¹æ³ã§ããŒãã®1ã€ã«èœã¡ãããã«ãã£ãŠå ±éç¹ã§ããäžè§åœ¢ã衚瀺ãããããšãããããŸãã
ããªãŒæ§ç¯ããã»ã¹
ããªãŒããŒããåå²ããæ¹æ³ãåŠã³ãŸããããä»ã§ã¯ãåŸãããç¥èãããªãŒå šäœã®æ§ç¯ããã»ã¹ã«é©çšããããšãæ®ã£ãŠããŸãã 以äžã«ãKD-Treeã®æ§ç¯ã®å®è£ ã«ã€ããŠèª¬æããŸãã
ããªãŒã¯ã«ãŒãããæ§ç¯ãããŸãã ããªãŒã®åããŒãã«ã¯ãå·Šããã³å³ã®ãµãããªãŒãžã®ãã€ã³ã¿ãŒãæ ŒçŽããŸãããã®ãããªããŒãããªãå Žåã¯ã ãªãŒã ïŒã·ãŒããã€ãŸãïŒãšèŠãªãããŸãã åããŒãã«ã¯ããã®ããŒãã®ãªããžã§ã¯ããèšè¿°ããå¢çããã¯ã¹ãä¿åãããŸãã ãªãŒãïŒ ãããŠãªãŒãã®ã¿ïŒ ïŒããŒãã«ã¯ããã®ããŒãã«ãããªããžã§ã¯ãã®ã€ã³ããã¯ã¹ãæ ŒçŽããŸãã ãã ããæ§ç¯ããã»ã¹äžã«ãããŒãã®ã¡ã¢ãªã¯éšåçã«å²ãåœãŠãããŸãïŒã€ãŸããKåã®ããŒãã«ããã«å²ãåœãŠãããŸãã第1ã«ãã¡ã¢ãªãããŒãžã£ã§äœæ¥ããæ¹ãå¹ççã§ãã第2ã«ãã¢ã€ãã ã®çž®å°ã¯ãã£ãã·ã¥ã«æé©ã§ãïŒã æ°ããèŠçŽ ããã¯ã¿ãŒã«è¿œå ãããšãå¥ã®å Žæã«ããæ¢åã®ãã¹ãŠã®èŠçŽ ã®ã¡ã¢ãªãå®è£ ãããå¯èœæ§ãããããããã®ãããªã¢ãããŒãã§ã¯ãã¯ã¿ãŒã«ããªãŒããŒããæ ŒçŽã§ããŸããã
ãããã£ãŠããµãããªãŒãžã®ãã€ã³ã¿ãŒã¯ãã¹ãŠã®æå³ã倱ããŸãã ã¿ã€ããªã¹ãïŒstd ::ãªã¹ãïŒã®ã³ã³ãããŒã䜿çšããŸãããã®åèŠçŽ ã¯ãããããã決ãããããµã€ãºïŒå®æ°ïŒã®ãã¯ã¿ãŒïŒstd ::ãã¯ã¿ãŒïŒã§ãã ïŒOpen MPã䜿çšããŠïŒãã«ãã¹ã¬ããã§ããªãŒãæ§ç¯ããŸããã€ãŸããåãµãããªãŒãåå¥ã®ã¹ã¬ããïŒé«éåã®ããã«x4ïŒã§æ§ç¯ããŸãã ã³ããŒã»ãã³ãã£ã¯ã¹ïŒC ++ 11ïŒïŒ+ 10ïŒ é床ïŒã®äœ¿çšã¯ãã€ã³ããã¯ã¹ããªãŒãããŒãã«ã³ããŒããã®ã«çæ³çã§ãã
KDããªãŒå ã®ãã€ã³ããžã®ãé£äººããèŠã€ãã
ãããã£ãŠãããªãŒãæ§ç¯ãããŸãããKD-Treeã§ã®æ€çŽ¢æäœã®å®è£ ã®èª¬æã«ç§»ããŸãããã
äžè§åœ¢ã®ã»ããã§æ€çŽ¢ãå®è¡ãããšããŸããç¹ãäžããããããã«æãè¿ãäžè§åœ¢ãèŠã€ããå¿ èŠããããŸãã
ãã«ãŒããã©ãŒã¹ã䜿çšããŠåé¡ã解決ããã®ã¯äžå©ã§ããNåã®ãã€ã³ããšMåã®äžè§åœ¢ã®ã»ããã®å Žåã挞è¿çãªåäœã¯OïŒN * MïŒã§ãã ããã«ãã¢ã«ãŽãªãºã ããã€ã³ãããäžè§åœ¢ãŸã§ã®è·é¢ããæ£çŽã«ãèšç®ãããããè¿ éã«è¡ãããã«ããããšæããŸãã
KDããªãŒã䜿çšããŠã次ã®ããšãè¡ããŸãã
⊠æé 1 ã ãã®ãã€ã³ãã«æãè¿ããªãŒãããŒããèŠã€ããŸãïŒåããŒãã§ã¯ããåç¥ã®ããã«ãå¢çããã¯ã¹ãæ ŒçŽããŸããããŒãã®å¢çããã¯ã¹ã®äžå¿ãŸã§ã®è·é¢ïŒïŒpointMax + pointMinïŒ* 0.5ïŒãå®å šã«èšç®ã§ããŸãïŒã
⊠ã¹ããã2 ã èŠã€ãã£ãããŒãïŒnearestNodeïŒã®ãã¹ãŠã®èŠçŽ ãåæããããšã«ããã çµæã®è·é¢ã¯minDistã§ç€ºãããŸãã
⊠ã¹ããã3 ã éå§ç¹ãäžå¿ãšããååŸãšé·ãminDistã®ååŸãäœæããŸãã ãã®çäœãå®å šã«å åŽã«ããïŒã€ãŸããããŠã³ãã£ã³ã°ããã¯ã¹ããŒãã®åŽé¢ã®äº€ç¹ããªãïŒãã©ããã確èªããŸãã ååšããå Žåã¯ãæãè¿ãèŠçŽ ãèŠã€ãããããã§ãªãå Žåã¯ãæé 4ã«é²ã¿ãŸãã
⊠æé 4 ã ããªãŒã®ã«ãŒãããå®è¡ããååŸå ã®æãè¿ãèŠçŽ ãæ€çŽ¢ããŸãïŒããªãŒãäžã£ãŠãå³ãŸãã¯å·Šã®ããŒãã亀差ãããã©ããã確èªããŸãïŒããã«ãããŒãã¯çå ãŸãã¯ããŒãå ã®çå ã«å®å šã«åãŸãããšãã§ããŸã...ïŒã ããŒãã亀差ããŠããå ŽåãåãããŒãã®å éšããŒãã«å¯ŸããŠåæ§ã®ãã§ãã¯ãå®è¡ãããŸãã ãªãŒãããŒãã«å°éããå Žåããã®ããŒãå ã®ãã€ããŒã培åºçã«æ€çŽ¢ããçµæãçã®ååŸã®é·ããšæ¯èŒããŸãã çã®ååŸãèŠã€ãã£ãè·é¢ããã倧ããå Žåãèšç®ãããæå°å€ã§çã®ååŸã®é·ããæŽæ°ããŸãã çäœã®æŽæ°ãããååŸã䜿çšããŠããªãŒã§ããã«äžéããŸãïŒååž°ã¢ã«ãŽãªãºã ã䜿çšããå ŽåãååŸã¯åç §ã«ãã£ãŠé¢æ°ã«æž¡ãããå¿ èŠã«å¿ããŠæŽæ°ãããŸãïŒã
次ã®å³ã¯ãäžèšã®ã¢ã«ãŽãªãºã ã®æ¬è³ªãç解ããã®ã«åœ¹ç«ã¡ãŸãã
å³ã«ãããš ïŒãã®ç¹ã«æãè¿ãèããŒãïŒââå³ã®éïŒãèŠã€ããïŒèµ€ã§åŒ·èª¿è¡šç€ºãããŠããïŒãšä»®å®ãããšãããŒãå ã®è¿åãæ€çŽ¢ãããšãããã¯ã€ã³ããã¯ã¹1ã®äžè§åœ¢ã§ããããšãããããŸãããããã¯ããã§ã¯ãããŸããã ååŸRã®åã¯é£æ¥ããããŒããšäº€å·®ããããããã®ããŒãã§æ€çŽ¢ããæ°ããèŠã€ãã£ãæå°å€ãšæ¢åã®æå°å€ãæ¯èŒããå¿ èŠããããŸãã ãã®çµæãã€ã³ããã¯ã¹2ã®äžè§åœ¢ãé£æ¥ããŠããããšãæããã«ãªããŸãã
ããã§ããè¿ãã®ãæ€çŽ¢ã¢ã«ãŽãªãºã ã§äœ¿çšãããäžéæäœã®å¹æçãªå®è£ ã«ã€ããŠã話ããããšæããŸãã
ããŒãå ã®è¿é£ãæ€çŽ¢ããå Žåããã€ã³ãããäžè§åœ¢ãŸã§ã®è·é¢ããã°ããèšç®ã§ããå¿ èŠããããŸãã æãç°¡åãªã¢ã«ãŽãªãºã ã«ã€ããŠèª¬æããŸãã
äžè§åœ¢ã®å¹³é¢äžã®ç¹AïŒæãè¿ããæ¢ããŠããç¹ïŒã®æ圱ãèŠã€ããŸãã èŠã€ãã£ãç¹ãPã§ç€ºããŸããPãäžè§åœ¢ã®å åŽã«ããå ŽåãAããäžè§åœ¢ãŸã§ã®è·é¢ã¯ã»ã°ã¡ã³ãAPã®é·ããšçãããªããŸããããã§ãªãå Žåã¯ãAããäžè§åœ¢ã®å蟺ïŒã»ã°ã¡ã³ãïŒãŸã§ã®è·é¢ãæ±ããŸããæå°å€ãéžæããŸãã åé¡ã¯è§£æ±ºããŸããã
説æãããŠããã¢ã«ãŽãªãºã ã¯ãæãå¹ççã§ã¯ãããŸããã ããå¹æçãªã¢ãããŒãã¯ãç¹å®ã®ãã€ã³ãããäžè§åœ¢ã®ä»»æã®ãã€ã³ããŸã§ã®ãã¹ãŠã®å¯èœãªè·é¢ãå€ãšããé¢æ°ã®æ€çŽ¢ãšåæïŒåŸé ã®æå°å€ã®æ€åºãªã©ïŒã«äŸåããŸãã ãã®æ¹æ³ã¯èªèãããè€éã§ãããç§ã®æèŠã§ã¯ãå¥ã®èšäºã«å€ããŸãïŒãããŸã§ã®ãšãããç§ã®ã³ãŒãã«å®è£ ãããŠããŸãã以äžã®ã³ãŒããžã®ãªã³ã¯ããããŸãïŒã [1]ã«ããæ¹æ³ã«æ £ããããšãã§ããŸãã ãã¹ãçµæã«ãããšããã®æ¹æ³ã¯å ã»ã©èª¬æããæ¹æ³ããã10åé«éã§ããã
çããå¢çããã¯ã¹ã§è¡šãããç¹å®ã®ããŒãå ã®ç¹OãšååŸRã®äžå¿ã«ãããã©ãããå€æããã®ã¯ç°¡åã§ãïŒ3DïŒïŒ
inline bool isSphereInBBox(const SBBox& bBox, const D3& point, const double& radius) { return (bBox.m_minBB[0] < point[0] - radius && bBox.m_maxBB[0] > point[0] + radius && bBox.m_minBB[1] < point[1] - radius && bBox.m_maxBB[1] > point[1] + radius && bBox.m_minBB[2] < point[2] - radius && bBox.m_maxBB[2] > point[2] + radius); }
çäœãšããŒãã®ããŠã³ãã£ã³ã°ããã¯ã¹ã®äº€ç¹ãçäœå ã®ããŒãã®äœçœ®ããŸãã¯ããŒãå ã®çäœã決å®ããã¢ã«ãŽãªãºã ã§ã¯ãç¶æ³ã¯å€å°ç°ãªããŸãã ç¹°ãè¿ããŸãããç§ã¯èª¬æãïŒåçã¯[2]ããåãããŸããïŒããã®æé ãå®è¡ã§ããæ£ããã³ãŒããæäŸããŸãïŒ2Dã3Dã«é¡äŒŒïŒã
bool intersects(CircleType circle, RectType rect) { circleDistance.x = abs(circle.x - rect.x); circleDistance.y = abs(circle.y - rect.y); if (circleDistance.x > (rect.width/2 + circle.r)) { return false; } if (circleDistance.y > (rect.height/2 + circle.r)) { return false; } if (circleDistance.x <= (rect.width/2)) { return true; } if (circleDistance.y <= (rect.height/2)) { return true; } cornerDistance_sq = (circleDistance.x - rect.width/2)^2 + (circleDistance.y - rect.height/2)^2; return (cornerDistance_sq <= (circle.r^2)); }
æåã®ïŒæåã®è¡ã®ãã¢ïŒ4ã€ã®è±¡éã®èšç®ã1ã€ã«æžãããŸãã 次ã®è¡ã®ãã¢ã§ã¯ãåãç·ã®é åã«ãããã©ããã確èªããŸãã ååšããå Žåã亀差ç¹ã¯ãããŸããã 次ã®æ°è¡ã¯ãåããã¿ãŒã³ã®ãªã¬ã³ãžãŸãã¯ã°ã¬ãŒã®é åã«ãããã©ããã確èªããŸãã é²å ¥ãããšã亀差ç¹ãæ€åºãããŸãã
次ã«ãåãé·æ¹åœ¢ã®è§ãšäº€å·®ãããã©ããã確èªããå¿ èŠããããŸãïŒæ¬¡ã®ã³ãŒãè¡ããããè¡ããŸãïŒã
å®éããã®èšç®ã¯ãäžå¿ãèµ€ã®é åå ã«ãããã¹ãŠã®åã«å¯ŸããŠãfalseããè¿ããäžå¿ãçœã®é åå ã«ãããã¹ãŠã®åã«å¯ŸããŠãtrueããè¿ããŸãã
äžè¬ã«ããã®ã³ãŒãã¯å¿ èŠãªãã®ãæäŸããŸãïŒããã§ã¯2Dã®ã³ãŒãã®å®è£ ã瀺ããŸããããKD-Treeã³ãŒãã§ã¯3DããŒãžã§ã³ã䜿çšããŠããŸãïŒã
æ€çŽ¢ã¢ã«ãŽãªãºã ã®é床ã«ã€ããŠã ãã§ãªããKD-Treeã§ã®æ€çŽ¢é床ãäœäžããé倧ãªç¶æ³ã«ã€ããŠã説æããŸãã
åè¿°ã®ããã«ã ããã¡ã³ãã®ç¶æ³ã§ã¯ããŒãå ã«å€æ°ã®èŠçŽ ãçæãããèŠçŽ ãå€ãã»ã©æ€çŽ¢ãé ããªããŸãã ããã«ããã¹ãŠã®èŠçŽ ãç¹å®ã®ç¹ããçè·é¢ã«ããå Žåãæ€çŽ¢ã¯OïŒNïŒ ïŒçã®è¡šé¢ã«ããç¹ã®ã»ãããããã³çã®äžå¿ã«æãè¿ããã®ãæ¢ããŸãïŒã§å®è¡ãããŸãã ãã ãããããã®ç¶æ³ã解æ¶ãããå Žåãå¹³åçãªæ€çŽ¢ã¯ãããã€ãã®ããŒãã®èŠçŽ ã®åæãæã€ããªãŒå šäœã®äžéã«çžåœããŸãã Oãè¶ ããïŒlogïŒNïŒïŒ ã æ€çŽ¢ã®é床ã¯ã蚪åããããªãŒã®ãªãŒãããŒãã®æ°ã«äŸåããããšã¯æããã§ãã
次ã®2ã€ã®å³ãæ€èšããŠãã ããã
ãããã®å³ã®æ¬è³ªã¯ãæãè¿ãèŠçŽ ãæ¢ããŠãããã€ã³ããã»ããã®å ã®å¢çããã¯ã¹ããéåžžã«é ãã«ããå ŽåãååŸminDistïŒæãè¿ããã®ãŸã§ã®è·é¢ïŒã®ååŸã®ååŸãæã€çã¯ãåãçäœãæ€èšããŸããããäžå¿ãã»ããã®å ã®å¢çããã¯ã¹ã«éåžžã«è¿ãç¹ã«ãããŸãïŒåœç¶ãminDistã¯å€ãããŸãïŒã äžè¬ã«ãéåžžã«é ããã€ã³ããžã®è¿åã®æ€çŽ¢ã¯ãå ã®ã»ããã®è¿ãã«ãããã€ã³ãã®æ€çŽ¢ãããé ããªããŸãã ç§ã®ãã¹ãã§ã¯ããã®æ å ±ã確èªããŸããã
çµæãšãŸãšã
ãã®çµæãKD-Treeã®å®è£ ã«ã€ããŠããã€ãã®èšèãè¿œå ããŠãçµæã瀺ããããšæããŸãã å®éãå ã®ã»ããã®ä»»æã®ãªããžã§ã¯ãïŒäžè§åœ¢ãçäœãç¹ãªã©ïŒã«ç°¡åã«é©å¿ã§ããããã«ãã³ãŒãèšèšãéçºãããŸããã å¿ èŠãªããšã¯ããªãŒããŒã©ã€ããããä»®æ³é¢æ°ã䜿çšããŠç¶æ¿ã¯ã©ã¹ãäœæããããšã ãã§ãã ããã«ãç§ã®å®è£ ã§ã¯ãç¹å¥ãªãŠãŒã¶ãŒå®çŸ©ã®Splitterã¯ã©ã¹ãæž¡ãããšãã§ããŸãã ãã®ã¯ã©ã¹ããŸãã¯ãã®ä»®æ³åå²ã¡ãœããã¯ãåæé¢ã®æ£ç¢ºãªäœçœ®ã決å®ããŸãã ç§ã®å®è£ ã§ã¯ãSAHã«åºã¥ããŠæ±ºå®ãäžãã¯ã©ã¹ãæäŸããŸãã ããã§ãSAHã«åºã¥ããŠKDããªãŒã®æ§ç¯ãå éããããšã«çŠç¹ãåœãŠãå€ãã®èšäºã§ã¯ãããªãŒã®æ·±ãã®åæå€ïŒäžè¬ã«ãããªãŒããŒãã®èŠçŽ ã®æ°ã倧ããå ŽåïŒã®å€ãã®èè ã¯ãåæé¢ïŒäžå¿ãŸãã¯äžå€®å€ã«ããåå²ãªã©ïŒ ïŒãããã³SAHãã¥ãŒãªã¹ãã£ãã¯ã¯ãããŒãå ã®èŠçŽ ã®æ°ãå°ãªããšãã«ã®ã¿é©çšãããŸãã
ç§ã®å®è£ ã«ã¯ãã®ãããªããªãã¯ã¯å«ãŸããŠããŸãããããããããã°ããè¿œå ã§ããŸãïŒæ°ãããã©ã¡ãŒã¿ãŒã§KD-Treeã³ã³ã¹ãã©ã¯ã¿ãŒãå±éããå¿ èŠãªå¶éãå¶åŸ¡ããŠãç®çã®ã¹ããªãã¿ãŒã§æ§ç¯ã¡ã³ããŒé¢æ°ãåŒã³åºãã ãã§ãïŒã ããªãŒå ã®æ€çŽ¢ã¯ãã«ãã¹ã¬ããã§ãã ãã¹ãŠã®èšç®ã¯å粟床ã®æ°å€ã§å®è¡ãããŸãã ããªãŒã®æ倧ã®æ·±ãã¯å®æ°ã§èšå®ãããŸãïŒããã©ã«ãã¯32ïŒã ããã€ãã®#definesãå®çŸ©ãããŠãããããšãã°ååž°ãªãã§æ€çŽ¢ãããšãã«ããªãŒããã©ããŒã¹ã§ããŸãïŒååž°ã䜿çšãããšãçµäºããæ¹ãé«éã§ããããã¹ãŠã®ããŒãã¯ç¹å®ã®ãã¯ãã«ã®èŠçŽ ã§ãïŒã€ãŸããã¡ã¢ãªå ã«è¿ãã«ãããŸãïŒã ã³ãŒããšäžç·ã«ããã¹ãããŒã¿ã»ãããæäŸããŸãïŒå éšã«ç°ãªãæ°ã®äžè§åœ¢ïŒ2ãã3,000,000ïŒãæã€ãä¿®æ£OFF圢åŒãã®3Dã¢ãã«ïŒã ãŠãŒã¶ãŒã¯ãæ§ç¯ãããããªãŒïŒDXF圢åŒïŒã®ãã³ããã¹ããŒãã察å¿ããã°ã©ãã£ãã¯ããã°ã©ã ã§è¡šç€ºã§ããŸãã ããã°ã©ã ã¯ãŸããããªãŒæ§ç¯ã®å質ããã°ã«èšé²ããŸãïŒãªã³/ãªãã§ããŸãïŒãããªãŒã®æ·±ãããªãŒãããŒãã®èŠçŽ ã®æ倧æ°ããªãŒãããŒãã®èŠçŽ ã®å¹³åæ°ãããã³æäœæéããªã»ãããããŸãã çµæã®å®è£ ãçæ³çã§ãããšäž»åŒµããããšã¯ãããŸããããããã§ããç§ã¯èŠèœãšããå Žæãç¥ã£ãŠããŸãïŒããšãã°ããã³ãã¬ãŒããã©ã¡ãŒã¿ã«ã¢ãã±ãŒã¿ãæž¡ããªããCã³ãŒããé »ç¹ã«ååšããïŒã¹ããªãŒã ã䜿çšããŠãã¡ã€ã«ãèªã¿æžãããªãïŒ ãæªæ€åºã®ãã°ãªã©ãèããããŸããä¿®æ£ãããšããæ¥ãŸããïŒã ãããŠãã¡ãããããªãŒã¯3D空éã§ã®äœæ¥çšã«å³å¯ã«äœæããã³æé©åãããŸãã
次ã®ç¹æ§ãæã€ã©ãããããã§ã³ãŒãããã¹ãããŸããïŒ Intel Core I7-4750HQã4ã³ã¢ïŒ8ã¹ã¬ããïŒ2 GHzãRAM-8gbãWindows 10äžã®Win x64ã¢ã㪠ã SAH Iãèšç®ããããã®ä¿æ°ã¯ã cT = 1.ãcI = 1.5ã§ããã ãããŠãçµæã«ã€ããŠè©±ããšã1ã5çŸäžã§ããããšãããããŸããã ããªãŒã1.5ç§æªæºã§æ§ç¯ãããäžè§åœ¢ã 2.4ç§ã§300äž ã 150äžäººã ãã€ã³ããš150äžåã®äžè§åœ¢ïŒãã€ã³ãã¯å ã®ã¢ãã«ããããã»ã©é ããªãïŒãæ€çŽ¢ã¯0.23ç§ã§å®äºããã¢ãã«ãããã€ã³ããåé€ããããšãæéã¯æ倧3ç§ã«ãªããŸãã 300äžãã€ã³ãïŒåã³ãã¢ãã«ã®è¿ãã«ãããŸãïŒãš300äžã®äžè§åœ¢ã®å Žåãæ€çŽ¢ã«ã¯çŽ0.7ç§ããããŸãã æ··ä¹±ããªãããšãé¡ã£ãŠããŸãã æåŸã«ãæ§ç¯ãããKDããªãŒã®èŠèŠåã®å³ïŒ
䟿å©ãªãªã³ã¯
[0] ïŒ GitHubã§ã®KDããªãŒã®å®è£
[1] ïŒ ç¹ããäžè§åœ¢ãŸã§ã®è·é¢ãæ€çŽ¢ããŸã
[2] ïŒ åãšé·æ¹åœ¢ã®äº€ç¹ã®å®çŸ©
[3] ïŒ ãŠã£ãããã£ã¢äžã®KD-Treeã®èª¬æ
[4] ïŒ SAHã«é¢ããèå³æ·±ãèšäº
[5] ïŒ ray-tracing.ruã§ã®KDããªãŒã®èª¬æ