|
Lagrange
|
Axis-Aligned Bounding Box (AABB) tree for efficient spatial queries. More...
#include <lagrange/bvh/AABB.h>
Public Types | |
| using | Index = uint32_t |
| using | Box = Eigen::AlignedBox<Scalar, Dim> |
| using | Point = typename Box::VectorType |
Public Member Functions | |
| void | build (span< Box > boxes) |
| Build the AABB tree from a collection of bounding boxes. | |
| void | intersect (const Box &query_box, std::vector< Index > &results) const |
| Find all boxes that intersect with a query box. | |
| void | intersect (const Box &query_box, function_ref< bool(Index)> callback) const |
| Find all boxes that intersect with a query box and call a function for each. | |
| Index | intersect_first (const Box &query_box) const |
| Find the first box that intersects with a query box. | |
| Index | get_closest_element (const Point &q, function_ref< Scalar(Index)> sq_dist_fn) const |
| Find the index of the closest element to a query point. | |
| void | foreach_element_within_radius (const Point &q, Scalar sq_radius, function_ref< void(Index)> func) const |
| Call a function for each element within a given radius from a query point. | |
| bool | empty () const |
| Check if the tree is empty. | |
Axis-Aligned Bounding Box (AABB) tree for efficient spatial queries.
This data structure organizes a collection of bounding boxes in a binary tree to enable fast intersection queries. The tree is built using a top-down approach by recursively splitting boxes along the longest Dimension of their centroids.
| Scalar | Numeric type for coordinates (e.g., float or double). |
| Dim | Spatial Dimension (2 or 3). |
Build the AABB tree from a collection of bounding boxes.
| [in] | boxes | Input bounding boxes to organize in the tree. |
| void intersect | ( | const Box & | query_box, |
| std::vector< Index > & | results ) const |
Find all boxes that intersect with a query box.
| [in] | query_box | The query bounding box. |
| [out] | results | Indices of boxes that intersect with the query box. |
| void intersect | ( | const Box & | query_box, |
| function_ref< bool(Index)> | callback ) const |
Find all boxes that intersect with a query box and call a function for each.
| [in] | query_box | The query bounding box. |
| [in] | callback | Function to call for each intersecting box index. The callback function takes an element ID as input and returns a bool indicating whether to continue the search (true) or terminate early (false). |
| AABB< Scalar, Dim >::Index intersect_first | ( | const Box & | query_box | ) | const |
Find the first box that intersects with a query box.
| [in] | query_box | The query bounding box. |
| AABB< Scalar, Dim >::Index get_closest_element | ( | const Point & | q, |
| function_ref< Scalar(Index)> | sq_dist_fn ) const |
Find the index of the closest element to a query point.
| [in] | q | The query point. |
| [in] | sq_dist_fn | Squared distance function for point-element distance. |
| void foreach_element_within_radius | ( | const Point & | q, |
| Scalar | sq_radius, | ||
| function_ref< void(Index)> | func ) const |
Call a function for each element within a given radius from a query point.
| [in] | q | The query point. |
| [in] | sq_radius | The search radius squared. |
| [in] | func | Function to call for each element whose bounding box is within the radius. |
|
inline |
Check if the tree is empty.