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 
13 #ifndef __GU_PolyBevel3_h__
14 #define __GU_PolyBevel3_h__
15 
16 #include "GU_API.h"
17 #include "GU_Detail.h"
18 
19 #include "GU_PolyBevel3Offset.h"
20 #include "GU_Decompose.h"
21 
22 #include <GEO/GEO_PolyInterface.h>
23 
24 #include <GA/GA_Handle.h>
25 #include <GA/GA_Types.h>
26 #include <UT/UT_Array.h>
27 #include <UT/UT_BitArray.h>
28 #include <UT/UT_Vector3.h>
29 #include <UT/UT_VectorTypes.h>
30 #include <UT/UT_StringStream.h>
31 #include <UT/UT_ArrayMap.h>
32 #include <SYS/SYS_Inline.h>
33 
34 #include <math.h>
35 
36 class GU_Decompose;
37 class GU_Insetter;
39 class GEO_Face;
40 class GEO_PolyCounts;
41 class GEO_PrimPoly;
42 
43 class GA_Attribute;
44 class GA_EdgeGroup;
45 class GA_PointGroup;
46 class GA_PointWrangler;
47 class GA_PrimitiveGroup;
49 class GA_VertexWrangler;
50 
51 
52 
53 namespace GU_PolyBevel3
54 {
55 
56 class Profile;
57 class OffsetParms;
58 class BevelParms;
59 class PatchMap;
60 class Fillet;
61 class UVBeveler;
62 class UVBevelerSet;
63 class Ring;
64 class EdgeGroupRing;
65 class PointGroupRing;
66 class RingMesh;
67 
72 
74 {
75  AUTO = 0,
78 };
79 
81 {
82 public:
84  {
85  NONE = 0,
89  ROUND
90  };
91 
93  {
94  UNIFORM = 0,
96  CONTROL_POINTS
97  };
98 
100 
101  explicit Beveler(const GU_Detail *gdp);
102 
103  virtual ~Beveler();
104 
105  virtual void bevel(GU_Detail *gdp,
106  fpreal offset, FilletShape shape, int divs,
107  const BevelParms *parms)
108  { doBevel(gdp, offset, shape, divs, parms); }
109 
110  void getEdgeFilletPolys(GA_PrimitiveGroup *group) const;
111  void getPointFilletPolys(GA_PrimitiveGroup *group) const;
112  void getPointFilletEdges(GA_EdgeGroup *group,
113  bool include_poly_bds = true) const;
114 
115  void getOffsetEdges(GA_EdgeGroup *group) const;
116  void getOffsetPoints(GA_PointGroup *group) const;
117  void getMergedPoints(GA_PointGroup *group) const;
118  void getAutoSlideEdges(GA_EdgeGroup *group) const;
119  void getSlideEdges(GA_EdgeGroup *group) const;
120  void getNonSlideEdges(GA_EdgeGroup *group) const;
121  void setEdgeFilletCorners(GA_RWHandleI dh) const;
122 
123  const
124  UT_Vector3RArray &getLimitPositions() { return myLimitPositions; }
125 
126  UT_StringHolder getErrorMessage(const GU_Detail *src);
127 
128  fpreal getLimit() const;
129 
130 #ifdef EXPLICIT_ELEMENT_INDEX
131  struct ElementIndex
132  {
133  explicit ElementIndex() = default;
134  explicit ElementIndex(int index) : myIndex(index) { }
135 
136  explicit
137  operator int() const { return myIndex; }
138 
139  bool operator==(const ElementIndex &other) const
140  { return myIndex == other.myIndex; }
141 
142  bool operator!=(const ElementIndex &other) const
143  { return myIndex != other.myIndex; }
144 
145  private:
146  int myIndex;
147  };
148 
149  struct Patch : public ElementIndex
150  {
151  using ElementIndex::ElementIndex;
152  };
153 
154  struct Mesh: public ElementIndex
155  {
156  using ElementIndex::ElementIndex;
157  };
158 #else
159  using ElementIndex = int;
162 #endif
163 
164 protected:
166 
167  void doBevel(GU_Detail *gdp,
168  fpreal offset, FilletShape shape, int divs,
169  const BevelParms *parms);
170 
171  void deleteHubs(GU_Detail *gdp);
172 
173  void destroyCapPolys(GU_Detail *gdp);
174 
175  void saveIndexMaps(const GU_Detail *gdp);
176 
177  void setupOffsetter(bool singleton_groupin,
178  fpreal max_speed = -1);
179 
180  void offsetCutEdges(GU_Detail *gdp,
181  fpreal offset,
182  bool limit_slides,
183  bool detect_collisions,
184  LimitTriggerMask limit_mask,
185  LimitGrouping limit_mode);
186 
187 
188 #ifdef DEBUG_BEVEL
189  void dumpHedge(GEO_Hedge h) const;
190  void dumpRimComponents();
191 #endif
192 
193  void stitchFilletGaps(GU_Detail *gdp,
194  GEO_PolyInterface *pip);
195 
196  void backInsertPolylineFilletPoints(GU_Detail *gdp);
197 
198  void updateAffectedNormals(GU_Detail *gdp);
199 
200  void applyPointScale(GU_Detail *gdp,
201  const GA_Attribute *attrib);
202 
203  void positionFilletPoints(GU_Detail *gdp,
204  FilletShape shape,
205  const Profile *profile,
206  const BevelParms *parms);
207 
208  void setRing(Ring *ring,
209  const GA_EdgeGroup *cuts = nullptr,
210  const char *polarization_overrides = nullptr);
211 
212  GU_Detail *getDetail() { return myGdp; }
213 
214  const PatchMap *patches() const { return myPatches.get(); }
215  const Fillet *fillet() const { return myFillet.get(); }
216 
217 private:
218  GA_Index lookupPrimIndex(GA_Offset prim) const;
219  GA_Index lookupPointIndex(GA_Offset pt) const;
220 
221  using PatchArray = UT_Array<Patch>;
222  using OffsetSet = UT_Set<GA_Offset>;
223  using FilletUptr = UT_UniquePtr<Fillet>;
224  using PatchMapUptr = UT_UniquePtr<PatchMap>;
225  using UVBevelerUptr = UT_UniquePtr<UVBeveler>;
226  using UVBevelerSetUptr = UT_UniquePtr<UVBevelerSet>;
227  using LoopOffsetUptr = UT_UniquePtr<LoopOffset>;
228  using UVBevelers = UT_Array<UVBevelerUptr>;
229 
230 
231  GU_Detail *myGdp = nullptr;
232 
233  PatchMapUptr myPatches;
234  UVBevelerSetUptr myUVBevelers;
235  FilletUptr myFillet;
236 
237  UT_Vector3RArray myLimitPositions;
238  GA_OffsetArray myMergedPoints;
239 
240  LoopOffsetUptr myOffsetter;
241 
242  Ring *myRing = nullptr;
243  GEO_PolyInterface *myPip = nullptr;
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 
261 
263 {
264 public:
267 
268  BevelParms() = default;
269 
270  bool limitSlides() const { return myLimitSlides; }
271  void setLimitSlides(bool limit) { myLimitSlides = limit; }
272 
273  bool detectCollisions() const { return myDetectCollisions; }
274  void setDetectCollisions(bool detect)
275  { myDetectCollisions = detect; }
276 
277  LimitTriggerMask limitTrigger() const { return myLimitType; }
279  { myLimitType = mask; }
280 
281  LimitGrouping limitGrouping() const { return myLimitLoops; }
283  { myLimitLoops = limitting; }
284 
285  bool symmetrizeProfile() const
286  { return mySymmetrizeProfile; }
287 
289  { mySymmetrizeProfile = b; }
290 
291  fpreal flatBoost() const { return myFlatBoost; }
293  { myFlatBoost = radians; }
294 
295  bool reverseProfile() const { return myReverseProfile; }
296  void setReverseProfile(bool b) { myReverseProfile = b; }
297 
299  const GA_Attribute *offsetScale() const { return myOffsetScale; }
301  { myOffsetScale = a; }
302 
303  const GA_Attribute *pointScale() const { return myPointScale; }
305  { myPointScale = a; }
306 
307  fpreal convexity() const { return myConvexity; }
308  void setConvexity(fpreal f) { myConvexity = f; }
309 
310  const UT_Ramp *profileRamp() const { return myProfileRamp; }
311  void setProfileRamp(const UT_Ramp *r) { myProfileRamp = r; }
312 
313  const GEO_Face *profileCurve() const { return myProfileCurve; }
315  { myProfileCurve = c; }
316 
317  fpreal profileScale() const { return myProfileScale; }
318  void setProfileScale(fpreal f) { myProfileScale = f; }
319 
320  ProfileSampling profileSampling() const { return myProfileSampling; }
322  { myProfileSampling = s; }
323 
324 private:
325  bool mySymmetrizeProfile = false;
326  fpreal myFlatBoost = M_PI / 6;
327  bool myReverseProfile = false;
328  const GA_Attribute *myOffsetScale = nullptr;
329  const GA_Attribute *myPointScale = nullptr;
330  fpreal myConvexity = 1.0;
331  const UT_Ramp *myProfileRamp = nullptr;
332  const GEO_Face *myProfileCurve = nullptr;
333  fpreal myProfileScale = 1.0;
334  ProfileSampling myProfileSampling = Beveler::UNIFORM;
335 
336  bool myLimitSlides = true;
337  bool myDetectCollisions = true;
338  LimitTriggerMask myLimitType = LimitTriggerMask(0);
340 
341 };
342 
344 {
345 public:
346  OffsetParms() = default;
347 
348  fpreal minNormalDiff() const { return myMinNormalDiff; }
350  { myMinNormalDiff = radians; }
351 
352  SlidingMode slidingMode() const { return mySlidingMode; }
354  { mySlidingMode = sliding; }
355 
356  fpreal asymmetryTol() const { return myAsymTol; }
357  void setAsymmetryTol(fpreal tol) { myAsymTol = tol; }
358 
359  fpreal pinchAngle() const { return myPinchAngle; }
361  { myPinchAngle = radians; }
362 
363  bool ignoreFlatEdges() const { return myIgnoreFlatEdges; }
364  void setIgnoreFlatEdges(bool ignore)
365  { myIgnoreFlatEdges = ignore; }
366 
367  bool ignoreFlatPoints() const { return myIgnoreFlatPoints; }
368  void setIgnoreFlatPoints(bool ignore)
369  { myIgnoreFlatPoints = ignore; }
370 
371  bool ignoreInlinePoints() const
372  { return myIgnoreInlinePoints; }
373  void setIgnoreInlinePoints(bool ignore)
374  { myIgnoreInlinePoints = ignore; }
375 
376  void setProfileDirection(const char *str)
377  { myProfileDirection.harden(str); }
378 
379  const char *profileDirection() const
380  { return myProfileDirection.c_str(); }
381 
382  const GA_EdgeGroup *slideEdges() const { return mySlideEdges; }
384  { mySlideEdges = group; }
385 
386  const GA_Attribute *offsetScaleAttr() const { return myOffsetScaleAttr; }
388  { myOffsetScaleAttr = attr; }
389 
390 private:
391  fpreal myMinNormalDiff = M_PI;
392  fpreal myPinchAngle = 0;
393  SlidingMode mySlidingMode = AUTO;
394  fpreal myAsymTol = 0.5;
395  bool myIgnoreFlatEdges = false;
396  bool myIgnoreFlatPoints = false;
397  bool myIgnoreInlinePoints = false;
398  UT_StringHolder myProfileDirection;
399  const GA_EdgeGroup *mySlideEdges = nullptr;
400  const GA_Attribute *myOffsetScaleAttr = nullptr;
401 };
402 
403 
404 class GU_API EdgeBeveler : public Beveler
405 {
406 public:
407  explicit EdgeBeveler(const GU_Detail *gdp,
408  const GA_EdgeGroup *edges_to_bevel,
409  const OffsetParms &oparms);
410 
411  ~EdgeBeveler() override;
412 
413 private:
414 
416  RingUptr myEdgeSetRing;
417 };
418 
419 
421 {
422 public:
423  explicit PointBeveler(const GU_Detail *gdp,
424  const GA_PointGroup *points,
425  const OffsetParms &oparms);
426 
427  ~PointBeveler() override;
428 
429  void bevel(GU_Detail *gdp,
430  fpreal offset, FilletShape shape, int divs,
431  const BevelParms *parms) override
432  { doBevel(gdp, offset, shape, divs, parms); }
433 
434 private:
435 
436  using RingUptr = UT_UniquePtr<PointGroupRing>;
437  RingUptr myPointSetRing;
438 
439 };
440 
441 } // namespace GU_PolyBevel3
442 
443 #endif
void setLimitTrigger(LimitTriggerMask mask)
GLdouble s
Definition: glew.h:1390
void setIgnoreFlatPoints(bool ignore)
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
Beveler::ProfileSampling ProfileSampling
const PatchMap * patches() const
Definition: UT_Set.h:58
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)
int divs(int x, int y)
Definition: ImathFun.h:180
GA_Size GA_Offset
Definition: GA_Types.h:637
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
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:631
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
double fpreal
Definition: SYS_Types.h:276
void bevel(GU_Detail *gdp, fpreal offset, FilletShape shape, int divs, const BevelParms *parms) override
void setPinchAngle(fpreal radians)
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
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