HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PolyExtrude2.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 (C++)
7  *
8  * COMMENTS: Poly Extrude code.
9  *
10  */
11 #ifndef __GU_PolyExtrude2_h__
12 #define __GU_PolyExtrude2_h__
13 
14 #include "GU_API.h"
15 #include "GU_PolyBridge.h"
16 #include <GU/GU_Decompose.h>
17 #include <GU/GU_Detail.h>
18 
19 #include <GEO/GEO_HedgeInterface.h>
20 #include <GA/GA_Types.h>
21 
22 #include <UT/UT_Matrix4.h>
23 #include <UT/UT_Array.h>
24 #include <UT/UT_Vector3.h>
25 
26 
27 class GA_Group;
28 class GA_PrimitiveGroup;
29 class GA_PointGroup;
30 class GA_PrimitiveGroup;
32 class GEO_Face;
33 class GEO_PrimPoly;
34 class GU_Detail;
35 class GA_Attribute;
37 
38 
39 template<typename T, bool B> class GA_EdgeT;
41 
42 
44 {
45 public:
46 
48  const GA_PrimitiveGroup *prims,
49  const GA_EdgeGroup *split_edges = nullptr,
50  bool split_all = false);
51 
53  const GA_EdgeGroup *edges,
54  const GA_PointGroup *split_points = nullptr,
55  bool split_all = false);
56 
57  ~GU_PolyExtrude2();
58 
60  {
61  PRIM_OR_EDGE_NORMAL = 0,
63  };
64 
67 
68  // Performs the extrusion
69  void extrude(fpreal distance = 0.0);
70 
71  // Methods to help placing a handle on the first component
72  UT_Vector3 getXformHandleCenter() const;
73  UT_Matrix4 getXformHandleXform() const;
74  UT_Vector3 getDraggerStart() const { return myDraggerStart; }
75  UT_Vector3 getDraggerDir() const { return myDraggerDir; }
76 
77 
78  bool isTrivial() const;
79 
81  { myExtrusionMode = m; }
83  { myMorphMethod = m; }
84 
85  void setOutputFront(bool b) { myOutputFront = b; }
86  void setOutputBack(bool b) { myOutputBack = b; }
87  void setOutputSide(bool b) { myOutputSide = b; }
88 
90  { myUseExistingNormal = b; }
91 
93  { mySuppliedPointNormal = ptnml; }
94 
96  { myAddFrontPrimGroup = grp; }
97 
99  { myAddFrontEdgeGroup = grp; }
100 
102  { myAddBackPrimGroup = grp; }
103 
105  { myAddBackEdgeGroup = grp; }
106 
108  { myAddSidePrimGroup = grp; }
109 
111  { myAddFrontSeamGroup = grp; }
112 
114  { myAddBackSeamGroup = grp; }
115 
117  { myPrimSelection = grp; }
118 
120  { myEdgeSelection = grp; }
121 
122  void setInset(float inset) { myInset = inset; }
123  void setDivisions(int div) { myDivisions = div; }
124  void setStraightSpine(bool b) { myStraightSpine = b; }
125  void setTwist(fpreal t) { myTwist = t; }
126  void setThicknessScale(fpreal s) { myThicknessScale = s; }
127  void setTwistScale(fpreal s) { myTwistScale = s; }
128  void setThicknessRamp(UT_Ramp *r) { myThicknessRamp = r; }
129  void setTwistRamp(UT_Ramp *r) { myTwistRamp = r; }
131  { myDeviationToleranceCos = SYScos(a); }
132  void setAxialRotation(fpreal r) { myAxialRotation = r; }
133 
135  { myExtSpineSrcBlend = s; myExtSpineDstBlend = d; }
136 
137  void setXform(const UT_Matrix4 &frontxform,
138  bool is_global = false);
139 
140  void setExternalSpine(const GEO_Face *curve)
141  { myExternalSpine = curve; }
142 
143 
145  { myThicknessAttrib = attrib; }
146 
148  { myTwistAttrib = attrib; }
149 
151  { mySpineStart = s; mySpineEnd = e; }
152 
153  void setReverseSpine(bool b) { myReverseSpine = b; }
155  { mySrcMagnitude = s; myDstMagnitude = d; }
156 
158  { mySrcStiffness = s; myDstStiffness = d; }
159 
160  void addVertexNormals(fpreal cusp_angle_degrees,
161  bool cusp_front, bool cusp_back);
162 
164  { mySpineSampleMethod = m; }
165 
166  void limitInset(bool limit, bool common_limit)
167  { myLimitInset = limit;
168  myCommonInsetLimit = common_limit; }
169 
170  void setLocalXDirAttrib(const char *attrib_name);
171  void setLocalZDirAttrib(const char *attrib_name);
172  void setLocalCtrAttrib(const char *attrib_name);
173  void setLocalDistScaleAttrib(const char *attrib_name);
174  void setLocalInsetScaleAttrib(const char *attrib_name);
175  void setLocalTwistScaleAttrib(const char *attrib_name);
176  void setLocalDivsScaleAttrib(const char *attrib_name);
177 
180 
181  void setSideTexturing(TextureMode mode,
182  TextureScaling scaling);
183 
184  fpreal getCompInsetScale(int k);
185  fpreal getCompDistScale(int k);
186  fpreal getCompTwistScale(int k);
187  fpreal getCompDivsScale(int k);
188 
189 private:
190 
195 
196  void initialize();
197  void cleanPrivateAttributes();
198  void computeOpenPolyNormals();
199 
200  void buildPrimFront();
201  void buildEdgeFront(bool generate_edge_polys);
202 
203  void setupGroupsAndAttribs();
204  void copyEdgeGroupMembership();
205  void wrangleFrontPt(GA_Offset fpt,
206  GA_PointWrangler &wrangler);
207  void wrangleFrontVtxs(GA_Offset fpt,
208  GA_VertexWrangler &wrangler);
209 
210  void buildPrimExtrusionMaps();
211 
212  void buildEdgeExtrusionMap();
213  void calculatePathNormals(bool trivial);
214 
215  void transformEdgeFront(bool trivial);
216 
217  UT_Vector3 calcBoundaryExtrusion(GEO_Hedge h0, GEO_Hedge h1,
218  int comp);
219 
220  UT_Vector3 calcInteriorExtrusion(GA_Offset pt, int comp,
221  HedgeInterface *fhip = nullptr);
222 
223 
224  UT_Vector3 calcBoundaryInset(GA_Offset pt0, GA_Offset pt1,
225  GA_Offset pt2, GA_Offset prim0,
226  GA_Offset prim1);
227 
228  UT_Vector3 calcPathNormal(GA_Offset pt_prev, GA_Offset pt,
229  GA_Offset pt_next,
230  UT_Vector3 *out_edge_nml = nullptr);
231 
232  UT_Vector3 calcHedgeNormal(GEO_Hedge h, int &degree,
233  UT_Vector3 *binormal = nullptr);
234 
235  void transformPrimFront(bool trivial);
236  void insetPrimFront();
237 
238  GU_PolyBridge *bridgeLoops(int comp, GA_OffsetArray &src_chain,
239  GA_OffsetArray &dst_chain,
240  bool closed);
241 
242  void bridgePrimComponents(int batch_size = -1);
243  void bridgeEdgeComponents(int batch_size = -1);
244 
245  void buildPrimSeams();
246  void buildEdgeSeams();
247 
248  void calcPrimLocalFrames();
249  void calcPrimCompLocalFrame(int k);
250 
251  void calcEdgeLocalFrames();
252  void calcEdgeCompLocalFrame(int k);
253 
254  void calcCenterAndNormal(int component_id,
255  UT_Vector3 &center,
256  UT_Vector3 &normal,
257  bool add_extrusion = false,
258  bool collect_from_attributes = false);
259 
260  UT_Vector3 farthestBoundaryEdgePerp(int k);
261  UT_Vector3 longestBoundaryEdgeDir(int k);
262 
263  void updateAffectedNormals();
264 
265  UT_Vector3 getMinAreaBoxXDirection(int comp);
266 
267  void fillOutputGroups();
268  void cleanup();
269  fpreal getRescaleFactor() const;
270 
271  void buildHandleSpaceChangMat();
272 
273  void saveEdgeGroupToDetailArray(const GA_EdgeGroup *grp,
274  const char *attrib_name);
275 
276  void rescaleFront();
277 
278  bool isFrontXformTrivial() const;
279 
281  int numCompFrontPts(int k)
282  { return (myCompFrontFirstPt(k + 1) -
283  myCompFrontFirstPt(k)); }
284 
286  GA_Offset compFrontPt(int k, int i)
287  { return myFrontPts(myCompFrontFirstPt(k) + i); }
288 
290  int numCompFrontPrims(int k)
291  { return (myCompFrontFirstPrim(k + 1) -
292  myCompFrontFirstPrim(k)); }
293 
295  GA_Offset compFrontPrim(int k, int i)
296  { return myFrontPrims(myCompFrontFirstPrim(k) + i); }
297 
298 
299  // NB: only used with edge extrusion
301  int frontPtIdx(int k, int i)
302  { return (myCompFrontFirstPt(k) + i); }
303 
305  UT_Vector3 &frontPtExtrusion(int k, int i)
306  { return myFrontPtExtrusion(frontPtIdx(k, i)); }
307 
309  UT_Vector3 &frontPtPathNormal(int k, int i)
310  { return myFrontPtPathNormal(frontPtIdx(k, i)); }
311  // ---
312 
313  // index of the the ith boundary of the kth component among all boundaries
315  int frontBdIdx(int k, int j)
316  { return (myCompFrontFirstBd(k) + j); }
317 
318  // index of the ith vertex of the jth boundary
320  int frontBdVtxIdx(int j, int i)
321  { return (myFrontBdFirstVtx(j) + i); }
322 
323  // The ith vertex of the jth front boundary
325  GA_Offset &frontBdVtx(int i)
326  { return myFrontBdVtxs(i); }
327 
328  // The ith vertex of the jth front boundary
330  GA_Offset &frontBdVtx(int j, int i)
331  { return myFrontBdVtxs(frontBdVtxIdx(j, i)); }
332 
333  // ith vertex of the jth boundary of the kth component
335  GA_Offset &compFrontBdVtx(int k, int j, int i)
336  { return frontBdVtx(frontBdIdx(k, j), i); }
337 
338  // total number of boundary components of the front
340  int numFrontBds()
341  { return int(myCompFrontFirstBd.size() - 1); }
342 
343  // number of boundaries of the kth front component
345  int numCompFrontBds(int k)
346  { return (myCompFrontFirstBd(k + 1)
347  - myCompFrontFirstBd(k)); }
348 
350  int numFrontBdVtxs()
351  { return int(myFrontBdVtxs.size()); }
352 
353  // number of vertices in the jth front boundary
355  int numFrontBdVtxs(int j)
356  { return (myFrontBdFirstVtx(j + 1)
357  - myFrontBdFirstVtx(j)); }
358 
359  // number of vertices in the jth boundary of the kth front component
361  int numCompFrontBdVtxs(int k, int j)
362  { return numFrontBdVtxs(frontBdIdx(k, j)); }
363 
364  // used only in primitive extrusion
366  GA_Offset frontVtxToBackVtx(GA_Offset v)
367  { return GA_Offset(myFrontToBackVtxMap.get(v)); }
368 
369  // used only in edge extrusion
371  GA_Offset frontPtToBackPt(GA_Offset pt)
372  { return GA_Offset(myFrontToBackPtMap.get(pt)); }
373 
374 
376  int bdComp(int j) { return myBdComp(j); }
377 
378  // used in edge extrusion only
380  bool isFrontCompClosed(int k)
381  { return myFrontCompClosed.getBitFast(k); }
382 
385  { return myHip->srcPoint(h); }
386 
388  GA_Offset dstPoint(GEO_Hedge h) const
389  { return myHip->dstPoint(h); }
390 
392  GA_Offset srcVertex(GEO_Hedge h) const
393  { return myHip->srcVertex(h); }
394 
396  GA_Offset dstVertex(GEO_Hedge h) const
397  { return myHip->dstVertex(h); }
398 
400  GA_Offset vertexPrimitive(GA_Offset vtx) const
401  { return myGdp->vertexPrimitive(vtx); }
402 
405  GA_Offset p1) const
406  { return myHip->findHedgeWithEndpoints(p0, p1); }
407 
409  GEO_Hedge sym(GEO_Hedge h) const
410  { return myHip->sym(h); }
411 
413  GEO_Hedge lnext(GEO_Hedge h) const
414  { return myHip->lnext(h); }
415 
417  GEO_Hedge lprev(GEO_Hedge h) const
418  { return myHip->lprev(h); }
419 
421  UT_Vector3 getPos3(GA_Offset pt) const
422  { return { myGdp->getPos3(pt) }; }
423 
425  bool isValidHedge(GEO_Hedge h) const
426  { return myHip->isValidHedge(h); }
427 
429  UT_Vector3 pointNormal(GA_Offset pt) const
430  { return { myPointNormal.get(pt) }; }
431 
433  UT_Vector3 polyNormal(GA_Offset pt) const
434  { return { myPolyNormal.get(pt) }; }
435 
436  GU_Detail *myGdp = nullptr;
437  GA_PrimitiveGroup *myPolys = nullptr;
438  const GA_EdgeGroup *myEdges = nullptr;
439 
440  GA_RWHandleV3 myPolyNormal;
441  GA_RWHandleV3 myPointNormal;
442 
443  UT_Vector3Array myBackCompCtr; // Center used for back
444  UT_Vector3Array myBackCompBary; // Barycenter of the back
445 
446  UT_Vector3Array myCompXDir, myCompYDir, myCompZDir;
447 
448  UT_Vector3Array myFrontCompCtr; // Calculated front center
449  UT_Vector3Array myExtrudedCompCtr; // Centroid of extruded comp
450  UT_Vector3Array myFrontCompZDir, myFrontCompXDir;
451 
452  UT_FprealArray myCompDivsScale;
453  UT_FprealArray myCompZScale;
454  UT_FprealArray myCompInsetScale;
455  UT_FprealArray myCompTwistScale;
456 
457 
458  UT_Matrix4 myHandleSpaceChangeMat;
459 
460  fpreal myDeviationToleranceCos = 0.984807753012208;
461  fpreal mySrcMagnitude = 1.0;
462  fpreal myDstMagnitude = 1.0;
463  fpreal mySrcStiffness = 1.0;
464  fpreal myDstStiffness = 1.0;
465  fpreal myExtSpineSrcBlend, myExtSpineDstBlend;
466 
467  UT_Vector3 myDraggerStart, myDraggerDir;
468 
469  //GU_Decompose *myDecompose = nullptr;
470  PolyPatches *myPolyPatches = nullptr;
471  EdgePaths *myEdgePaths = nullptr;
472 
473 
474  GA_PointGroupUPtr myFrontBoundaryPtGroup;
475  GA_PrimitiveGroup *myFrontPrimGroup = nullptr;
476  GA_PrimitiveGroup *myBackPrimGroup = nullptr;
477  GA_PrimitiveGroup *mySidePrimGroup = nullptr;
478  GA_EdgeGroup *myFrontEdgeGroup = nullptr;
479  GA_EdgeGroup *myBackEdgeGroup = nullptr;
480 
481  GA_PrimitiveGroup *myAddFrontPrimGroup = nullptr;
482  GA_PrimitiveGroup *myAddBackPrimGroup = nullptr;
483  GA_PrimitiveGroup *myAddSidePrimGroup = nullptr;
484  GA_EdgeGroup *myAddFrontEdgeGroup = nullptr;
485  GA_EdgeGroup *myAddBackEdgeGroup = nullptr;
486  GA_EdgeGroup *myAddFrontSeamGroup = nullptr;
487  GA_EdgeGroup *myAddBackSeamGroup = nullptr;
488 
489  GA_PrimitiveGroup *myPrimSelection = nullptr;
490  GA_EdgeGroup *myEdgeSelection = nullptr;
491 
492  ExtrusionMode myExtrusionMode = PRIM_OR_EDGE_NORMAL;
493 
494  UT_Matrix4 myFrontXform;
495  fpreal myDistance = 0.0;
496  int myNumFrontPts = 0;
497 
498  MorphMethod myMorphMethod = MorphMethod::LINEAR;
499 
500  bool myOutputFront = true;
501  bool myOutputBack = false;
502  bool myReverseBack = true;
503  bool myOutputSide = true;
504  bool myStraightSpine = true;
505  bool myReverseSpine = false;
506  bool myUseExistingNormal = false;
507 
508  bool myAddVertexNormal = false;
509  bool myCuspFront = true;
510  bool myCuspBack = true;
511 
512  bool myWranglePt = false;
513  bool myWranglePrim = false;
514  bool myWrangleVtx = false;
515 
516  bool myXformIsTrivial = true;
517  bool myTrivialNormal = true;
518 
519  bool myLimitInset = true;
520  bool myCommonInsetLimit = true;
521 
522  fpreal myCuspAngleDegrees = 60.06;
523 
524  int myDivisions = 1;
525  fpreal myTwist = 0.0;
526  fpreal myInset = 0.0;
527  fpreal myThicknessScale = 1.0;
528  fpreal myTwistScale = M_PI;
529  UT_Ramp *myTwistRamp = nullptr;
530  UT_Ramp *myThicknessRamp = nullptr;
531 
532  const GEO_Face *myExternalSpine = nullptr;
533  GA_Attribute *myThicknessAttrib = nullptr;
534  GA_Attribute *myTwistAttrib = nullptr;
535 
536  fpreal mySpineStart = 0.0;
537  fpreal mySpineEnd = 1.0;
538  fpreal myAxialRotation = 0.0;
539 
540  GA_AttributeUPtr myFrontPtIdxOwner;
541  GA_AttributeUPtr myFrontToBackVtxMapOwner;
542  GA_AttributeUPtr myFrontToBackPtMapOwner;
543 
544  GA_ROHandleI myFrontPtIdx;
545  GA_ROHandleI myFrontToBackVtxMap;
546  GA_ROHandleI myFrontToBackPtMap;
547 
548  GA_ROHandleV3 myLocalXDirAttr;
549  GA_ROHandleV3 myLocalZDirAttr;
550  GA_ROHandleV3 myLocalCtrAttr;
551  GA_ROHandleF myLocalZScaleAttr;
552  GA_ROHandleF myLocalInsetScaleAttr;
553  GA_ROHandleF myLocalTwistScaleAttr;
554  GA_ROHandleF myLocalDivsScaleAttr;
555 
556  GA_ROHandleV3 mySuppliedPointNormal;
557 
558  int myNumComponents = 0;
559  int myNumCompBoundaries = 0;
560 
561  SpineSampleMethod mySpineSampleMethod;
562 
563  UT_Vector3Array myFrontPtPos;
564  UT_Vector3Array myFrontPtExtrusion;
565  UT_Vector3Array myFrontPtInset;
566  UT_Vector3Array myFrontPtPathNormal;
567 
568  bool myXformIsGlobal = false;
569 
570  GA_OffsetArray myFrontPts;
571  UT_IntArray myCompFrontFirstPt;
572  UT_BitArray myFrontCompClosed; // edge extrusion use only
573 
574  GA_OffsetArray myFrontPrims;
575  UT_IntArray myCompFrontFirstPrim;
576 
577  GA_OffsetArray myFrontBdVtxs;
578  UT_IntArray myFrontBdFirstVtx;
579  UT_IntArray myCompFrontFirstBd;
580  UT_IntArray myBdComp;
581 
582  TextureMode mySideTextureMode = GU_PolyBridge::INTERPOLATE;
583  TextureScaling mySideTextureScaling = GU_PolyBridge::FIT_UNIT_SQUARE;
584 
585  IndexPairArray myBridgePairing;
586  HedgeInterface *myHip;
587 };
588 
589 #endif
void setReverseSpine(bool b)
void setTwistScale(fpreal s)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
SYS_FORCE_INLINE GA_Offset srcPoint(const GA_Detail *gdp, GEO_Hedge h)
Definition: GEO_Hedge.h:186
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GA_API const UT_StringHolder div
UT_Array< IndexPair > IndexPairArray
UT_Array< IndexPair > IndexPairArray
Definition: USD_Utils.h:224
void setExternalSpine(const GEO_Face *curve)
void limitInset(bool limit, bool common_limit)
void setStiffnesses(fpreal s, fpreal d)
const GLdouble * v
Definition: glcorearb.h:837
#define M_PI
Definition: fmath.h:98
GA_Offset srcVertex(GEO_Hedge)
Definition: GEO_Hedge.h:179
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
void setOutputSide(bool b)
void setPointNormalAttrib(GA_ROHandleV3 ptnml)
void setSpineSampleMethod(SpineSampleMethod m)
void setDivisions(int div)
UT_Vector3 getDraggerDir() const
void setThicknessScale(fpreal s)
void setTwistAttrib(GA_Attribute *attrib)
void setTwist(fpreal t)
void setBackGroup(GA_EdgeGroup *grp)
void setOutputBack(bool b)
void setSideGroup(GA_PrimitiveGroup *grp)
GA_Size GA_Offset
Definition: GA_Types.h:646
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
void setFrontGroup(GA_EdgeGroup *grp)
void setMorphMethod(MorphMethod m)
void setThicknessRamp(UT_Ramp *r)
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Vector3 getDraggerStart() const
void setFrontGroup(GA_PrimitiveGroup *grp)
void setMagnitudes(fpreal s, fpreal d)
#define GU_API
Definition: GU_API.h:14
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
SYS_FORCE_INLINE GA_Offset dstVertex(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:215
FS_API bool cleanup(UT_StringArray &removed, UT_StringArray &error_files, exint &memory_freed, bool dry_run, const char *override_path=nullptr)
GLdouble t
Definition: glad.h:2397
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:943
GLenum mode
Definition: glcorearb.h:99
void setBackSeamGroup(GA_EdgeGroup *grp)
void setSpineRange(fpreal s, fpreal e)
void setAxialRotation(fpreal r)
GLint j
Definition: glad.h:2733
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void setThicknessAttrib(GA_Attribute *attrib)
GEO_Hedge findHedgeWithEndpoints(T &iface, GA_Offset p0, GA_Offset p1)
Definition: GEO_Hedge.h:809
void setDeviationTolerance(fpreal a)
void setTwistRamp(UT_Ramp *r)
fpreal64 fpreal
Definition: SYS_Types.h:278
void setExtrusionMode(ExtrusionMode m)
Utility class for containing a color ramp.
Definition: UT_Ramp.h:96
void setExtSpineBlend(fpreal s, fpreal d)
void setBackGroup(GA_PrimitiveGroup *grp)
void setOutputFront(bool b)
GU_Spine::SampleMode SpineSampleMethod
void setSelectionGroup(GA_EdgeGroup *grp)
void setUseExistingPointNormal(bool b)
const GEO_DetachedHedgeInterface HedgeInterface
Definition: GU_Decompose.h:54
GLboolean r
Definition: glcorearb.h:1222
UT_UniquePtr< GA_PointGroup > GA_PointGroupUPtr
SIM_API const UT_StringHolder distance
void setStraightSpine(bool b)
void setSelectionGroup(GA_PrimitiveGroup *grp)
void setInset(float inset)
void setFrontSeamGroup(GA_EdgeGroup *grp)
SYS_FORCE_INLINE GA_Offset dstPoint(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:244