PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
pbat::geometry::AabbRadixTreeHierarchy< Dims > Class Template Reference

Axis-aligned radix tree hierarchy of axis-aligned bounding boxes. More...

#include <AabbRadixTreeHierarchy.h>

Public Types

using IndexType = Index
 Type of the indices.
 
using SelfType = AabbRadixTreeHierarchy<kDims>
 Type of this template instantiation.
 

Public Member Functions

template<class TDerivedL, class TDerivedU>
 AabbRadixTreeHierarchy (Eigen::DenseBase< TDerivedL > const &L, Eigen::DenseBase< TDerivedU > const &U)
 Construct an AabbRadixTreeHierarchy from an input AABB matrix B.
 
template<class TDerivedL, class TDerivedU>
void Construct (Eigen::DenseBase< TDerivedL > const &L, Eigen::DenseBase< TDerivedU > const &U)
 Construct an AabbRadixTreeHierarchy from an input AABB matrix B.
 
template<class TDerivedL, class TDerivedU>
void Update (Eigen::DenseBase< TDerivedL > const &L, Eigen::DenseBase< TDerivedU > const &U)
 Recomputes k-D tree node AABBs given the object AABBs.
 
template<class FNodeOverlaps, class FObjectOverlaps, class FOnOverlap>
void Overlaps (FNodeOverlaps fNodeOverlaps, FObjectOverlaps fObjectOverlaps, FOnOverlap fOnOverlap) const
 Find all objects that overlap with some user-defined query.
 
template<class FDistanceToNode, class FDistanceToObject, class FOnNearestNeighbour>
void NearestNeighbours (FDistanceToNode fDistanceToNode, FDistanceToObject fDistanceToObject, FOnNearestNeighbour fOnNearestNeighbour, Scalar radius=std::numeric_limits< Scalar >::max(), Scalar eps=Scalar(0)) const
 Find the nearest neighbour to some user-defined query. If there are multiple nearest neighbours, we may return a certain number > 1 of them.
 
template<class FDistanceToNode, class FDistanceToObject, class FOnNearestNeighbour>
void KNearestNeighbours (FDistanceToNode fDistanceToNode, FDistanceToObject fDistanceToObject, FOnNearestNeighbour fOnNearestNeighbour, Index K, Scalar radius=std::numeric_limits< Scalar >::max()) const
 Find the K nearest neighbours to some user-defined query.
 
template<class FObjectsOverlap, class FOnSelfOverlap>
void SelfOverlaps (FObjectsOverlap fObjectsOverlap, FOnSelfOverlap fOnSelfOverlap) const
 Find all object pairs that overlap.
 
template<class FObjectsOverlap, class FOnOverlap>
void Overlaps (SelfType const &rhs, FObjectsOverlap fObjectsOverlap, FOnOverlap fOnOverlap) const
 Find all object pairs that overlap with another hierarchy.
 
auto InternalNodeBoundingBoxes () const
 Get the internal node bounding boxes.
 
auto Tree () const -> common::BinaryRadixTree< IndexType > const &
 Get the underlying tree hierarchy.
 

Static Public Attributes

static auto constexpr kDims = Dims
 Number of spatial dimensions.
 

Protected Member Functions

template<class TDerivedL, class TDerivedU>
void ComputeMortonCodes (Eigen::DenseBase< TDerivedL > const &L, Eigen::DenseBase< TDerivedU > const &U)
 Compute Morton codes for the AABBs.
 
void SortMortonCodes ()
 Sort the Morton codes.
 

Detailed Description

template<auto Dims>
class pbat::geometry::AabbRadixTreeHierarchy< Dims >

Axis-aligned radix tree hierarchy of axis-aligned bounding boxes.

This BVH does not store the AABBs themselves, only the tree topology and the AABBs of the tree nodes. The user is responsible for storing the objects and their AABBs. Doing so allows this BVH implementation to support arbitrary object types.

Note
This BVH implementation relies on a binary radix tree, thus tree topology should be rebuilt from scratch whenever updates are required. However, this aabb radix tree construction has average time complexity of \( O(n) \) and worst-case time complexity of \( O(n log n) \).
Template Parameters
DimsNumber of spatial dimensions

