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 setPreserveGroups(bool b) { myPreserveGroups = b; }
125  void setStraightSpine(bool b) { myStraightSpine = b; }
126  void setTwist(fpreal t) { myTwist = t; }
127  void setThicknessScale(fpreal s) { myThicknessScale = s; }
128  void setTwistScale(fpreal s) { myTwistScale = s; }
129  void setThicknessRamp(UT_Ramp *r) { myThicknessRamp = r; }
130  void setTwistRamp(UT_Ramp *r) { myTwistRamp = r; }
132  { myDeviationToleranceCos = SYScos(a); }
133  void setAxialRotation(fpreal r) { myAxialRotation = r; }
134 
136  { myExtSpineSrcBlend = s; myExtSpineDstBlend = d; }
137 
138  void setXform(const UT_Matrix4 &frontxform,
139  bool is_global = false);
140 
141  void setExternalSpine(const GEO_Face *curve)
142  { myExternalSpine = curve; }
143 
144 
146  { myThicknessAttrib = attrib; }
147 
149  { myTwistAttrib = attrib; }
150 
152  { mySpineStart = s; mySpineEnd = e; }
153 
154  void setReverseSpine(bool b) { myReverseSpine = b; }
156  { mySrcMagnitude = s; myDstMagnitude = d; }
157 
159  { mySrcStiffness = s; myDstStiffness = d; }
160 
161  void addVertexNormals(fpreal cusp_angle_degrees,
162  bool cusp_front, bool cusp_back);
163 
165  { mySpineSampleMethod = m; }
166 
167  void limitInset(bool limit, bool common_limit)
168  { myLimitInset = limit;
169  myCommonInsetLimit = common_limit; }
170 
171  void setLocalXDirAttrib(const char *attrib_name);
172  void setLocalZDirAttrib(const char *attrib_name);
173  void setLocalCtrAttrib(const char *attrib_name);
174  void setLocalDistScaleAttrib(const char *attrib_name);
175  void setLocalInsetScaleAttrib(const char *attrib_name);
176  void setLocalTwistScaleAttrib(const char *attrib_name);
177  void setLocalDivsScaleAttrib(const char *attrib_name);
178 
181 
182  void setSideTexturing(TextureMode mode,
183  TextureScaling scaling);
184 
185  fpreal getCompInsetScale(int k);
186  fpreal getCompDistScale(int k);
187  fpreal getCompTwistScale(int k);
188  fpreal getCompDivsScale(int k);
189 
190 private:
191 
196 
197  void initialize();
198  void computeOpenPolyNormals();
199 
200  void buildPrimFront();
201  void buildEdgeFront(bool generate_edge_polys);
202 
203  void setupGroupsAndAttribs();
204 
205  void buildPrimExtrusionMaps();
206 
207  void buildEdgeExtrusionMap();
208  void calculatePathNormals(bool trivial);
209 
210  void transformEdgeFront(bool trivial);
211 
212  UT_Vector3 calcBoundaryExtrusion(GEO_Hedge h0, GEO_Hedge h1,
213  int comp);
214 
215  UT_Vector3 calcInteriorExtrusion(GA_Offset pt, int comp,
216  HedgeInterface *fhip = nullptr);
217 
218 
219  UT_Vector3 calcBoundaryInset(GA_Offset pt0, GA_Offset pt1,
220  GA_Offset pt2, GA_Offset prim0,
221  GA_Offset prim1);
222 
223  UT_Vector3 calcPathNormal(GA_Offset pt_prev, GA_Offset pt,
224  GA_Offset pt_next,
225  UT_Vector3 *in_edge_nml = nullptr,
226  UT_Vector3 *out_edge_nml = nullptr);
227 
228  UT_Vector3 calcHedgeNormal(GEO_Hedge h, int &degree,
229  UT_Vector3 *binormal = nullptr);
230 
231  void transformPrimFront(bool trivial);
232  void insetPrimFront();
233 
234  GU_PolyBridge *bridgeLoops(int comp, GA_OffsetArray &src_chain,
235  GA_OffsetArray &dst_chain,
236  bool closed);
237 
238  void bridgePrimComponents(int batch_size = -1);
239  void bridgeEdgeComponents(int batch_size = -1);
240 
241  void buildPrimSeams();
242  void buildEdgeSeams();
243 
244  void calcPrimLocalFrames();
245  void calcPrimCompLocalFrame(int k);
246 
247  void calcEdgeLocalFrames();
248  void calcEdgeCompLocalFrame(int k);
249 
250  void calcCenterAndNormal(int component_id,
252  UT_Vector3 &normal,
253  bool add_extrusion = false,
254  bool collect_from_attributes = false);
255 
256  UT_Vector3 farthestBoundaryEdgePerp(int k);
257  UT_Vector3 longestBoundaryEdgeDir(int k);
258 
259  void updateAffectedNormals();
260 
261  UT_Vector3 getMinAreaBoxXDirection(int comp);
262 
263  void fillOutputGroups();
264  void cleanup();
265  fpreal getRescaleFactor() const;
266 
267  void buildHandleSpaceChangMat();
268 
269  void saveEdgeGroupToDetailArray(const GA_EdgeGroup *grp,
270  const char *attrib_name);
271 
272  void rescaleFront();
273 
274  bool isFrontXformTrivial() const;
275 
277  int numCompFrontPts(int k)
278  { return (myCompFrontFirstPt(k + 1) -
279  myCompFrontFirstPt(k)); }
280 
282  GA_Offset compFrontPt(int k, int i)
283  { return myFrontPts(myCompFrontFirstPt(k) + i); }
284 
286  int numCompFrontPrims(int k)
287  { return (myCompFrontFirstPrim(k + 1) -
288  myCompFrontFirstPrim(k)); }
289 
291  GA_Offset compFrontPrim(int k, int i)
292  { return myFrontPrims(myCompFrontFirstPrim(k) + i); }
293 
294 
295  // NB: only used with edge extrusion
297  int frontPtIdx(int k, int i)
298  { return (myCompFrontFirstPt(k) + i); }
299 
301  UT_Vector3 &frontPtExtrusion(int k, int i)
302  { return myFrontPtExtrusion(frontPtIdx(k, i)); }
303 
305  UT_Vector3 &frontPtPathNormal(int k, int i)
306  { return myFrontPtPathNormal(frontPtIdx(k, i)); }
307  // ---
308 
309  // index of the the ith boundary of the kth component among all boundaries
311  int frontBdIdx(int k, int j)
312  { return (myCompFrontFirstBd(k) + j); }
313 
314  // index of the ith vertex of the jth boundary
316  int frontBdVtxIdx(int j, int i)
317  { return (myFrontBdFirstVtx(j) + i); }
318 
319  // The ith vertex of the jth front boundary
321  GA_Offset &frontBdVtx(int i)
322  { return myFrontBdVtxs(i); }
323 
324  // The ith vertex of the jth front boundary
326  GA_Offset &frontBdVtx(int j, int i)
327  { return myFrontBdVtxs(frontBdVtxIdx(j, i)); }
328 
329  // ith vertex of the jth boundary of the kth component
331  GA_Offset &compFrontBdVtx(int k, int j, int i)
332  { return frontBdVtx(frontBdIdx(k, j), i); }
333 
334  // total number of boundary components of the front
336  int numFrontBds()
337  { return int(myCompFrontFirstBd.size() - 1); }
338 
339  // number of boundaries of the kth front component
341  int numCompFrontBds(int k)
342  { return (myCompFrontFirstBd(k + 1)
343  - myCompFrontFirstBd(k)); }
344 
346  int numFrontBdVtxs()
347  { return int(myFrontBdVtxs.size()); }
348 
349  // number of vertices in the jth front boundary
351  int numFrontBdVtxs(int j)
352  { return (myFrontBdFirstVtx(j + 1)
353  - myFrontBdFirstVtx(j)); }
354 
355  // number of vertices in the jth boundary of the kth front component
357  int numCompFrontBdVtxs(int k, int j)
358  { return numFrontBdVtxs(frontBdIdx(k, j)); }
359 
360  // used only in primitive extrusion
362  GA_Offset frontVtxToBackVtx(GA_Offset v)
363  { return GA_Offset(myFrontToBackVtxMap.get(v)); }
364 
365  // used only in edge extrusion
367  GA_Offset frontPtToBackPt(GA_Offset pt)
368  { return GA_Offset(myFrontToBackPtMap.get(pt)); }
369 
370 
372  int bdComp(int j) { return myBdComp(j); }
373 
374  // used in edge extrusion only
376  bool isFrontCompClosed(int k)
377  { return myFrontCompClosed.getBitFast(k); }
378 
381  { return myHip->srcPoint(h); }
382 
384  GA_Offset dstPoint(GEO_Hedge h) const
385  { return myHip->dstPoint(h); }
386 
388  GA_Offset srcVertex(GEO_Hedge h) const
389  { return myHip->srcVertex(h); }
390 
392  GA_Offset dstVertex(GEO_Hedge h) const
393  { return myHip->dstVertex(h); }
394 
396  GA_Offset vertexPrimitive(GA_Offset vtx) const
397  { return myGdp->vertexPrimitive(vtx); }
398 
401  GA_Offset p1) const
402  { return myHip->findHedgeWithEndpoints(p0, p1); }
403 
405  GEO_Hedge sym(GEO_Hedge h) const
406  { return myHip->sym(h); }
407 
409  GEO_Hedge lnext(GEO_Hedge h) const
410  { return myHip->lnext(h); }
411 
413  GEO_Hedge lprev(GEO_Hedge h) const
414  { return myHip->lprev(h); }
415 
417  UT_Vector3 getPos3(GA_Offset pt) const
418  { return { myGdp->getPos3(pt) }; }
419 
421  bool isValidHedge(GEO_Hedge h) const
422  { return myHip->isValidHedge(h); }
423 
425  UT_Vector3 pointNormal(GA_Offset pt) const
426  { return { myPointNormal.get(pt) }; }
427 
429  UT_Vector3 polyNormal(GA_Offset pt) const
430  { return { myPolyNormal.get(pt) }; }
431 
432  GU_Detail *myGdp = nullptr;
433  GA_PrimitiveGroup *myPolys = nullptr;
434  const GA_EdgeGroup *myEdges = nullptr;
435 
436  GA_RWHandleV3 myPolyNormal;
437  GA_RWHandleV3 myPointNormal;
438 
439  UT_Vector3Array myBackCompCtr; // Center used for back
440  UT_Vector3Array myBackCompBary; // Barycenter of the back
441 
442  UT_Vector3Array myCompXDir, myCompYDir, myCompZDir;
443 
444  UT_Vector3Array myFrontCompCtr; // Calculated front center
445  UT_Vector3Array myExtrudedCompCtr; // Centroid of extruded comp
446  UT_Vector3Array myFrontCompZDir, myFrontCompXDir;
447 
448  UT_FprealArray myCompDivsScale;
449  UT_FprealArray myCompZScale;
450  UT_FprealArray myCompInsetScale;
451  UT_FprealArray myCompTwistScale;
452 
453 
454  UT_Matrix4 myHandleSpaceChangeMat;
455 
456  fpreal myDeviationToleranceCos = 0.984807753012208;
457  fpreal mySrcMagnitude = 1.0;
458  fpreal myDstMagnitude = 1.0;
459  fpreal mySrcStiffness = 1.0;
460  fpreal myDstStiffness = 1.0;
461  fpreal myExtSpineSrcBlend, myExtSpineDstBlend;
462 
463  UT_Vector3 myDraggerStart, myDraggerDir;
464 
465  //GU_Decompose *myDecompose = nullptr;
466  PolyPatches *myPolyPatches = nullptr;
467  EdgePaths *myEdgePaths = nullptr;
468 
469 
470  GA_PointGroupUPtr myFrontBoundaryPtGroup;
471  GA_PrimitiveGroup *myFrontPrimGroup = nullptr;
472  GA_PrimitiveGroup *myBackPrimGroup = nullptr;
473  GA_PrimitiveGroup *mySidePrimGroup = nullptr;
474  GA_EdgeGroup *myFrontEdgeGroup = nullptr;
475  GA_EdgeGroup *myBackEdgeGroup = nullptr;
476 
477  GA_PrimitiveGroup *myAddFrontPrimGroup = nullptr;
478  GA_PrimitiveGroup *myAddBackPrimGroup = nullptr;
479  GA_PrimitiveGroup *myAddSidePrimGroup = nullptr;
480  GA_EdgeGroup *myAddFrontEdgeGroup = nullptr;
481  GA_EdgeGroup *myAddBackEdgeGroup = nullptr;
482  GA_EdgeGroup *myAddFrontSeamGroup = nullptr;
483  GA_EdgeGroup *myAddBackSeamGroup = nullptr;
484 
485  GA_PrimitiveGroup *myPrimSelection = nullptr;
486  GA_EdgeGroup *myEdgeSelection = nullptr;
487 
488  ExtrusionMode myExtrusionMode = PRIM_OR_EDGE_NORMAL;
489 
490  UT_Matrix4 myFrontXform;
491  fpreal myDistance = 0.0;
492  int myNumFrontPts = 0;
493 
494  MorphMethod myMorphMethod = MorphMethod::LINEAR;
495 
496  bool myOutputFront = true;
497  bool myOutputBack = false;
498  bool myReverseBack = true;
499  bool myOutputSide = true;
500  bool myStraightSpine = true;
501  bool myPreserveGroups = true;
502  bool myReverseSpine = false;
503  bool myUseExistingNormal = false;
504 
505  bool myAddVertexNormal = false;
506  bool myCuspFront = true;
507  bool myCuspBack = true;
508 
509  bool myWranglePt = false;
510  bool myWranglePrim = false;
511  bool myWrangleVtx = false;
512 
513  bool myXformIsTrivial = true;
514  bool myTrivialNormal = true;
515 
516  bool myLimitInset = true;
517  bool myCommonInsetLimit = true;
518 
519  fpreal myCuspAngleDegrees = 60.06;
520 
521  int myDivisions = 1;
522  fpreal myTwist = 0.0;
523  fpreal myInset = 0.0;
524  fpreal myThicknessScale = 1.0;
525  fpreal myTwistScale = M_PI;
526  UT_Ramp *myTwistRamp = nullptr;
527  UT_Ramp *myThicknessRamp = nullptr;
528 
529  const GEO_Face *myExternalSpine = nullptr;
530  GA_Attribute *myThicknessAttrib = nullptr;
531  GA_Attribute *myTwistAttrib = nullptr;
532 
533  fpreal mySpineStart = 0.0;
534  fpreal mySpineEnd = 1.0;
535  fpreal myAxialRotation = 0.0;
536 
537  GA_AttributeUPtr myFrontPtIdxOwner;
538  GA_AttributeUPtr myFrontToBackVtxMapOwner;
539  GA_AttributeUPtr myFrontToBackPtMapOwner;
540 
541  GA_ROHandleI myFrontPtIdx;
542  GA_ROHandleI myFrontToBackVtxMap;
543  GA_ROHandleI myFrontToBackPtMap;
544 
545  GA_ROHandleV3 myLocalXDirAttr;
546  GA_ROHandleV3 myLocalZDirAttr;
547  GA_ROHandleV3 myLocalCtrAttr;
548  GA_ROHandleF myLocalZScaleAttr;
549  GA_ROHandleF myLocalInsetScaleAttr;
550  GA_ROHandleF myLocalTwistScaleAttr;
551  GA_ROHandleF myLocalDivsScaleAttr;
552 
553  GA_ROHandleV3 mySuppliedPointNormal;
554 
555  int myNumComponents = 0;
556  int myNumCompBoundaries = 0;
557 
558  SpineSampleMethod mySpineSampleMethod;
559 
560  UT_Vector3Array myFrontPtPos;
561  UT_Vector3Array myFrontPtExtrusion;
562  UT_Vector3Array myFrontPtInset;
563  UT_Vector3Array myFrontPtPathNormal;
564 
565  bool myXformIsGlobal = false;
566 
567  GA_OffsetArray myFrontPts;
568  UT_IntArray myCompFrontFirstPt;
569  UT_BitArray myFrontCompClosed; // edge extrusion use only
570 
571  GA_OffsetArray myFrontPrims;
572  UT_IntArray myCompFrontFirstPrim;
573 
574  GA_OffsetArray myFrontBdVtxs;
575  UT_IntArray myFrontBdFirstVtx;
576  UT_IntArray myCompFrontFirstBd;
577  UT_IntArray myBdComp;
578 
579  TextureMode mySideTextureMode = GU_PolyBridge::INTERPOLATE;
580  TextureScaling mySideTextureScaling = GU_PolyBridge::FIT_UNIT_SQUARE;
581 
582  IndexPairArray myBridgePairing;
583  HedgeInterface *myHip;
584 };
585 
586 #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:90
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 setPreserveGroups(bool b)
void setOutputBack(bool b)
void setSideGroup(GA_PrimitiveGroup *grp)
GA_Size GA_Offset
Definition: GA_Types.h:641
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
GLdouble t
Definition: glad.h:2397
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:930
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:277
void setExtrusionMode(ExtrusionMode m)
Utility class for containing a color ramp.
Definition: UT_Ramp.h:88
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