#include <SphericalClumpBVH.hpp>
Classes | |
| class | Clump |
| struct | LeafStatistics |
| class | Node |
Public Member Functions | |
| vector< int > | allDisjointClumps () const |
| int | anyClumpContaining (Vec bfr) const |
| vector< std::pair< int, double > > | clumpsCrossingPlane (int axis, double value) const |
| LeafStatistics | leafStatistics () const |
| void | loadClumps (const vector< Clump > &clumps) |
| int | nearestClumpAlongRay (Position r0, Direction k, double &sBest) const |
Private Member Functions | |
| int | buildRecursive (int begin, int end) |
Private Attributes | |
| const vector< Clump > * | _clumps |
| vector< int > | _index |
| vector< Node > | _nodes |
SphericalClumpBVH is a low-level utility class that organizes a set of non-overlapping spheres ("clumps"), each defined by a center and a radius, in a data structure that allows efficient queries: finding the clump (if any) containing a given position, finding the nearest clump intersected by a ray, and so on.
The implementation employs a linearized Bounding Volume Hierarchy (BVH) that is bulk-loaded using a surface area heuristic (SAH) for optimal balance. Construction of the data structure runs in a single serial thread. Because the data structure does not change after the initial call to loadClumps(), all query functions are thread-safe.
| vector< int > SphericalClumpBVH::allDisjointClumps | ( | ) | const |
This function returns the indices, into the vector most recently passed to loadClumps(), of a maximal subset of mutually non-overlapping clumps. The subset is built greedily in order of increasing index: clump 0 is always kept, and each subsequent clump is kept unless it overlaps a clump already kept.
| int SphericalClumpBVH::anyClumpContaining | ( | Vec | bfr | ) | const |
This function returns the index, into the vector most recently passed to loadClumps(), of any clump containing the given position, or -1 if none does. If the loaded clumps are not mutually disjoint, which of the overlapping clumps is returned is unspecified.
| vector< std::pair< int, double > > SphericalClumpBVH::clumpsCrossingPlane | ( | int | axis, |
| double | value ) const |
This function returns, for each clump that actually crosses the coordinate plane where coordinate axis (0 for x, 1 for y, 2 for z) equals value, a pair holding the index of that clump (into the vector most recently passed to loadClumps()) and the radius of the circle formed by the intersection of the clump's sphere with the plane. A cheap bounding-box test is used to prune the search, but every returned clump has already been confirmed by an exact sphere/plane test, so the caller does not need to repeat it. The ordering of the returned clumps is unspecified.
| LeafStatistics SphericalClumpBVH::leafStatistics | ( | ) | const |
This function walks all leaves of the already-built BVH and returns summary statistics on (1) the depth of each leaf in the tree (the root has depth zero), (2) the number of clumps held by each leaf, and (3) the diagonal of each leaf's bounding box. This is a read-only, optional diagnostic pass performed after construction – it does not affect, and is not affected by, the build itself – intended for logging or for tuning the BVH build parameters (NumBins and MaxLeafSize in the source file). If the BVH is empty (no clumps loaded), all statistics are zero.
This function bulk-loads the specified clumps into the BVH, replacing any previous content. The clumps are not required to be mutually disjoint; see allDisjointClumps(). The specified vector must remain valid, unchanged, and at the same memory location for as long as the BVH is used, because the BVH stores a pointer to it rather than a copy.
This function returns the index, into the vector most recently passed to loadClumps(), of the nearest clump intersected by the ray \(({\bf{r}}_0,{\bf{k}})\) at a forward distance strictly between 0 and the value of sBest on entry, or -1 if there is none. On success, the distance to the entry point of that clump is stored in sBest.