Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
AABBTreeBuilder.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
10
12
14{
17
19 float mSAHCost = 0.0f;
20 int mMinDepth = 0;
21 int mMaxDepth = 0;
22 int mNodeCount = 0;
24
27
32};
33
36{
37public:
39 class Node : public NonCopyable
40 {
41 public:
43
45 Node();
46 ~Node();
47
49 inline uint GetTriangleCount() const { return uint(mTriangles.size()); }
50
52 inline bool HasChildren() const { return mChild[0] != nullptr || mChild[1] != nullptr; }
53
55 uint GetMinDepth() const;
56
58 uint GetMaxDepth() const;
59
61 uint GetNodeCount() const;
62
64 uint GetLeafNodeCount() const;
65
68
70 void GetTriangleCountPerNode(float &outAverage, uint &outMin, uint &outMax) const;
71
73 float CalculateSAHCost(float inCostTraversal, float inCostLeaf) const;
74
76 void GetNChildren(uint inN, Array<const Node *> &outChildren) const;
77
80
83
86
87 private:
88 friend class AABBTreeBuilder;
89
91 float CalculateSAHCostInternal(float inCostTraversalDivSurfaceArea, float inCostLeafDivSurfaceArea) const;
92
94 void GetTriangleCountPerNodeInternal(float &outAverage, uint &outAverageDivisor, uint &outMin, uint &outMax) const;
95 };
96
98 AABBTreeBuilder(TriangleSplitter &inSplitter, uint inMaxTrianglesPerLeaf = 16);
99
101 Node * Build(AABBTreeBuilderStats &outStats);
102
103private:
104 Node * BuildInternal(const TriangleSplitter::Range &inTriangles);
105
106 TriangleSplitter & mTriangleSplitter;
107 const uint mMaxTrianglesPerLeaf;
108};
109
unsigned int uint
Definition: Core.h:309
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
Array< IndexedTriangle > IndexedTriangleList
Definition: IndexedTriangle.h:105
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
A node in the tree, contains the AABox for the tree and any child nodes or triangles.
Definition: AABBTreeBuilder.h:40
void GetTriangleCountPerNode(float &outAverage, uint &outMin, uint &outMax) const
Calculate min and max triangles per node.
Definition: AABBTreeBuilder.cpp:71
uint GetMinDepth() const
Min depth of tree.
Definition: AABBTreeBuilder.cpp:23
uint GetLeafNodeCount() const
Number of leaf nodes in tree.
Definition: AABBTreeBuilder.cpp:55
AABox mBounds
Bounding box.
Definition: AABBTreeBuilder.h:79
IndexedTriangleList mTriangles
Triangles (if no child nodes)
Definition: AABBTreeBuilder.h:82
void GetNChildren(uint inN, Array< const Node * > &outChildren) const
Recursively get children (breadth first) to get in total inN children (or less if there are no more)
Definition: AABBTreeBuilder.cpp:88
JPH_OVERRIDE_NEW_DELETE Node()
Constructor.
Definition: AABBTreeBuilder.cpp:11
uint GetTriangleCount() const
Get number of triangles in this node.
Definition: AABBTreeBuilder.h:49
~Node()
Definition: AABBTreeBuilder.cpp:17
uint GetTriangleCountInTree() const
Get triangle count in tree.
Definition: AABBTreeBuilder.cpp:63
Node * mChild[2]
Child nodes (if no triangles)
Definition: AABBTreeBuilder.h:85
bool HasChildren() const
Check if this node has any children.
Definition: AABBTreeBuilder.h:52
uint GetNodeCount() const
Number of nodes in tree.
Definition: AABBTreeBuilder.cpp:47
uint GetMaxDepth() const
Max depth of tree.
Definition: AABBTreeBuilder.cpp:35
float CalculateSAHCost(float inCostTraversal, float inCostLeaf) const
Calculate the total cost of the tree using the surface area heuristic.
Definition: AABBTreeBuilder.cpp:82
Helper class to build an AABB tree.
Definition: AABBTreeBuilder.h:36
Node * Build(AABBTreeBuilderStats &outStats)
Recursively build tree, returns the root node of the tree.
Definition: AABBTreeBuilder.cpp:162
Axis aligned box.
Definition: AABox.h:16
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
A class that splits a triangle list into two parts for building a tree.
Definition: TriangleSplitter.h:13
Definition: AABBTreeBuilder.h:14
int mTreeMinTrianglesPerLeaf
Minimal amount of triangles in a leaf.
Definition: AABBTreeBuilder.h:29
float mSAHCost
Surface Area Heuristic cost of this tree.
Definition: AABBTreeBuilder.h:19
int mMaxTrianglesPerLeaf
Configured max triangles per leaf.
Definition: AABBTreeBuilder.h:26
int mMaxDepth
Maximum depth of tree (number of nodes)
Definition: AABBTreeBuilder.h:21
int mLeafNodeCount
Number of leaf nodes (that contain triangles)
Definition: AABBTreeBuilder.h:23
float mTreeAvgTrianglesPerLeaf
Average amount of triangles in leaf nodes.
Definition: AABBTreeBuilder.h:31
int mMinDepth
Minimal depth of tree (number of nodes)
Definition: AABBTreeBuilder.h:20
TriangleSplitter::Stats mSplitterStats
Stats returned by the triangle splitter algorithm.
Definition: AABBTreeBuilder.h:16
int mNodeCount
Number of nodes in the tree.
Definition: AABBTreeBuilder.h:22
int mTreeMaxTrianglesPerLeaf
Maximal amount of triangles in a leaf.
Definition: AABBTreeBuilder.h:30
Helper struct to indicate triangle range before and after the split.
Definition: TriangleSplitter.h:32
Definition: TriangleSplitter.h:22