GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
StaticAABBTree Class Reference

#include <StaticAABBTree.hpp>

Public Member Functions

 StaticAABBTree ()
 instanciates a new empty StaticAABBTree object. More...
 
 StaticAABBTree (const std::vector< AABB > &leavesAABBs)
 instanciates a new StaticAABBTree with given AABBs. More...
 
 ~StaticAABBTree ()
 Default destructor. More...
 
void build (const std::vector< AABB > &leavesAABBs)
 Builds the AABB tree from a list of AABBs. More...
 
const unsigned int node_number () const
 
const AABBNode node_at_index (unsigned int nodeIndex) const
 
const unsigned int aabb_number () const
 
const AABB aabb_at_index (unsigned int aabbIndex) const
 
const bool is_node_leaf (unsigned int nodeIndex) const
 
void xraycast_aabb_tree (Ray aRay, unsigned int aNode=0) const
 Raycasts the AABB tree using an x-oriented axis. More...
 
void raycast_aabb_tree (Ray aRay, unsigned int aNode=0) const
 Raycasts the AABB tree using an arbitrarily oriented axis. More...
 
void closest_point (const double *aPoint, double &distance, unsigned int aNode=0) const
 Finds the closest point to the query. More...
 
void furthest_vertex_along_axis (const double *aPoint, const double *anAxis, double &distance, unsigned int aNode=0) const
 Finds the furthest vertex in a given direction. More...
 
void set_closest_point_callback (std::function< void(unsigned int, const double *, double &)> callback) const
 Allows to define the callback method that will be used to check if a primitive contains a vertex closer to aPoint, resulting in a distance smaller than distance. More...
 
void set_raycast_aabb_tree_callback (std::function< bool(unsigned int, Ray)> callback) const
 Allows to define the callback method that will be used to check if a primitive is intersected by a ray. More...
 
void set_furthest_vertex_callback (std::function< void(unsigned int, const double *, const double *, double &)> callback) const
 Allows to define the callback that will be used to check if a primitive contains a vertex further to aPoint, resulting in a distance greater than distance. More...
 

Static Public Member Functions

static AABB new_lonely_aabb (double minPoint[3], double maxPoint[3], unsigned int primtiveIndex=-1)
 Creates a new 'lonely' AABB with given extreme points. More...
 

Private Member Functions

unsigned int build (std::vector< unsigned int > aabbsIndices, unsigned int depth=0)
 Builds the AABB tree from a list of AABBs indices, for a given depth in the tree. More...
 
void clear ()
 Clears the AABB tree data structure. More...
 
unsigned int new_aabb_node ()
 Creates a new AABBNode. More...
 
unsigned int new_aabb_node (AABB anAABB)
 Creates a new AABBNode associated to a new AABB. More...
 
unsigned int new_aabb (double minPoint[3], double maxPoint[3], unsigned int primitiveIndex=-1)
 Creates a new AABB with given extreme points and, optionally, the primitive index. More...
 
unsigned int new_aabb (AABB anAABB)
 Creates a new AABB using the provided AABB. More...
 
unsigned int new_aabb_from_aabb (const std::vector< unsigned int > &aabbs)
 Creates a new AABB that encloses all the AABBs contained in aabbs. More...
 
bool is_point_inside_aabb (const double *aPoint, unsigned int anAABB) const
 Checks whether a point is inside an AABB. More...
 
double squared_distance_to_aabb_centre (const double *aPoint, unsigned int anAABB) const
 Computes the squared distance between a point and the AABB centre. More...
 
double squared_distance_to_aabb (const double *aPoint, unsigned int anAABB) const
 Computes the quared distance between a point and the AABB. More...
 
double inner_squared_distance_to_aabb (const double *aPoint, unsigned int anAABB) const
 Computes the inner squared distance between a point and the AABB. More...
 
void furthest_vertex_on_aabb_along_axis (const double *anAxis, unsigned int anAABB, double(&furthestPoint)[3]) const
 Finds the furthest point on an AABB along a given axis. More...
 
bool is_aabb_hit_by_xray (unsigned int anAABB, Ray aRay) const
 Checks wether an AABB is hit by an x-oriented ray. More...
 
bool is_aabb_hit_by_ray (unsigned int anAABB, Ray aRay) const
 Checks wether an AABB is hit by an arbitrarily oriented ray. More...
 
bool AABBFacetIsHitByRay (unsigned int anAABB, double facetNormal[3], Ray aRay) const
 Checks wether a facet of an AABB is hit by an arbitrarily oriented ray. More...
 

Private Attributes

unsigned int _aabbsCount
 The current number of AABBs in the tree. More...
 
