Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBinaryBvhNode.ipp
Go to the documentation of this file.
1#pragma once
2
4#include "Math/constant.h"
5
6namespace ph::math
7{
8
9template<typename Item, typename Index>
10inline auto TBinaryBvhNode<Item, Index>
11::makeInternal(
12 const AABB3D& nodeAABB,
13 const std::size_t childOffset,
14 const std::size_t splitAxis)
16{
17 static_assert(constant::X_AXIS == X_AXIS_FLAG);
18 static_assert(constant::Y_AXIS == Y_AXIS_FLAG);
19 static_assert(constant::Z_AXIS == Z_AXIS_FLAG);
20
21 PH_ASSERT_IN_RANGE_INCLUSIVE(splitAxis, 0, 2);
22
23 TBinaryBvhNode node;
24 node.m_aabb = nodeAABB;
25 node.u0_childOffset = lossless_cast<decltype(node.u0_childOffset)>(childOffset);
26 node.m_numItemsAndFlags = static_cast<uint8>(splitAxis);
27
28 return node;
29}
30
31template<typename Item, typename Index>
34 const AABB3D& nodeAABB,
35 const std::size_t itemOffset,
36 const std::size_t numItems)
38{
39 PH_ASSERT_LE(numItems, MAX_NODE_ITEMS);
40
41 TBinaryBvhNode node;
42 node.m_aabb = nodeAABB;
43 node.u0_itemOffset = lossless_cast<decltype(node.u0_itemOffset)>(itemOffset);
44 node.m_numItemsAndFlags = static_cast<uint8>((numItems << NUM_FLAG_BITS) | LEAF_FLAG);
45
46 return node;
47}
48
49template<typename Item, typename Index>
52 : m_aabb(AABB3D::makeEmpty())
53 , u0_itemOffset(static_cast<decltype(u0_itemOffset)>(-1))
54 , m_numItemsAndFlags(LEAF_FLAG)// leaf with 0 item
55{}
56
57template<typename Item, typename Index>
59::getAABB() const
60-> const AABB3D&
61{
62 return m_aabb;
63}
64
65template<typename Item, typename Index>
67::isLeaf() const
68{
69 return (m_numItemsAndFlags & FLAG_BITS_MASK) == LEAF_FLAG;
70}
71
72template<typename Item, typename Index>
75{
76 return !isLeaf();
77}
78
79template<typename Item, typename Index>
82-> std::size_t
83{
84 PH_ASSERT(isInternal());
85
86 return static_cast<std::size_t>(u0_childOffset);
87}
88
89template<typename Item, typename Index>
92-> std::size_t
93{
94 PH_ASSERT(isInternal());
95
96 return static_cast<std::size_t>(m_numItemsAndFlags & FLAG_BITS_MASK);
97}
98
99template<typename Item, typename Index>
102-> std::size_t
103{
104 PH_ASSERT(isLeaf());
105
106 return static_cast<std::size_t>(u0_itemOffset);
107}
108
109template<typename Item, typename Index>
112-> std::size_t
113{
114 PH_ASSERT(isLeaf());
115
116 return static_cast<std::size_t>(m_numItemsAndFlags >> NUM_FLAG_BITS);
117}
118
119}// end namespace ph::math
Definition TBinaryBvhNode.h:16
Index u0_itemOffset
Definition TBinaryBvhNode.h:60
Index u0_childOffset
Definition TBinaryBvhNode.h:59
constexpr std::size_t Y_AXIS
Definition constant.h:91
constexpr std::size_t Z_AXIS
Definition constant.h:92
constexpr std::size_t X_AXIS
Definition constant.h:90
Math functions and utilities.
Definition TransformInfo.h:10
Definition TAABB2D.h:96