Skip to main content

AABB Tree Construction and Acceleration of Nearest Neighbor Queries

The MR::AABBTree class (as well as the specialized AABBTreePoints for vertex sets) is utilized to organize spatial indexing. During construction, the algorithm partitions all triangles (or points) into an axis-aligned bounding box tree, where each node contains bounding box information for several triangles. For point-to-mesh projections or nearest point queries, the AABB tree allows for a rapid exclusion of the vast majority of unrelated triangles, enabling precise distance calculations on only the candidate nodes' triangles. This reduces the query complexity from linear to approximately logarithmic levels. In other words, when invoking projection functions (such as MR::projectPoint or MR::onSurfaceClosestPoint), the underlying system first constructs or utilizes an existing MR::AABBTree, subsequently calling its search interface to expedite nearest neighbor computations. This significantly enhances the efficiency of point-to-face or point-to-point lookups (related source implementations can be found in MRMeshIntersect.h, MRMeshDistance.h, and other files).