Constructor & Destructor Documentation

◆ AabbRadixTreeHierarchy()

template<auto Dims>
template<class TDerivedL, class TDerivedU>
pbat::geometry::AabbRadixTreeHierarchy< Dims >::AabbRadixTreeHierarchy ( Eigen::DenseBase< TDerivedL > const & L,
Eigen::DenseBase< TDerivedU > const & U )
inline

Construct an AabbRadixTreeHierarchy from an input AABB matrix B.

Template Parameters
TDerivedType of the input matrix
Parameters
LkDims x |# objects| matrix of object AABB lower bounds, such that for an object o, L.col(o).head<kDims>() is the lower bound.
UkDims x |# objects| matrix of object AABB upper bounds, such that for an object o, U.col(o).head<kDims>() is the upper bound.

Member Function Documentation

◆ ComputeMortonCodes()

template<auto Dims>
template<class TDerivedL, class TDerivedU>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::ComputeMortonCodes ( Eigen::DenseBase< TDerivedL > const & L,
Eigen::DenseBase< TDerivedU > const & U )
inlineprotected

Compute Morton codes for the AABBs.

Template Parameters
TDerivedBType of the input matrix
Parameters
LkDims x |# objects| matrix of object AABB lower bounds, such that for an object o, L.col(o).head<kDims>() is the lower bound.
UkDims x |# objects| matrix of object AABB upper bounds, such that for an object o, U.col(o).head<kDims>() is the upper bound.

◆ Construct()

template<auto Dims>
template<class TDerivedL, class TDerivedU>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::Construct ( Eigen::DenseBase< TDerivedL > const & L,
Eigen::DenseBase< TDerivedU > const & U )
inline

Construct an AabbRadixTreeHierarchy from an input AABB matrix B.

Construction has \( O(n log n) \) average time complexity due to morton code sorting.

Template Parameters
TDerivedType of the input matrix
Parameters
LkDims x |# objects| matrix of object AABB lower bounds, such that for an object o, L.col(o).head<kDims>() is the lower bound.
UkDims x |# objects| matrix of object AABB upper bounds, such that for an object o, U.col(o).head<kDims>() is the upper bound.

◆ InternalNodeBoundingBoxes()

template<auto Dims>
auto pbat::geometry::AabbRadixTreeHierarchy< Dims >::InternalNodeBoundingBoxes ( ) const
inline

Get the internal node bounding boxes.

Returns
2*kDims x |# internal nodes| matrix of AABBs, such that for an internal node node, IB.col(node).head<kDims>() is the lower bound and IB.col(node).tail<kDims>() is the upper bound.

◆ KNearestNeighbours()

template<auto Dims>
template<class FDistanceToNode, class FDistanceToObject, class FOnNearestNeighbour>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::KNearestNeighbours ( FDistanceToNode fDistanceToNode,
FDistanceToObject fDistanceToObject,
FOnNearestNeighbour fOnNearestNeighbour,
Index K,
Scalar radius = std::numeric_limits<Scalar>::max() ) const
inline

Find the K nearest neighbours to some user-defined query.

Template Parameters
FDistanceToNodeFunction with signature template <class TDerivedL, class TDerivedU> Scalar(TDerivedL const& L, TDerivedU const& U)
FDistanceToObjectFunction with signature Scalar(Index o)
FOnNearestNeighbourFunction with signature void(Index o, Scalar d, Index k)
Parameters
fDistanceToNodeFunction to compute the distance to a node
fDistanceToObjectFunction to compute the distance to an object
fOnNearestNeighbourFunction to process a nearest neighbour
KNumber of nearest neighbours to find
radiusMaximum distance to search for nearest neighbours

◆ NearestNeighbours()

template<auto Dims>
template<class FDistanceToNode, class FDistanceToObject, class FOnNearestNeighbour>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::NearestNeighbours ( FDistanceToNode fDistanceToNode,
FDistanceToObject fDistanceToObject,
FOnNearestNeighbour fOnNearestNeighbour,
Scalar radius = std::numeric_limits<Scalar>::max(),
Scalar eps = Scalar(0) ) const
inline

