MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
Classes | Public Member Functions | List of all members
mingfx::BVH Class Reference

Detailed Description

A Bounding Volume Hierarchy (BVH) data structure that can be used to accelerate ray-object intersection tests by carving up space into a hierarchy of partitions represented in a tree.

Each node of the tree is represented as an AABB (Axis-Aligned Bounding Box) that contains all of the nodes under it. Different objects can be stored inside each bounding box. For example, when a BVH is created for a mesh, each leaf node can contain a AABB that contains just a single triangle. Or, when a BVH is created for an entire scene, you could have each leaf node contain an entire mesh or other object within the scene. In each case, use AABB's set_user_data() and user_data() methods to store a handle for whetever you want to store inside the nodes.

Definition at line 40 of file bvh.h.

#include <bvh.h>

Public Member Functions

 BVH ()
 Initializes the class with an empty hierarchy. More...
 
virtual ~BVH ()
 
void CreateFromMesh (const Mesh &mesh)
 Creates a bounding volume hierarchy where each leaf node contains a single triangle from the mesh. More...
 
void CreateFromListOfBoxes (const std::vector< AABB > &boxes)
 Creates a BVH where each leaf node contains one of the boxes passed in to the function. More...
 
std::vector< int > IntersectAndReturnUserData (const Ray &r) const
 Traverse the BVH to find leaf nodes whose AABBs are intersected by the ray. More...
 

Constructor & Destructor Documentation

◆ BVH()

mingfx::BVH::BVH ( )

Initializes the class with an empty hierarchy.

◆ ~BVH()

virtual mingfx::BVH::~BVH ( )
virtual

Member Function Documentation

◆ CreateFromListOfBoxes()

void mingfx::BVH::CreateFromListOfBoxes ( const std::vector< AABB > &  boxes)

Creates a BVH where each leaf node contains one of the boxes passed in to the function.

◆ CreateFromMesh()

void mingfx::BVH::CreateFromMesh ( const Mesh mesh)

Creates a bounding volume hierarchy where each leaf node contains a single triangle from the mesh.

For leaf nodes, the triangle index can be retrieved with:

int tri_id = leafnode->box.user_data();

The user_data will be -1 for non-leaf nodes. Once the structure has been created, it can be used to perform fast ray-mesh intersection tests. See Ray::FastIntersectMesh().

◆ IntersectAndReturnUserData()

std::vector<int> mingfx::BVH::IntersectAndReturnUserData ( const Ray r) const

Traverse the BVH to find leaf nodes whose AABBs are intersected by the ray.

These are candidates to test more thoroughly using whatever ray-object intersection test is appropriate for the objects stored inside the AABB. This routine returns the user_data for each AABB leaf node. In the case of a BVH created using CreateFromMesh, this means it stores the indices to the mesh triangles that should be tested for ray-triangle intersection.


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