Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
KdtreeNode.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/primitive_type.h>
6
7#include <memory>
8#include <vector>
9
10namespace ph
11{
12
13class Intersectable;
14class HitProbe;
15
16class KdtreeNode final
17{
18public:
19 KdtreeNode(std::vector<const Intersectable*>* intersectableBuffer);
20
21 void buildTree(const std::vector<const Intersectable*>& intersectables);
22 bool findClosestIntersection(const Ray& ray, HitProbe& probe) const;
23 KdtreeAABB getAABB() const;
24
25private:
26 std::unique_ptr<KdtreeNode> m_positiveChild;
27 std::unique_ptr<KdtreeNode> m_negativeChild;
28
29 std::vector<const Intersectable*>* m_intersectableBuffer;
30 KdtreeAABB m_aabb;
31
32 int32 m_splitAxis;
33 real m_splitPos;
34 std::size_t m_nodeBufferStartIndex;
35 std::size_t m_nodeBufferEndIndex;
36
37 void buildChildrenNodes(const std::vector<const Intersectable*>& intersectables);
38 std::unique_ptr<KdtreeNode> buildChildNode(const KdtreeAABB& childAABB,
39 const std::vector<const Intersectable*>& parentIntersectables);
40 bool traverseAndFindClosestIntersection(const Ray& ray, HitProbe& probe,
41 real rayDistMin, real rayDistMax) const;
42 void analyzeSplitCostSAH(const std::vector<const Intersectable*>& intersectables, int32 axis,
43 float64* out_minCost, real* out_splitPoint) const;
44 bool isLeaf() const;
45
46private:
47 static constexpr float64 COST_TRAVERSAL = 1.0;
48 static constexpr float64 COST_INTERSECTION = 1.0;
49};
50
51// In-header Implementations:
52
54{
55 return m_aabb;
56}
57
58}// end namespace ph
Lightweight ray intersection testing and reporting object. If an intersection is found,...
Definition HitProbe.h:27
Definition KdtreeAABB.h:15
Definition KdtreeNode.h:17
KdtreeAABB getAABB() const
Definition KdtreeNode.h:53
void buildTree(const std::vector< const Intersectable * > &intersectables)
Definition KdtreeNode.cpp:62
KdtreeNode(std::vector< const Intersectable * > *intersectableBuffer)
Definition KdtreeNode.cpp:46
bool findClosestIntersection(const Ray &ray, HitProbe &probe) const
Definition KdtreeNode.cpp:80
Represents a ray in space.
Definition Ray.h:21
The root for all renderer implementations.
Definition EEngineProject.h:6