DHART
Loading...
Searching...
No Matches
nanort::BVHAccel< T > Class Template Reference

Bounding Volume Hierarchy acceleration. More...

#include <nanort.h>

+ Collaboration diagram for nanort::BVHAccel< T >:

Public Member Functions

 BVHAccel ()
 
 ~BVHAccel ()
 
template<class Prim , class Pred >
bool Build (const unsigned int num_primitives, const Prim &p, const Pred &pred, const BVHBuildOptions< T > &options=BVHBuildOptions< T >())
 Build BVH for input primitives. More...
 
BVHBuildStatistics GetStatistics () const
 Get statistics of built BVH tree. Valid after Build() More...
 
void Debug ()
 
template<class I , class H >
bool Traverse (const Ray< T > &ray, const I &intersector, H *isect, const BVHTraceOptions &options=BVHTraceOptions()) const
 Traverse into BVH along ray and find closest hit point & primitive if found. More...
 
template<class I >
bool ListNodeIntersections (const Ray< T > &ray, int max_intersections, const I &intersector, StackVector< NodeHit< T >, 128 > *hits) const
 List up nodes which intersects along the ray. This function is useful for two-level BVH traversal. See examples/nanosg for example. More...
 
const std::vector< BVHNode< T > > & GetNodes () const
 
const std::vector< unsigned int > & GetIndices () const
 
void BoundingBox (T bmin[3], T bmax[3]) const
 Returns bounding box of built BVH. More...
 
bool IsValid () const
 

Private Member Functions

template<class P , class Pred >
unsigned int BuildTree (BVHBuildStatistics *out_stat, std::vector< BVHNode< T > > *out_nodes, unsigned int left_idx, unsigned int right_idx, unsigned int depth, const P &p, const Pred &pred)
 Builds BVH tree recursively. More...
 
template<class I >
bool TestLeafNode (const BVHNode< T > &node, const Ray< T > &ray, const I &intersector) const
 
template<class I >
bool TestLeafNodeIntersections (const BVHNode< T > &node, const Ray< T > &ray, const int max_intersections, const I &intersector, std::priority_queue< NodeHit< T >, std::vector< NodeHit< T > >, NodeHitComparator< T > > *isect_pq) const
 

Private Attributes

std::vector< BVHNode< T > > nodes_
 
std::vector< unsigned int > indices_
 
std::vector< BBox< T > > bboxes_
 
BVHBuildOptions< T > options_
 
BVHBuildStatistics stats_
 
unsigned int pad0_
 

Detailed Description

template<typename T>
class nanort::BVHAccel< T >

Bounding Volume Hierarchy acceleration.

BVHAccel is central part of ray tracing(ray traversal). BVHAccel takes an input geometry(primitive) information and build a data structure for efficient ray tracing(O(log2 N) in theory, where N is the number of primitive in the scene).

Template Parameters
Treal value type(float or double).

Definition at line 705 of file nanort.h.

Constructor & Destructor Documentation

◆ BVHAccel()

template<typename T >
nanort::BVHAccel< T >::BVHAccel ( )
inline

Definition at line 707 of file nanort.h.

References nanort::BVHAccel< T >::pad0_.

◆ ~BVHAccel()

template<typename T >
nanort::BVHAccel< T >::~BVHAccel ( )
inline

Definition at line 708 of file nanort.h.

Member Function Documentation

◆ BoundingBox()

template<typename T >
void nanort::BVHAccel< T >::BoundingBox ( bmin[3],
bmax[3] 
) const
inline

Returns bounding box of built BVH.

Definition at line 798 of file nanort.h.

References nanort::BVHAccel< T >::nodes_.

◆ Build()

template<typename T >
template<class Prim , class Pred >
bool nanort::BVHAccel< T >::Build ( const unsigned int  num_primitives,
const Prim &  p,
const Pred &  pred,
const BVHBuildOptions< T > &  options = BVHBuildOptions<T>() 
)

Build BVH for input primitives.

Template Parameters
PrimPrimitive(e.g. Triangle) accessor class.
PredPredicator(comparator class object for Prim class to find nearest hit point)
Parameters
[in]num_primitivesThe number of primitive.
[in]pPrimitive accessor class object.
[in]predPredicator object.
Returns
true upon success.

Definition at line 1907 of file nanort.h.

References nanort::BBox< T >::bmax, nanort::BBox< T >::bmin, nanort::BVHBuildOptions< T >::cache_bbox, nanort::ComputeBoundingBox(), nanort::BVHBuildOptions< T >::min_primitives_for_parallel_build, and nanort::BVHBuildOptions< T >::shallow_depth.

Referenced by HF::nanoGeom::nanoRT_BVH().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ BuildTree()

template<typename T >
template<class P , class Pred >
unsigned int nanort::BVHAccel< T >::BuildTree ( BVHBuildStatistics out_stat,
std::vector< BVHNode< T > > *  out_nodes,
unsigned int  left_idx,
unsigned int  right_idx,
unsigned int  depth,
const P &  p,
const Pred &  pred 
)
private

◆ Debug()

template<typename T >
void nanort::BVHAccel< T >::Debug

