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 <UT/UT_UniquePtr.h>
18 
19 class UT_Classifier;
20 class GU_QuadLayout;
21 
23 {
25 public:
26  explicit GU_UVAutoseam(const GU_Detail *gdp,
27  const GA_PrimitiveGroup *grp);
28 
29  ~GU_UVAutoseam();
30 
31  void generateSeams(fpreal grain_threshold,
32  fpreal merge_threshold,
33  fpreal avoidance_weight,
34  const GA_EdgeGroup *precuts,
35  const GA_EdgeGroup *noncuts,
36  const GA_Attribute *avoid_attr,
37  GA_EdgeGroup *seams);
38 
39 
40  void generateSeams(const GA_Attribute *uv_attr,
41  fpreal connectivity_tolerance,
42  fpreal merge_threshold,
43  fpreal avoidance_weight,
44  const GA_EdgeGroup *precuts,
45  const GA_EdgeGroup *noncuts,
46  const GA_Attribute *avoid_attr,
47  GA_EdgeGroup *seams);
48 
49 
50  void getSymmetryLineEdges(GA_EdgeGroup *grp);
51 
52  const
53  HedgeInterface *getHedgeInterface() const { return myHip; }
54 
55  const
56  GU_Detail *getDetail() const { return myGdp; }
57 
58  void getIslandNumbers(GA_RWHandleI &island_num);
59 
60 private:
62 
64  GEO_Hedge sym(GEO_Hedge h) const { return myHip->sym(h); }
65 
67  GEO_Hedge lnext(GEO_Hedge h) const { return myHip->lnext(h); }
68 
70  GEO_Hedge lprev(GEO_Hedge h) const { return myHip->lprev(h); }
71 
72 
75  { return myHip->srcVertex(h); }
76 
79  { return myHip->dstVertex(h); }
80 
83  { return myHip->srcPoint(h); }
84 
87  { return myHip->dstPoint(h); }
88 
90  GA_Offset hedgePoly(GEO_Hedge h) const
91  { return myGdp->vertexPrimitive(srcVertex(h)); }
92 
94  UT_Vector3R getPos3(GA_Offset pt) const
95  { return myGdp->getPos3(pt); }
96 
98  fpreal length(GEO_Hedge h) const
99  {
100  return (getPos3(srcPoint(h))
101  - getPos3(dstPoint(h))).length(); }
102 
103 
104  struct IslandInfo;
105  struct ChainInfo;
106 
107  class Partition;
108 
109  void extractIslandBoundaries(GA_EdgeGroup *seams);
110 
111  void findSymmetryLines();
112 
113  void calcPolyNormals();
114  void calcCurvatures();
115 
116  fpreal pointCurvature(GA_Offset pt) const
117  { return myPointCurvature.get(pt); }
118 
120  fpreal polyArea(GA_Offset poly) const
121  { return myPolyNormals(polyIndex(poly)).length(); }
122 
124  UT_Vector3R polyNormal(GA_Offset poly) const
125  {
126  auto n = myPolyNormals(polyIndex(poly));
127  n.normalize();
128  return n;
129  }
130 
131  void trimInnerSeams(const GA_PointGroup *nodes = nullptr,
132  fpreal curvature_threshold = -1.0);
133 
134 
135  void removeInnerSeams();
136 
137  fpreal grainJoin(exint i, exint j,
138  const ChainInfo &chain,
139  fpreal avoidance_weight,
140  fpreal grain_threshold) const;
141 
142  fpreal islandJoin(exint i, exint j,
143  const ChainInfo &chain,
144  fpreal avoidance_weight,
145  fpreal merge_threshold) const;
146 
147  const
148  GA_PointGroup *extractNodes(Partition *partition) const;
149 
150  template <typename T>
151  void growIslands(T join_func,
152  const GA_PointGroup *nodes,
153  const GA_EdgeGroup *precuts,
154  const GA_Attribute *avoid_attr,
155  const char *prompt,
156  bool symmetry_lin = false);
157 
158  void shortenCuts(const GA_PointGroup *nodes);
159 
160  void refreshChains(exint i,
161  const GA_PointGroup *nodes);
162 
163  void premergeExistingIslands(const GA_ROHandleV3 &uvh,
164  fpreal tol,
165  const GA_EdgeGroup *cuts);
166 
167  void premergeNonSeams(const GA_EdgeGroup *noncuts);
168 
169  void premergeQuadBlocks(const GA_EdgeGroup *cuts);
170 
171 
172  fpreal calcPolyArea(GA_Offset poly,
173  UT_Vector3R *normal = nullptr) const;
174 
175  // Returns true when all the primitives in the give group are polygons.
176  bool indexGroupPolys(const GA_PrimitiveGroup *grp);
177 
178  GA_Range polys() const
179  {
180  return myPolyIndex.isValid()
181  ? GA_Range(myGdp->getIndexMap(GA_ATTRIB_PRIMITIVE),
182  GA_OffsetList(myIndexPoly))
183  : myGdp->getPrimitiveRange();
184  }
185 
187  bool isPoly(GA_Offset prim) const
188  {
189  return myGdp->getPrimitiveTypeId(prim) == GEO_PRIMPOLY
190  && myGdp->getPrimitiveClosedFlag(prim);
191  }
192 
194  bool isQuad(GA_Offset prim) const
195  {
196  return isPoly(prim) && myGdp->getPrimitiveVertexCount(prim) == 4;
197  }
198 
200  GEO_Hedge twin(GEO_Hedge h) const
201  {
202  if (myTwinMap.isInvalid())
203  return GEO_INVALID_HEDGE;
204 
205  GA_Offset tvtx(myTwinMap.get(srcVertex(h)));
206  return GEO_Hedge(tvtx);
207  }
208 
210  bool isOnSymmetryLine(GEO_Hedge h) const
211  { return twin(h) == sym(h); }
212 
214  int numPolys() const
215  { return myPolyIndex.isValid()
216  ? int(myIndexPoly.size())
217  : int(myGdp->getNumPrimitives()); }
218 
220  int polyIndex(GA_Offset poly) const
221  { return myPolyIndex.isValid()
222  ? myPolyIndex.get(poly)
223  : int(myGdp->primitiveIndex(poly)); }
224 
226  GA_Offset polyAtIndex(exint i) const
227  { return myPolyIndex.isValid()
228  ? myIndexPoly(i)
229  : myGdp->primitiveOffset(GA_Index(i)); }
230 
231  static fpreal calcL21MergeCost(const IslandInfo &i,
232  const IslandInfo &j);
233 
234  static fpreal calcCovarianceMergeCost(const IslandInfo &i,
235  const IslandInfo &j);
236 
237  void resetQuadLayout(fpreal cutoff_curvature);
238 
239  using PartitionUptr = UT_UniquePtr<Partition>;
240 
242  fpreal infinity() const { return 1e10; }
243 
244  const GU_Detail *myGdp;
245  HedgeInterface *myHip = nullptr;
246 
247  GA_RWHandleI myTwinMap;
248  PartitionUptr myPartition;
249 
250  UT_Array<fpreal> myGaussianCurvature;
251  GU_QuadLayout *myQuadLayout = nullptr;
252  fpreal myQuadLayoutGrainThreshold = -1.0;
253 
254  // Group two-way reindexing.
255  GA_RWHandleI myPolyIndex;
256  GA_RWHandleF myPointCurvature;
257 
258  UT_Vector3RArray myPolyNormals;
259 
260  GA_OffsetArray myIndexPoly;
261 };
262 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
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.
GA_Offset srcVertex(GEO_Hedge)
Definition: GEO_Hedge.h:166
bool isValid() const
Check whether range is valid (i.e. has an implementation)
Definition: GA_Range.h:240
SYS_FORCE_INLINE GA_Offset srcPoint(const GA_Detail *gdp, GEO_Hedge e)
Definition: GEO_Hedge.h:173
#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
SYS_FORCE_INLINE GA_Offset dstVertex(T &iface, GEO_Hedge e)
Definition: GEO_Hedge.h:202
GA_Size GA_Offset
Definition: GA_Types.h:637
int64 exint
Definition: SYS_Types.h:120
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
GLsizei n
Definition: glew.h:4040
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
#define GU_API
Definition: GU_API.h:14
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
SYS_FORCE_INLINE GA_Offset dstPoint(T &iface, GEO_Hedge e)
Definition: GEO_Hedge.h:231
const HedgeInterface * getHedgeInterface() const
Definition: GU_UVAutoseam.h:53
const GU_Detail * getDetail() const
Definition: GU_UVAutoseam.h:56
double fpreal
Definition: SYS_Types.h:276
UT_Array< GEO_Hedge > HedgeArray
Definition: GU_Decompose.h:55
const GEO_DetachedHedgeInterface HedgeInterface
Definition: GU_Decompose.h:54