RavEngine
Loading...
Searching...
No Matches
ExtOctreeTetrahedralizer.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29
30#ifndef EXT_OCTREE_TETRAHEDRALIZER_H
31#define EXT_OCTREE_TETRAHEDRALIZER_H
32
33#include "ExtMultiList.h"
34#include "ExtVec3.h"
35#include "foundation/PxVec3.h"
36#include "ExtInsideTester.h"
37
38namespace physx
39{
40 namespace Ext
41 {
42
43 class InsideTester;
44
45 // ------------------------------------------------------------------------------
46
48 {
49 public:
51
52 void clear();
53 void createTetMesh(const PxArray<PxVec3> &verts, const PxArray<PxU32> &triIds,
54 bool includeOctreeNodes = true, PxI32 maxVertsPerCell = 20, PxI32 maxTreeDepth = 5);
55
56 void readBack(PxArray<PxVec3> &tetVertices, PxArray<PxU32> &tetIndices);
57
58 private:
59 // input mesh
60
61 PxArray<PxVec3> surfaceVerts;
62 PxArray<PxI32> surfaceTriIds;
63
64 // octree
65
66 PxI32 maxVertsPerCell;
67 PxI32 maxTreeDepth;
68
69 struct Cell
70 {
71 void init()
72 {
73 firstChild = -1;
74 orig = Vec3(0.0, 0.0, 0.0);
75 size = 0.0;
76 numVerts = 0;
77 closestTetNr = -1;
78 depth = 0;
79 }
80
81 PxI32 getChildNr(const Vec3& p);
82
83 PX_FORCE_INLINE PxI32 getChildNr(const PxVec3& p)
84 {
85 return getChildNr(Vec3(p.x, p.y, p.z));
86 }
87
88 PxI32 firstChild;
89 PxI32 firstCellVert;
90 PxI32 firstCellTet;
91 Vec3 orig;
92 double size;
93 PxI32 numVerts;
94 PxI32 closestTetNr;
95 PxI32 depth;
96 };
97
98 PxArray<Cell> cells;
99 MultiList<PxI32> vertsOfCell;
100
101 // tet mesh
102
103 PxArray<Vec3> tetVerts;
104 PxArray<PxI32> tetIds;
105 PxArray<PxI32> tetNeighbors;
106 PxArray<PxI32> tetMarks;
107 PxI32 currentTetMark;
108 PxArray<PxI32> stack;
109 PxArray<PxI32> violatingTets;
110 PxI32 firstABBVert;
111
112 struct Edge
113 {
114
115 PxI32 id0, id1;
116 PxI32 faceNr, tetNr;
117
118 void init(PxI32 _id0, PxI32 _id1, PxI32 _tetNr, PxI32 _faceNr)
119 {
120 this->id0 = _id0 < _id1 ? _id0 : _id1;
121 this->id1 = _id0 > _id1 ? _id0 : _id1;
122 this->tetNr = _tetNr;
123 this->faceNr = _faceNr;
124 }
125
126 PX_FORCE_INLINE bool operator < (Edge e) const
127 {
128 if (id0 < e.id0) return true;
129 if (id0 > e.id0) return false;
130 return id1 < e.id1;
131 }
132
133 PX_FORCE_INLINE bool operator == (Edge e)
134 {
135 return id0 == e.id0 && id1 == e.id1;
136 }
137 };
138 PxArray<Edge> edges;
139
140 void clearTets();
141 void createTree();
142 void treeInsertVert(PxI32 cellNr, PxI32 vertNr);
143 void createTetVerts(bool includeOctreeNodes);
144
145 bool findSurroundingTet(const Vec3& p, PxI32 startTetNr, PxI32& tetNr);
146 bool findSurroundingTet(const Vec3& p, PxI32& tetNr);
147 void treeInsertTet(PxI32 tetNr);
148 void treeRemoveTet(PxI32 tetNr);
149
150 PxI32 firstFreeTet;
151 PxI32 getNewTetNr();
152 void removeTetNr(PxI32 tetNr);
153
154 Vec3 getTetCenter(PxI32 tetNr) const;
155 bool meshInsertTetVert(PxI32 vertNr);
156
157 InsideTester insideTester;
158 void pruneTets();
159
160 mutable float prevClip;
161 mutable float prevScale;
162 mutable PxArray<PxVec3> renderVerts;
163 mutable PxArray<PxVec3> renderNormals;
164 mutable PxArray<PxI32> renderTriIds;
165 };
166 }
167}
168
169#endif
Definition ExtInsideTester.h:48
Definition ExtMultiList.h:44
Definition ExtOctreeTetrahedralizer.h:48
Definition ExtVec3.h:39
Definition PxArray.h:53
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39