Find the nearest neighbour to some user-defined query. If there are multiple nearest neighbours, we may return a certain number > 1 of them.

Template Parameters
FDistanceToNodeFunction with signature template <class TDerivedL, class TDerivedU> Scalar(TDerivedL const& L, TDerivedU const& U)
FDistanceToObjectFunction with signature Scalar(Index o)
FOnNearestNeighbourFunction with signature void(Index o, Scalar d, Index k)
Parameters
fDistanceToNodeFunction to compute the distance to a node
fDistanceToObjectFunction to compute the distance to an object
fOnNearestNeighbourFunction to process a nearest neighbour
radiusMaximum distance to search for nearest neighbours
epsMaximum distance error

◆ Overlaps() [1/2]

template<auto Dims>
template<class FNodeOverlaps, class FObjectOverlaps, class FOnOverlap>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::Overlaps ( FNodeOverlaps fNodeOverlaps,
FObjectOverlaps fObjectOverlaps,
FOnOverlap fOnOverlap ) const
inline

Find all objects that overlap with some user-defined query.

Template Parameters
FNodeOverlapsFunction with signature template <class TDerivedL, class TDerivedU> bool(TDerivedL const& L, TDerivedU const& U)
FObjectOverlapsFunction with signature bool(Index o)
FOnOverlapFunction with signature void(Index n, Index o)
Parameters
fNodeOverlapsFunction to determine if a node overlaps with the query
fObjectOverlapsFunction to determine if an object overlaps with the query
fOnOverlapFunction to process an overlap

◆ Overlaps() [2/2]

template<auto Dims>
template<class FObjectsOverlap, class FOnOverlap>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::Overlaps ( SelfType const & rhs,
FObjectsOverlap fObjectsOverlap,
FOnOverlap fOnOverlap ) const
inline

Find all object pairs that overlap with another hierarchy.

Template Parameters
FObjectsOverlapCallable with signature bool(Index o1, Index o2)
FOnOverlapCallable with signature void(Index o1, Index o2, Index k)
Parameters
rhsOther hierarchy to compare against
fObjectsOverlapFunction to determine if 2 objects (o1,o2) overlap, where o1 is an object from this tree and o2 is an object from the rhs tree
fOnOverlapFunction to process an overlap (o1,o2) where o1 is an object from this tree and o2 is an object from the rhs tree

◆ SelfOverlaps()

template<auto Dims>
template<class FObjectsOverlap, class FOnSelfOverlap>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::SelfOverlaps ( FObjectsOverlap fObjectsOverlap,
FOnSelfOverlap fOnSelfOverlap ) const
inline

Find all object pairs that overlap.

Template Parameters
FObjectsOverlapFunction with signature bool(Index o1, Index o2)
FOnSelfOverlapFunction with signature void(Index o1, Index o2, Index k)
Parameters
fObjectsOverlapFunction to determine if 2 objects from this tree overlap
fOnSelfOverlapFunction to process an overlap

◆ Tree()

template<auto Dims>
auto pbat::geometry::AabbRadixTreeHierarchy< Dims >::Tree ( ) const -> common::BinaryRadixTree<IndexType> const&
inline

Get the underlying tree hierarchy.

Returns
Binary radix tree

◆ Update()

template<auto Dims>
template<class TDerivedL, class TDerivedU>
void pbat::geometry::AabbRadixTreeHierarchy< Dims >::Update ( Eigen::DenseBase< TDerivedL > const & L,
Eigen::DenseBase< TDerivedU > const & U )
inline

Recomputes k-D tree node AABBs given the object AABBs.

A sequential post-order traversal of the k-D tree is performed, i.e. bottom up nodal AABB computation, leading to \( O(n) \) time complexity.

Template Parameters
TDerivedBType of the input matrix
Parameters
LkDims x |# objects| matrix of object AABB lower bounds, such that for an object o, L.col(o).head<kDims>() is the lower bound.
UkDims x |# objects| matrix of object AABB upper bounds, such that for an object o, U.col(o).head<kDims>() is the upper bound.

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