HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_TetConnectivity.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU Library.
7  *
8  * COMMENTS: This file contains useful tetrahedra-connectivity and
9  * surface related methods.
10  *
11  */
12 #ifndef __GU_TetConnectivity_h__
13 #define __GU_TetConnectivity_h__
14 
15 #include "GU_API.h"
16 #include "GU_Detail.h"
17 #include "GU_PrimTetrahedron.h"
18 #include <GA/GA_AttributeFilter.h>
19 #include <GA/GA_AttributeDict.h>
20 #include <GA/GA_AttributeSet.h>
21 #include <GA/GA_AIFCopyData.h>
22 #include <GA/GA_AIFMerge.h>
23 #include <GA/GA_MergeMap.h>
24 #include <GA/GA_MergeOptions.h>
25 #include <GA/GA_Types.h>
26 #include <GA/GA_ElementWrangler.h>
27 
28 //
29 // GU_AdjacentTetrahedra represents a tetrahedron
30 // and the at most 4 tetrahedra that are adjacent to it
31 //
33 {
34 public:
36  {
37  myPrimitiveIndex = GA_INVALID_INDEX;
38 
39  for(int excluded_vertex = 0; excluded_vertex != 4; ++excluded_vertex)
40  {
41  myNeighborForExcludedVertex[excluded_vertex] = GA_INVALID_INDEX;
42  }
43  }
44 
45  void setPrimitiveIndex(const GA_Index primitive_index)
46  {
47  UT_ASSERT( primitive_index >= 0 );
48 
49  myPrimitiveIndex = primitive_index;
50  }
51 
52  // Assign the neighbor's primitive index for a facet
53  // The facet is identified by the vertex that's excluded from it
54  // "neighbor" must be a valid primitive index.
56  const int excluded_vertex,
57  const GA_Index neighbor
58  )
59  {
60  UT_ASSERT( (0 <= excluded_vertex) && (excluded_vertex < 4) );
61  UT_ASSERT( neighbor != GA_INVALID_INDEX );
62  UT_ASSERT( neighbor != myPrimitiveIndex );
63 
64  myNeighborForExcludedVertex[excluded_vertex] = neighbor;
65  }
66 
67  void removeNeighbor(const int excluded_vertex)
68  {
69  UT_ASSERT( (0 <= excluded_vertex) && (excluded_vertex < 4) );
70  myNeighborForExcludedVertex[excluded_vertex] = GA_INVALID_INDEX;
71  }
72 
74  {
75  return myPrimitiveIndex;
76  }
77 
78  // Return the primitive index of the neighbor tetrahedron
79  // along the facet that's opposite to "excluded_vertex"
80  // If there is no neighbor at that facet, then return GA_INVALID_INDEX
81  GA_Index neighbor(const int excluded_vertex) const
82  {
83  UT_ASSERT( (0 <= excluded_vertex) && (excluded_vertex < 4) );
84 
85  return myNeighborForExcludedVertex[excluded_vertex];
86  }
87 
88  // Return whether this tetrahedron has at least one face with
89  // no adjacent tetrahedron
90  bool isBoundaryTet() const
91  {
92  for(int excluded_vertex = 0; excluded_vertex != 4; ++excluded_vertex)
93  {
94  if( myNeighborForExcludedVertex[excluded_vertex] == GA_INVALID_INDEX )
95  return true;
96  }
97  return false;
98  }
99 
100 private:
101  // The index into the detail's list of primitives
102  // NOTE: some of the detail's primitives may not be tetrahedrons
103  GA_Index myPrimitiveIndex;
104 
105  // For each excluded vertex, store the neighbors for the
106  // facet that opposes it.
107  // Note that at most one valid adjacent tetrahedron is stored
108  // for each facet.
109  // If there is no neighbor, then GA_INVALID_INDEX is stored.
110  // Any additional adjacent tetrahedrons are discarded.
111  GA_Index myNeighborForExcludedVertex[4];
112 };
113 
114 // This class is used when constructing the list of adjacent tetrahedra
115 //
116 // A structure containing 3 point indices and a primitive index
117 // representing the boundary triangle of a tetrahedron
118 //
119 // Note: the point indices must be in increasing order
120 //
122 {
123  // Sorted list of point indices for tetrahedron face
125 
126  // Primitive index for the tetrahedron
128 
129  // The single tet vertex not included in the facet
130  // A number between 0 and 3
132 
133  // PRE: pids is sorted
135  const GA_Index pids[3],
136  const GA_Index primitive_index,
137  const int excluded_vertex
138  )
139  {
140  UT_ASSERT( pids[0] < pids[1] );
141  UT_ASSERT( pids[1] < pids[2] );
142 
143  myPS[0] = pids[0];
144  myPS[1] = pids[1];
145  myPS[2] = pids[2];
146 
147  myPrimitiveIndex = primitive_index;
148  myExcludedVertex = excluded_vertex;
149  }
150 
151 private:
152  // Disallow
154 };
155 
156 // Order first by point triple, second by primitive index
157 // When you sort using this order, all tetrahedrons that
158 // share a designated facet will be contiguous
159 inline bool operator< (
160  const GU_TetrahedronFacet& a,
161  const GU_TetrahedronFacet& b
162 )
163 {
164  for( int id = 0; id != 3; ++id )
165  {
166  if( a.myPS[id] < b.myPS[id] )
167  return true;
168 
169  if( a.myPS[id] > b.myPS[id] )
170  return false;
171  }
172 
174  return true;
175 
177  return false;
178 
179  return false; // these are equal
180 }
181 
182 // Determine whether two tetrahedron facets are equal
183 // NOTE: This does not mean that the tetrahedra themselves are equal
184 inline bool GUhaveSameFacet(
185  const GU_TetrahedronFacet& a,
186  const GU_TetrahedronFacet& b
187 )
188 {
189  for( int id = 0; id != 3; ++id )
190  if( a.myPS[id] != b.myPS[id] )
191  return false;
192 
193  return true;
194 }
195 
197 {
198 public:
199  GU_TetrahedronAdjacency(const GU_Detail& detail);
200 
202  GA_Index prim_index) const
203  {
204  UT_ASSERT_P(GAisValid(prim_index) && prim_index < GA_Index(adjacent_tetrahedra.size()));
205  return adjacent_tetrahedra[prim_index];
206  }
207 
209  {
210  return tetrahedra_connections_with_more_than_two_tetrahedra;
211  }
212 
213  const std::vector<GU_AdjacentTetrahedra> &raw() const
214  {
215  return adjacent_tetrahedra;
216  }
217 
218 private:
219  std::vector< GU_AdjacentTetrahedra > adjacent_tetrahedra;
220  int tetrahedra_connections_with_more_than_two_tetrahedra;
221 };
222 
223 ////////////////////////////////////////////////////////////////////
224 // Useful tetrahedron-related functions
225 
226 
227 //
228 // Create a triangle for each tet face that lies on the boundary of the tet mesh// Try to copy the proper vertex and primitive information over.
229 // Because a single tetrahedron may contribute multiple boundary triangles,
230 // it is possible that there are multiple triangle vertices for
231 // a single tet vertex.
232 //
233 // Requires gdp and src_gdp to be different.
234 //
236  GU_Detail& gdp,
237  const GU_Detail& src_gdp,
238 
239  bool keepprimitives=false,
240  bool keeppoints=false,
241 
242  bool buildpolysoup=false
243 );
244 
245 #endif
bool GAisValid(GA_Size v)
Definition: GA_Types.h:649
bool GUhaveSameFacet(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
const GU_AdjacentTetrahedra & getAdjacentTetrahedraForPrimitive(GA_Index prim_index) const
GU_TetrahedronFacet(const GA_Index pids[3], const GA_Index primitive_index, const int excluded_vertex)
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
void setPrimitiveIndex(const GA_Index primitive_index)
GLuint id
Definition: glcorearb.h:655
const std::vector< GU_AdjacentTetrahedra > & raw() const
#define GU_API
Definition: GU_API.h:14
void removeNeighbor(const int excluded_vertex)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:635
GU_API bool GUgetTetSurface(GU_Detail &gdp, const GU_Detail &src_gdp, bool keepprimitives=false, bool keeppoints=false, bool buildpolysoup=false)
int myNumTetConnectionsWithMoreThanTwoTets() const
#define GA_INVALID_INDEX
Definition: GA_Types.h:677
GA_Index neighbor(const int excluded_vertex) const
void setNeighbor(const int excluded_vertex, const GA_Index neighbor)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GA_Index getPrimitiveIndex() const