PURE API 0.5
PR00F's Ultimate Rendering Engine full documentation
Loading...
Searching...
No Matches
PureBoundingVolumeHierarchy Class Reference

BVH: Bounding Volume Hierarchy class. More...

Detailed Description

BVH: Bounding Volume Hierarchy class.

The bounding volumes of objects are put in a hierarchical tree. With the help of an octree, we can easily build this hierarchy: First insert the objects into the octree, traverse it from bottom to top: starting with the leaf nodes, we calculate the bounding boxes of the objects in the leaf nodes. Then we go 1 level above, and calculate the bounding volume for the node grouping all its children together. We recursively progressing up towards the root node, where the biggest bounding volume containing all previously calculated bounding volumes is created.

This implementation is basically extending PureOctree nodes with bounding box calculation.

Definition at line 29 of file PureBoundingVolumeHierarchy.h.

#include <PureBoundingVolumeHierarchy.h>

+ Inheritance diagram for PureBoundingVolumeHierarchy:

Public Member Functions

 PureBoundingVolumeHierarchy (const PureVector &pos, TPureFloat size, TPureUInt maxDepthLevel, TPureUInt currentDepthLevel)
 Creates an octree-derived bounding volume hierarchy (BVH) node.
 
virtual ~PureBoundingVolumeHierarchy ()
 
virtual PureBoundingVolumeHierarchyinsertObject (const PureObject3D &obj)
 Inserts the given object in the octree.
 
virtual const PureBoundingVolumeHierarchyfindObject (const PureObject3D &obj) const
 Finds the given object in the octree.
 
const PureAxisAlignedBoundingBoxgetAABB () const
 Gets the AABB of this node.
 
- Public Member Functions inherited from PureOctree
 PureOctree (const PureVector &pos, TPureFloat size, TPureUInt maxDepthLevel, TPureUInt currentDepthLevel)
 Creates an octree node.
 
virtual ~PureOctree ()
 
ChildIndex calculateIndex (const PureVector &pos) const
 Calculates child node index for the given position in the current node.
 
TPureUInt getDepthLevel () const
 Gets the current depth level of the octree node.
 
TPureUInt getMaxDepthLevel () const
 Gets the maximum depth level of the octree node as it was specified in the constructor of the octree.
 
NodeType getNodeType () const
 Gets the type of the octree node which depends on if the node has any objects or children nodes.
 
const PureVectorgetPos () const
 Gets the world-space position of the node as specified in the constructor.
 
TPureFloat getSize () const
 Gets the length of the side of the cube represented by this node as it was specified in the constructor.
 
const std::vector< PureOctree * > & getChildren () const
 Gets the children nodes of this node.
 
const PureOctreegetParent () const
 Gets the parent node of this node.
 
const std::set< const PureObject3D * > & getObjects () const
 Gets the stored objects of this node.
 

Protected Member Functions

 PureBoundingVolumeHierarchy ()
 
 PureBoundingVolumeHierarchy (const PureBoundingVolumeHierarchy &)
 
PureBoundingVolumeHierarchyoperator= (const PureBoundingVolumeHierarchy &)
 
virtual TPureBool subdivide ()
 
- Protected Member Functions inherited from PureOctree
 PureOctree ()
 
 PureOctree (const PureOctree &)
 
PureOctreeoperator= (const PureOctree &)
 
void DeleteChildren ()
 

Private Attributes

PureAxisAlignedBoundingBox aabb
 

Additional Inherited Members

- Public Types inherited from PureOctree
enum  NodeType { Parent , LeafEmpty , LeafContainer }
 NodeType tells if the given node has children nodes or Objects. More...
 
typedef TPureUInt ChildIndex
 ChildIndex indexes a child node within a vector of children nodes.
 
- Static Public Attributes inherited from PureOctree
static const ChildIndex BIT_AXIS_Y = 0
 Bit to set to TOP or BOTTOM.
 
static const ChildIndex BIT_AXIS_X = 1
 Bit to set to LEFT or RIGHT.
 
static const ChildIndex BIT_AXIS_Z = 2
 Bit to set to FRONT or BACK.
 
static const ChildIndex TOP = 0
 Child is above or in same as parent's position on Y-axis.
 
static const ChildIndex BOTTOM = BIT(PureOctree::BIT_AXIS_Y)
 Child is under parent's position on Y-axis.
 
static const ChildIndex LEFT = 0
 Child is left to parent's position on X-axis.
 
