Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
default_builder.h
Go to the documentation of this file.
1#ifndef BVH_V2_DEFAULT_BUILDER_H
2#define BVH_V2_DEFAULT_BUILDER_H
3
9
10namespace bvh::v2 {
11
12/// This builder is only a wrapper around all the other builders, which selects the best builder
13/// depending on the desired BVH quality and whether a multi-threaded build is desired.
14template <typename Node>
16 using Scalar = typename Node::Scalar;
19
20public:
21 enum class Quality { Low, Medium, High };
22
23 struct Config : TopDownSahBuilder<Node>::Config {
24 /// The quality of the BVH produced by the builder. The higher the quality the faster the
25 /// BVH is to traverse, but the slower it is to build.
27
28 /// Threshold, in number of primitives, under which the builder operates in a single-thread.
29 size_t parallel_threshold = 1024;
30 };
31
32 /// Build a BVH in parallel using the given thread pool.
34 ThreadPool& thread_pool,
35 std::span<const BBox> bboxes,
36 std::span<const Vec> centers,
37 const Config& config = {})
38 {
39 if (bboxes.size() < config.parallel_threshold)
40 return build(bboxes, centers, config);
42 thread_pool, bboxes, centers, make_mini_tree_config(config));
43 if (config.quality == Quality::High)
45 return bvh;
46 }
47
48 /// Build a BVH in a single-thread.
50 std::span<const BBox> bboxes,
51 std::span<const Vec> centers,
52 const Config& config = {})
53 {
54 if (config.quality == Quality::Low)
55 return BinnedSahBuilder<Node>::build(bboxes, centers, config);
56 else {
57 auto bvh = SweepSahBuilder<Node>::build(bboxes, centers, config);
58 if (config.quality == Quality::High)
60 return bvh;
61 }
62 }
63
64private:
65 BVH_ALWAYS_INLINE static auto make_mini_tree_config(const Config& config) {
66 typename MiniTreeBuilder<Node>::Config mini_tree_config;
67 static_cast<typename TopDownSahBuilder<Node>::Config&>(mini_tree_config) = config;
68 mini_tree_config.enable_pruning = config.quality == Quality::Low ? false : true;
69 mini_tree_config.pruning_area_ratio =
70 config.quality == Quality::High ? static_cast<Scalar>(0.01) : static_cast<Scalar>(0.1);
71 mini_tree_config.parallel_threshold = config.parallel_threshold;
72 return mini_tree_config;
73 }
74};
75
76} // namespace bvh::v2
77
78#endif
This builder is only a wrapper around all the other builders, which selects the best builder dependin...
typename Node::Scalar Scalar
static BVH_ALWAYS_INLINE auto make_mini_tree_config(const Config &config)
static BVH_ALWAYS_INLINE Bvh< Node > build(std::span< const BBox > bboxes, std::span< const Vec > centers, const Config &config={})
Build a BVH in a single-thread.
static BVH_ALWAYS_INLINE Bvh< Node > build(ThreadPool &thread_pool, std::span< const BBox > bboxes, std::span< const Vec > centers, const Config &config={})
Build a BVH in parallel using the given thread pool.
static BVH_ALWAYS_INLINE Bvh< Node > build(ThreadPool &thread_pool, std::span< const BBox > bboxes, std::span< const Vec > centers, const Config &config={})
Starts building a BVH with the given primitive data.
static void optimize(ThreadPool &thread_pool, Bvh< Node > &bvh, const Config &config={})
Base class for all SAH-based, top-down builders.
Definition bbox.h:9
Definition bbox.h:9
#define BVH_ALWAYS_INLINE
Definition platform.h:19
Quality quality
The quality of the BVH produced by the builder.
size_t parallel_threshold
Threshold, in number of primitives, under which the builder operates in a single-thread.
Scalar pruning_area_ratio
Threshold on the area of a mini-tree node above which it is pruned, expressed in fraction of the area...
bool enable_pruning
Flag that turns on/off mini-tree pruning.
size_t parallel_threshold
Minimum number of primitives per parallel task.