Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBinaryBvhNode.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/primitive_type.h>
6#include <Common/utility.h>
7
8#include <cstddef>
9#include <type_traits>
10
11namespace ph::math
12{
13
14template<typename Item, typename Index>
15class TBinaryBvhNode final
16{
17 static_assert(std::is_unsigned_v<Index>);
18
19 inline static constexpr std::size_t NUM_FLAG_BITS = 2;
20 inline static constexpr std::size_t NUM_ITEMS_BITS = sizeof_in_bits<uint8>() - NUM_FLAG_BITS;
21
22 inline static constexpr uint8 FLAG_BITS_MASK = 0b11;
23 inline static constexpr uint8 X_AXIS_FLAG = 0b00;
24 inline static constexpr uint8 Y_AXIS_FLAG = 0b01;
25 inline static constexpr uint8 Z_AXIS_FLAG = 0b10;
26 inline static constexpr uint8 LEAF_FLAG = 0b11;
27
28public:
30 inline static constexpr std::size_t MAX_NODE_ITEMS = (std::size_t(1) << NUM_ITEMS_BITS) - 1;
31
32 static auto makeInternal(
33 const AABB3D& nodeAABB,
34 std::size_t childOffset,
35 std::size_t splitAxis)
37
38 static auto makeLeaf(
39 const AABB3D& nodeAABB,
40 std::size_t itemOffset,
41 std::size_t numItems)
43
45
46 const AABB3D& getAABB() const;
47 bool isLeaf() const;
48 bool isInternal() const;
49 std::size_t getChildOffset() const;
50 std::size_t getSplitAxis() const;
51 std::size_t getItemOffset() const;
52 std::size_t numItems() const;
53
54private:
55 AABB3D m_aabb;
56
57 union
58 {
59 Index u0_childOffset;// for internal
60 Index u0_itemOffset; // for leaf
61 };
62
75 uint8 m_numItemsAndFlags;
76};
77
78}// end namespace ph::math
79
Definition TBinaryBvhNode.h:16
static constexpr std::size_t MAX_NODE_ITEMS
Definition TBinaryBvhNode.h:30
static auto makeInternal(const AABB3D &nodeAABB, std::size_t childOffset, std::size_t splitAxis) -> TBinaryBvhNode
Definition TBinaryBvhNode.ipp:11
std::size_t getSplitAxis() const
Definition TBinaryBvhNode.ipp:91
std::size_t getChildOffset() const
Definition TBinaryBvhNode.ipp:81
bool isInternal() const
Definition TBinaryBvhNode.ipp:74
static auto makeLeaf(const AABB3D &nodeAABB, std::size_t itemOffset, std::size_t numItems) -> TBinaryBvhNode
Definition TBinaryBvhNode.ipp:33
Index u0_itemOffset
Definition TBinaryBvhNode.h:60
bool isLeaf() const
Definition TBinaryBvhNode.ipp:67
std::size_t getItemOffset() const
Definition TBinaryBvhNode.ipp:101
TBinaryBvhNode()
Definition TBinaryBvhNode.ipp:51
Index u0_childOffset
Definition TBinaryBvhNode.h:59
std::size_t numItems() const
Definition TBinaryBvhNode.ipp:111
const AABB3D & getAABB() const
Definition TBinaryBvhNode.ipp:59
Math functions and utilities.
Definition TransformInfo.h:10