HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_Flatten2.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: Flatten GU
9  */
10 
11 #ifndef __GU_Flatten2_h__
12 #define __GU_Flatten2_h__
13 
14 #include "GU_API.h"
15 #include "GU_Detail.h"
16 #include <GA/GA_Edge.h>
17 #include <GA/GA_EdgeGroup.h>
18 #include <UT/UT_StringStream.h>
19 #include <UT/UT_Map.h>
20 #include <GEO/GEO_HedgeInterface.h>
22 #include <UT/UT_SparseMatrix.h>
23 
24 class UT_Classifier;
25 
26 #define USE_EIGEN
27 #define USE_SPECTRA
28 
29 
30 class UT_AutoInterrupt;
31 
33 {
34 public:
35  enum Method
36  {
37  SPECTRAL, // Spectral variant of LSCM
38  LSCM, // Original LSCM
39  LINEAR_ABF // Linear version of Angle-Based Flattening
40  };
41 
42  enum DirLabel {
46  CONTRADICTION
47  };
48 
49  GU_Flatten2(GU_Detail *gdp, GA_Attribute *uv_attrib,
50  const GA_PrimitiveGroup *prims,
51  const GA_EdgeGroup *seams,
52  const GA_EdgeGroup *extra_seams,
53  bool use_input_uv,
54  bool axis_align_islands,
55  bool repack_wasted,
56  Method method,
57  bool straighten_boundary,
58  bool straighten_interior, bool orthogonalize,
59  bool use_input_boundary_uv,
60  int test = 0);
61 
62  ~GU_Flatten2();
63 
64 
65  int getNumIslands() { return myNumIslands; }
66 
67  /// Updates UVs in myTGdp and packs all islands into the unit square.
68  void flattenAndPack();
69 
70  /// Re-flattens islands affected by the constrinats.
71  void reflattenConstrainedIslands();
72 
73 
74  void getAlignUVs(UT_Vector2FArray &uvs);
75  void getAlignPointsUVs(UT_Vector2FArray &uvs);
76  void getStraightenEdgesUVs(UT_Vector2FArray &uvs);
77  void getAlignEdgesUVs(UT_Vector2FArray &uvs);
78  void getExtraSeamEdgesUVs(UT_Vector2FArray &uvs);
79  void getUPathUVs(UT_Vector2FArray &uvs);
80  void getVPathUVs(UT_Vector2FArray &uvs);
81  void getUnalignedPathUVs(UT_Vector2FArray &uvs);
82 
83 
84  // Adds an vertex attribute called "uvpointid" mapping vertices of myGdp to
85  // the corresponding point indices of myRGdp; this is used in MPI and MSS
86  void addPointIdAttribute();
87 
88  /// Creates a primitive attribute for island number
89  void addIslandAttribute(bool add);
90 
91  /// Change the extra cuts edge group
92  void updateExtraSeamsGroup(const GA_EdgeGroup *exgp);
93 
94  /// Change the primitive group
95  void updatePrimitiveGroup(const GA_PrimitiveGroup *prims);
96 
97  /// Add one pinned point
98  void addPin(int prim, int vert, fpreal u, fpreal v);
99 
100  /// Create a vertex group of all original pins.
101  void addOriginalPinGroup(const char *name);
102 
103  /// Create a vertex group of all pins used during the flattening, both
104  /// initial and user-specified.
105  void addActivePinGroup(const char *name);
106 
107  void addSeamsGroup(const char *name);
108 
109  // The class encapsulating a pin
110  class Pin
111  {
112  public:
113  Pin() :
114  myInputVertex(GA_INVALID_OFFSET), myPoint(GA_INVALID_OFFSET),
115  myIslandIndex(-1), myU(0.0), myV(0.0), myToRemove(false) {}
116 
117  Pin(GA_Offset voff, GA_Offset ptof, int is, fpreal u, fpreal v) :
118  myInputVertex(voff), myPoint(ptof), myIslandIndex(is),
119  myU(u), myV(v), myToRemove(false) {}
120 
121  Pin(const Pin &other) :
122  myInputVertex(other.myInputVertex), myPoint(other.myPoint),
123  myIslandIndex(other.myIslandIndex), myU(other.myU), myV(other.myV),
124  myToRemove(other.myToRemove) {}
125 
126  GA_Offset getInputVertex() const { return myInputVertex; }
127  GA_Offset getPoint() const { return myPoint; }
128 
130  void setU(fpreal u) { myU = u; }
131 
133  void setV(fpreal v) { myV = v; }
134 
136  fpreal u() const { return myU; }
137 
139  fpreal v() const { return myV; }
140 
142  int getIslandIndex() const { return myIslandIndex; }
144  void setToRemove(bool b) { myToRemove = b; }
146  bool isToRemove() const { return myToRemove; }
147  private:
148  GA_Offset myInputVertex; // vertex offset in myGdp
149  GA_Offset myPoint; // point offset in myRGdp for regular
150  // pins or in myTGdp for "original" pins
151  fpreal myU, myV;
152  bool myToRemove;
153  int myIslandIndex;
154  };
155 
157  {
158  public:
160  myInputVertex(GA_INVALID_OFFSET), myPoint(GA_INVALID_OFFSET),
161  myIslandIndex(-1), myToRemove(false),
162  myFromVertex(GA_INVALID_OFFSET), myToVertex(GA_INVALID_OFFSET){}
163 
164  AlignVertex(GA_Offset v, GA_Offset p, int isInd, bool rem = false) :
165  myInputVertex(v), myPoint(p),
166  myIslandIndex(isInd), myToRemove(rem){}
167 
169  GA_Offset to_pt, int isInd, bool rem = false) :
170  myInputVertex(v), myPoint(p), myFromVertex(from_pt),
171  myToVertex(to_pt), myIslandIndex(isInd), myToRemove(rem){}
172 
173  AlignVertex (const AlignVertex &other) :
174  myInputVertex(other.myInputVertex), myPoint(other.myPoint),
175  myIslandIndex(other.myIslandIndex),
176  myFromVertex(other.myFromVertex),
177  myToVertex(other.myToVertex),
178  myToRemove(other.myToRemove) { }
179 
180  GA_Offset getInputVertex() const { return myInputVertex; }
181  GA_Offset getPoint() const { return myPoint; }
183  int getIslandIndex() const { return myIslandIndex; }
185  void setToRemove(bool b) { myToRemove = b; }
187  bool isToRemove() const { return myToRemove; }
188 
189  private:
190  GA_Offset myInputVertex; // vertex offset in myGdp
191  GA_Offset myPoint; // point offset in myRGdp for regular
192  // pins or in myTGdp for "original" pins
193  GA_Offset myFromVertex;
194  GA_Offset myToVertex;
195  bool myToRemove;
196  int myIslandIndex;
197  };
198 
200  {
201  public:
203  myAlignVertices(0), myIslandIndex(-1), myDirection(0) {}
204 
205  explicit
206  AlignGroup (int d) :
207  myAlignVertices(0), myIslandIndex(-1), myDirection(d) {}
208 
209  int getIslandIndex() { return myIslandIndex; }
210  void setIslandIndex(int i) { myIslandIndex = i; }
211  AlignVertex operator() (int i) { return myAlignVertices(i); }
212  exint size() { return myAlignVertices.size(); }
214  { myAlignVertices.append(v); }
215  int getDirection() { return myDirection; }
216  bool getActive() { return myActive; }
217  void setActive(bool b) { myActive = b; }
218 
219  private:
220  using AlignArray = UT_Array<AlignVertex>;
221 
222  AlignArray myAlignVertices;
223  int myIslandIndex;
224  int myDirection;
225  bool myActive;
226  };
227 
229  {
230  public:
231  VirtualHedge() : myOppAngle(0.0), myPolyArea(0.0),
232  myBoundary(false),
233  mySrcPoint(GA_INVALID_OFFSET),
234  myDstPoint(GA_INVALID_OFFSET) {}
235 
236  VirtualHedge(GA_Offset src_p, GA_Offset dst_p, fpreal opp_angle,
237  fpreal area, bool boundary) :
238  mySrcPoint(src_p), myDstPoint(dst_p),
239  myOppAngle(opp_angle), myPolyArea(area),
240  myBoundary(boundary) {}
241 
242  GA_Offset getSrcPoint() { return mySrcPoint; }
243  GA_Offset getDstPoint() { return myDstPoint; }
244  fpreal getOppAngle() { return myOppAngle; }
245  fpreal getPolyArea() { return myPolyArea; }
246  bool isBoundary() { return myBoundary; }
247 
248  private:
249  GA_Offset mySrcPoint;
250  GA_Offset myDstPoint;
251  fpreal myOppAngle;
252  fpreal myPolyArea;
253  bool myBoundary;
254  };
255 
256 
257  // This structure represents constraints in angles
258  // The angle swept when moving from myInHedge to myOutHedge is constrained
259  // to be myAngle
260  // Starting from myInHedge, we move from hedge to hedge in the following way :
261  // hedge to sym of lnext of hedge
262  // We move until we reach the sym of myOutHedge
263  // The sum of all angles at the dst vertex of all the hedges we see is
264  // constrained to be myAngle
266  {
267  public:
269  myFromPoint(GA_INVALID_OFFSET),
270  myToPoint(GA_INVALID_OFFSET),
271  myInHedge(GEO_INVALID_HEDGE),
272  myOutHedge(GEO_INVALID_HEDGE) {}
273 
275  GEO_Hedge in_hedge, GEO_Hedge out_hedge) :
276  myPoint(pt), myFromPoint(from_pt), myToPoint(to_pt), myAngle(a),
277  myInHedge(in_hedge), myOutHedge(out_hedge) {}
278 
279 
280  bool operator==(AngleConstraint &align_trip)
281  {
282  if (myPoint != align_trip.getPoint())
283  return false;
284 
285  if (GAisValid(myFromPoint))
286  {
287  if (GAisValid(align_trip.getFromPoint()) &&
288  myFromPoint == align_trip.getFromPoint())
289  return true;
290  if (GAisValid(align_trip.getToPoint()) &&
291  myFromPoint == align_trip.getToPoint())
292  return true;
293  }
294 
295  if (GAisValid(myToPoint))
296  {
297  if (GAisValid(align_trip.getFromPoint()) &&
298  myToPoint == align_trip.getFromPoint())
299  return true;
300  if (GAisValid(align_trip.getToPoint()) &&
301  myToPoint == align_trip.getToPoint())
302  return true;
303  }
304 
305  return false;
306  }
307 
308  GA_Offset getPoint() const { return myPoint; };
309  GA_Offset getFromPoint() const { return myFromPoint; };
310  GA_Offset getToPoint() const { return myToPoint; };
311  fpreal getAngle() const { return myAngle; }
312  GEO_Hedge getInHedge() const { return myInHedge; }
313  GEO_Hedge getOutHedge() const { return myOutHedge; }
314 
315  private:
316  GA_Offset myPoint;
317  GA_Offset myFromPoint;
318  GA_Offset myToPoint;
319  fpreal myAngle = 0.0;
320 
321  GEO_Hedge myInHedge;
322  GEO_Hedge myOutHedge;
323  };
324 
329 
330  void clearAlignGroups();
331 
332  void pinInputBoundary();
333 
334  void addAlignGroup
335  (GA_VertexGroup *vtx_group, int dir = 0);
336  void processAlignGroups();
337  void addAlignGroupToMap
338  (AlignGroupMap &map,AlignGroup align_group);
339 
340  void getPathUVs(UT_Vector2FArray &uvs, GA_OffsetArray &hedges);
341 
342  const
344  { return myWarningMessage.str().toStdString(); }
345 private:
346 
347  void buildIslands(GU_Detail *gdp, int num_islands, const GA_RWHandleV3 &uvattrib);
348 
349  class Island
350  {
351  public:
352  Island(GU_Detail *gdp, int island_id, bool pos_from_uv, const GA_RWHandleV3 &uvattrib);
353 
354  const GU_Detail *getDetail() const { return myGdp; }
355  GU_Detail *getDetail() { return myGdp; }
356  int getIndex() const { return myIndex; }
357  GA_RWHandleV3 &getUVHandle() { return myUV; }
358 
359  const
360  GA_OffsetArray &getPoints() const { return myPoints; }
361  const
362  GA_OffsetArray &getPrimitives() const { return myPrimitives; }
363  //GA_OffsetArray islandPrimitives() const { return myPrimitives; }
364  const
365  GA_OffsetArray &getInputPrimitives() const { return myInputPrimitives; }
366 
368  UT_Vector3 getPos3(GA_Offset pt) const;
369 
371  void appendPrimitive(GA_Offset primoff)
372  { myPrimitives.append(primoff); }
374  void appendPoint(GA_Offset ptoff)
375  { myPoints.append(ptoff); }
377  void appendInputPrimitive(GA_Offset primoff)
378  { myInputPrimitives.append(primoff); }
379 
380  void setCentroidPosn(UT_Vector3 v)
381  { myCentroidPosition = v; }
382  void setReferencePoint(GA_Offset p)
383  { myReferencePoint = p; }
384  void setReferencePosition(UT_Vector3 v)
385  { myReferencePosition = v; }
386  void setArea(fpreal a)
387  { myArea = a; }
388 
389 
390  UT_Vector3 getCentroidPosition() const { return myCentroidPosition; }
391  fpreal getArea() const { return myArea; }
392  UT_Vector3 getReferencePosition() const { return myReferencePosition; }
393  GA_Offset getReferencePoint() const
394  {return myReferencePoint;}
395 
396  private:
397  GA_OffsetArray myPrimitives;
398  GA_OffsetArray myPoints;
399  GA_OffsetArray myInputPrimitives;
400 
401  GU_Detail *myGdp;
402  int myIndex;
403  bool myPosFromUV;
404  GA_RWHandleV3 myUV;
405  GA_ROHandleV3 myOrigUV;
406 
407 
408  UT_Vector3 myCentroidPosition;
409  fpreal myArea;
410  GA_Offset myReferencePoint;
411  UT_Vector3 myReferencePosition;
412 
413  };
414 
415 
416 
417  typedef UT_Array<Island *> IslandArray;
418 
419  typedef UT_Array<Pin> PinArray;
420  typedef UT_Map<int, PinArray> PinMap;
421 
422  typedef UT_Array<VirtualHedge> VirtualHedgeArray;
423 
424 
425 
426  /// Reflatten an island using given constraints.
427  void reflattenIsland(Island &island);
428 
429 
430  // Calculates centroid, area, and reference points of the island.
431  void calcIslandInfos(Island &island);
432 
433  exint getBoundaryVertices(const Island &island,
434  GA_OffsetArray &boundary_vtxs,
435  UT_BitArray *is_boundary_pt = nullptr);
436 
437 
438  exint getInternalVertices(const Island &island,
439  GA_OffsetArray &internal,
440  UT_BitArray *is_bdry = nullptr);
441 
442 
443  void buildVirtualHedges(Island &island,
444  VirtualHedgeArray &virtual_hedges,
445  UT_IntArray &angle_idx, UT_VectorD &angles);
446 
447  void buildVirtualHedgesWithFlip(Island &island,
448  VirtualHedgeArray &virtual_hedges,
449  UT_IntArray &angle_idx, UT_VectorD &angles);
450 
451  fpreal numInputVerticesAtIslandVertex(GA_Offset vtx);
452  GEO_Hedge nextAlignHedge(GEO_Hedge h);
453  GEO_Hedge getWorkHedge(GEO_Hedge in_h);
454  void setCorners(const GA_OffsetArray &boundary_verts,
455  UT_BitArray &is_corner);
456 
457  void saveStraightenedPaths(Island &island, UT_IntArray &path_ind,
458  UT_Array<DirLabel> &labels);
459 
460  GA_Offset nextBoundaryHedgeSource(GA_Offset vtx);
461 
462  void findAndLabelPaths(Island &island, GA_OffsetArray &path_start,
463  GA_OffsetArray &path_end,
464  UT_IntArray &path_ind,
465  UT_Array<DirLabel> &path_labels,
466  const GA_OffsetArray &boundary_vertices,
467  UT_BitArray &is_boundary,
468  UT_BitArray &is_corner);
469 
470  void formTripletsForPathConstraints
471  (Island &island,
472  const GA_OffsetArray &path_start,
473  const UT_IntArray &path_ind,
474  const UT_Array<DirLabel> &path_labels,
475  const UT_BitArray &is_boundary,
476  const UT_BitArray &is_corner,
477  int num_ortho_corners,
478  AngleConstraintArray &path_trips);
479 
480  void findBoundaryPaths(int &path_num, GA_OffsetArray &path_start,
481  GA_OffsetArray &path_end,
482  UT_IntArray &path_ind,
483  const GA_OffsetArray &boundary_vertices,
484  const UT_BitArray &is_corner,
485  GU_Detail *gdp);
486 
487  void findInteriorPaths(int &path_num, GA_OffsetArray &path_start,
488  GA_OffsetArray &path_end,
489  UT_IntArray &path_ind,
490  const GA_OffsetArray &boundary_vertices,
491  const UT_BitArray &is_boundary,
492  const UT_BitArray &is_corner,
493  GU_Detail *gdp);
494 
495  void findInputVerticesOfIslandPoint(GA_Offset work_pt,
496  UT_Array<GA_Offset> &vtxs);
497 
498  bool findPathsPassingThroughPoint(UT_IntArray &a,
499  GA_Offset work_pt,
500  int my_ind,
501  bool orthogonal,
502  const UT_IntArray &path_ind);
503 
504  // Find a boundary hedge out of a work point (in myRGdp).
505  GEO_Hedge boundaryHedgeFromPoint(GA_Offset work_pt,
506  const UT_BitArray &is_boundary);
507 
508  // Find a boundary hedge with the given work point as its destination.
509  GEO_Hedge boundaryHedgeToPoint(GA_Offset work_pt,
510  const UT_BitArray &is_boundary);
511 
512 
513  // Given point on the boundary finds all boundary paths containing it.
514  void findPointBoundaryPaths(GA_Offset work_pt,
515  int &b1, int &b2,
516  const UT_IntArray &path_ind,
517  const UT_BitArray &is_boundary);
518 
519  // Given the source of the start half-edge of a path returns true
520  // if the given end vertex is the source of the end half-edge of the path.
521  bool isPathLastHedgeSrc(GA_Offset start, GA_Offset end,
522  const UT_BitArray &is_boundary,
523  const UT_BitArray &is_corner);
524 
525  bool isBoundaryPath(GA_Offset start);
526 
527  void findPathFromStart(GA_OffsetArray &path, GA_Offset start,
528  const UT_IntArray &path_ind,
529  const UT_BitArray &is_border,
530  const UT_BitArray &is_corner);
531 
532  fpreal calcPathLength(GA_OffsetArray &path);
533 
534  void getIncidentPaths(UT_IntArray &incident_paths,
535  int path_index, bool orthogonal,
536  const GA_OffsetArray &path_start,
537  const UT_IntArray &path_ind,
538  const UT_BitArray &is_boundary,
539  const UT_BitArray &is_corner);
540 
541  DirLabel assignLabel(const UT_IntArray &incident_paths,
542  const UT_BitArray &paths_seen,
543  const UT_Array<DirLabel> &path_labels);
544 
545  int pickBestPath(const UT_IntArray &paths,
546  const UT_IntArray &index_to_order,
547  const UT_BitArray &paths_seen);
548 
549 
550  void labelPaths(UT_Array<DirLabel> &path_labels,
551  UT_BitArray &paths_seen,
552  const GA_OffsetArray &path_start,
553  const UT_IntArray &path_ind,
554  const UT_BitArray &is_boundary,
555  const UT_BitArray &is_corner,
556  const UT_IntArray &ordered_paths,
557  const UT_IntArray &index_to_order);
558 
559 
560  fpreal calcIslandArea(const Island &island,
561  GA_RWHandleV3 uvh);
562 
563  /// Flatten an island using the auto-assigned initial pins
564  void firstFlatten(Island &island);
565 
566  /// The main flattening method; flattens the given island with the given
567  /// pins. Returns true if interrupted and false otherwise.
568  void flattenLSCM(Island &island,
569  const PinArray &pins,
570  bool write_to_input_detail);
571 
572 
573  /// The main flattening method; flattens the given island with the given
574  /// pins. Returns true if interrupted and false otherwise.
575 
576 #ifdef USE_EIGEN
577 #ifdef USE_SPECTRA
578 
579  bool flattenSpectral(Island &island, const PinArray &pins,
580  bool write_to_input_detail,
581  AlignGroupArray &align_groups,
582  bool solve_with_pins, bool verify,
583  VirtualHedgeArray &virtual_hedges);
584 
585  bool flattenSpectral(Island &island, const PinArray &pins,
586  bool write_to_input_detail,
587  AlignGroupArray &align_groups);
588 
589 #endif
590 #endif
591 
592  void flattenLinearABF(Island &island,
593  AlignGroupArray &align_groups,
594  bool write_to_input_detail);
595 
596 
597 
598 
600  fpreal angleFromVertex(GU_Detail *gdp, GA_Offset v);
601 
602 
603  /// Given all the angles of all triangles in an island (computed by
604  /// ABF) generates UV coordinates for the vertices.
605 
606  void uvCoordsFromAngles(Island &island,
607  bool write_to_input_detail,
608  UT_VectorD &angles,
609  UT_IntArray &angle_idx,
610  VirtualHedgeArray &virtual_hedges,
611  bool need_to_verify);
612 
613 
614  /// Translate UVs of an island by vector t
615  void translateIsland(Island &island, UT_Vector3 t,
616  bool write_to_input_detail = true);
617 
618  /// Scale UVs of an island by factor of s about o
619  void scaleIsland(UT_Vector3 o, Island &island,
620  bool write_to_input_detail = true,
621  fpreal s = 0.001);
622 
623 
624  void rotateIsland(UT_Vector3 o, Island &island, fpreal cos,
625  fpreal sin, bool write_to_input_detail);
626 
627  /// Attach symmetric pins to each original island. Fill myOriginalPins
628  void assignIslandInitialPins(Island &island);
629 
630  /// Construct myRGdp by cutting myTGdp along extra edges
631  void recutWithExtraSeams(bool force_rebuild_islands = false);
632 
633  void calcPinCoeffs(const PinArray &pins,
634  UT_Array<UT_Vector3T<fpreal> > &pin_coeff_map);
635 
636  exint buildIndexMap(AlignGroupArray &align_groups,
637  const GA_OffsetArray &i_points,
638  UT_Array<GA_OffsetArray> &align_points,
639  exint num_pins, exint num_coords,
640  UT_IntArray &pt_var_id,
641  UT_Array<exint> &index_map);
642 
643  void writeUVsToInputDetail(GA_ROHandleV3 &uvh);
644 
645  /// Returns a representative input vertex for a given point in myTGdp
646  SYS_FORCE_INLINE GA_Offset workPointToInputVertex(GA_Offset work_pt)
647  { return myWorkPointToInputVertex(work_pt); }
648 
649  /// Returns a representative vertex in the myTGdp (equivalently myRGdp)
650  // for the given input vertex
651  SYS_FORCE_INLINE GA_Offset getWorkVertex(GA_Offset vtx)
652  { return myWorkVertex(vtx); }
653 
654  SYS_FORCE_INLINE GA_Offset getInputVertex(GA_Offset vtx)
655  { return myInputVertex(vtx); }
656 
657 
658  void getIslandPins(PinMap &pin_map, int island,
659  PinArray &pins);
660 
661  void getIslandAlignGroups(AlignGroupMap &align_map,
662  int island, AlignGroupArray &align_groups);
663 
664  int cutDetailAlongSeams(GU_Detail *gdp,
665  const GEO_DetachedHedgeInterface *hip,
666  const GA_EdgeGroup *seams,
667  GU_Detail *seams_gdp,
668  GA_RWHandleI &islandh);
669 
670 
672  exint indexIslandPoints(Island &island,
673  GA_OffsetArray &pin_points,
674  UT_Array<GA_OffsetArray> &align_points,
675  UT_BitArray &is_point_pinned,
676  UT_BitArray &is_point_aligned,
677  UT_IntArray &pt_var_id,
678  bool align = false);
679 
680 
681  void adjustIslandPosAndScale(Island &island,
682  bool do_not_rotate = false,
683  bool write_to_input_detail = true);
684 
685  void adjustIslandPosAndScale(Island &island, GA_Offset pin,
686  UT_Vector3 pin_pos, GA_Offset ref,
687  UT_Vector3 ref_pos,
688  bool write_to_input_detail = true,
689  fpreal scale = 0.0,
690  bool do_not_rotate = false);
691 
692  enum PinStatus
693  {
694  NEW_PIN,
695  DUPLICATE_PIN,
696  MODIFIED_PIN
697  };
698 
699  PinStatus addPinToPinMap(GU_Flatten2::PinMap &pin_map, Pin pin);
700  void processPins();
701 
702  /// map an input vertex to a work point
703  SYS_FORCE_INLINE GA_Offset getWorkPoint(GA_Offset in_vtx)
704  {
705  GA_Offset vtx = getWorkVertex(in_vtx);
706  if (!GAisValid(vtx))
707  return GA_INVALID_OFFSET;
708  return myRGdp->vertexPoint(vtx);
709  }
710 
711  GA_Attribute *getTextureAttribute(GU_Detail *gdp,
712  const UT_StringHolder &attribname,
713  bool add_if_missing=true);
714  GA_Attribute *getIslandAttribute(GU_Detail *gdp,
715  bool add_if_missing = true);
716 
717  void purgeIslands(int new_num_islands = 0);
718  Island *getIsland(int i, GU_Detail *gdp, const GA_RWHandleV3 &uvattrib);
719 
721  *getInputHedgeInterface();
722 
723  // We compute a partitioning of input vertices into equivalence classes
724  // for computation of distortion.
725  // Two vertices are placed in the same equivalence class if and only if
726  // they have the same 3D position and the same assigned UV coordinates.
727  // The root of each class is used for the purpose of accumulation of
728  // distortion amounts.
729 
730  UT_Classifier *myInputVertexClasses = nullptr;
731 
732  PinMap myInitialPins;
733  PinMap myCurrentPins;
734 
735  AlignGroupMap myCurrentAlignGroups;
736  AngleConstraintMap myAlignTripletMap;
737 
738  GA_OffsetArray myWorkPointToInputVertex;
739 
740  GA_OffsetArray myWorkVertex;
741  GA_OffsetArray myInputVertex;
742 
743  UT_Array<UT_Vector3> myBasePositions;
744 
745  GA_OffsetArray myUPaths;
746  GA_OffsetArray myVPaths;
747  GA_OffsetArray myUnalignedPaths;
748 
749  // input detail
750  GU_Detail *myGdp = nullptr;
751 
752  // triangulated and cut detail
753  GU_Detail *myTGdp = nullptr;
754 
755  // re-cut (additional seams) detail
756  GU_Detail *myRGdp = nullptr;
757 
758  GA_RWHandleV3 myUV;
759  GA_RWHandleV3 myTUV;
760  GA_RWHandleV3 myRUV; // attribute handle on myRGdp
761  GA_RWHandleI myPrimitiveIsland; // attribute handle on myRGdp
762 
763  UT_Array<bool> myReflattenIslandFlags;
764  UT_BitArray myIslandsToReflatten;
765 
766  GA_EdgeGroup *myInitialSeams;
767  GA_EdgeGroup *myExtraSeams;
768 
769  int myInitialNumIslands;
770  int myNumIslands;
771  IslandArray myIslands;
772 
773 
774  fpreal myTotalArea; // used for scaling
775  UT_Vector3 myInputCentroid;
776 
777  bool myUseInputUV;
778  bool myUseInputBoundaryUV;
779  bool myAxisAlignIslands;
780  bool myRepackWasted;
781  UT_StringStream myWarningMessage;
782 
783 
784  using HedgeInterface = GEO_DetachedHedgeInterface;
785 
786  HedgeInterface *myInputHip = nullptr;
787  HedgeInterface *myHip = nullptr;
788  HedgeInterface *myTHip = nullptr;
789 
790  // Input primitive group:
791  GA_PrimitiveGroup *myGroup = nullptr;
792 
793  int myMethod;
794  int myTest;
795 
796  bool myStraightenBoundary;
797  bool myStraightenInterior;
798  bool myOrthogonalize;
799 
800 };
801 
802 
804 GU_Flatten2::Island::getPos3(GA_Offset pt) const
805 {
806  if (myPosFromUV)
807  return myOrigUV.get(myGdp->pointVertex(pt));
808  else
809  return myGdp->getPos3(pt);
810 }
811 
812 #endif
SYS_API double cos(double x)
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
cvex test(vector P=0;int unbound=3;export float s=0;export vector Cf=0;)
Definition: test.vfl:11
SYS_FORCE_INLINE bool isToRemove() const
Definition: GU_Flatten2.h:146
SYS_FORCE_INLINE bool isToRemove() const
Definition: GU_Flatten2.h:187
UT_Map< int, AngleConstraintArray > AngleConstraintMap
Definition: GU_Flatten2.h:328
Vec orthogonal(const Vec &s, const Vec &t)
Definition: ImathVecAlgo.h:104
GA_Offset getInputVertex() const
Definition: GU_Flatten2.h:126
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
bool GAisValid(GA_Size v)
Definition: GA_Types.h:625
GEO_Hedge getOutHedge() const
Definition: GU_Flatten2.h:313
UT_Array< AlignGroup > AlignGroupArray
Definition: GU_Flatten2.h:325
GA_Offset getFromPoint() const
Definition: GU_Flatten2.h:309
UT_Map< int, AlignGroupArray > AlignGroupMap
Definition: GU_Flatten2.h:327
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
SYS_FORCE_INLINE void setToRemove(bool b)
Definition: GU_Flatten2.h:185
SYS_FORCE_INLINE int getIslandIndex() const
Definition: GU_Flatten2.h:142
#define GEO_INVALID_HEDGE
An invalid hedge is sometimes returned if an operation is unsuccessful.
Definition: GEO_Hedge.h:32
3D Vector class.
SYS_FORCE_INLINE fpreal u() const
Definition: GU_Flatten2.h:136
const std::string getWarningMessage()
Definition: GU_Flatten2.h:343
GA_Offset getToPoint() const
Definition: GU_Flatten2.h:310
void addAlignVertex(AlignVertex v)
Definition: GU_Flatten2.h:213
png_uint_32 i
Definition: png.h:2877
void setActive(bool b)
Definition: GU_Flatten2.h:217
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
SYS_FORCE_INLINE void setToRemove(bool b)
Definition: GU_Flatten2.h:144
SYS_FORCE_INLINE int getIslandIndex() const
Definition: GU_Flatten2.h:183
GA_Size GA_Offset
Definition: GA_Types.h:617
GEO_Hedge getInHedge() const
Definition: GU_Flatten2.h:312
GA_API const UT_StringHolder scale
GA_Offset getPoint() const
Definition: GU_Flatten2.h:127
GLint ref
Definition: glcorearb.h:123
int64 exint
Definition: SYS_Types.h:109
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
GLuint GLuint end
Definition: glcorearb.h:474
int method
Definition: png.h:1924
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
An bi-directional stream object that owns its own string buffer storage.
UT_Array< AngleConstraint > AngleConstraintArray
Definition: GU_Flatten2.h:326
bool operator==(AngleConstraint &align_trip)
Definition: GU_Flatten2.h:280
#define GU_API
Definition: GU_API.h:11
GLuint const GLchar * name
Definition: glcorearb.h:785
int getNumIslands()
Definition: GU_Flatten2.h:65
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Offset getPoint() const
Definition: GU_Flatten2.h:308
Pin(const Pin &other)
Definition: GU_Flatten2.h:121
AngleConstraint(GA_Offset pt, GA_Offset from_pt, GA_Offset to_pt, fpreal a, GEO_Hedge in_hedge, GEO_Hedge out_hedge)
Definition: GU_Flatten2.h:274
AlignVertex(GA_Offset v, GA_Offset p, GA_Offset from_pt, GA_Offset to_pt, int isInd, bool rem=false)
Definition: GU_Flatten2.h:168
SYS_FORCE_INLINE void setU(fpreal u)
Definition: GU_Flatten2.h:130
SYS_FORCE_INLINE fpreal v() const
Definition: GU_Flatten2.h:139
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:263
AlignVertex(const AlignVertex &other)
Definition: GU_Flatten2.h:173
SYS_FORCE_INLINE void setV(fpreal v)
Definition: GU_Flatten2.h:133
GA_Offset getPoint() const
Definition: GU_Flatten2.h:181
Pin(GA_Offset voff, GA_Offset ptof, int is, fpreal u, fpreal v)
Definition: GU_Flatten2.h:117
AlignVertex(GA_Offset v, GA_Offset p, int isInd, bool rem=false)
Definition: GU_Flatten2.h:164
void setIslandIndex(int i)
Definition: GU_Flatten2.h:210
SYS_API double sin(double x)
VirtualHedge(GA_Offset src_p, GA_Offset dst_p, fpreal opp_angle, fpreal area, bool boundary)
Definition: GU_Flatten2.h:236
GA_API const UT_StringHolder area
GA_Offset getInputVertex() const
Definition: GU_Flatten2.h:180