HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PathHedge.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_PathHedge.C
7  *
8  * COMMENTS:
9  */
10 
11 
12 #ifndef __GU_PathHedge_h__
13 #define __GU_PathHedge_h__
14 
15 #include "GU_API.h"
16 #include "GU_Detail.h"
17 #include <GEO/GEO_Hedge.h>
18 #include <GEO/GEO_Primitive.h>
19 #include <GA/GA_Edge.h>
20 #include <GA/GA_Types.h>
21 
22 #include <UT/UT_Array.h>
23 #include <UT/UT_Assert.h>
24 #include <UT/UT_BitArray.h>
25 #include <UT/UT_Function.h>
26 #include <UT/UT_Map.h>
27 #include <UT/UT_Vector3.h>
28 
29 #include <SYS/SYS_Hash.h>
30 #include <SYS/SYS_Inline.h>
31 #include <SYS/SYS_Types.h>
32 
33 #include <stddef.h>
34 
35 class GU_PathSHedge;
36 class GA_Primitive;
37 class GA_PrimitiveGroup;
38 
40  public:
42  : myV0{v0},
43  myV1{v1}
44  {}
45 
47 
49  {
50  return GEO_Hedge(myV0);
51  }
52 
54  {
55  return myV0;
56  }
57 
59  {
60  return myV1;
61  }
62 
64  {
65  return GAisValid(myV0) && GAisValid(myV1);
66  }
67 
68  SYS_FORCE_INLINE bool operator==(const GU_PathHedge & other) const
69  {
70  return myV0 == other.myV0
71  && myV1 == other.myV1;
72  }
73  SYS_FORCE_INLINE bool operator!=(const GU_PathHedge & other) const
74  {
75  return !(*this == other);
76  }
77 
79  {
80  myV0 = new_v0;
81  myV1 = new_v1;
82  return *this;
83  }
84 
86  {
87  myV0 = GA_INVALID_OFFSET;
88  myV1 = GA_INVALID_OFFSET;
89  return *this;
90  }
91 
92  //The same hash that GA_Edge uses
93  SYS_FORCE_INLINE size_t hash() const
94  {
95  size_t hash_val = GA_Size(myV0);
96  SYShashCombine(hash_val, GA_Size(myV1));
97  return hash_val;
98  }
99 private:
100  GA_Offset myV0;
101  GA_Offset myV1;
102 
103 public:
105  {
106  public:
107  Interface(const GU_Detail & gdp,
108  const GA_PrimitiveGroup * prim_group = nullptr,
109  bool exclude_prims = true);
110 
111  //Get the first Hedge using this vertex
112  void fromVertex(GU_PathHedge & out, GA_Offset vtx);
113 
114  //Get the next/prev hedge on this poly
115  //These are the next or previous hedge on the polygon
116  void lnext(GU_PathHedge & out, const GU_PathHedge & hedge);
117  void lprev(GU_PathHedge & out, const GU_PathHedge & hedge);
118 
119  //Get the Hedge on this poly with the lowest vtx offset
120  void primaryLNext(GU_PathHedge & out, const GU_PathHedge & hedge);
121 
122  //Go through all the equivalent hedges, hedges are equivalent if the end points
123  //are equal
124  void iterEquivalentHedges(
125  GA_Offset p0, GA_Offset p1,
126  const UT_Function<bool(const GU_PathHedge &)> & fn);
127 
128  void iterEquivalentHedges(
129  const GU_PathHedge & hedge,
130  const UT_Function<bool(const GU_PathHedge &)> & fn);
131 
132  //Return the first hedge found with the given end points.
134 
135  //Get the next hedge that is equivalent.
136  //The order is the order specified by iterEquivalentHedges
137  GU_PathHedge nextEquivalentHedge(const GU_PathHedge & hedge);
138  //alias for nextequivalenthedge
140  {
141  return nextEquivalentHedge(hedge);
142  }
143 
144  //find first equivalent hedge
145  GU_PathHedge primary(const GU_PathHedge & e);
146  GU_PathSHedge primary(const GU_PathSHedge & e);
147 
148  //Go through hedges incident with this point (one of points on hedge is pt)
149  void iterIncidentHedges(GA_Offset pt,
150  const UT_Function<bool(const GU_PathHedge &)> &fn);
151 
153 
154  //Similar to iterIncidentHedges but only considers each edge once
155  void iterIncidentEdges(GA_Offset pt,
156  const UT_Function<bool(const GU_PathHedge &)> & fn);
157 
159  {
160  return firstIncidentHedge(pt);
161  }
162 
163  //Only goes through edges where dstPoint == pt
164  void iterIncomingHedges(GA_Offset pt,
165  const UT_Function<bool(const GU_PathHedge &)> & fn);
166 
168 
169  //Get the array of vertices that are reached by a hedge from vtx
170  const GA_OffsetArray & getVtxNexts(GA_Offset vtx);
171 
172  //Get the array of vertices that can reach vtx by a hedge
173  const GA_OffsetArray & getVtxPrevs(GA_Offset vtx);
174 
175  //Check if the vertices on hedge are valid
176  SYS_FORCE_INLINE bool isValidHedge(const GU_PathHedge & hedge) const
177  {
178  return hedge.isValid();
179  }
180 
181  //check if h1, h2 have the same end points
183  const GU_PathHedge & h2)
184  {
185  GA_Offset h1_p0 = srcPoint(h1);
186  GA_Offset h1_p1 = dstPoint(h1);
187  GA_Offset h2_p0 = srcPoint(h2);
188  GA_Offset h2_p1 = dstPoint(h2);
189 
190  return (h1_p0 == h2_p0 && h1_p1 == h2_p1) ||
191  (h1_p0 == h2_p1 && h1_p1 == h2_p0);
192  }
193 
194  //Signed Hedges are equivelent if they have the same primary
195  bool areEquivalent(const GU_PathSHedge & sh1,
196  const GU_PathSHedge & sh2);
197 
199  {
200  return h.v0();
201  }
202 
204  {
205  return h.v1();
206  }
207 
209  {
210  return GAisValid(srcVertex(h)) ?
211  myGdp.vertexPoint(srcVertex(h)) : GA_INVALID_OFFSET;
212  }
213 
215  {
216  return GAisValid(dstVertex(h)) ?
217  myGdp.vertexPoint(dstVertex(h)) : GA_INVALID_OFFSET;
218  }
219 
220  GA_Offset srcVertex(const GU_PathSHedge & sh) const;
221 
222  GA_Offset dstVertex(const GU_PathSHedge & sh) const;
223 
224  GA_Offset srcPoint(const GU_PathSHedge & sh) const;
225 
226  GA_Offset dstPoint(const GU_PathSHedge & sh) const;
227 
229  {
230  return GAisValid(srcVertex(h)) ? myGdp.vertexPrimitive(srcVertex(h)) :
232  }
233 
235  {
236  if (!GAisValid(h.v0()))
237  return nullptr;
238 
239  return static_cast<const GEO_Primitive *>(
240  myGdp.getPrimitive(myGdp.vertexPrimitive(h.v0())));
241  }
242 
243  //
245  {
246  //By storing the vertices that are polygons in a bit array
247  //We see a significant speed up as this allows fast use of
248  //polygon specific caches. Using this way to text if polygon
249  //We get a 20% speed up over converting to primitive then checking type
250 
251  exploreVtxPrim(h.v0());
252  return GAisValid(h.v0()) && myPolyVtx.getBitFast(h.v0());
253  }
254 
255  bool isHedgeValidPolygon(const GU_PathSHedge & hedge);
256 
258  {
259  UT_ASSERT(isValidHedge(h));
260  return isValidHedge(h) ? distance3d(myGdp.getPos3(srcPoint(h)),
261  myGdp.getPos3(dstPoint(h))) : 0;
262  }
263 
265  { return &myGdp; }
266 
267  //Check if elements are on a geometry boundary
268  bool isVtxBoundary(GA_Offset vtx);
269 
270  bool isPointBoundary(GA_Offset pt);
271 
272  bool isHedgeBoundary(const GU_PathHedge & hedge)
273  {
274  if (!isValidHedge(hedge))
275  return false;
276 
277  return sym(hedge) == hedge;
278  }
279 
280  //check if an element is on a quad poly
281  bool isQuadVtx(GA_Offset vtx);
282 
283  bool isQuadPt(GA_Offset pt);
284 
285  bool isQuadHedge(const GU_PathHedge & hedge)
286  {
287  return isQuadVtx(hedge.v0());
288  }
289 
290  //convert to GA_Edge
292  {
293  UT_ASSERT(hedge.isValid());
294  return GA_Edge(srcPoint(hedge), dstPoint(hedge));
295  }
296 
297  void reset()
298  {
299  exint nvtx = myGdp.getNumVertexOffsets();
300 
301  myVtxNextArr.clear();
302  myVtxPrevArr.clear();
303  myVtxNextArr.setSize(nvtx);
304  myVtxPrevArr.setSize(nvtx);
305  myLPrevMap.clear();
306  myLNextMap.clear();
307  myQuadVtx.setAllBits(false);
308  myPolyVtx.setAllBits(false);
309  myPolySymCache.clear();
310  myPolyPrimaryCache.clear();
311  myPolySymCache.setSize(nvtx);
312  myPolyPrimaryCache.setSize(nvtx);
313 
314  mySymCache.clear();
315  myPrimaryCache.clear();
316  }
317  private:
318  void exploreVtxPrim(GA_Offset vtx);
319 
320  //in here I think we should check for boundaries as well
321  void explorePrim(GA_Offset pr);
322 
323  void iterAreas(
324  const GA_Primitive *prim,
325  const UT_Function<bool(const GA_OffsetArray & /*vtxs*/)> &fn);
326 
327  const GU_Detail & myGdp;
328  const GA_PrimitiveGroup * myPrimGroup = nullptr;
329  bool myExcludePrims = true;
330 
331  UT_Array<GA_OffsetArray> myVtxNextArr;
332  UT_Array<GA_OffsetArray> myVtxPrevArr;
333 
334  UT_BitArray myPolyVtx;
335  UT_Array<GU_PathHedge> myPolySymCache;
336  UT_Array<GU_PathHedge> myPolyPrimaryCache;
337  //This is for anything that is not a polygon primitive
338  //It is a bit slower however
339  UT_BitArray myQuadVtx;
340 
341  //Caches, offer some speed up
342  UT_Map<GU_PathHedge, GA_Offset> myLPrevMap, myLNextMap;
344  UT_Map<GU_PathHedge, GU_PathHedge> myPrimaryCache;
345  };
346 };
347 
348 //To allow using in a set, or map
349 SYS_FORCE_INLINE size_t
350 hash_value(const GU_PathHedge & hedge)
351 {
352  return hedge.hash();
353 }
354 
355 namespace std {
356  template <>
357  struct hash<GU_PathHedge>
358  {
359  size_t operator()(const GU_PathHedge & hedge) const
360  {
361  return hedge.hash();
362  }
363  };
364 }
365 
366 //A signed version of the hedge
368 public:
370 
371  GU_PathSHedge(const GU_PathHedge & hedge, int sign = 1)
372  : myHedge{hedge}, mySign{sign} {}
373 
375  { return myHedge.isValid(); }
376 
378  { return myHedge; }
379 
381  {
382  return GEO_SHedge(myHedge.hedge(), sign());
383  }
384 
385  SYS_FORCE_INLINE int sign() const
386  { return mySign; }
387 
389  { return mySign >= 0; }
390 
392  { return !isPositive(); }
393 
394  SYS_FORCE_INLINE bool isEqual(const GU_PathSHedge & other, bool has_sign = true) const
395  {
396  return myHedge == other.myHedge &&
397  (!has_sign || mySign == other.mySign);
398  }
399 
400  SYS_FORCE_INLINE bool operator==(const GU_PathSHedge & other) const
401  { return isEqual(other); }
402 
403  SYS_FORCE_INLINE bool operator!=(const GU_PathSHedge & other) const
404  { return !(*this == other); }
405 
407  {
408  return GU_PathSHedge(hedge(), -sign());
409  }
410 
411 private:
412  GU_PathHedge myHedge;
413  int mySign = 1;
414 };
415 #endif
SYS_FORCE_INLINE GEO_Hedge hedge() const
Definition: GU_PathHedge.h:48
SYS_FORCE_INLINE GA_Offset srcPoint(const GA_Detail *gdp, GEO_Hedge h)
Definition: GEO_Hedge.h:186
SYS_FORCE_INLINE bool isPositive() const
Definition: GU_PathHedge.h:388
GU_PathHedge firstIncidentEdge(GA_Offset pt)
Definition: GU_PathHedge.h:158
SYS_FORCE_INLINE GA_Edge hedgeToEdge(const GU_PathHedge &hedge) const
Definition: GU_PathHedge.h:291
T distance3d(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector3.h:1116
SYS_FORCE_INLINE fpreal length(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:257
SYS_FORCE_INLINE GEO_SHedge shedge() const
Definition: GU_PathHedge.h:380
SYS_FORCE_INLINE GU_PathHedge & set(GA_Offset new_v0, GA_Offset new_v1)
Definition: GU_PathHedge.h:78
GU_PathHedge(GA_Offset v0, GA_Offset v1)
Definition: GU_PathHedge.h:41
size_t operator()(const GU_PathHedge &hedge) const
Definition: GU_PathHedge.h:359
int64 exint
Definition: SYS_Types.h:125
GA_Offset srcVertex(GEO_Hedge)
Definition: GEO_Hedge.h:179
SYS_FORCE_INLINE bool isNegative() const
Definition: GU_PathHedge.h:391
SYS_FORCE_INLINE bool areEquivalent(const GU_PathHedge &h1, const GU_PathHedge &h2)
Definition: GU_PathHedge.h:182
SYS_FORCE_INLINE const GU_PathHedge & hedge() const
Definition: GU_PathHedge.h:377
bool isHedgeBoundary(const GU_PathHedge &hedge)
Definition: GU_PathHedge.h:272
SYS_FORCE_INLINE bool operator!=(const GU_PathSHedge &other) const
Definition: GU_PathHedge.h:403
GA_EdgeT< GA_Offset, false > GA_Edge
Definition: GA_Edge.h:140
SYS_FORCE_INLINE bool GAisValid(GA_Size v)
Definition: GA_Types.h:655
SYS_FORCE_INLINE bool isEqual(const GU_PathSHedge &other, bool has_sign=true) const
Definition: GU_PathHedge.h:394
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
SYS_FORCE_INLINE GA_Offset v1() const
Definition: GU_PathHedge.h:58
SYS_FORCE_INLINE bool isValid() const
Definition: GU_PathHedge.h:374
GA_Size GA_Offset
Definition: GA_Types.h:646
SYS_FORCE_INLINE bool operator==(const GU_PathHedge &other) const
Definition: GU_PathHedge.h:68
SYS_FORCE_INLINE GA_Offset hedgePrimitiveOffset(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:228
bool isQuadHedge(const GU_PathHedge &hedge)
Definition: GU_PathHedge.h:285
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE GA_Offset dstVertex(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:203
GU_PathSHedge(const GU_PathHedge &hedge, int sign=1)
Definition: GU_PathHedge.h:371
SYS_FORCE_INLINE GA_Offset srcVertex(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:198
SYS_FORCE_INLINE const GEO_Primitive * hedgePrimitive(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:234
GEO_Hedge firstIncomingHedge(T &iface, GA_Offset pt)
Definition: GEO_Hedge.h:558
#define GU_API
Definition: GU_API.h:14
IMATH_HOSTDEVICE constexpr int sign(T a) IMATH_NOEXCEPT
Definition: ImathFun.h:33
SYS_FORCE_INLINE GU_PathSHedge operator-() const
Definition: GU_PathHedge.h:406
std::function< T > UT_Function
Definition: UT_Function.h:37
SYS_FORCE_INLINE GA_Offset dstVertex(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:215
SYS_FORCE_INLINE bool operator==(const GU_PathSHedge &other) const
Definition: GU_PathHedge.h:400
GLfloat v0
Definition: glcorearb.h:816
SYS_FORCE_INLINE size_t hash() const
Definition: GU_PathHedge.h:93
SYS_FORCE_INLINE bool operator!=(const GU_PathHedge &other) const
Definition: GU_PathHedge.h:73
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
SYS_FORCE_INLINE int sign() const
Definition: GU_PathHedge.h:385
SYS_FORCE_INLINE bool isValid() const
Definition: GU_PathHedge.h:63
SYS_FORCE_INLINE size_t hash_value(const GU_PathHedge &hedge)
Definition: GU_PathHedge.h:350
GEO_Hedge findHedgeWithEndpoints(T &iface, GA_Offset p0, GA_Offset p1)
Definition: GEO_Hedge.h:809
fpreal64 fpreal
Definition: SYS_Types.h:277
SYS_FORCE_INLINE GU_PathHedge & reset()
Definition: GU_PathHedge.h:85
SYS_FORCE_INLINE const GU_Detail * getDetail() const
Definition: GU_PathHedge.h:264
GLfloat GLfloat v1
Definition: glcorearb.h:817
SYS_FORCE_INLINE bool areEquivalent(T &iface, GEO_Hedge h1, GEO_Hedge h2)
Definition: GEO_Hedge.h:298
SYS_FORCE_INLINE GA_Offset dstPoint(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:214
GU_PathHedge sym(const GU_PathHedge &hedge)
Definition: GU_PathHedge.h:139
SYS_FORCE_INLINE GA_Offset srcPoint(const GU_PathHedge &h) const
Definition: GU_PathHedge.h:208
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GEO_Hedge firstIncidentHedge(T &iface, GA_Offset pt)
Definition: GEO_Hedge.h:392
SYS_FORCE_INLINE bool isHedgeValidPolygon(const GU_PathHedge &h)
Definition: GU_PathHedge.h:244
SYS_FORCE_INLINE bool isValidHedge(const GU_PathHedge &hedge) const
Definition: GU_PathHedge.h:176
SYS_FORCE_INLINE GA_Offset v0() const
Definition: GU_PathHedge.h:53
SYS_FORCE_INLINE GA_Offset dstPoint(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:244