HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <UT/UT_Matrix4.h>
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Vector3.h>
18 #include <GA/GA_Types.h>
19 #include <GEO/GEO_HedgeInterface.h>
20 #include "GU_PolyBridge.h"
21 
22 class GA_Group;
23 class GA_PrimitiveGroup;
24 class GA_PointGroup;
25 class GA_PrimitiveGroup;
27 class GEO_Face;
28 class GEO_PrimPoly;
29 class GU_Detail;
30 class GA_Attribute;
32 class GU_Decompose;
33 
34 template<typename T, bool B> class GA_EdgeT;
36 
37 
39 {
40 public:
41 
43  const GA_PrimitiveGroup *prims,
44  const GA_EdgeGroup *split_edges = NULL,
45  bool split_all = false);
46 
48  const GA_EdgeGroup *edges,
49  const GA_PointGroup *split_points = NULL,
50  bool split_all = false);
51 
52  ~GU_PolyExtrude2();
53 
55  {
56  PRIM_OR_EDGE_NORMAL = 0,
58  };
59 
62 
63  // Performs the extrusion
64  void extrude(fpreal distance = 0.0);
65 
66  // Methods to help placing a handle on the first component
67  UT_Vector3 getXformHandleCenter();
68  UT_Matrix4 getXformHandleXform();
69  UT_Vector3 getDraggerStart();
70  UT_Vector3 getDraggerDir();
71 
72 
73  bool isTrivial() const;
74 
76  { myExtrusionMode = m; }
78  { myMorphMethod = m; }
79 
80  void setOutputFront(bool b) { myOutputFront = b; }
81  void setOutputBack(bool b) { myOutputBack = b; }
82  void setOutputSide(bool b) { myOutputSide = b; }
83 
85  { myUseExistingNormal = b; }
86 
88  { mySuppliedPointNormal = ptnml; }
89 
91  { myAddFrontPrimGroup = grp; }
92 
94  { myAddFrontEdgeGroup = grp; }
95 
97  { myAddBackPrimGroup = grp; }
98 
100  { myAddBackEdgeGroup = grp; }
101 
103  { myAddSidePrimGroup = grp; }
104 
106  { myAddFrontSeamGroup = grp; }
107 
109  { myAddBackSeamGroup = grp; }
110 
112  { myPrimSelection = grp; }
113 
115  { myEdgeSelection = grp; }
116 
117  void setInset(float inset) { myInset = inset; }
118  void setDivisions(int div) { myDivisions = div; }
119  void setPreserveGroups(bool b) { myPreserveGroups = b; }
120  void setStraightSpine(bool b) { myStraightSpine = b; }
121  void setTwist(fpreal t) { myTwist = t; }
122  void setThicknessScale(fpreal s) { myThicknessScale = s; }
123  void setTwistScale(fpreal s) { myTwistScale = s; }
124  void setThicknessRamp(UT_Ramp *r) { myThicknessRamp = r; }
125  void setTwistRamp(UT_Ramp *r) { myTwistRamp = r; }
127  { myDeviationToleranceCos = SYScos(a); }
128  void setAxialRotation(fpreal r) { myAxialRotation = r; }
129 
131  { myExtSpineSrcBlend = s; myExtSpineDstBlend = d; }
132 
133  void setXform(const UT_Matrix4 &frontxform,
134  bool is_global = false);
135 
137  { myExternalSpine = curve; }
138 
139 
141  { myThicknessAttrib = attrib; }
142 
144  { myTwistAttrib = attrib; }
145 
147  { mySpineStart = s; mySpineEnd = e; }
148 
149  void setReverseSpine(bool b) { myReverseSpine = b; }
151  { mySrcMagnitude = s; myDstMagnitude = d; }
152 
154  { mySrcStiffness = s; myDstStiffness = d; }
155 
156  void addVertexNormals(fpreal cusp_angle_degrees,
157  bool cusp_front, bool cusp_back);
158 
160  { mySpineSampleMethod = m; }
161 
162  void limitInset(bool limit, bool common_limit)
163  { myLimitInset = limit;
164  myCommonInsetLimit = common_limit; }
165 
166  void setLocalXDirAttrib(const char *attrib_name);
167  void setLocalZDirAttrib(const char *attrib_name);
168  void setLocalCtrAttrib(const char *attrib_name);
169  void setLocalDistScaleAttrib(const char *attrib_name);
170  void setLocalInsetScaleAttrib(const char *attrib_name);
171  void setLocalTwistScaleAttrib(const char *attrib_name);
172  void setLocalDivsScaleAttrib(const char *attrib_name);
173 
176 
177  void setSideTexturing(TextureMode mode,
178  TextureScaling scaling);
179 
180  fpreal getCompInsetScale(int k);
181  fpreal getCompDistScale(int k);
182  fpreal getCompTwistScale(int k);
183  fpreal getCompDivsScale(int k);
184 
185 private:
186 
187  void initialize();
188  void computeOpenPolyNormals();
189 
190  void buildPrimFront();
191  void buildEdgeFront(bool generate_edge_polys);
192 
193  void setupGroupsAndAttribs();
194 
195  void buildPrimExtrusionMaps();
196  void buildComponentExtrusionMap(int k);
197 
198  void buildEdgeExtrusionMap();
199  void calculatePathNormals(bool trivial);
200 
201  void setFrontPointPositions();
202  void transformEdgeFront(bool trivial);
203 
204  UT_Vector3 calcBoundaryExtrusion(GEO_Hedge h0, GEO_Hedge h1,
205  int comp);
206 
207  UT_Vector3 calcInteriorExtrusion(GA_Offset pt, int comp);
208  UT_Vector3 calcInteriorExtrusion(GA_Offset pt, int comp,
209  const GEO_DetachedHedgeInterface *fhip = 0);
210 
211 
212  UT_Vector3 calcBoundaryInset(GA_Offset pt0, GA_Offset pt1,
213  GA_Offset pt2, GA_Offset prim0,
214  GA_Offset prim1);
215 
216  UT_Vector3 calcPathNormal(GA_Offset p0, GA_Offset p1,
217  GA_Offset p2, int comp, UT_Vector3 *en0 = NULL,
218  UT_Vector3 *en1 = NULL);
219 
220  UT_Vector3 calcHedgeNormal(GEO_Hedge h, int &degree,
221  UT_Vector3 *binormal = 0);
222 
223  void transformPrimFront(bool trivial);
224  void insetPrimFront();
225 
226  GU_PolyBridge *bridgeLoops(int comp, GA_OffsetArray &src_chain,
227  GA_OffsetArray &dst_chain,
228  bool closed);
229 
230  void bridgePrimComponents(int batch_size = -1);
231  void bridgeEdgeComponents(int batch_size = -1);
232 
233  void buildPrimSeams();
234  void buildEdgeSeams();
235 
236  void calcPrimLocalFrames();
237  void calcPrimCompLocalFrame(int k);
238 
239  void calcEdgeLocalFrames();
240  void calcEdgeCompLocalFrame(int k);
241 
242  void calcCenterAndNormal(int component_id,
243  UT_Vector3 &center,
244  UT_Vector3 &normal,
245  bool add_extrusion = false,
246  bool collect_from_attributes = false);
247 
248  UT_Vector3 farthestBoundaryEdgePerp(int k);
249  UT_Vector3 longestBoundaryEdgeDir(int k);
250 
251  void updateAffectedNormals();
252 
253  UT_Vector3 getMinAreaBoxXDirection(int comp);
254 
255  void fillOutputGroups();
256  void cleanup();
257  fpreal getRescaleFactor() const;
258 
259  void buildHandleSpaceChangMat();
260 
261  void saveEdgeGroupToDetailArray(const GA_EdgeGroup *grp,
262  const char *attrib_name);
263 
264  void rescaleFront();
265 
266  void buildXformFromExternalSpine();
267 
268  bool isFrontXformTrivial() const;
269 
270  inline int numCompFrontPts(int k)
271  { return (myCompFrontFirstPt(k + 1) -
272  myCompFrontFirstPt(k)); }
273 
274  inline GA_Offset compFrontPt(int k, int i)
275  { return myFrontPts(myCompFrontFirstPt(k) + i); }
276 
277  inline int numCompFrontPrims(int k)
278  { return (myCompFrontFirstPrim(k + 1) -
279  myCompFrontFirstPrim(k)); }
280 
281  inline GA_Offset compFrontPrim(int k, int i)
282  { return myFrontPrims(myCompFrontFirstPrim(k) + i); }
283 
284 
285  // NB: only used with edge extrusion
286  inline int frontPtIdx(int k, int i)
287  { return (myCompFrontFirstPt(k) + i); }
288 
289  inline UT_Vector3 &frontPtExtrusion(int k, int i)
290  { return myFrontPtExtrusion(frontPtIdx(k, i)); }
291 
292  inline UT_Vector3 &frontPtPathNormal(int k, int i)
293  { return myFrontPtPathNormal(frontPtIdx(k, i)); }
294  // ---
295 
296  // index of the the ith boundary of the kth component among all boundaries
297  inline int frontBdIdx(int k, int j)
298  { return (myCompFrontFirstBd(k) + j); }
299 
300  // index of the ith vertex of the jth boundary
301  inline int frontBdVtxIdx(int j, int i)
302  { return (myFrontBdFirstVtx(j) + i); }
303 
304  // The ith vertex of the jth front boundary
305  inline GA_Offset &frontBdVtx(int i)
306  { return myFrontBdVtxs(i); }
307 
308  // The ith vertex of the jth front boundary
309  inline GA_Offset &frontBdVtx(int j, int i)
310  { return myFrontBdVtxs(frontBdVtxIdx(j, i)); }
311 
312  // ith vertex of the jth boundary of the kth component
313  inline GA_Offset &compFrontBdVtx(int k, int j, int i)
314  { return frontBdVtx(frontBdIdx(k, j), i); }
315 
316  // total number of boundary components of the front
317  inline int numFrontBds()
318  { return myCompFrontFirstBd.entries() - 1; }
319 
320  // number of boundaries of the kth front component
321  inline int numCompFrontBds(int k)
322  { return (myCompFrontFirstBd(k + 1)
323  - myCompFrontFirstBd(k)); }
324 
325  inline int numFrontBdVtxs()
326  { return myFrontBdVtxs.entries(); }
327 
328  // number of vertices in the jth front boundary
329  inline int numFrontBdVtxs(int j)
330  { return (myFrontBdFirstVtx(j + 1)
331  - myFrontBdFirstVtx(j)); }
332 
333  // number of vertices in the jth boundary of the kth front component
334  inline int numCompFrontBdVtxs(int k, int j)
335  { return numFrontBdVtxs(frontBdIdx(k, j)); }
336 
337  // used only in primitive extrusion
338  inline GA_Offset frontVtxToBackVtx(GA_Offset v)
339  { return GA_Offset(myFrontToBackVtxMap.get(v)); }
340 
341  // used only in edge extrusion
342  inline GA_Offset frontPtToBackPt(GA_Offset pt)
343  { return GA_Offset(myFrontToBackPtMap.get(pt)); }
344 
345 
346  inline int bdComp(int j) { return myBdComp(j); }
347 
348  // used in edge extrusion only
349  inline int isFrontCompClosed(int k)
350  { return myFrontCompClosed.getBitFast(k); }
351 
352 
353  typedef GU_PolyBridge::IndexPairArray IndexPairArray;
354 
355  GU_Detail *myGdp;
356 
357  GA_PrimitiveGroup *myPrims;
358 
359  const
360  GA_EdgeGroup *myEdges;
361 
362  GU_Decompose *myDecompose;
363 
364  GA_RWHandleV3 myPrimNormal;
365  GA_RWHandleV3 myPointNormal;
366 
367  UT_Vector3Array myBackCompCtr; // Center used for back
368  UT_Vector3Array myBackCompBary; // Barycenter of the back
369 
370  UT_Vector3Array myCompXDir, myCompYDir, myCompZDir;
371 
372  UT_Vector3Array myFrontCompCtr; // Calculated front center
373  UT_Vector3Array myExtrudedCompCtr; // Centroid of extruded comp
374  UT_Vector3Array myFrontCompZDir, myFrontCompXDir;
375 
376  UT_FprealArray myCompDivsScale;
377  UT_FprealArray myCompZScale;
378  UT_FprealArray myCompInsetScale;
379  UT_FprealArray myCompTwistScale;
380 
381 
382  UT_Matrix4 myHandleSpaceChangeMat;
383 
384  fpreal myDeviationToleranceCos;
385  fpreal mySrcMagnitude, myDstMagnitude;
386  fpreal mySrcStiffness, myDstStiffness;
387  fpreal myExtSpineSrcBlend, myExtSpineDstBlend;
388 
389  UT_Vector3 myDraggerStart, myDraggerDir;
390 
391  GA_PointGroup *myFrontBoundaryPtGroup;
392  GA_PrimitiveGroup *myFrontPrimGroup;
393  GA_PrimitiveGroup *myBackPrimGroup;
394  GA_PrimitiveGroup *mySidePrimGroup;
395  GA_EdgeGroup *myFrontEdgeGroup;
396  GA_EdgeGroup *myBackEdgeGroup;
397 
398  GA_PrimitiveGroup *myAddFrontPrimGroup;
399  GA_PrimitiveGroup *myAddBackPrimGroup;
400  GA_PrimitiveGroup *myAddSidePrimGroup;
401  GA_EdgeGroup *myAddFrontEdgeGroup;
402  GA_EdgeGroup *myAddBackEdgeGroup;
403  GA_EdgeGroup *myAddFrontSeamGroup;
404  GA_EdgeGroup *myAddBackSeamGroup;
405 
406  GA_PrimitiveGroup *myPrimSelection;
407  GA_EdgeGroup *myEdgeSelection;
408 
409  ExtrusionMode myExtrusionMode;
410 
411  UT_Matrix4 myFrontXform;
412  fpreal myDistance;
413 
414  exint myNumFrontPts;
415  exint myNumBackVtxs;
416 
417  MorphMethod myMorphMethod;
418 
419  bool myOutputFront: 1;
420  bool myOutputBack: 1;
421  bool myReverseBack: 1;
422  bool myOutputSide: 1;
423  bool myStraightSpine: 1;
424  bool myPreserveGroups: 1;
425  bool myReverseSpine: 1;
426  bool myUseExistingNormal: 1;
427 
428  bool myAddVertexNormal: 1;
429  bool myCuspFront: 1;
430  bool myCuspBack: 1;
431 
432  bool myWranglePt: 1;
433  bool myWranglePrim: 1;
434  bool myWrangleVtx: 1;
435 
436  bool myXformIsTrivial: 1;
437  bool myTrivialNormal: 1;
438 
439  bool myLimitInset: 1;
440  bool myCommonInsetLimit: 1;
441 
442  fpreal myCuspAngleDegrees;
443 
444  int myDivisions;
445  fpreal myTwist;
446  fpreal myInset;
447  fpreal myThicknessScale;
448  fpreal myTwistScale;
449  UT_Ramp *myTwistRamp;
450  UT_Ramp *myThicknessRamp;
451 
452  GEO_Face *myExternalSpine;
453  GA_Attribute *myThicknessAttrib;
454  GA_Attribute *myTwistAttrib;
455 
456  fpreal mySpineStart;
457  fpreal mySpineEnd;
458  fpreal myAxialRotation;
459 
460  GA_ROHandleI myFrontPtIdx;
461  GA_ROHandleI myFrontToBackVtxMap;
462  GA_ROHandleI myFrontToBackPtMap;
463 
464  GA_ROHandleV3 myLocalXDirAttr;
465  GA_ROHandleV3 myLocalZDirAttr;
466  GA_ROHandleV3 myLocalCtrAttr;
467  GA_ROHandleF myLocalZScaleAttr;
468  GA_ROHandleF myLocalInsetScaleAttr;
469  GA_ROHandleF myLocalTwistScaleAttr;
470  GA_ROHandleF myLocalDivsScaleAttr;
471 
472  GA_ROHandleV3 mySuppliedPointNormal;
473 
474  int myNumComponents;
475  int myNumCompBoundaries;
476 
477  SpineSampleMethod mySpineSampleMethod;
478 
479  UT_Vector3Array myFrontPtPos;
480  UT_Vector3Array myFrontPtExtrusion;
481  UT_Vector3Array myFrontPtInset;
482  UT_Vector3Array myFrontPtPathNormal;
483 
484  bool myXformIsGlobal;
485 
486  GA_OffsetArray myFrontPts;
487  UT_IntArray myCompFrontFirstPt;
488  UT_BitArray myFrontCompClosed; // edge extrusion use only
489 
490  GA_OffsetArray myFrontPrims;
491  UT_IntArray myCompFrontFirstPrim;
492 
493  GA_OffsetArray myFrontBdVtxs;
494  UT_IntArray myFrontBdFirstVtx;
495  UT_IntArray myCompFrontFirstBd;
496  UT_IntArray myBdComp;
497 
498  TextureMode mySideTextureMode = GU_PolyBridge::INTERPOLATE;
499  TextureScaling mySideTextureScaling = GU_PolyBridge::FIT_UNIT_SQUARE;
500 
501  IndexPairArray myBridgePairing;
502  const GEO_DetachedHedgeInterface *myHip;
503 };
504 
505 #endif
void setReverseSpine(bool b)
void setTwistScale(fpreal s)
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
GA_API const UT_StringHolder div
void limitInset(bool limit, bool common_limit)
void setStiffnesses(fpreal s, fpreal d)
const GLdouble * v
Definition: glcorearb.h:836
GU_PolyBridge::MorphMethod MorphMethod
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void setOutputSide(bool b)
void setPointNormalAttrib(GA_ROHandleV3 ptnml)
void setSpineSampleMethod(SpineSampleMethod m)
void setDivisions(int div)
png_uint_32 i
Definition: png.h:2877
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:617
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
int64 exint
Definition: SYS_Types.h:109
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)
void setFrontGroup(GA_PrimitiveGroup *grp)
void setMagnitudes(fpreal s, fpreal d)
#define GU_API
Definition: GU_API.h:11
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLenum mode
Definition: glcorearb.h:98
void setBackSeamGroup(GA_EdgeGroup *grp)
void setSpineRange(fpreal s, fpreal e)
void setAxialRotation(fpreal r)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:263
void setThicknessAttrib(GA_Attribute *attrib)
void setDeviationTolerance(fpreal a)
void setTwistRamp(UT_Ramp *r)
void setExtrusionMode(ExtrusionMode m)
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
void setExtSpineBlend(fpreal s, fpreal d)
void setBackGroup(GA_PrimitiveGroup *grp)
void setOutputFront(bool b)
void setSelectionGroup(GA_EdgeGroup *grp)
void setUseExistingPointNormal(bool b)
GU_PolyBridge::SpineSampleMethod SpineSampleMethod
GLboolean r
Definition: glcorearb.h:1221
void setStraightSpine(bool b)
void setExternalSpine(GEO_Face *curve)
void setSelectionGroup(GA_PrimitiveGroup *grp)
void setInset(float inset)
void setFrontSeamGroup(GA_EdgeGroup *grp)