EBGeometry  1.0
Public Types | Public Member Functions | Protected Attributes | List of all members
BVH::LinearNodeT< T, P, BV, K > Class Template Reference

Forward declare linear node class. More...

#include <EBGeometry_BVH.hpp>

Public Types

using Vec3 = Vec3T< T >
 Alias for vector type.
 

Public Member Functions

 LinearNodeT () noexcept
 Constructor.
 
virtual ~LinearNodeT ()
 Destructor.
 
void setBoundingVolume (const BV &a_boundingVolume) noexcept
 Set the bounding volume. More...
 
void setPrimitivesOffset (const size_t a_primitivesOffset) noexcept
 Set the offset into the primitives array.
 
void setNumPrimitives (const size_t a_numPrimitives) noexcept
 Set number of primitives. More...
 
void setChildOffset (const size_t a_childOffset, const size_t a_whichChild) noexcept
 Set the child offsets. More...
 
const BV & getBoundingVolume () const noexcept
 Get the node bounding volume. return m_boundingVolume.
 
const size_t & getPrimitivesOffset () const noexcept
 Get the primitives offset. More...
 
const size_t & getNumPrimitives () const noexcept
 Get the number of primitives. More...
 
const std::array< size_t, K > & getChildOffsets () const noexcept
 Get the child offsets. More...
 
bool isLeaf () const noexcept
 Is leaf or not.
 
bool isPartitioned () const noexcept
 Check if BVH is already partitioned.
 
getDistanceToBoundingVolume (const Vec3 &a_point) const noexcept
 Get the distance from a 3D point to the bounding volume. More...
 
std::vector< T > getDistances (const Vec3 &a_point, const std::vector< std::shared_ptr< const P >> &a_primitives) const noexcept
 Compute signed distance to primitives. More...
 

Protected Attributes

BV m_boundingVolume
 Bounding volume.
 
bool m_partitioned
 Determines whether or not the partitioning function has already been called.
 
size_t m_primitivesOffset
 Offset into primitives array.
 
size_t m_numPrimitives
 Number of primitives.
 
std::array< size_t, K > m_childOffsets
 Offset to child nodes.
 

Detailed Description

template<class T, class P, class BV, size_t K>
class BVH::LinearNodeT< T, P, BV, K >

Forward declare linear node class.

Node type for linearized (flattened) BVH. This will be constructed from the other (conventional) BVH type.

T is the precision used in the BVH computations, P is the enclosing primitive and BV is the bounding volume used in the BVH. K is the tree degree.

T is the precision for Vec3, P is the primitive type you want to enclose, BV is the bounding volume you use for it.

Note
P MUST supply function signedDistance(...) BV must supply a function getDistance (had this been C++20, we would have use concepts to enforce this). Note that LinearNode is the result of a flattened BVH hierarchy where nodes are stored with depth-first ordering for improved cache-location in the downward traversal.
This class exists so that we can fit the nodes with a smaller memory footprint. The standard BVH node (NodeT) is very useful when building the tree but less useful when traversing it since it stores references to the primitives in the node itself. It will span multiple cache lines. This node exists so that we can fit all the BVH info onto fewer cache lines. The number of cache lines will depend on the tree degree, precision, and bounding volume that is chosen.
Todo:
There's a minor optimization that can be made to the memory alignment, which is as follows: For a leaf node we never really need the m_childOffsets array, and for a regular node we never really need the m_primitivesOffset member. Moreover, m_childOffsets could be made into a K-1 sized array because we happen to know that the linearized hierarchy will store the first child node immediately after the regular node. We could shave off 16 bytes of storage, which would mean that a double-precision binary tree only takes up one word of CPU memory.

Member Function Documentation

◆ getChildOffsets()

template<class T , class P , class BV , size_t K>
const std::array<size_t, K>& BVH::LinearNodeT< T, P, BV, K >::getChildOffsets ( ) const
inlinenoexcept

Get the child offsets.

Returns
Returns m_childOffsets

◆ getDistances()

template<class T , class P , class BV , size_t K>
std::vector<T> BVH::LinearNodeT< T, P, BV, K >::getDistances ( const Vec3 a_point,
const std::vector< std::shared_ptr< const P >> &  a_primitives 
) const
inlinenoexcept

Compute signed distance to primitives.

Parameters
[in]a_pointPoint
[in]a_primitivesList of primitives
Note
Only call if this is a leaf node.

◆ getDistanceToBoundingVolume()

template<class T , class P , class BV , size_t K>
T BVH::LinearNodeT< T, P, BV, K >::getDistanceToBoundingVolume ( const Vec3 a_point) const
inlinenoexcept

Get the distance from a 3D point to the bounding volume.

Parameters
[in]a_point3D point
Returns
Returns distance to bounding volume. A zero distance implies that the input point is inside the bounding volume.

◆ getNumPrimitives()

template<class T , class P , class BV , size_t K>
const size_t& BVH::LinearNodeT< T, P, BV, K >::getNumPrimitives ( ) const
inlinenoexcept

Get the number of primitives.

Returns
Returns m_numPrimitives

◆ getPrimitivesOffset()

template<class T , class P , class BV , size_t K>
const size_t& BVH::LinearNodeT< T, P, BV, K >::getPrimitivesOffset ( ) const
inlinenoexcept

Get the primitives offset.

Returns
Returns m_primitivesOffset

◆ setBoundingVolume()

template<class T , class P , class BV , size_t K>
void BVH::LinearNodeT< T, P, BV, K >::setBoundingVolume ( const BV &  a_boundingVolume)
inlinenoexcept

Set the bounding volume.

Parameters
[in]a_boundingVolumeBounding volume for this node.

◆ setChildOffset()

template<class T , class P , class BV , size_t K>
void BVH::LinearNodeT< T, P, BV, K >::setChildOffset ( const size_t  a_childOffset,
const size_t  a_whichChild 
)
inlinenoexcept

Set the child offsets.

Parameters
[in]a_childOffsetOffset in node array.
[in]a_whichChildChild index in m_childrenOffsets. Must be [0,K-1]

◆ setNumPrimitives()

template<class T , class P , class BV , size_t K>
void BVH::LinearNodeT< T, P, BV, K >::setNumPrimitives ( const size_t  a_numPrimitives)
inlinenoexcept

Set number of primitives.

Parameters
[in]a_numPrimitivesNumber of primitives.

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