HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_SplitLoc.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_SplitLoc.h ( GU Library, C++)
7  *
8  * COMMENTS: This class defines a split location. It represents a place where
9  * a split will occur. A list of these things is what we need to
10  * make a complete cut.
11  */
12 
13 #ifndef __GU_SplitLoc_h__
14 #define __GU_SplitLoc_h__
15 
16 #include "GU_API.h"
17 #include "GU_Detail.h"
18 
19 #include <GA/GA_Edge.h>
20 #include <GEO/GEO_PrimPoly.h>
21 #include <UT/UT_VectorTypes.h>
22 
23 namespace GU_EdgeSplitUtils
24 {
25  template <typename Prec>
27  const Prec getTol()
28  {
29  if constexpr (std::is_same_v<Prec, fpreal32>)
30  return 1e-5;
31  else
32  return SYS_FP64_EPSILON;
33  }
34 }
35 
37 {
38 public:
39  GU_SplitLocParent(const GU_Detail *curve = nullptr,
40  exint v0 = -1,
41  exint v1 = -1,
43  : myCV0(v0)
44  , myCV1(v1)
45  , myCPrim(cp)
46  , myCurve(curve) {}
47 
48  bool operator==(const GU_SplitLocParent& src) const
49  {
50  return myCPrim == src.myCPrim
51  && myCV0 == src.myCV0
52  && myCV1 == src.myCV1;
53  }
54 
55  bool operator<(const GU_SplitLocParent& src) const
56  {
57  if (myCPrim != src.myCPrim)
58  return myCPrim < src.myCPrim;
59  else if (myCV0 != src.myCV0)
60  return myCV0 < src.myCV0;
61  else
62  return myCV1 < src.myCV1;
63  }
64 
65  size_t hash() const
66  {
67  size_t hash_val;
68  hash_val = GA_Size(myCPrim);
69  hashCombine(hash_val, GA_Size(myCV0));
70  hashCombine(hash_val, GA_Size(myCV1));
71  return hash_val;
72  }
73 
75  {
76  GU_SplitLocParent next = *this;
77 
78  exint nv =
79  (exint)myCurve->getPrimitiveVertexCount(myCPrim);
80  next.myCV0 = (myCV0 + 1) % nv;
81  next.myCV1 = (myCV1 + 1) % nv;
82  return next;
83  }
84 
86  exint myCV0; // Curve vertex (projection point)
87  exint myCV1; // Curve vertex (surface direction)
88  GA_Offset myCPrim; // Curve primitive
89 
90 private:
91  // TODO: copied from GA_Edge.h:
92  static size_t hashValueSigned(GA_Size val)
93  {
94  const unsigned int size_t_bits =
95  std::numeric_limits<size_t>::digits;
96  const int length = (std::numeric_limits<fpreal>::digits - 1)
97  / static_cast<int>(size_t_bits);
98 
99  size_t seed = 0;
100  GA_Size positive = val < 0 ? -1 - val : val;
101 
102  // Hopefully, this loop can be unrolled.
103  for(unsigned int i = length * size_t_bits; i > 0; i -= size_t_bits)
104  {
105  seed ^= (size_t) (positive >> i) + (seed<<6) + (seed>>2);
106  }
107  seed ^= (size_t) val + (seed<<6) + (seed>>2);
108 
109  return seed;
110  }
111 
112  static void hashCombine(size_t &seed, GA_Size const &value)
113  {
114  auto hash_value = hashValueSigned(value);
115 
116  // On macOS, size_t != hboost::uint64_t
117  const size_t m = UINT64_C(0xc6a4a7935bd1e995);
118  const int r = 47;
119 
120  hash_value *= m;
121  hash_value ^= hash_value >> r;
122  hash_value *= m;
123 
124  seed ^= hash_value;
125  seed *= m;
126 
127  // Completely arbitrary number, to prevent 0's
128  // from hashing to 0.
129  seed += 0xe6546b64;
130  }
131 };
132 
134 {
135  return parent.hash();
136 }
137 
138 // Templated abstraction of the GU_SplitLoc allowing for different floating
139 // point types and tolerances.
140 template<typename Prec>
141 class GU_API GU_SplitLocT
142 {
143 public:
144  GU_SplitLocT(const GA_Detail *gdp = nullptr,
147  Prec t = 0,
148  GEO_PrimPoly *poly = nullptr,
149  const UT_SharedPtr<GU_Detail> curve = nullptr,
150  exint v0 = -1,
151  exint v1 = -1,
153  : myP0Off(p0off)
154  , myP1Off(p1off)
155  , myT(t)
156  , myT2(-1)
157  , myPoly(poly)
158  , myOldPoly(poly)
159  , myInsidePrim(false)
160  , myIsFirst(false)
161  , myIsLast(false)
162  , myGdp(gdp)
163  , myCurveSegment(curve.get(), v0, v1, cp)
164  { }
165 
167  GA_Offset p0off,
168  GA_Offset p1off,
169  Prec t,
170  GEO_PrimPoly *poly,
171  bool is_first,
172  bool is_last,
173  const UT_SharedPtr<GU_Detail> curve = nullptr,
174  exint v0 = -1,
175  exint v1 = -1,
177  : myP0Off(p0off)
178  , myP1Off(p1off)
179  , myT(t)
180  , myT2(-1)
181  , myPoly(poly)
182  , myOldPoly(poly)
183  , myInsidePrim(false)
184  , myIsFirst(is_first)
185  , myIsLast(is_last)
186  , myGdp(gdp)
187  , myCurveSegment(curve.get(), v0, v1, cp)
188  { }
189 
190  GU_SplitLocT(Prec u,
191  Prec v,
192  GEO_PrimPoly *poly,
193  const UT_SharedPtr<GU_Detail> curve = nullptr,
194  exint v0 = -1,
195  exint v1 = -1,
197  : myP0Off(GA_INVALID_OFFSET)
198  , myP1Off(GA_INVALID_OFFSET)
199  , myT(u)
200  , myT2(v)
201  , myPoly(poly)
202  , myInsidePrim(true)
203  , myIsFirst(false)
204  , myIsLast(false)
205  , myOldPoly(poly)
206  , myGdp(&poly->getDetail())
207  , myCurveSegment(curve.get(), v0, v1, cp)
208  { }
209 
210  GU_SplitLocT(Prec u,
211  Prec v,
212  GEO_PrimPoly *poly,
213  bool is_first,
214  bool is_last,
215  const UT_SharedPtr<GU_Detail> curve = nullptr,
216  exint v0 = -1,
217  exint v1 = -1,
219  : myP0Off(GA_INVALID_OFFSET)
220  , myP1Off(GA_INVALID_OFFSET)
221  , myT(u)
222  , myT2(v)
223  , myPoly(poly)
224  , myInsidePrim(true)
225  , myIsFirst(is_first)
226  , myIsLast(is_last)
227  , myOldPoly(poly)
228  , myGdp(&poly->getDetail())
229  , myCurveSegment(curve.get(), v0, v1, cp)
230  { }
231 
232  bool operator==(const GU_SplitLocT& src) const;
233 
234  bool operator!=(const GU_SplitLocT &src) const
235  {
236  return !(operator==(src));
237  }
238 
239  UT_Vector3T<Prec> getPos3() const;
240 
242  {
243  myCurveSegment = src.myCurveSegment;
244  }
245 
246  void print() const; // TODO: debug only
247 
250  Prec myT;
251  Prec myT2; // second uv value for face vertices
252  bool myInsidePrim; // the point is not a vertex/edge cut
254  GEO_PrimPoly *myOldPoly; // used to store references to old polygons
255  // for in-polygon cuts to save recalculating
256  // u, v values
257  bool myIsFirst; // Indicator for closed curves
258  bool myIsLast; // Indicator for closed curves
259 
260  const GA_Detail *myGdp;
262 };
263 
267 
272 
273 #endif /* __GU_SplitLoc_h__ */
UT_SharedPtr< GU_SplitLocT< fpreal > > GU_SplitLocTPtr
Definition: GU_SplitLoc.h:268
#define SYS_FP64_EPSILON
Definition: SYS_Types.h:214
UT_Array< GU_SplitLocTPtr > GU_SplitLocTArray
Definition: GU_SplitLoc.h:269
const GLdouble * v
Definition: glcorearb.h:837
size_t hash() const
Definition: GU_SplitLoc.h:65
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GEO_PrimPoly * myPoly
Definition: GU_SplitLoc.h:253
int64 exint
Definition: SYS_Types.h:125
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GA_Offset myCPrim
Definition: GU_SplitLoc.h:88
GU_SplitLocParent myCurveSegment
Definition: GU_SplitLoc.h:261
3D Vector class.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:243
#define GA_INVALID_OFFSET
Definition: GA_Types.h:694
SYS_FORCE_INLINE size_t hash_value(const GU_SplitLocParent &parent)
Definition: GU_SplitLoc.h:133
GA_Size GA_Offset
Definition: GA_Types.h:653
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
SYS_FORCE_INLINE const Prec getTol()
Definition: GU_SplitLoc.h:27
GU_SplitLocT(Prec u, Prec v, GEO_PrimPoly *poly, bool is_first, bool is_last, const UT_SharedPtr< GU_Detail > curve=nullptr, exint v0=-1, exint v1=-1, GA_Offset cp=GA_INVALID_OFFSET)
Definition: GU_SplitLoc.h:210
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
const GU_Detail * myCurve
Definition: GU_SplitLoc.h:85
UT_Array< GU_SplitLoc * > GU_SplitLocArray
Definition: GU_SplitLoc.h:271
const GA_Detail * myGdp
Definition: GU_SplitLoc.h:260
GU_SplitLocT(const GA_Detail *gdp, GA_Offset p0off, GA_Offset p1off, Prec t, GEO_PrimPoly *poly, bool is_first, bool is_last, const UT_SharedPtr< GU_Detail > curve=nullptr, exint v0=-1, exint v1=-1, GA_Offset cp=GA_INVALID_OFFSET)
Definition: GU_SplitLoc.h:166
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GU_EXTERN_TEMPLATE(GU_SplitLocT< fpreal32 >)
GU_SplitLocT(Prec u, Prec v, GEO_PrimPoly *poly, const UT_SharedPtr< GU_Detail > curve=nullptr, exint v0=-1, exint v1=-1, GA_Offset cp=GA_INVALID_OFFSET)
Definition: GU_SplitLoc.h:190
void hashCombine(size_t &seed, const T &value)
Combine the hash of a value with an existing seed.
Definition: Util.h:58
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
Definition: UT_ARTMap.h:1173
#define GU_API
Definition: GU_API.h:14
GA_Offset myP1Off
Definition: GU_SplitLoc.h:249
GU_SplitLocT< fpreal32 > GU_SplitLoc
Definition: GU_SplitLoc.h:266
GLdouble t
Definition: glad.h:2397
GLfloat v0
Definition: glcorearb.h:816
UT_Array< GU_SplitLocParent > GU_SplitLocParentArray
Definition: GU_SplitLoc.h:270
void setParentCurve(const GU_SplitLocT &src)
Definition: GU_SplitLoc.h:241
bool myInsidePrim
Definition: GU_SplitLoc.h:252
GEO_PrimPoly * myOldPoly
Definition: GU_SplitLoc.h:254
GU_SplitLocParent next() const
Definition: GU_SplitLoc.h:74
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
GA_Offset myP0Off
Definition: GU_SplitLoc.h:248
bool operator<(const GU_SplitLocParent &src) const
Definition: GU_SplitLoc.h:55
Container class for all geometry.
Definition: GA_Detail.h:105
bool operator!=(const GU_SplitLocT &src) const
Definition: GU_SplitLoc.h:234
GU_SplitLocT(const GA_Detail *gdp=nullptr, GA_Offset p0off=GA_INVALID_OFFSET, GA_Offset p1off=GA_INVALID_OFFSET, Prec t=0, GEO_PrimPoly *poly=nullptr, const UT_SharedPtr< GU_Detail > curve=nullptr, exint v0=-1, exint v1=-1, GA_Offset cp=GA_INVALID_OFFSET)
Definition: GU_SplitLoc.h:144
GLboolean r
Definition: glcorearb.h:1222
bool operator==(const GU_SplitLocParent &src) const
Definition: GU_SplitLoc.h:48
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2903
GU_SplitLocParent(const GU_Detail *curve=nullptr, exint v0=-1, exint v1=-1, GA_Offset cp=GA_INVALID_OFFSET)
Definition: GU_SplitLoc.h:39
GLenum src
Definition: glcorearb.h:1793