Lagrange
Loading...
Searching...
No Matches
AABB< Scalar, Dim > Class Template Reference

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.
 

Detailed Description

template<typename Scalar, int Dim>
class lagrange::bvh::AABB< Scalar, Dim >

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.

Template Parameters
ScalarNumeric type for coordinates (e.g., float or double).
DimSpatial Dimension (2 or 3).

Member Function Documentation

◆ build()

template<typename Scalar, int Dim>
void build ( span< Box > boxes)

Build the AABB tree from a collection of bounding boxes.

Parameters
[in]boxesInput bounding boxes to organize in the tree.

◆ intersect() [1/2]

template<typename Scalar, int Dim>
void intersect ( const Box & query_box,
std::vector< Index > & results ) const

Find all boxes that intersect with a query box.

Parameters
[in]query_boxThe query bounding box.
[out]resultsIndices of boxes that intersect with the query box.

◆ intersect() [2/2]

template<typename Scalar, int Dim>
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.

Parameters
[in]query_boxThe query bounding box.
[in]callbackFunction 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).

◆ intersect_first()

template<typename Scalar, int Dim>
AABB< Scalar, Dim >::Index intersect_first ( const Box & query_box) const

Find the first box that intersects with a query box.

Parameters
[in]query_boxThe query bounding box.
Returns
Element ID of the first intersecting box, or invalid<Index>() if none found.

◆ get_closest_element()

template<typename Scalar, int Dim>
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.

Parameters
[in]qThe query point.
[in]sq_dist_fnSquared distance function for point-element distance.
Returns
Index of the closest element, or invalid<Index>() if tree is empty.

◆ foreach_element_within_radius()

template<typename Scalar, int Dim>
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.

Parameters
[in]qThe query point.
[in]sq_radiusThe search radius squared.
[in]funcFunction to call for each element whose bounding box is within the radius.
Remarks
This method checks bounding boxes, not exact geometry.

◆ empty()

template<typename Scalar, int Dim>
bool empty ( ) const
inline

Check if the tree is empty.

Returns
True if the tree is empty, false otherwise.

The documentation for this class was generated from the following files: