VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Static Protected Member Functions | Protected Attributes
DtBackgroundBvhBuilder Class Reference

Background BVH builder that processes triangle mesh shapes in parallel.

This class encapsulates a worker thread that builds Bounding Volume Hierarchies (BVH) for DtBvhTriangleMeshShape objects using Intel TBB for parallel processing. The class uses a task arena to limit thread usage and a task group for parallel execution of buildBvh() operations.

Key features:

Public Member Functions

 DtBackgroundBvhBuilder (size_t maxThreads)
 
virtual ~DtBackgroundBvhBuilder ()
 
virtual void addTrianleMeshShape (DtBvhTriangleMeshShape::Ptr shape)
 

Static Protected Member Functions

static void threadMain (DtBackgroundBvhBuilder *builder)
 

Protected Attributes

tbb::concurrent_queue
< DtBvhTriangleMeshShape::Ptr
myShapesToProcess
 
std::atomic< boolmyShutdownFlag
 
std::thread * myProcessingThread
 
std::mutex myMutex
 
std::condition_variable myThreadCV
 
std::unique_ptr< tbb::task_arena > myTaskArena
 
std::unique_ptr< tbb::task_group > myTaskGroup
 

Constructor & Destructor Documentation

DtBackgroundBvhBuilder::DtBackgroundBvhBuilder ( size_t  maxThreads)
explicit

Constructor that initializes the background BVH builder.

Parameters
maxThreadsMaximum number of worker threads to use for parallel BVH building. This limits the TBB task arena size to control resource usage.
virtual DtBackgroundBvhBuilder::~DtBackgroundBvhBuilder ( )
virtual

Virtual destructor.

Safely shuts down the background processing thread and waits for all parallel tasks to complete before destroying the object.

Member Function Documentation

virtual void DtBackgroundBvhBuilder::addTrianleMeshShape ( DtBvhTriangleMeshShape::Ptr  shape)
virtual

Adds a triangle mesh shape to the processing queue.

This method is thread-safe and can be called from multiple threads. The shape will be queued for background BVH building and processed when worker threads become available.

Parameters
shapeShared pointer to the triangle mesh shape that needs BVH building. The shape's buildBvh() method will be called in the background.
static void DtBackgroundBvhBuilder::threadMain ( DtBackgroundBvhBuilder builder)
staticprotected

Main processing thread function.

This static function runs in a separate thread and continuously processes shapes from the queue using parallel TBB tasks within the limited arena.

Parameters
builderPointer to the DtBackgroundBvhBuilder instance to process.

Member Data Documentation

tbb::concurrent_queue<DtBvhTriangleMeshShape::Ptr> DtBackgroundBvhBuilder::myShapesToProcess
protected

Thread-safe queue containing shapes waiting to be processed.

Uses TBB concurrent queue to allow safe access from multiple threads without additional synchronization.

std::atomic<bool> DtBackgroundBvhBuilder::myShutdownFlag
protected

Atomic flag indicating whether the processing thread should shutdown.

Set to true during destruction to signal the worker thread to exit cleanly.

std::thread* DtBackgroundBvhBuilder::myProcessingThread
protected

Worker thread that processes the shape queue.

This thread runs threadMain() and handles the background processing of BVH building operations.

std::mutex DtBackgroundBvhBuilder::myMutex
protected

Mutex for protecting access to the condition variable and shutdown coordination.

Used to synchronize thread startup, shutdown, and wake-up notifications between the main thread and worker thread.

std::condition_variable DtBackgroundBvhBuilder::myThreadCV
protected

Condition variable for waking up the worker thread.

Used to notify the worker thread when new shapes are added to the queue or when shutdown is requested.

std::unique_ptr<tbb::task_arena> DtBackgroundBvhBuilder::myTaskArena
protected

TBB task arena that limits the number of threads used for parallel processing.

This arena enforces the maxThreads limit specified in the constructor, preventing the BVH builder from consuming too many system resources.

std::unique_ptr<tbb::task_group> DtBackgroundBvhBuilder::myTaskGroup
protected

TBB task group for managing parallel BVH building operations.

All parallel buildBvh() calls are executed within this task group, which operates within the limited task arena to respect thread limits.


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

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)