Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBvhInfoNode.ipp
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
5
6#include <Common/assertion.h>
7#include <Common/utility.h>
8
9namespace ph::math
10{
11
12template<std::size_t N, typename Item>
13inline auto TBvhInfoNode<N, Item>
14::makeInternal(
15 const std::array<const TBvhInfoNode*, N>& children,
16 const std::size_t singleSplitAxis)
18{
19 PH_ASSERT_LT(singleSplitAxis, NO_AXIS_FLAG);
20
21 const auto splitAxis = lossless_cast<uint8>(singleSplitAxis);
22
23 TBvhInfoNode internalNode{};
24 internalNode.m_children = children;
25 internalNode.m_singleSplitAxis = splitAxis;
26 internalNode.m_isLeaf = false;
27
28 for(std::size_t ci = 0; ci < children.size(); ++ci)
29 {
30 if(children[ci])
31 {
32 internalNode.m_aabb.unionWith(children[ci]->getAABB());
33 }
34
35 internalNode.m_perChildFlags[ci].splitAxis = splitAxis;
36 }
37
38 return internalNode;
39}
40
41template<std::size_t N, typename Item>
42inline auto TBvhInfoNode<N, Item>
45 const AABB3D& leafAabb)
47{
48 TBvhInfoNode leafNode{};
49 leafNode.m_items = leafItems;
50 leafNode.m_aabb = leafAabb;
51 leafNode.m_isLeaf = true;
52
53 return leafNode;
54}
55
56template<std::size_t N, typename Item>
57inline constexpr bool TBvhInfoNode<N, Item>
59{
60 return numChildren() == 2;
61}
62
63template<std::size_t N, typename Item>
64inline constexpr auto TBvhInfoNode<N, Item>
66-> std::size_t
67{
68 return N;
69}
70
71template<std::size_t N, typename Item>
72inline constexpr auto TBvhInfoNode<N, Item>
74-> std::size_t
75{
76 return NO_AXIS_FLAG;
77}
78
79template<std::size_t N, typename Item>
81 : m_children{}
82 , m_items{}
83 , m_aabb(AABB3D::makeEmpty())
84 , m_perChildFlags{}
85 , m_singleSplitAxis(NO_AXIS_FLAG)
86 , m_isLeaf(true)
87{}
88
89template<std::size_t N, typename Item>
91{
92 if constexpr(!isBinary())
93 {
94 return false;
95 }
96
97 return isLeaf();
98}
99
100template<std::size_t N, typename Item>
101inline bool TBvhInfoNode<N, Item>
103{
104 if constexpr(!isBinary())
105 {
106 return false;
107 }
108
109 return !isLeaf();
110}
111
112template<std::size_t N, typename Item>
114{
115 return m_isLeaf;
116}
117
118template<std::size_t N, typename Item>
119inline bool TBvhInfoNode<N, Item>
121{
122 return !isLeaf();
123}
124
125template<std::size_t N, typename Item>
126inline auto TBvhInfoNode<N, Item>
127::getChild(const std::size_t childIdx) const
128-> const TBvhInfoNode*
129{
130 PH_ASSERT_LT(childIdx, m_children.size());
131
132 return m_children[childIdx];
133}
134
135template<std::size_t N, typename Item>
136inline auto TBvhInfoNode<N, Item>
139{
140 return m_items;
141}
142
143template<std::size_t N, typename Item>
144inline auto TBvhInfoNode<N, Item>
146-> const AABB3D&
147{
148 return m_aabb;
149}
150
151template<std::size_t N, typename Item>
152inline auto TBvhInfoNode<N, Item>
154-> std::size_t
155{
156 PH_ASSERT(isInternal());
157 PH_ASSERT(isSingleSplitAxis());
158
159 return m_singleSplitAxis;
160}
161
162template<std::size_t N, typename Item>
163inline auto TBvhInfoNode<N, Item>
164::getSplitAxis(const std::size_t childIdx) const
165-> std::size_t
166{
167 PH_ASSERT(isInternal());
168 PH_ASSERT_LT(childIdx, m_perChildFlags.size());
169
170 return m_perChildFlags[childIdx].splitAxis;
171}
172
173template<std::size_t N, typename Item>
174inline bool TBvhInfoNode<N, Item>
176{
177 PH_ASSERT(isInternal());
178
179 return m_singleSplitAxis != NO_AXIS_FLAG;
180}
181
182}// end namespace ph::math
General BVH node packed with additional information. This node type is typically used for building ot...
Definition TLinearDepthFirstWideBvh.h:21
bool isBinaryLeaf() const
Definition TBvhInfoNode.ipp:90
TBvhInfoNode()
Definition TBvhInfoNode.ipp:80
bool isLeaf() const
Definition TBvhInfoNode.ipp:113
Definition TBvhItemInfo.h:11
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19
Definition TAABB2D.h:96