RavEngine
Loading...
Searching...
No Matches
GuAdjacencies.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#ifndef GU_ADJACENCIES_H
30#define GU_ADJACENCIES_H
31
32#define MSH_ADJACENCIES_INCLUDE_CONVEX_BITS
33#include "foundation/Px.h"
34#include "GuTriangle.h"
35#include "common/PxPhysXCommonConfig.h"
36
37namespace physx
38{
39namespace Gu
40{
41#ifdef MSH_ADJACENCIES_INCLUDE_CONVEX_BITS
42 #define ADJ_TRIREF_MASK 0x1fffffff
43 #define IS_CONVEX_EDGE(x) (x & 0x20000000)
44#else
45 #define ADJ_TRIREF_MASK 0x3fffffff
46#endif
47
48 #define MAKE_ADJ_TRI(x) (x & ADJ_TRIREF_MASK)
49 #define GET_EDGE_NB(x) (x>>30)
50// #define IS_BOUNDARY(x) (x==PX_INVALID_U32) //!< Returns true for boundary edges.
51 #define IS_BOUNDARY(x) ((x & ADJ_TRIREF_MASK)==ADJ_TRIREF_MASK)
52
53 // Forward declarations
54 class Adjacencies;
55
56 enum SharedEdgeIndex
57 {
58 EDGE01 = 0,
59 EDGE02 = 1,
60 EDGE12 = 2
61 };
62
63/* PX_INLINE void GetEdgeIndices(SharedEdgeIndex edge_index, PxU32& id0, PxU32& id1)
64 {
65 if(edge_index==0)
66 {
67 id0 = 0;
68 id1 = 1;
69 }
70 else if(edge_index==1)
71 {
72 id0 = 0;
73 id1 = 2;
74 }
75 else if(edge_index==2)
76 {
77 id0 = 1;
78 id1 = 2;
79 }
80 }*/
81
83 #define SET_EDGE_NB(link, code) \
84 link&=ADJ_TRIREF_MASK; \
85 link|=code<<30; \
86
89#ifdef MSH_ADJACENCIES_INCLUDE_TOPOLOGY
90 : public IndexedTriangle
91#else
92 : public PxUserAllocated
93#endif
94 {
95 public:
100
105 PxU32 ComputeNbBoundaryEdges() const;
106
111 PxU32 ComputeNbNeighbors() const;
112
119 bool HasNeighbor(PxU32 tref, PxU32* index=NULL) const;
120
124 void Flip();
125
126 // Data access
127 PX_INLINE PxU32 GetLink(SharedEdgeIndex edge_index) const { return mATri[edge_index]; }
128 PX_INLINE PxU32 GetAdjTri(SharedEdgeIndex edge_index) const { return MAKE_ADJ_TRI(mATri[edge_index]); }
129 PX_INLINE PxU32 GetAdjEdge(SharedEdgeIndex edge_index) const { return GET_EDGE_NB(mATri[edge_index]); }
130 PX_INLINE PxIntBool IsBoundaryEdge(SharedEdgeIndex edge_index) const { return IS_BOUNDARY(mATri[edge_index]); }
131#ifdef MSH_ADJACENCIES_INCLUDE_CONVEX_BITS
132 PX_INLINE PxIntBool HasActiveEdge01() const { return PxIntBool(IS_CONVEX_EDGE(mATri[EDGE01])); }
133 PX_INLINE PxIntBool HasActiveEdge20() const { return PxIntBool(IS_CONVEX_EDGE(mATri[EDGE02])); }
134 PX_INLINE PxIntBool HasActiveEdge12() const { return PxIntBool(IS_CONVEX_EDGE(mATri[EDGE12])); }
135 PX_INLINE PxIntBool HasActiveEdge(PxU32 i) const { return PxIntBool(IS_CONVEX_EDGE(mATri[i])); }
136#endif
137// private:
142 PxU32 mATri[3];
143 };
144
147 {
150 {
151#ifdef MSH_ADJACENCIES_INCLUDE_CONVEX_BITS
152 Verts = NULL;
153 Epsilon = 0.1f;
154// Epsilon = 0.001f;
155#endif
156 }
157
158 PxU32 NbFaces;
159 const PxU32* DFaces;
160 const PxU16* WFaces;
161#ifdef MSH_ADJACENCIES_INCLUDE_CONVEX_BITS
162 const PxVec3* Verts;
163 float Epsilon;
164#endif
165 };
166
168 {
169 public:
170 Adjacencies();
171 ~Adjacencies();
172
173 PxU32 mNbFaces;
175
176 bool Load(PxInputStream& stream);
177 // Basic mesh walking
178 PX_INLINE const AdjTriangle* GetAdjacentFace(const AdjTriangle& current_tri, SharedEdgeIndex edge_nb) const
179 {
180 // No checkings here, make sure mFaces has been created
181
182 // Catch the link
183 PxU32 Link = current_tri.GetLink(edge_nb);
184
185 // Returns NULL for boundary edges
186 if(IS_BOUNDARY(Link)) return NULL;
187
188 // Else transform into face index
189 PxU32 Id = MAKE_ADJ_TRI(Link);
190
191 // Possible counterpart edge is:
192 // PxU32 Edge = GET_EDGE_NB(Link);
193
194 // And returns adjacent triangle
195 return &mFaces[Id];
196 }
197 // Helpers
198 PxU32 ComputeNbBoundaryEdges() const;
199#ifdef MSH_ADJACENCIES_INCLUDE_TOPOLOGY
200 bool GetBoundaryVertices(PxU32 nb_verts, bool* bound_status) const;
201#else
202 bool GetBoundaryVertices(PxU32 nb_verts, bool* bound_status, const IndexedTriangle32* faces) const;
203#endif
204 //
205#ifdef MSH_ADJACENCIES_INCLUDE_TOPOLOGY
206 bool MakeLastRef(AdjTriangle& cur_tri, PxU32 vref);
207#else
208 bool MakeLastRef(AdjTriangle& cur_tri, PxU32 vref, IndexedTriangle32* cur_topo);
209#endif
210 private:
211 // New edge codes assignment
212 void AssignNewEdgeCode(PxU32 link, PxU8 edge_nb);
213 };
214
215//#ifdef PX_COOKING
217 {
218 public:
221
222 bool Init(const ADJACENCIESCREATE& create);
223// bool Save(Stream& stream) const;
224 };
225//#endif
226}
227}
228
229#endif
A triangle class used to compute the adjacency structures.
Definition GuAdjacencies.h:94
PxU32 ComputeNbBoundaryEdges() const
Definition GuAdjacencies.cpp:65
PxU32 ComputeNbNeighbors() const
Definition GuAdjacencies.cpp:79
PX_INLINE ~AdjTriangle()
Destructor.
Definition GuAdjacencies.h:99
bool HasNeighbor(PxU32 tref, PxU32 *index=NULL) const
Definition GuAdjacencies.cpp:94
void Flip()
Definition GuAdjacencies.cpp:50
PxU32 mATri[3]
Definition GuAdjacencies.h:142
PX_INLINE AdjTriangle()
Constructor.
Definition GuAdjacencies.h:97
Definition GuAdjacencies.h:217
bool Init(const ADJACENCIESCREATE &create)
Definition GuAdjacencies.cpp:568
Definition GuAdjacencies.h:168
PxU32 mNbFaces
Number of faces involved in the computation.
Definition GuAdjacencies.h:173
PxU32 ComputeNbBoundaryEdges() const
Definition GuAdjacencies.cpp:116
bool MakeLastRef(AdjTriangle &cur_tri, PxU32 vref, IndexedTriangle32 *cur_topo)
Definition GuAdjacencies.cpp:227
AdjTriangle * mFaces
A list of AdjTriangles (one/face)
Definition GuAdjacencies.h:174
bool GetBoundaryVertices(PxU32 nb_verts, bool *bound_status, const IndexedTriangle32 *faces) const
Definition GuAdjacencies.cpp:140
Input stream class for I/O.
Definition PxIO.h:50
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
The adjacencies creation structure.
Definition GuAdjacencies.h:147
PxU32 NbFaces
Number of faces in source topo.
Definition GuAdjacencies.h:158
ADJACENCIESCREATE()
Constructor.
Definition GuAdjacencies.h:149
const PxU16 * WFaces
List of faces (words) or NULL.
Definition GuAdjacencies.h:160
const PxU32 * DFaces
List of faces (dwords) or NULL.
Definition GuAdjacencies.h:159
Definition GuTriangle.h:48