opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
bvh_node.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6
7namespace osc
8{
9 // an inner/leaf node of a BVH
10 //
11 // has a spatial and hierarchical bounds, plus an index to a `BVHPrim`
12 class BVHNode final {
13 public:
14 static BVHNode leaf(const AABB& bounds, size_t first_prim_offset)
15 {
16 return BVHNode{bounds, first_prim_offset | c_leaf_mask};
17 }
18
19 static BVHNode node(const AABB& bounds, size_t num_lhs_children)
20 {
22 }
23
24 private:
25 BVHNode(const AABB& bounds, size_t data) :
26 bounds_{bounds},
27 data_{data}
28 {}
29 public:
30 const AABB& bounds() const
31 {
32 return bounds_;
33 }
34
35 bool is_leaf() const
36 {
37 return (data_ & c_leaf_mask) > 0;
38 }
39
40 bool is_node() const
41 {
42 return !is_leaf();
43 }
44
45 size_t num_lhs_nodes() const
46 {
47 return data_ & ~c_leaf_mask;
48 }
49
50 void set_num_lhs_nodes(size_t n)
51 {
52 data_ = n & ~c_leaf_mask;
53 }
54
55 size_t first_prim_offset() const
56 {
57 return data_ & ~c_leaf_mask;
58 }
59
60 private:
61 static inline constexpr size_t c_leaf_mask = 1uz << (8*sizeof(size_t) - 1);
62
63 // the union of all AABBs below, and including, this node
64 AABB bounds_{};
65
66 // bit-packed node data
67 size_t data_{};
68 };
69}
Definition bvh_node.h:12
bool is_leaf() const
Definition bvh_node.h:35
static BVHNode node(const AABB &bounds, size_t num_lhs_children)
Definition bvh_node.h:19
static BVHNode leaf(const AABB &bounds, size_t first_prim_offset)
Definition bvh_node.h:14
bool is_node() const
Definition bvh_node.h:40
size_t first_prim_offset() const
Definition bvh_node.h:55
void set_num_lhs_nodes(size_t n)
Definition bvh_node.h:50
size_t num_lhs_nodes() const
Definition bvh_node.h:45
const AABB & bounds() const
Definition bvh_node.h:30
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
Definition aabb.h:14