HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_UVAutoseam.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: SOP library (C++)
7  *
8  * COMMENTS: UVFlatten SOP
9  */
10 
11 #ifndef __GU_AutoSeam_h__
12 #define __GU_AutoSeam_h__
13 
14 #include "GU_API.h"
15 
16 #include "GU_Detail.h"
17 #include <GEO/GEO_HedgeInterface.h>
18 #include <UT/UT_UniquePtr.h>
19 
20 class UT_Classifier;
21 class GU_QuadLayout;
22 
24 {
26 public:
27  explicit GU_UVAutoseam(const GU_Detail *gdp,
28  const GA_PrimitiveGroup *grp);
29 
30  ~GU_UVAutoseam();
31 
32  void generateSeams(fpreal grain_threshold,
33  fpreal merge_threshold,
34  fpreal avoidance_weight,
35  const GA_EdgeGroup *precuts,
36  const GA_EdgeGroup *noncuts,
37  const GA_Attribute *avoid_attr,
38  GA_EdgeGroup *seams);
39 
40 
41  void generateSeams(const GA_Attribute *uv_attr,
42  fpreal connectivity_tolerance,
43  fpreal merge_threshold,
44  fpreal avoidance_weight,
45  const GA_EdgeGroup *precuts,
46  const GA_EdgeGroup *noncuts,
47  const GA_Attribute *avoid_attr,
48  GA_EdgeGroup *seams);
49 
50 
51  void getSymmetryLineEdges(GA_EdgeGroup *grp);
52 
53  const
54  HedgeInterface *getHedgeInterface() const { return myHip; }
55 
56  const
57  GU_Detail *getDetail() const { return myGdp; }
58 
59  void getIslandNumbers(GA_RWHandleI &island_num);
60 
61 private:
63 
65  GEO_Hedge sym(GEO_Hedge h) const { return myHip->sym(h); }
66 
68  GEO_Hedge lnext(GEO_Hedge h) const { return myHip->lnext(h); }
69 
71  GEO_Hedge lprev(GEO_Hedge h) const { return myHip->lprev(h); }
72 
73 
76  { return myHip->srcVertex(h); }
77 
80  { return myHip->dstVertex(h); }
81 
84  { return myHip->srcPoint(h); }
85 
88  { return myHip->dstPoint(h); }
89 
91  GA_Offset hedgePoly(GEO_Hedge h) const
92  { return myGdp->vertexPrimitive(srcVertex(h)); }
93 
95  UT_Vector3R getPos3(GA_Offset pt) const
96  { return myGdp->getPos3(pt); }
97 
99  fpreal length(GEO_Hedge h) const
100  {
101  return (getPos3(srcPoint(h))
102  - getPos3(dstPoint(h))).length(); }
103 
104 
105  struct IslandInfo;
106  struct ChainInfo;
107 
108  class Partition;
109 
110  void extractIslandBoundaries(GA_EdgeGroup *seams);
111 
112  void findSymmetryLines();
113 
114  void calcPolyNormals();
115  void calcCurvatures();
116 
117  fpreal pointCurvature(GA_Offset pt) const
118  { return myPointCurvature.get(pt); }
119 
121  fpreal polyArea(GA_Offset poly) const
122  { return myPolyNormals(polyIndex(poly)).length(); }
123 
125  UT_Vector3R polyNormal(GA_Offset poly) const
126  {
127  auto n = myPolyNormals(polyIndex(poly));
128  n.normalize();
129  return n;
130  }
131 
132  void trimInnerSeams(const GA_PointGroup *nodes = nullptr,
133  fpreal curvature_threshold = -1.0);
134 
135 
136  void removeInnerSeams();
137 
138  fpreal grainJoin(exint i, exint j,
139  const ChainInfo &chain,
140  fpreal avoidance_weight,
141  fpreal grain_threshold) const;
142 
143  fpreal islandJoin(exint i, exint j,
144  const ChainInfo &chain,
145  fpreal avoidance_weight,
146  fpreal merge_threshold) const;
147 
149  extractNodes(Partition *partition) const;
150 
151  template <typename T>
152  void growIslands(T join_func,
153  const GA_PointGroup *nodes,
154  const GA_EdgeGroup *precuts,
155  const GA_Attribute *avoid_attr,
156  const char *prompt,
157  bool symmetry_lin = false);
158 
159  void shortenCuts(const GA_PointGroup *nodes);
160 
161  void refreshChains(exint i,
162  const GA_PointGroup *nodes);
163 
164  void premergeExistingIslands(const GA_ROHandleV3 &uvh,
165  fpreal tol,
166  const GA_EdgeGroup *cuts);
167 
168  void premergeNonSeams(const GA_EdgeGroup *noncuts);
169 
170  void premergeQuadBlocks(const GA_EdgeGroup *cuts);
171 
172 
173  fpreal calcPolyArea(GA_Offset poly,
174  UT_Vector3R *normal = nullptr) const;
175 
176  // Returns true when all the primitives in the give group are polygons.
177  bool indexGroupPolys(const GA_PrimitiveGroup *grp);
178 
179  GA_Range polys() const
180  {
181  return myPolyIndex.isValid()
182  ? GA_Range(myGdp->getIndexMap(GA_ATTRIB_PRIMITIVE),
183  GA_OffsetList(myIndexPoly))
184  : myGdp->getPrimitiveRange();
185  }
186 
188  bool isPoly(GA_Offset prim) const
189  {
190  return myGdp->getPrimitiveTypeId(prim) == GEO_PRIMPOLY
191  && myGdp->getPrimitiveClosedFlag(prim)
192  && myGdp->getPrimitiveVertexCount(prim) > 2;
193  }
194 
196  bool isQuad(GA_Offset prim) const
197  {
198  return isPoly(prim) && myGdp->getPrimitiveVertexCount(prim) == 4;
199  }
200 
202  GEO_Hedge twin(GEO_Hedge h) const
203  {
204  if (myTwinMap.isInvalid())
205  return GEO_INVALID_HEDGE;
206 
207  GA_Offset tvtx(myTwinMap.get(srcVertex(h)));
208  return GEO_Hedge(tvtx);
209  }
210 
212  bool isOnSymmetryLine(GEO_Hedge h) const
213  { return twin(h) == sym(h); }
214 
216  int numPolys() const
217  { return myPolyIndex.isValid()
218  ? int(myIndexPoly.size())
219  : int(myGdp->getNumPrimitives()); }
220 
222  int polyIndex(GA_Offset poly) const
223  { return myPolyIndex.isValid()
224  ? myPolyIndex.get(poly)
225  : int(myGdp->primitiveIndex(poly)); }
226 
228  GA_Offset polyAtIndex(exint i) const
229  { return myPolyIndex.isValid()
230  ? myIndexPoly(i)
231  : myGdp->primitiveOffset(GA_Index(i)); }
232 
233  static fpreal calcL21MergeCost(const IslandInfo &i,
234  const IslandInfo &j);
235 
236  static fpreal calcCovarianceMergeCost(const IslandInfo &i,
237  const IslandInfo &j);
238 
239  void resetQuadLayout(fpreal cutoff_curvature);
240 
241  using PartitionUptr = UT_UniquePtr<Partition>;
242 
244  fpreal infinity() const { return 1e10; }
245 
246  const GU_Detail *myGdp;
247  HedgeInterface *myHip = nullptr;
248 
249  GA_AttributeUPtr myTwinMapOwner;
250  GA_RWHandleI myTwinMap;
251  PartitionUptr myPartition;
252 
253  UT_Array<fpreal> myGaussianCurvature;
254  GU_QuadLayout *myQuadLayout = nullptr;
255  fpreal myQuadLayoutGrainThreshold = -1.0;
256 
257  // Group two-way reindexing.
258  GA_AttributeUPtr myPolyIndexOwner;
259  GA_RWHandleI myPolyIndex;
260  GA_RWHandleF myPointCurvature;
261 
262  UT_Vector3RArray myPolyNormals;
263 
264  GA_OffsetArray myIndexPoly;
265 };
266 #endif
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
void partition(I begin, I middle, I end, const Pred &pred, I *out_eqbeg, I *out_eqend)
Definition: pugixml.cpp:7255
GA_OffsetListType< GA_Size > GA_OffsetList
GA_OffsetList is a map from index to offset.
int64 exint
Definition: SYS_Types.h:125
GA_Offset srcVertex(GEO_Hedge)
Definition: GEO_Hedge.h:179
bool isValid() const
Check whether range is valid (i.e. has an implementation)
Definition: GA_Range.h:241
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
#define GEO_INVALID_HEDGE
An invalid hedge is sometimes returned if an operation is unsuccessful.
Definition: GEO_Hedge.h:32
A range of elements in an index-map.
Definition: GA_Range.h:42
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GA_Size GA_Offset
Definition: GA_Types.h:646
UT_UniquePtr< const GA_PointGroup > GA_ConstPointGroupUPtr
GLdouble n
Definition: glcorearb.h:2008
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
#define GU_API
Definition: GU_API.h:14
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
SYS_FORCE_INLINE GA_Offset dstVertex(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:215
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:930
const HedgeInterface * getHedgeInterface() const
Definition: GU_UVAutoseam.h:54
const GU_Detail * getDetail() const
Definition: GU_UVAutoseam.h:57
GLint j
Definition: glad.h:2733
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Array< GEO_Hedge > HedgeArray
Definition: GU_Decompose.h:55
const GEO_DetachedHedgeInterface HedgeInterface
Definition: GU_Decompose.h:54
SYS_FORCE_INLINE GA_Offset dstPoint(T &iface, GEO_Hedge h)
Definition: GEO_Hedge.h:244