unsigned int _node_count
 The current number of AABB nodes in the tree. More...
 
std::vector< AABB_aabbs
 The AABBs container. More...
 
std::vector< AABBNode_nodes
 The AABB nodes container. More...
 
std::function< void(unsigned int primitiveIndex, const double *aPoint, double &distance)> closestPointCallback_
 The callback used to check if a primitive with index primitiveIndex contains a vertex closer to aPoint, resulting in a distance smaller than distance. More...
 
std::function< bool(unsigned int primitiveIndex, Ray aRay)> raycastAABBTreeCallback_
 The callback used to check if a primitive with index primitiveIndex is hit by the ray aRay. More...
 
std::function< void(unsigned int primitiveIndex, const double *aPoint, const double *anAxis, double &distance)> furthestVertexCallback_
 The callback used to check if a vertex of a primitive with index primitiveIndex is further than the one previously found. More...
 

Static Private Attributes

static const unsigned int NotInList = (unsigned int)(-1)
 A flag to determine if an index is in a list. More...
 

Constructor & Destructor Documentation

◆ StaticAABBTree() [1/2]

StaticAABBTree::StaticAABBTree ( )

instanciates a new empty StaticAABBTree object.

◆ StaticAABBTree() [2/2]

StaticAABBTree::StaticAABBTree ( const std::vector< AABB > &  leavesAABBs)

instanciates a new StaticAABBTree with given AABBs.

◆ ~StaticAABBTree()

StaticAABBTree::~StaticAABBTree ( )

Default destructor.

Member Function Documentation

◆ aabb_at_index()

const AABB StaticAABBTree::aabb_at_index ( unsigned int  aabbIndex) const
inline
Returns
The AABB stored at index nodeIndex.

◆ aabb_number()

const unsigned int StaticAABBTree::aabb_number ( ) const
inline
Returns
The number of AABBs in the data structure.

◆ AABBFacetIsHitByRay()

bool StaticAABBTree::AABBFacetIsHitByRay ( unsigned int  anAABB,
double  facetNormal[3],
Ray  aRay 
) const
private

Checks wether a facet of an AABB is hit by an arbitrarily oriented ray.

Checks wether the facet with normal facetNormal of the AABB index anAABB is hit by the arbitrarily oriented ray aRay. This method is used during an arbitrarily oriented raycast.

◆ build() [1/2]

void StaticAABBTree::build ( const std::vector< AABB > &  leavesAABBs)

Builds the AABB tree from a list of AABBs.

This method builds an AABB tree from the list of AABBs passed as argument. It first clears the tree data structure through the clear() method, then calls the build(std::vector<unsigned int>) method to actually build the tree.

◆ build() [2/2]

unsigned int StaticAABBTree::build ( std::vector< unsigned int >  aabbsIndices,
unsigned int  depth = 0 
)
private

Builds the AABB tree from a list of AABBs indices, for a given depth in the tree.

This is the recursive method that actually builds the AABB tree.

Returns
The index of the newly created node.

◆ clear()

void StaticAABBTree::clear ( )
private

Clears the AABB tree data structure.

Clears the contents of vectors containing informations related to the tree data structure, i.e. _aabbsCount, _aabbs, _node_count and _nodes.

◆ closest_point()

void StaticAABBTree::closest_point ( const double *  aPoint,
double &  distance,
unsigned int  aNode = 0 
) const

Finds the closest point to the query.

Traverse the AABB tree recursively to find the AABBs as close as possible to the query defined by aPoint. Each time a candidate AABB is found, the callback method is called to check whether the point on its primitive can be closer.

◆ furthest_vertex_along_axis()

void StaticAABBTree::furthest_vertex_along_axis ( const double *  aPoint,
const double *  anAxis,
double &  distance,
unsigned int  aNode = 0 
) const

Finds the furthest vertex in a given direction.

Traverse the AABB tree recursively to find the AABBs as far as possible to the axis defined by anAxis. Each time a candidate AABB is found, the callback method is called to check whether the vertices on its primitive can be further.

◆ furthest_vertex_on_aabb_along_axis()

void StaticAABBTree::furthest_vertex_on_aabb_along_axis ( const double *  anAxis,
unsigned int  anAABB,
double(&)  furthestPoint[3] 
) const
private

Finds the furthest point on an AABB along a given axis.

Finds the furthest point on the AABB with index anAABB along axis anAxis and returns its coordinates through the furthestPoint double array.

◆ inner_squared_distance_to_aabb()

double StaticAABBTree::inner_squared_distance_to_aabb ( const double *  aPoint,
unsigned int  anAABB 
) const
private

