AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
The BVHTree class provides functionality for generating a Bounding Volume Hierarchy (BVH) of axis-aligned bounding boxes, i.e., buckets that spatially partitions a set of objects. Each object is defined by its bounding box and user-supplied data-structure specified as a template argument. Once generated, the BVHTree can then be used as an acceleration structure to speed up the performance of point queries on the given objects, e.g., minimum distance, closest point, orientation, etc. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/v0.3.3/src/axom/spin/BVHTree.hpp>
Public Types | |
using | BoxType = primal::BoundingBox< double, NDIMS > |
using | PointType = primal::Point< double, NDIMS > |
Public Member Functions | |
BVHTree (int maxNumLevel=5) | |
Default constructor, creates an empty BVHTree instance. More... | |
BVHTree (int estNumObjects, int maxNumLevels) | |
Creates a BVHTree instance that can grow up to the specified number of levels and can hold approximately the given number of objects. More... | |
~BVHTree () | |
Destructor. More... | |
int | getMaxNumLevels () const |
Returns the maximum number of levels in the tree possible. More... | |
int | getNumLevels () const |
Returns the number of levels in the given BVHTree instance. More... | |
void | insert (const BoxType &box, const T &data) |
Inserts an object, identified by its bounding box and user-supplied data, to the bucket tree. More... | |
int | getNumberOfObjects () const |
Returns the total number of inserted objects in the tree. More... | |
void | build (int threshold=25) |
Builds a hierarchical decomposition of axis-aligned bounding boxes that partitions the set of objects in different buckets. More... | |
bool | empty () const |
Checks if the tree is empty. More... | |
void | clear () |
Deletes the tree and all associated objects. More... | |
void | writeVtkFile (const std::string &fileName, bool include_objects=false) const |
Writes the hierarchical decomposition in a VTK file. More... | |
void | writeVtkFile (const std::string &fileName, const int *bins, int nbins) const |
Writes the user-supplied set of bins in a VTK file. More... | |
Point Query API | |
bool | contains (const PointType &pt) const |
Checks if the point is inside the BVHTree. More... | |
void | find (const PointType &pt, std::vector< int > &candidate_buckets) const |
Finds a subset of candidate buckets for the given point query. More... | |
BVHTree Access methods | |
const BoxType & | getBucketBox (int bucketIdx) const |
Returns a const reference to the bounding box of the given bucket. More... | |
int | getBucketNumObjects (int bucketIdx) const |
Returns the number of object within the given bucket. More... | |
const int * | getBucketObjectArray (int bucketIdx) const |
Return const pointer to the object array of the given bucket. More... | |
const BoxType & | getObjectBox (int objIdx) const |
Returns a const reference to the bounding box of the given object. More... | |
const T & | getObjectData (int objIdx) const |
Returns const reference to the data associated with the given object. More... | |
int | getObjectBucketIndex (int objIdx) const |
Returns the bucket index of the given object. More... | |
The BVHTree class provides functionality for generating a Bounding Volume Hierarchy (BVH) of axis-aligned bounding boxes, i.e., buckets that spatially partitions a set of objects. Each object is defined by its bounding box and user-supplied data-structure specified as a template argument. Once generated, the BVHTree can then be used as an acceleration structure to speed up the performance of point queries on the given objects, e.g., minimum distance, closest point, orientation, etc.
T | the type of data inserted in a BVH bin |
NDIMS | the number of dimensions |
using axom::spin::BVHTree< T, NDIMS >::BoxType = primal::BoundingBox< double,NDIMS > |
using axom::spin::BVHTree< T, NDIMS >::PointType = primal::Point< double,NDIMS > |
axom::spin::BVHTree< T, NDIMS >::BVHTree | ( | int | maxNumLevel = 5 | ) |
Default constructor, creates an empty BVHTree instance.
[in] | maxNumLevel | maximum number of subdivision levels. Default is 5. |
axom::spin::BVHTree< T, NDIMS >::BVHTree | ( | int | estNumObjects, |
int | maxNumLevels | ||
) |
Creates a BVHTree instance that can grow up to the specified number of levels and can hold approximately the given number of objects.
[in] | estNumObjects | user-supplied estimated number of objects. |
[in] | maxNumLevels | the maximum number of levels. |
axom::spin::BVHTree< T, NDIMS >::~BVHTree | ( | ) |
Destructor.
References axom::spin::BVHTree< T, NDIMS >::clear().
|
inline |
Returns the maximum number of levels in the tree possible.
|
inline |
Returns the number of levels in the given BVHTree instance.
References axom::spin::BVHTree< T, NDIMS >::insert().
void axom::spin::BVHTree< T, NDIMS >::insert | ( | const BoxType & | box, |
const T & | data | ||
) |
Inserts an object, identified by its bounding box and user-supplied data, to the bucket tree.
[in] | box | Axis-Aligned bounding box enclosing the object. |
[in] | data | user-supplied data associated with the object. |
References axom::primal::BoundingBox< T, NDIMS >::contains(), axom::spin::BVHTree< T, NDIMS >::empty(), axom::spin::BVHTree< T, NDIMS >::getBucketNumObjects(), axom::primal::BoundingBox< T, NDIMS >::isValid(), SLIC_ASSERT, and SLIC_ERROR.
Referenced by axom::spin::BVHTree< T, NDIMS >::getNumLevels(), and axom::quest::SignedDistance< NDIMS >::SignedDistance().
|
inline |
Returns the total number of inserted objects in the tree.
References axom::spin::BVHTree< T, NDIMS >::build().
void axom::spin::BVHTree< T, NDIMS >::build | ( | int | threshold = 25 | ) |
Builds a hierarchical decomposition of axis-aligned bounding boxes that partitions the set of objects in different buckets.
[in] | threshold | subdivision threshold, buckets consisting of a number of objects greater than the given threshold will be subdivided. |
References axom::spin::BVHTree< T, NDIMS >::empty(), and SLIC_ASSERT.
Referenced by axom::spin::BVHTree< T, NDIMS >::getNumberOfObjects(), and axom::quest::SignedDistance< NDIMS >::SignedDistance().
|
inline |
Checks if the tree is empty.
References axom::spin::BVHTree< T, NDIMS >::clear(), axom::spin::BVHTree< T, NDIMS >::contains(), DISABLE_COPY_AND_ASSIGNMENT, DISABLE_MOVE_AND_ASSIGNMENT, axom::spin::BVHTree< T, NDIMS >::find(), axom::spin::BVHTree< T, NDIMS >::getBucketBox(), axom::spin::BVHTree< T, NDIMS >::getBucketNumObjects(), axom::spin::BVHTree< T, NDIMS >::getBucketObjectArray(), axom::primal::BoundingBox< T, NDIMS >::getMax(), axom::primal::BoundingBox< T, NDIMS >::getMin(), axom::spin::BVHTree< T, NDIMS >::getObjectBox(), axom::spin::BVHTree< T, NDIMS >::getObjectBucketIndex(), axom::spin::BVHTree< T, NDIMS >::getObjectData(), axom::utilities::max(), axom::utilities::min(), SLIC_ASSERT, and axom::spin::BVHTree< T, NDIMS >::writeVtkFile().
Referenced by axom::spin::BVHTree< T, NDIMS >::build(), axom::spin::BVHTree< T, NDIMS >::contains(), axom::spin::BVHTree< T, NDIMS >::find(), and axom::spin::BVHTree< T, NDIMS >::insert().
void axom::spin::BVHTree< T, NDIMS >::clear | ( | ) |
Deletes the tree and all associated objects.
Referenced by axom::spin::BVHTree< T, NDIMS >::empty(), and axom::spin::BVHTree< T, NDIMS >::~BVHTree().
bool axom::spin::BVHTree< T, NDIMS >::contains | ( | const PointType & | pt | ) | const |
Checks if the point is inside the BVHTree.
[in] | pt | the point in query. |
References axom::spin::BVHTree< T, NDIMS >::empty(), axom::primal::BoundingBox< double, NDIMS >::getPoints(), axom::utilities::max(), axom::utilities::min(), SLIC_ASSERT, and axom::primal::squared_distance().
Referenced by axom::spin::BVHTree< T, NDIMS >::empty().
void axom::spin::BVHTree< T, NDIMS >::find | ( | const PointType & | pt, |
std::vector< int > & | candidate_buckets | ||
) | const |
Finds a subset of candidate buckets for the given point query.
[in] | pt | the point in query. |
[out] | candidate_buckets | list of bucket IDs for the given point query. |
References axom::spin::BVHTree< T, NDIMS >::empty(), axom::utilities::max(), axom::utilities::min(), and SLIC_ASSERT.
Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), and axom::spin::BVHTree< T, NDIMS >::empty().
const primal::BoundingBox< double, NDIMS > & axom::spin::BVHTree< T, NDIMS >::getBucketBox | ( | int | bucketIdx | ) | const |
Returns a const reference to the bounding box of the given bucket.
[in] | bucketIdx | the index of the bucket in query. |
References SLIC_ASSERT.
Referenced by axom::spin::BVHTree< T, NDIMS >::empty().
int axom::spin::BVHTree< T, NDIMS >::getBucketNumObjects | ( | int | bucketIdx | ) | const |
Returns the number of object within the given bucket.
[in] | bucketIdx | the index of the bucket in query. |
References SLIC_ASSERT.
Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), axom::spin::BVHTree< T, NDIMS >::empty(), and axom::spin::BVHTree< T, NDIMS >::insert().
const int * axom::spin::BVHTree< T, NDIMS >::getBucketObjectArray | ( | int | bucketIdx | ) | const |
Return const pointer to the object array of the given bucket.
[in] | bucketIdx | the index of the bucket in query. |
References SLIC_ASSERT.
Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), and axom::spin::BVHTree< T, NDIMS >::empty().
const primal::BoundingBox< double, NDIMS > & axom::spin::BVHTree< T, NDIMS >::getObjectBox | ( | int | objIdx | ) | const |
Returns a const reference to the bounding box of the given object.
[in] | objIdx | the ID of the object in query. |
References SLIC_ASSERT.
Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), and axom::spin::BVHTree< T, NDIMS >::empty().
const T & axom::spin::BVHTree< T, NDIMS >::getObjectData | ( | int | objIdx | ) | const |
Returns const reference to the data associated with the given object.
objIdx | the ID of the object in query. |
References SLIC_ASSERT.
Referenced by axom::quest::SignedDistance< NDIMS >::computeDistance(), and axom::spin::BVHTree< T, NDIMS >::empty().
int axom::spin::BVHTree< T, NDIMS >::getObjectBucketIndex | ( | int | objIdx | ) | const |
Returns the bucket index of the given object.
[in] | objIdx | the ID of the object in query. |
References SLIC_ASSERT.
Referenced by axom::spin::BVHTree< T, NDIMS >::empty().
void axom::spin::BVHTree< T, NDIMS >::writeVtkFile | ( | const std::string & | fileName, |
bool | include_objects = false |
||
) | const |
Writes the hierarchical decomposition in a VTK file.
[in] | fileName | the name of the VTK formatted file to generate. |
[in] | include_objects | optional parameter, when true it also writes out the bounding boxes of the supplied objects. |
Referenced by axom::spin::BVHTree< T, NDIMS >::empty(), and axom::spin::BVHTree< T, NDIMS >::writeVtkFile().
void axom::spin::BVHTree< T, NDIMS >::writeVtkFile | ( | const std::string & | fileName, |
const int * | bins, | ||
int | nbins | ||
) | const |
Writes the user-supplied set of bins in a VTK file.
[in] | fileName | the name of the VTK formatted file to generate. |
[in] | bins | array of bins to dump in the VTK file. |
[in] | nbins | the number of bins. |
References AXOM_NOT_USED, SLIC_ASSERT, and axom::spin::BVHTree< T, NDIMS >::writeVtkFile().