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, bool copyedgegrps = true,
70  bool copyptgrps = true, bool copyprimgrps = true);
71 
72  // Methods to help placing a handle on the first component
73  UT_Vector3 getXformHandleCenter() const;
74  UT_Matrix4 getXformHandleXform() const;
75  UT_Vector3 getDraggerStart() const { return myDraggerStart; }
76  UT_Vector3 getDraggerDir() const { return myDraggerDir; }
77 
78 
79  bool isTrivial() const;
80 
82  { myExtrusionMode = m; }
84  { myMorphMethod = m; }
85 
86  void setOutputFront(bool b) { myOutputFront = b; }
87  void setOutputBack(bool b) { myOutputBack = b; }
88  void setOutputSide(bool b) { myOutputSide = b; }
89 
91  { myUseExistingNormal = b; }
92 
94  { mySuppliedPointNormal = ptnml; }
95 
97  { myAddFrontPrimGroup = grp; }
98 
100  { myAddFrontEdgeGroup = grp; }
101 
103  { myAddBackPrimGroup = grp; }
104 
106  { myAddBackEdgeGroup = grp; }
107 
109  { myAddSidePrimGroup = grp; }
110 
112  { myAddFrontSeamGroup = grp; }
113 
115  { myAddBackSeamGroup = grp; }
116 
118  { myPrimSelection = grp; }
119 
121  { myEdgeSelection = grp; }
122 
123  void setInset(float inset) { myInset = inset; }
124  void setDivisions(int div) { myDivisions = div; }
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 cleanPrivateAttributes();
199  void computeOpenPolyNormals();
200 
201  void buildPrimFront();
202  void buildEdgeFront(bool generate_edge_polys);
203 
204  void setupGroupsAndAttribs();
205  void copyEdgeGroupMembership();
206  void wrangleFrontPt(GA_Offset fpt,
207  GA_PointWrangler &wrangler);
208  void wrangleFrontVtxs(GA_Offset fpt,
209  GA_VertexWrangler &wrangler);
210 
211  void buildPrimExtrusionMaps();
212 
213  void buildEdgeExtrusionMap();
214  void calculatePathNormals(bool trivial);
215 
216  void transformEdgeFront(bool trivial);
217 
218  UT_Vector3 calcBoundaryExtrusion(GEO_Hedge h0, GEO_Hedge h1,
219  int comp);
220 
221  UT_Vector3 calcInteriorExtrusion(GA_Offset pt, int comp,
222  HedgeInterface *fhip = nullptr);
223 
224 
225  UT_Vector3 calcBoundaryInset(GA_Offset pt0, GA_Offset pt1,
226  GA_Offset pt2, GA_Offset prim0,
227  GA_Offset prim1);
228 
229  UT_Vector3 calcPathNormal(GA_Offset pt_prev, GA_Offset pt,
230  GA_Offset pt_next,
231  UT_Vector3 *out_edge_nml = nullptr);
232 
233  UT_Vector3 calcHedgeNormal(GEO_Hedge h, int &degree,
234  UT_Vector3 *binormal = nullptr);
235 
236  void transformPrimFront(bool trivial);
237  void insetPrimFront();
238 
239  GU_PolyBridge *bridgeLoops(int comp, GA_OffsetArray &src_chain,
240  GA_OffsetArray &dst_chain,
241  bool closed);
242 
243  void bridgePrimComponents(int batch_size = -1);
244  void bridgeEdgeComponents(int batch_size = -1);
245 
246  void buildPrimSeams();
247  void buildEdgeSeams();
248 
249  void calcPrimLocalFrames();
250  void calcPrimCompLocalFrame(int k);
251 
252  void calcEdgeLocalFrames();
253  void calcEdgeCompLocalFrame(int k);
254 
255  void calcCenterAndNormal(int component_id,
256  UT_Vector3 &center,
257  UT_Vector3 &normal,
258  bool add_extrusion = false,
259  bool collect_from_attributes = false);
260 
261  UT_Vector3 farthestBoundaryEdgePerp(int k);
262  UT_Vector3 longestBoundaryEdgeDir(int k);
263 
264  void updateAffectedNormals();
265 
266  UT_Vector3 getMinAreaBoxXDirection(int comp);
267 
268  void fillOutputGroups();
269  void cleanup();
270  fpreal getRescaleFactor() const;
271 
272  void buildHandleSpaceChangMat();
273 
274  void saveEdgeGroupToDetailArray(const GA_EdgeGroup *grp,
275  const char *attrib_name);
276 
277  void rescaleFront();
278 
279  bool isFrontXformTrivial() const;
280 
282  int numCompFrontPts(int k)
283  { return (myCompFrontFirstPt(k + 1) -
284  myCompFrontFirstPt(k)); }
285 
287  GA_Offset compFrontPt(int k, int i)
288  { return myFrontPts(myCompFrontFirstPt(k) + i); }
289 
291  int numCompFrontPrims(int k)
292  { return (myCompFrontFirstPrim(k + 1) -
293  myCompFrontFirstPrim(k)); }
294 
296  GA_Offset compFrontPrim(int k, int i)
297  { return myFrontPrims(myCompFrontFirstPrim(k) + i); }
298 
299 
300  // NB: only used with edge extrusion
302  int frontPtIdx(int k, int i)
303  { return (myCompFrontFirstPt(k) + i); }
304 
306  UT_Vector3 &frontPtExtrusion(int k, int i)
307  { return myFrontPtExtrusion(frontPtIdx(k, i)); }
308 
310  UT_Vector3 &frontPtPathNormal(int k, int i)
311  { return myFrontPtPathNormal(frontPtIdx(k, i)); }
312  // ---
313 
314  // index of the the ith boundary of the kth component among all boundaries
316  int frontBdIdx(int k, int j)
317  { return (myCompFrontFirstBd(k) + j); }
318 
319  // index of the ith vertex of the jth boundary
321  int frontBdVtxIdx(int j, int i)
322  { return (myFrontBdFirstVtx(j) + i); }
323 
324  // The ith vertex of the jth front boundary
326  GA_Offset &frontBdVtx(int i)
327  { return myFrontBdVtxs(i); }
328 
329  // The ith vertex of the jth front boundary
331  GA_Offset &frontBdVtx(int j, int i)
332  { return myFrontBdVtxs(frontBdVtxIdx(j, i)); }
333 
334  // ith vertex of the jth boundary of the kth component
336  GA_Offset &compFrontBdVtx(int k, int j, int i)
337  { return frontBdVtx(frontBdIdx(k, j), i); }
338 
339  // total number of boundary components of the front
341  int numFrontBds()
342  { return int(myCompFrontFirstBd.size() - 1); }
343 
344  // number of boundaries of the kth front component
346  int numCompFrontBds(int k)
347  { return (myCompFrontFirstBd(k + 1)
348  - myCompFrontFirstBd(k)); }
349 
351  int numFrontBdVtxs()
352  { return int(myFrontBdVtxs.size()); }
353 
354  // number of vertices in the jth front boundary
356  int numFrontBdVtxs(int j)
357  { return (myFrontBdFirstVtx(j + 1)
358  - myFrontBdFirstVtx(j)); }
359 
360  // number of vertices in the jth boundary of the kth front component
362  int numCompFrontBdVtxs(int k, int j)
363  { return numFrontBdVtxs(frontBdIdx(k, j)); }
364 
365  // used only in primitive extrusion
367  GA_Offset frontVtxToBackVtx(GA_Offset v)
368  { return GA_Offset(myFrontToBackVtxMap.get(v)); }
369 
370  // used only in edge extrusion
372  GA_Offset frontPtToBackPt(GA_Offset pt)
373  { return GA_Offset(myFrontToBackPtMap.get(pt)); }
374 
375 
377  int bdComp(int j) { return myBdComp(j); }
378 
379  // used in edge extrusion only
381  bool isFrontCompClosed(int k)
382  { return myFrontCompClosed.getBitFast(k); }
383 
386  { return myHip->srcPoint(h); }
387 
389  GA_Offset dstPoint(GEO_Hedge h) const
390  { return myHip->dstPoint(h); }
391 
393  GA_Offset srcVertex(GEO_Hedge h) const
394  { return myHip->srcVertex(h); }
395 
397  GA_Offset dstVertex(GEO_Hedge h) const
398  { return myHip->dstVertex(h); }
399 
401  GA_Offset vertexPrimitive(GA_Offset vtx) const
402  { return myGdp->vertexPrimitive(vtx); }
403 
406  GA_Offset p1) const
407  { return myHip->findHedgeWithEndpoints(p0, p1); }
408 
410  GEO_Hedge sym(GEO_Hedge h) const
411  { return myHip->sym(h); }
412 
414  GEO_Hedge lnext(GEO_Hedge h) const
415  { return myHip->lnext(h); }
416 
418  GEO_Hedge lprev(GEO_Hedge h) const
419  { return myHip->lprev(h); }
420 
422  UT_Vector3 getPos3(GA_Offset pt) const
423  { return { myGdp->getPos3(pt) }; }
424 
426  bool isValidHedge(GEO_Hedge h) const
427  { return myHip->isValidHedge(h); }
428 
430  UT_Vector3 pointNormal(GA_Offset pt) const
431  { return { myPointNormal.get(pt) }; }
432 
434  UT_Vector3 polyNormal(GA_Offset pt) const
435  { return { myPolyNormal.get(pt) }; }
436 
437  GU_Detail *myGdp = nullptr;
438  GA_PrimitiveGroup *myPolys = nullptr;
439  const GA_EdgeGroup *myEdges = nullptr;
440  fpreal myTolerance;
441 
442  GA_RWHandleV3 myPolyNormal;
443  GA_RWHandleV3 myPointNormal;
444 
445  UT_Vector3Array myBackCompCtr; // Center used for back
446  UT_Vector3Array myBackCompBary; // Barycenter of the back
447 
448  UT_Vector3Array myCompXDir, myCompYDir, myCompZDir;
449 
450  UT_Vector3Array myFrontCompCtr; // Calculated front center
451  UT_Vector3Array myExtrudedCompCtr; // Centroid of extruded comp
452  UT_Vector3Array myFrontCompZDir, myFrontCompXDir;
453 
454  UT_FprealArray myCompDivsScale;
455  UT_FprealArray myCompZScale;
456  UT_FprealArray myCompInsetScale;
457  UT_FprealArray myCompTwistScale;
458 
459 
460  UT_Matrix4 myHandleSpaceChangeMat;
461 
462  fpreal myDeviationToleranceCos = 0.984807753012208;
463  fpreal mySrcMagnitude = 1.0;
464  fpreal myDstMagnitude = 1.0;
465  fpreal mySrcStiffness = 1.0;
466  fpreal myDstStiffness = 1.0;
467  fpreal myExtSpineSrcBlend, myExtSpineDstBlend;
468 
469  UT_Vector3 myDraggerStart, myDraggerDir;
470 
471  //GU_Decompose *myDecompose = nullptr;
472  PolyPatches *myPolyPatches = nullptr;
473  EdgePaths *myEdgePaths = nullptr;
474 
475 
476  GA_PointGroupUPtr myFrontBoundaryPtGroup;
477  GA_PrimitiveGroup *myFrontPrimGroup = nullptr;
478  GA_PrimitiveGroup *myBackPrimGroup = nullptr;
479  GA_PrimitiveGroup *mySidePrimGroup = nullptr;
480  GA_EdgeGroup *myFrontEdgeGroup = nullptr;
481  GA_EdgeGroup *myBackEdgeGroup = nullptr;
482 
483  GA_PrimitiveGroup *myAddFrontPrimGroup = nullptr;
484  GA_PrimitiveGroup *myAddBackPrimGroup = nullptr;
485  GA_PrimitiveGroup *myAddSidePrimGroup = nullptr;
486  GA_EdgeGroup *myAddFrontEdgeGroup = nullptr;
487  GA_EdgeGroup *myAddBackEdgeGroup = nullptr;
488  GA_EdgeGroup *myAddFrontSeamGroup = nullptr;
489  GA_EdgeGroup *myAddBackSeamGroup = nullptr;
490 
491  GA_PrimitiveGroup *myPrimSelection = nullptr;
492  GA_EdgeGroup *myEdgeSelection = nullptr;
493 
494  ExtrusionMode myExtrusionMode = PRIM_OR_EDGE_NORMAL;
495 
496  UT_Matrix4 myFrontXform;
497  fpreal myDistance = 0.0;
498  int myNumFrontPts = 0;
499 
500  MorphMethod myMorphMethod = MorphMethod::LINEAR;
501 
502  bool myOutputFront = true;
503  bool myOutputBack = false;
504  bool myReverseBack = true;
505  bool myOutputSide = true;
506  bool myStraightSpine = true;
507  bool myReverseSpine = false;
508  bool myUseExistingNormal = false;
509  bool myCopyPtGrps = true;
510  bool myCopyPrimGrps = true;
511 
512  bool myAddVertexNormal = false;
513  bool myCuspFront = true;
514  bool myCuspBack = true;
515 
516  bool myWranglePt = false;
517  bool myWranglePrim = false;
518  bool myWrangleVtx = false;
519 
520  bool myXformIsTrivial = true;
521  bool myTrivialNormal = true;
522 
523  bool myLimitInset = true;
524  bool myCommonInsetLimit = true;
525 
526  fpreal myCuspAngleDegrees = 60.06;
527 
528  int myDivisions = 1;
529  fpreal myTwist = 0.0;
530  fpreal myInset = 0.0;
531  fpreal myThicknessScale = 1.0;
532  fpreal myTwistScale = M_PI;
533  UT_Ramp *myTwistRamp = nullptr;
534  UT_Ramp *myThicknessRamp = nullptr;
535 
536  const GEO_Face *myExternalSpine = nullptr;
537  GA_Attribute *myThicknessAttrib = nullptr;
538  GA_Attribute *myTwistAttrib = nullptr;
539 
540  fpreal mySpineStart = 0.0;
541  fpreal mySpineEnd = 1.0;
542  fpreal myAxialRotation = 0.0;
543 
544  GA_AttributeUPtr myFrontPtIdxOwner;
545  GA_AttributeUPtr myFrontToBackVtxMapOwner;
546  GA_AttributeUPtr myFrontToBackPtMapOwner;
547 
548  GA_ROHandleI myFrontPtIdx;
549  GA_ROHandleI myFrontToBackVtxMap;
550  GA_ROHandleI myFrontToBackPtMap;
551 
552  GA_ROHandleV3 myLocalXDirAttr;
553  GA_ROHandleV3 myLocalZDirAttr;
554  GA_ROHandleV3 myLocalCtrAttr;
555  GA_ROHandleF myLocalZScaleAttr;
556  GA_ROHandleF myLocalInsetScaleAttr;
557  GA_ROHandleF myLocalTwistScaleAttr;
558  GA_ROHandleF myLocalDivsScaleAttr;
559 
560  GA_ROHandleV3 mySuppliedPointNormal;
561 
562  int myNumComponents = 0;
563  int myNumCompBoundaries = 0;
564 
565  SpineSampleMethod mySpineSampleMethod;
566 
567  UT_Vector3Array myFrontPtPos;
568  UT_Vector3Array myFrontPtExtrusion;
569  UT_Vector3Array myFrontPtInset;
570  UT_Vector3Array myFrontPtPathNormal;
571 
572  bool myXformIsGlobal = false;
573 
574  GA_OffsetArray myFrontPts;
575  UT_IntArray myCompFrontFirstPt;
576  UT_BitArray myFrontCompClosed; // edge extrusion use only
577 
578  GA_OffsetArray myFrontPrims;
579  UT_IntArray myCompFrontFirstPrim;
580 
581  GA_OffsetArray myFrontBdVtxs;
582  UT_IntArray myFrontBdFirstVtx;
583  UT_IntArray myCompFrontFirstBd;
584  UT_IntArray myBdComp;
585 
586  TextureMode mySideTextureMode = GU_PolyBridge::INTERPOLATE;
587  TextureScaling mySideTextureScaling = GU_PolyBridge::FIT_UNIT_SQUARE;
588 
589  IndexPairArray myBridgePairing;
590  HedgeInterface *myHip;
591 };
592 
593 #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:203
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:653
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:995
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:283
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