Debian Codegraph @

thirdparty/jolt_physics/Jolt/TriangleSplitter/TriangleSplitter.h

raw symbols SCIP
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
7 #include <Jolt/Geometry/IndexedTriangle.h>
8 #include <Jolt/Core/NonCopyable.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 /// A class that splits a triangle list into two parts for building a tree
13 class JPH_EXPORT TriangleSplitter : public NonCopyable
14 {
15 public:
16 /// Constructor
17 TriangleSplitter(const VertexList &inVertices, const IndexedTriangleList &inTriangles);
18
19 /// Virtual destructor
20 virtual ~TriangleSplitter() = default;
21
22 struct Stats
23 {
24 const char * mSplitterName = nullptr;
25 int mLeafSize = 0;
26 };
27
28 /// Get stats of splitter
29 virtual void GetStats(Stats &outStats) const = 0;
30
31 /// Helper struct to indicate triangle range before and after the split
32 struct Range
33 {
34 /// Constructor
35 Range() = default;
36 Range(uint inBegin, uint inEnd) : mBegin(inBegin), mEnd(inEnd) { }
37
38 /// Get number of triangles in range
39 uint Count() const
40 {
41 return mEnd - mBegin;
42 }
43
44 /// Start and end index (end = 1 beyond end)
45 uint mBegin;
46 uint mEnd;
47 };
48
49 /// Range of triangles to start with
50 Range GetInitialRange() const
51 {
52 return Range(0, (uint)mSortedTriangleIdx.size());
53 }
54
55 /// Split triangles into two groups left and right, returns false if no split could be made
56 /// @param inTriangles The range of triangles (in mSortedTriangleIdx) to process
57 /// @param outLeft On return this will contain the ranges for the left subpart. mSortedTriangleIdx may have been shuffled.
58 /// @param outRight On return this will contain the ranges for the right subpart. mSortedTriangleIdx may have been shuffled.
59 /// @return Returns true when a split was found
60 virtual bool Split(const Range &inTriangles, Range &outLeft, Range &outRight) = 0;
61
62 /// Get the list of vertices
63 const VertexList & GetVertices() const
64 {
65 return mVertices;
66 }
67
68 /// Get triangle by index
69 const IndexedTriangle & GetTriangle(uint inIdx) const
70 {
71 return mTriangles[mSortedTriangleIdx[inIdx]];
72 }
73
74 protected:
75 /// Helper function to split triangles based on dimension and split value
76 bool SplitInternal(const Range &inTriangles, uint inDimension, float inSplit, Range &outLeft, Range &outRight);
77
78 const VertexList & mVertices; ///< Vertices of the indexed triangles
79 const IndexedTriangleList & mTriangles; ///< Unsorted triangles
80 Array<Float3> mCentroids; ///< Unsorted centroids of triangles
81 Array<uint> mSortedTriangleIdx; ///< Indices to sort triangles
82 };
83
84 JPH_NAMESPACE_END