Computes the inner squared distance between a point and the AABB.

Computes the inner squared distance between point aPoint and the AABB with index defined by anAABB, stored in the aabbs_ vector.

◆ is_aabb_hit_by_ray()

bool StaticAABBTree::is_aabb_hit_by_ray ( unsigned int  anAABB,
Ray  aRay 
) const
private

Checks wether an AABB is hit by an arbitrarily oriented ray.

Checks wether the AABB with index anAABB is hit by the arbitrarily oriented ray aRay. This method is used during an arbitrarily oriented raycast.

◆ is_aabb_hit_by_xray()

bool StaticAABBTree::is_aabb_hit_by_xray ( unsigned int  anAABB,
Ray  aRay 
) const
private

Checks wether an AABB is hit by an x-oriented ray.

Checks wether the AABB with index anAABB is hit by the x-oriented ray aRay. This method is used during an x-oriented raycast.

◆ is_node_leaf()

const bool StaticAABBTree::is_node_leaf ( unsigned int  nodeIndex) const
inline
Returns
true or false whether the node with index nodeIndex is a leaf node.

◆ is_point_inside_aabb()

bool StaticAABBTree::is_point_inside_aabb ( const double *  aPoint,
unsigned int  anAABB 
) const
private

Checks whether a point is inside an AABB.

Checks whether the point aPoint is inside an AABB with index defined by anAABB, stored in the aabbs_ vector.

◆ new_aabb() [1/2]

unsigned int StaticAABBTree::new_aabb ( AABB  anAABB)
private

Creates a new AABB using the provided AABB.

Creates a new AABB based on the extreme points of anAABB, and stores it into the _aabbs vector.

Returns
The index of the newly created AABB.

◆ new_aabb() [2/2]

unsigned int StaticAABBTree::new_aabb ( double  minPoint[3],
double  maxPoint[3],
unsigned int  primitiveIndex = -1 
)
private

Creates a new AABB with given extreme points and, optionally, the primitive index.

Creates a new AABB based on the extreme points minPoint and maxPoint and, optionally, the primitive index, primitiveIndex. This method invokes the static method new_lonely_aabb to create the AABB and compute its parameters. It is then added to the list of AABBs of the tree _aabbs.

Returns
The index of the newly created AABB.

◆ new_aabb_from_aabb()

unsigned int StaticAABBTree::new_aabb_from_aabb ( const std::vector< unsigned int > &  aabbs)
private

Creates a new AABB that encloses all the AABBs contained in aabbs.

Creates a new AABB based on the extreme points minPoint and maxPoint of all the AABBs contained in aabbs. It then adds the newly create AABB to the list of AABBs, _aabbs.

Returns
The index of the newly created AABB.

◆ new_aabb_node() [1/2]

unsigned int StaticAABBTree::new_aabb_node ( )
private

Creates a new AABBNode.

Creates a new empty AABBNode and add it to the list of AABB nodes, _nodes.

Returns
The index of the newly created node.

◆ new_aabb_node() [2/2]

unsigned int StaticAABBTree::new_aabb_node ( AABB  anAABB)
private

Creates a new AABBNode associated to a new AABB.

Creates a new AABBNode and set its AABB with a copy of anAABB, through a call to new_aabb() method.

Returns
The index of the newly created node.

◆ new_lonely_aabb()

AABB StaticAABBTree::new_lonely_aabb ( double  minPoint[3],
double  maxPoint[3],
unsigned int  primtiveIndex = -1 
)
static

Creates a new 'lonely' AABB with given extreme points.

Creates a new AABB based on the extreme points minPoint and maxPoint, and compute its parameters, such as its mid point, length in the three directions and volume. Optionally, a reference of the primitive it contains can be given with the primtiveIndex argument, which defaults to -1.

It is said 'lonely' since it is not added to the list of AABBs _aabbs.

Returns
The created AABB instance.

◆ node_at_index()

const AABBNode StaticAABBTree::node_at_index ( unsigned int  nodeIndex) const
inline
Returns
The AABB node stored at index nodeIndex.

◆ node_number()

const unsigned int StaticAABBTree::node_number ( ) const
inline
Returns
The number of nodes in the data structure.

◆ raycast_aabb_tree()

void StaticAABBTree::raycast_aabb_tree ( Ray  aRay,
unsigned int  aNode = 0 
) const

Raycasts the AABB tree using an arbitrarily oriented axis.

Performs a ray casting on the tree starting from node index aNode. Each time a leaf AABB is hit by the x-oriented ray aRay, the raycastAABBTreeCallback_ method, which must be defined using the set_raycast_aabb_tree_callback(), is invoked. It is thus the responsibility of the program that implements the raycastAABBTreeCallback_ method to count the hit primitives, store their indices, etc.

