HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PolyBevel3.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_PolyBevel3.h (GU Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __GU_PolyBevel3_h__
13 #define __GU_PolyBevel3_h__
14 
15 #include "GU_API.h"
16 #include "GU_Detail.h"
17 
18 #include "GU_PolyBevel3Offset.h"
19 #include "GU_Decompose.h"
20 
21 #include <GEO/GEO_PolyInterface.h>
22 
23 #include <GA/GA_Handle.h>
24 #include <GA/GA_Types.h>
25 #include <UT/UT_Array.h>
26 #include <UT/UT_BitArray.h>
27 #include <UT/UT_Vector3.h>
28 #include <UT/UT_VectorTypes.h>
29 #include <UT/UT_StringStream.h>
30 #include <UT/UT_ArrayMap.h>
31 #include <SYS/SYS_Inline.h>
32 
33 #include <math.h>
34 
35 class GU_Decompose;
36 class GU_Insetter;
38 class GEO_Face;
39 class GEO_PolyCounts;
40 class GEO_PrimPoly;
41 
42 class GA_Attribute;
43 class GA_EdgeGroup;
44 class GA_PointGroup;
45 class GA_PointWrangler;
46 class GA_PrimitiveGroup;
48 class GA_VertexWrangler;
49 
50 namespace GU_PolyBevel3
51 {
52 
53 class Profile;
54 class OffsetParms;
55 class BevelParms;
56 class PatchMap;
57 class Fillet;
58 class UVBeveler;
59 class UVBevelerSet;
60 class Ring;
61 class EdgeGroupRing;
62 class PointGroupRing;
63 class RingMesh;
64 
69 
71 {
72  AUTO = 0,
75 };
76 
78 {
79 public:
81  {
82  NONE = 0,
86  ROUND
87  };
88 
90  {
91  UNIFORM = 0,
93  CONTROL_POINTS
94  };
95 
97 
98  explicit Beveler(const GU_Detail *gdp);
99 
100  virtual ~Beveler();
101 
102  virtual void bevel(GU_Detail *gdp,
103  fpreal offset, FilletShape shape, int divs,
104  const BevelParms *parms)
105  { doBevel(gdp, offset, shape, divs, parms); }
106 
107  void getEdgeFilletPolys(GA_PrimitiveGroup *group) const;
108  void getPointFilletPolys(GA_PrimitiveGroup *group) const;
109  void getPointFilletEdges(GA_EdgeGroup *group,
110  bool include_poly_bds = true) const;
111 
112  void getOffsetEdges(GA_EdgeGroup *group) const;
113  void getOffsetPoints(GA_PointGroup *group) const;
114  void getMergedPoints(GA_PointGroup *group) const;
115  void getAutoSlideEdges(GA_EdgeGroup *group) const;
116  void getSlideEdges(GA_EdgeGroup *group) const;
117  void getNonSlideEdges(GA_EdgeGroup *group) const;
118  void setEdgeFilletCorners(GA_RWHandleI dh) const;
119 
120  const
121  UT_Vector3RArray &getLimitPositions() { return myLimitPositions; }
122 
123  UT_StringHolder getErrorMessage(const GU_Detail *src);
124 
125  fpreal getLimit() const;
126 
127 #ifdef EXPLICIT_ELEMENT_INDEX
128  struct ElementIndex
129  {
130  explicit ElementIndex() = default;
131  explicit ElementIndex(int index) : myIndex(index) { }
132 
133  explicit
134  operator int() const { return myIndex; }
135 
136  bool operator==(const ElementIndex &other) const
137  { return myIndex == other.myIndex; }
138 
139  bool operator!=(const ElementIndex &other) const
140  { return myIndex != other.myIndex; }
141 
142  private:
143  int myIndex;
144  };
145 
146  struct Patch : public ElementIndex
147  {
148  using ElementIndex::ElementIndex;
149  };
150 
151  struct Mesh: public ElementIndex
152  {
153  using ElementIndex::ElementIndex;
154  };
155 #else
156  using ElementIndex = int;
159 #endif
160 
161 protected:
163 
164  void doBevel(GU_Detail *gdp,
165  fpreal offset, FilletShape shape, int divs,
166  const BevelParms *parms);
167 
168  void deleteHubs(GU_Detail *gdp);
169 
170  void destroyCapPolys(GU_Detail *gdp);
171 
172  void saveIndexMaps(const GU_Detail *gdp);
173 
174  void setupOffsetter(bool singleton_groupin,
175  fpreal max_speed = -1);
176 
177  void offsetCutEdges(GU_Detail *gdp,
178  fpreal offset,
179  bool limit_slides,
180  bool detect_collisions,
181  LimitTriggerMask limit_mask,
182  LimitGrouping limit_mode);
183 
184 #ifdef DEBUG_BEVEL
185  void dumpHedge(GEO_Hedge h) const;
186  void dumpRimComponents();
187 #endif
188 
189  void stitchFilletGaps(GU_Detail *gdp,
190  GEO_PolyInterface *pip);
191 
192  void backInsertPolylineFilletPoints(GU_Detail *gdp);
193 
194  void updateAffectedNormals(GU_Detail *gdp);
195 
196  void applyPointScale(GU_Detail *gdp,
197  const GA_Attribute *attrib);
198 
199  void positionFilletPoints(GU_Detail *gdp,
200  FilletShape shape,
201  const Profile *profile,
202  const BevelParms *parms,
203  bool force_circular);
204 
205  void setRing(Ring *ring,
206  const GA_EdgeGroup *cuts = nullptr,
207  const char *polarization_overrides = nullptr);
208 
209  GU_Detail *getDetail() { return myGdp; }
210 
211  const PatchMap *patches() const { return myPatches.get(); }
212  const Fillet *fillet() const { return myFillet.get(); }
213 
214 private:
215  GA_Index lookupPrimIndex(GA_Offset prim) const;
216  GA_Index lookupPointIndex(GA_Offset pt) const;
217 
218  using PatchArray = UT_Array<Patch>;
219  using OffsetSet = UT_Set<GA_Offset>;
220  using FilletUptr = UT_UniquePtr<Fillet>;
221  using PatchMapUptr = UT_UniquePtr<PatchMap>;
222  using UVBevelerUptr = UT_UniquePtr<UVBeveler>;
223  using UVBevelerSetUptr = UT_UniquePtr<UVBevelerSet>;
224  using LoopOffsetUptr = UT_UniquePtr<LoopOffset>;
225  using UVBevelers = UT_Array<UVBevelerUptr>;
226 
227  GU_Detail *myGdp = nullptr;
228 
229  PatchMapUptr myPatches;
230  UVBevelerSetUptr myUVBevelers;
231  FilletUptr myFillet;
232 
233  UT_Vector3RArray myLimitPositions;
234  GA_OffsetArray myMergedPoints;
235 
236  LoopOffsetUptr myOffsetter;
237 
238  Ring *myRing = nullptr;
239  GEO_PolyInterface *myPip = nullptr;
240 
241  // We store the maps for the final offset to index mapping of the output.
242  // This is needed for generating groups and attributes on guide geometry
243  // that may be defragmented.
244 
245 #define CREATE_OFFSET_MAP 0
246 
247 #if CREATE_OFFSET_MAP
248  // using OffsetMap = UT_Map<GA_Offset, GA_Index>;
249 
250  using OffsetMap = UT_ArrayMap<GA_Offset, GA_Index>;
251 
252  OffsetMap myPointIndexMap;
253  OffsetMap myPrimIndexMap;
254 #else
255  using OffsetMap = GA_ListType<GA_Offset, GA_Index>;
256  OffsetMap myPointIndexMap;
257  OffsetMap myPrimIndexMap;
258 #endif
259 };
260 
262 {
263 public:
266 
267  BevelParms() = default;
268 
269  bool limitSlides() const { return myLimitSlides; }
270  void setLimitSlides(bool limit) { myLimitSlides = limit; }
271 
272  bool detectCollisions() const { return myDetectCollisions; }
273  void setDetectCollisions(bool detect)
274  { myDetectCollisions = detect; }
275 
276  LimitTriggerMask limitTrigger() const { return myLimitType; }
278  { myLimitType = mask; }
279 
280  LimitGrouping limitGrouping() const { return myLimitLoops; }
282  { myLimitLoops = limitting; }
283 
284  bool symmetrizeProfile() const
285  { return mySymmetrizeProfile; }
286 
288  { mySymmetrizeProfile = b; }
289 
290  fpreal flatBoost() const { return myFlatBoost; }
292  { myFlatBoost = radians; }
293 
294  bool reverseProfile() const { return myReverseProfile; }
295  void setReverseProfile(bool b) { myReverseProfile = b; }
296 
297  bool forceCircular() const { return myForceCircular; }
298  void setFoceCircular(bool force)
299  { myForceCircular = force; }
300 
302  const GA_Attribute *offsetScale() const { return myOffsetScale; }
304  { myOffsetScale = a; }
305 
306  const GA_Attribute *pointScale() const { return myPointScale; }
308  { myPointScale = a; }
309 
310  fpreal convexity() const { return myConvexity; }
311  void setConvexity(fpreal f) { myConvexity = f; }
312 
313  const UT_Ramp *profileRamp() const { return myProfileRamp; }
314  void setProfileRamp(const UT_Ramp *r) { myProfileRamp = r; }
315 
316  const GEO_Face *profileCurve() const { return myProfileCurve; }
318  { myProfileCurve = c; }
319 
320  fpreal profileScale() const { return myProfileScale; }
321  void setProfileScale(fpreal f) { myProfileScale = f; }
322 
323  ProfileSampling profileSampling() const { return myProfileSampling; }
325  { myProfileSampling = s; }
326 
327 private:
328  bool mySymmetrizeProfile = false;
329  fpreal myFlatBoost = M_PI / 6;
330  bool myReverseProfile = false;
331  const GA_Attribute *myOffsetScale = nullptr;
332  const GA_Attribute *myPointScale = nullptr;
333  fpreal myConvexity = 1.0;
334  const UT_Ramp *myProfileRamp = nullptr;
335  const GEO_Face *myProfileCurve = nullptr;
336  fpreal myProfileScale = 1.0;
337  ProfileSampling myProfileSampling = Beveler::UNIFORM;
338  bool myForceCircular = false;
339  bool myLimitSlides = true;
340  bool myDetectCollisions = true;
341  LimitTriggerMask myLimitType = LimitTriggerMask(0);
343 
344 };
345 
347 {
348 public:
349  OffsetParms() = default;
350 
351  fpreal minNormalDiff() const { return myMinNormalDiff; }
353  { myMinNormalDiff = radians; }
354 
355  SlidingMode slidingMode() const { return mySlidingMode; }
357  { mySlidingMode = sliding; }
358 
359  fpreal asymmetryTol() const { return myAsymTol; }
360  void setAsymmetryTol(fpreal tol) { myAsymTol = tol; }
361 
362  fpreal pinchAngle() const { return myPinchAngle; }
364  { myPinchAngle = radians; }
365 
366  bool ignoreFlatEdges() const { return myIgnoreFlatEdges; }
367  void setIgnoreFlatEdges(bool ignore)
368  { myIgnoreFlatEdges = ignore; }
369 
370  bool ignoreFlatPoints() const { return myIgnoreFlatPoints; }
371  void setIgnoreFlatPoints(bool ignore)
372  { myIgnoreFlatPoints = ignore; }
373 
374  bool ignoreInlinePoints() const
375  { return myIgnoreInlinePoints; }
376  void setIgnoreInlinePoints(bool ignore)
377  { myIgnoreInlinePoints = ignore; }
378 
379  void setProfileDirection(const char *str)
380  { myProfileDirection.harden(str); }
381 
382  const char *profileDirection() const
383  { return myProfileDirection.c_str(); }
384 
385  const GA_EdgeGroup *slideEdges() const { return mySlideEdges; }
387  { mySlideEdges = group; }
388 
389  const GA_Attribute *offsetScaleAttr() const { return myOffsetScaleAttr; }
391  { myOffsetScaleAttr = attr; }
392 
393 private:
394  fpreal myMinNormalDiff = M_PI;
395  fpreal myPinchAngle = 0;
396  SlidingMode mySlidingMode = AUTO;
397  fpreal myAsymTol = 0.5;
398  bool myIgnoreFlatEdges = false;
399  bool myIgnoreFlatPoints = false;
400  bool myIgnoreInlinePoints = false;
401  UT_StringHolder myProfileDirection;
402  const GA_EdgeGroup *mySlideEdges = nullptr;
403  const GA_Attribute *myOffsetScaleAttr = nullptr;
404 };
405 
406 class GU_API EdgeBeveler : public Beveler
407 {
408 public:
409  explicit EdgeBeveler(const GU_Detail *gdp,
410  const GA_EdgeGroup *edges_to_bevel,
411  const OffsetParms &oparms);
412 
413  ~EdgeBeveler() override;
414 
415 private:
416 
417  using RingUptr = UT_UniquePtr<EdgeGroupRing>;
418  RingUptr myEdgeSetRing;
419 };
420 
422 {
423 public:
424  explicit PointBeveler(const GU_Detail *gdp,
425  const GA_PointGroup *points,
426  const OffsetParms &oparms);
427 
428  ~PointBeveler() override;
429 
430  void bevel(GU_Detail *gdp,
431  fpreal offset, FilletShape shape, int divs,
432  const BevelParms *parms) override
433  { doBevel(gdp, offset, shape, divs, parms); }
434 
435 private:
436 
437  using RingUptr = UT_UniquePtr<PointGroupRing>;
438  RingUptr myPointSetRing;
439 
440 };
441 
442 } // namespace GU_PolyBevel3
443 
444 #endif
void setLimitTrigger(LimitTriggerMask mask)
GLdouble s
Definition: glew.h:1390
void setIgnoreFlatPoints(bool ignore)
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
Beveler::ProfileSampling ProfileSampling
const PatchMap * patches() const
Definition: UT_Set.h:58
void setFoceCircular(bool force)
void setLimitGrouping(LimitGrouping limitting)
GLenum src
Definition: glew.h:2410
void offsetScale(const GA_Attribute *a)
void setConvexity(fpreal f)
void setOffsetScaleAttr(const GA_Attribute *attr)
OIIO_HOSTDEVICE T radians(T deg)
Convert degrees to radians.
Definition: fmath.h:525
GLuint index
Definition: glew.h:1814
void setProfileDirection(const char *str)
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
LimitTriggerMask limitTrigger() const
void setDetectCollisions(bool detect)
bool ignoreInlinePoints() const
void setReverseProfile(bool b)
void setPointScale(const GA_Attribute *a)
GLint limit
Definition: glew.h:12988
Beveler::FilletShape FilletShape
GLenum GLint GLuint mask
Definition: glew.h:1845
GU_Detail * getDetail()
ProfileSampling profileSampling() const
void setSlideEdges(const GA_EdgeGroup *group)
#define M_PI
Definition: ImathPlatform.h:51
fpreal pinchAngle() const
virtual void bevel(GU_Detail *gdp, fpreal offset, FilletShape shape, int divs, const BevelParms *parms)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
int divs(int x, int y)
Definition: ImathFun.h:180
GA_Size GA_Offset
Definition: GA_Types.h:639
void setFlatBoost(fpreal radians)
void setLimitSlides(bool limit)
SlidingMode slidingMode() const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
void setSymmetrizeProfile(bool b)
bool symmetrizeProfile() const
void setIgnoreFlatEdges(bool ignore)
GLclampf f
Definition: glew.h:3499
UT_UniquePtr< GEO_PolyInterface > PolyInterfaceUptr
Definition: GU_PolyBevel3.h:68
bool reverseProfile() const
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
const UT_Vector3RArray & getLimitPositions()
fpreal profileScale() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const GA_Attribute * offsetScaleAttr() const
const GLfloat * c
Definition: glew.h:16296
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define GU_API
Definition: GU_API.h:14
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
bool detectCollisions() const
fpreal flatBoost() const
void setIgnoreInlinePoints(bool ignore)
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
void setProfileCurve(const GEO_Face *c)
void setProfileSampling(ProfileSampling s)
void setMinNormalDiff(fpreal radians)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
LimitGrouping limitGrouping() const
void bevel(GU_Detail *gdp, fpreal offset, FilletShape shape, int divs, const BevelParms *parms) override
void setPinchAngle(fpreal radians)
fpreal64 fpreal
Definition: SYS_Types.h:277
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3446
const UT_Ramp * profileRamp() const
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
void setSlidingMode(SlidingMode sliding)
fpreal minNormalDiff() const
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
fpreal asymmetryTol() const
SYS_FORCE_INLINE const GA_Attribute * offsetScale() const
bool ignoreFlatPoints() const
void setAsymmetryTol(fpreal tol)
const GA_EdgeGroup * slideEdges() const
const GEO_Face * profileCurve() const
const GA_Attribute * pointScale() const
const Fillet * fillet() const
void setProfileScale(fpreal f)
fpreal convexity() const
const char * profileDirection() const
void setProfileRamp(const UT_Ramp *r)
GLboolean GLuint group
Definition: glew.h:2745
GLintptr offset
Definition: glew.h:1682