![]() |
VR-Forces Developer's Guide
|
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< bool > | myShutdownFlag |
| std::thread * | myProcessingThread |
| std::mutex | myMutex |
| std::condition_variable | myThreadCV |
| std::unique_ptr< tbb::task_arena > | myTaskArena |
| std::unique_ptr< tbb::task_group > | myTaskGroup |
|
explicit |
Constructor that initializes the background BVH builder.
| maxThreads | Maximum number of worker threads to use for parallel BVH building. This limits the TBB task arena size to control resource usage. |
|
virtual |
Virtual destructor.
Safely shuts down the background processing thread and waits for all parallel tasks to complete before destroying the object.
|
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.
| shape | Shared pointer to the triangle mesh shape that needs BVH building. The shape's buildBvh() method will be called in the background. |
|
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.
| builder | Pointer to the DtBackgroundBvhBuilder instance to process. |
|
protected |
Thread-safe queue containing shapes waiting to be processed.
Uses TBB concurrent queue to allow safe access from multiple threads without additional synchronization.
|
protected |
Atomic flag indicating whether the processing thread should shutdown.
Set to true during destruction to signal the worker thread to exit cleanly.
|
protected |
Worker thread that processes the shape queue.
This thread runs threadMain() and handles the background processing of BVH building operations.
|
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.
|
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.
|
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.
|
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.