◆ set_closest_point_callback()

void StaticAABBTree::set_closest_point_callback ( std::function< void(unsigned int, const double *, double &)>  callback) const
inline

Allows to define the callback method that will be used to check if a primitive contains a vertex closer to aPoint, resulting in a distance smaller than distance.

This callback is used in the closest_point() recursive method, and is called whenever a candidate AABB is found.

◆ set_furthest_vertex_callback()

void StaticAABBTree::set_furthest_vertex_callback ( std::function< void(unsigned int, const double *, const double *, double &)>  callback) const
inline

Allows to define the callback that will be used to check if a primitive contains a vertex further to aPoint, resulting in a distance greater than distance.

This callback is used in the furthest_vertex_along_axis() recursive method, and is called whenever a candidate AABB is found.

◆ set_raycast_aabb_tree_callback()

void StaticAABBTree::set_raycast_aabb_tree_callback ( std::function< bool(unsigned int, Ray)>  callback) const
inline

Allows to define the callback method that will be used to check if a primitive is intersected by a ray.

This callback is used in the raycast_aabb_tree() and xraycast_aabb_tree() recursive methods, and is called whenever a candidate AABB is found.

◆ squared_distance_to_aabb()

double StaticAABBTree::squared_distance_to_aabb ( const double *  aPoint,
unsigned int  anAABB 
) const
private

Computes the quared distance between a point and the AABB.

Computes the squared distance between point aPoint and the AABB with index defined by anAABB, stored in the aabbs_ vector.

◆ squared_distance_to_aabb_centre()

double StaticAABBTree::squared_distance_to_aabb_centre ( const double *  aPoint,
unsigned int  anAABB 
) const
private

Computes the squared distance between a point and the AABB centre.

Computes the squared distance between point aPoint and the centre of AABB with index defined by anAABB, stored in the aabbs_ vector.

◆ xraycast_aabb_tree()

void StaticAABBTree::xraycast_aabb_tree ( Ray  aRay,
unsigned int  aNode = 0 
) const

Raycasts the AABB tree using an x-oriented axis.

Performs a ray casting on the tree starting from node index aNode. Each time a leaf AABB is hit by the x-oriented ray aRay, the raycastAABBTreeCallback_ method, which must be defined using the set_raycast_aabb_tree_callback, is invoked. It is thus the responsibility of the program that implements the raycastAABBTreeCallback_ method to count the hit primitives, store their indices, etc.

It is a more specific version of the raycast_aabb_tree() method, focusing only on x-oriented faces of AABBs to speed up computations. It is especially usefull to count the number of times a mesh is hit by a ray when performing containment checks.

Member Data Documentation

◆ _aabbs

std::vector<AABB> StaticAABBTree::_aabbs
private

The AABBs container.

◆ _aabbsCount

unsigned int StaticAABBTree::_aabbsCount
private

The current number of AABBs in the tree.

◆ _node_count

unsigned int StaticAABBTree::_node_count
private

The current number of AABB nodes in the tree.

◆ _nodes

std::vector<AABBNode> StaticAABBTree::_nodes
private

The AABB nodes container.

◆ closestPointCallback_

std::function<void(unsigned int primitiveIndex, const double *aPoint, double &distance)> StaticAABBTree::closestPointCallback_
mutableprivate

The callback used to check if a primitive with index primitiveIndex contains a vertex closer to aPoint, resulting in a distance smaller than distance.

This callback is used in the closest_point() recursive method, and is called each time a candidate AABB is found.

◆ furthestVertexCallback_

std::function<void(unsigned int primitiveIndex, const double *aPoint, const double *anAxis, double &distance)> StaticAABBTree::furthestVertexCallback_
mutableprivate

The callback used to check if a vertex of a primitive with index primitiveIndex is further than the one previously found.

This callback is used in the furthest_vertex_along_axis() recursive method, and is called each time a candidate AABB is found.

◆ NotInList

const unsigned int StaticAABBTree::NotInList = (unsigned int)(-1)
staticprivate

A flag to determine if an index is in a list.

◆ raycastAABBTreeCallback_

std::function<bool(unsigned int primitiveIndex, Ray aRay)> StaticAABBTree::raycastAABBTreeCallback_
mutableprivate

The callback used to check if a primitive with index primitiveIndex is hit by the ray aRay.

This callback is used in the xraycast_aabb_tree() and raycast_aabb_tree() recursive methods, and is called each time a candidate AABB is found.


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