Definition at line 2168 of file nanort.h.

◆ GetIndices()

template<typename T >
const std::vector< unsigned int > & nanort::BVHAccel< T >::GetIndices ( ) const
inline

Definition at line 793 of file nanort.h.

References nanort::BVHAccel< T >::indices_.

◆ GetNodes()

template<typename T >
const std::vector< BVHNode< T > > & nanort::BVHAccel< T >::GetNodes ( ) const
inline

Definition at line 792 of file nanort.h.

References nanort::BVHAccel< T >::nodes_.

◆ GetStatistics()

template<typename T >
BVHBuildStatistics nanort::BVHAccel< T >::GetStatistics ( ) const
inline

Get statistics of built BVH tree. Valid after Build()

Returns
BVH build statistics.

Definition at line 731 of file nanort.h.

References nanort::BVHAccel< T >::stats_.

◆ IsValid()

template<typename T >
bool nanort::BVHAccel< T >::IsValid ( ) const
inline

Definition at line 813 of file nanort.h.

References nanort::BVHAccel< T >::nodes_.

◆ ListNodeIntersections()

template<typename T >
template<class I >
bool nanort::BVHAccel< T >::ListNodeIntersections ( const Ray< T > &  ray,
int  max_intersections,
const I &  intersector,
StackVector< NodeHit< T >, 128 > *  hits 
) const

List up nodes which intersects along the ray. This function is useful for two-level BVH traversal. See examples/nanosg for example.

Template Parameters
IIntersection class

Definition at line 2628 of file nanort.h.

References nanort::BVHNode< T >::axis, nanort::BVHNode< T >::bmax, nanort::BVHNode< T >::bmin, nanort::BVHNode< T >::data, nanort::Ray< T >::dir, nanort::BVHNode< T >::flag, nanort::IntersectRayAABB(), nanort::Ray< T >::max_t, nanort::Ray< T >::min_t, nanort::Ray< T >::org, and nanort::vsafe_inverse().

+ Here is the call graph for this function:

◆ TestLeafNode()

template<typename T >
template<class I >
bool nanort::BVHAccel< T >::TestLeafNode ( const BVHNode< T > &  node,
const Ray< T > &  ray,
const I &  intersector 
) const
inlineprivate

◆ TestLeafNodeIntersections()

template<typename T >
template<class I >
bool nanort::BVHAccel< T >::TestLeafNodeIntersections ( const BVHNode< T > &  node,
const Ray< T > &  ray,
const int  max_intersections,
const I &  intersector,
std::priority_queue< NodeHit< T >, std::vector< NodeHit< T > >, NodeHitComparator< T > > *  isect_pq 
) const
inlineprivate

◆ Traverse()

template<typename T >
template<class I , class H >
bool nanort::BVHAccel< T >::Traverse ( const Ray< T > &  ray,
const I &  intersector,
H *  isect,
const BVHTraceOptions options = BVHTraceOptions() 
) const

Traverse into BVH along ray and find closest hit point & primitive if found.

Template Parameters
IIntersector class
HHit class
Parameters
[in]rayInput ray
[in]intersectorIntersector object. This object is called for each possible intersection of ray and BVH during traversal.
[out]isectIntersection point information(filled when any hit point was found)
[in]optionsTraversal options.
Returns
true if any hit point found

Definition at line 2505 of file nanort.h.

References nanort::BVHNode< T >::axis, nanort::BVHNode< T >::bmax, nanort::BVHNode< T >::bmin, nanort::BVHNode< T >::data, nanort::Ray< T >::dir, nanort::BVHNode< T >::flag, nanort::IntersectRayAABB(), kNANORT_MAX_STACK_DEPTH, nanort::Ray< T >::max_t, nanort::Ray< T >::min_t, nanort::Ray< T >::org, and nanort::vsafe_inverse().

Referenced by HF::RayTracer::NanoRTRayTracer::Intersect(), HF::nanoGeom::nanoRT_Intersect(), and HF::nanoGeom::nanoRT_RayCast().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ bboxes_

template<typename T >
std::vector<BBox<T> > nanort::BVHAccel< T >::bboxes_
private

Definition at line 863 of file nanort.h.

◆ indices_

template<typename T >
std::vector<unsigned int> nanort::BVHAccel< T >::indices_
private

Definition at line 862 of file nanort.h.

Referenced by nanort::BVHAccel< T >::GetIndices().

◆ nodes_

template<typename T >
std::vector<BVHNode<T> > nanort::BVHAccel< T >::nodes_
private

◆ options_

template<typename T >
BVHBuildOptions<T> nanort::BVHAccel< T >::options_
private

Definition at line 864 of file nanort.h.

◆ pad0_

template<typename T >
unsigned int nanort::BVHAccel< T >::pad0_
private

Definition at line 866 of file nanort.h.

Referenced by nanort::BVHAccel< T >::BVHAccel().

◆ stats_

template<typename T >
BVHBuildStatistics nanort::BVHAccel< T >::stats_
private

Definition at line 865 of file nanort.h.

Referenced by nanort::BVHAccel< T >::GetStatistics().


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