static const ChildIndex RIGHT = BIT(PureOctree::BIT_AXIS_X)
 Child is right to or in same as parent's position on X-axis.
 
static const ChildIndex FRONT = 0
 Child is closer to camera than parent's position on Z-axis.
 
static const ChildIndex BACK = BIT(PureOctree::BIT_AXIS_Z)
 Child is farther or same distance from camera than parent's position on Z-axis.
 
- Protected Attributes inherited from PureOctree
std::vector< PureOctree * > vChildren
 
PureOctreeparent
 

Constructor & Destructor Documentation

◆ PureBoundingVolumeHierarchy() [1/3]

PureBoundingVolumeHierarchy::PureBoundingVolumeHierarchy ( const PureVector & pos,
TPureFloat size,
TPureUInt maxDepthLevel,
TPureUInt currentDepthLevel )

Creates an octree-derived bounding volume hierarchy (BVH) node.

Basically this is doing the same octree initialization as PureOctree's public constructor.

Parameters
posThe world-space position of this node. For global use, you can specify just (0;0;0).
sizeThe length of the side of the cube represented by this octree-derived node. Recommend this to be big enough to contain any scene objects. Note that this is NOT the size of the bounding box used by the BVH, that will be calculated.
maxDepthLevelThe maximum node depth level supported by this BVH. 0 means there is no depth limit.
currentDepthLevelThe depth level of this specific node being created. For global use, just specify 0 so this will be the root node of the BVH.

Definition at line 37 of file PureBoundingVolumeHierarchy.cpp.

◆ ~PureBoundingVolumeHierarchy()

PureBoundingVolumeHierarchy::~PureBoundingVolumeHierarchy ( )
virtual

Definition at line 44 of file PureBoundingVolumeHierarchy.cpp.

◆ PureBoundingVolumeHierarchy() [2/3]

PureBoundingVolumeHierarchy::PureBoundingVolumeHierarchy ( )
protected

Definition at line 126 of file PureBoundingVolumeHierarchy.cpp.

◆ PureBoundingVolumeHierarchy() [3/3]

PureBoundingVolumeHierarchy::PureBoundingVolumeHierarchy ( const PureBoundingVolumeHierarchy & )
protected

Definition at line 132 of file PureBoundingVolumeHierarchy.cpp.

Member Function Documentation

◆ findObject()

const PureBoundingVolumeHierarchy * PureBoundingVolumeHierarchy::findObject ( const PureObject3D & obj) const
virtual

Finds the given object in the octree.

Same behavior as PureOctree::findObject().

Parameters
objThe object to be found.
Returns
The BVH node containing the object. If the object is not found, PGENULL is returned.

Reimplemented from PureOctree.

Definition at line 93 of file PureBoundingVolumeHierarchy.cpp.

◆ getAABB()

const PureAxisAlignedBoundingBox & PureBoundingVolumeHierarchy::getAABB ( ) const

Gets the AABB of this node.

Note that the AABB has nothing to do with the position and size of the ancestor Octree node. Position and size of Octree node is just for determining which node should be the storage for an inserted object. However, the AABB is calculated purely by the position and size of the inserted objects, thus its position and size can easily differ from the position and size of the Octree node.

Returns
The calculated AABB volume for this node.

Definition at line 117 of file PureBoundingVolumeHierarchy.cpp.

◆ insertObject()

PureBoundingVolumeHierarchy * PureBoundingVolumeHierarchy::insertObject ( const PureObject3D & obj)
virtual

Inserts the given object in the octree.

Same behavior as PureOctree::insertObject().

Parameters
objThe object to be inserted in the octree.
Returns
The node where the object ends up after insertion. In case of error, PGENULL is returned. If the given object is outside the bounds of this Octree Node, it is considered as an error.

Reimplemented from PureOctree.

Definition at line 57 of file PureBoundingVolumeHierarchy.cpp.

◆ operator=()

PureBoundingVolumeHierarchy & PureBoundingVolumeHierarchy::operator= ( const PureBoundingVolumeHierarchy & )
protected

Definition at line 137 of file PureBoundingVolumeHierarchy.cpp.

◆ subdivide()

TPureBool PureBoundingVolumeHierarchy::subdivide ( )
protectedvirtual

Reimplemented from PureOctree.

Definition at line 143 of file PureBoundingVolumeHierarchy.cpp.

Member Data Documentation

◆ aabb

PureAxisAlignedBoundingBox PureBoundingVolumeHierarchy::aabb
private

Definition at line 61 of file PureBoundingVolumeHierarchy.h.


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