HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Remesh.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_Remesh.h (GU Library, C++)
7  *
8  * COMMENTS:s
9  */
10 
11 
12 #ifndef GU_REMESH_H_
13 #define GU_REMESH_H_
14 
15 #include <GA/GA_ElementWrangler.h>
16 // #include <GA/GA_Topology.h>
17 #include "GU_Detail.h"
18 #include <GEO/GEO_HedgeInterface.h>
19 
20 #include "GU_API.h"
21 
22 typedef enum {
30 
31 
33 {
34 public:
35  GU_Remesh(GU_Detail *gdp, GA_PrimitiveGroup *group, GA_EdgeGroup *hard_edges);
36  ~GU_Remesh();
37 
38  void
39  remesh(bool adaptive, int iterations, fpreal density, fpreal gradation,
40  fpreal target_edge_len = -1.0, fpreal min_edge_len = -1.0, fpreal max_edge_len = -1.0,
41  fpreal smoothing_level = 0.0, bool use_input_pts_only = false);
42 
43 private:
44 
45  inline bool
46  isBoundaryPoint(GA_Offset pt)
47  {
48  return (myPointStatus.get(pt) & POINT_STATUS_BOUNDARY);
49  }
50 
51  inline bool
52  isManifoldPoint(GA_Offset pt)
53  {
54  return !(myPointStatus.get(pt) & POINT_STATUS_NONMANIFOLD);
55  }
56 
57  inline bool
58  isHardenedPoint(GA_Offset pt)
59  {
60  return (myPointStatus.get(pt) & POINT_STATUS_HARDENED);
61  }
62 
63  inline bool
64  isGroupPoint(GA_Offset pt)
65  {
66  return (myPointStatus.get(pt) & POINT_STATUS_INGROUP);
67  }
68 
69  inline void
70  setPointStatus(GA_Offset pt, uint8 mask)
71  {
72  myPointStatus.set(pt, myPointStatus.get(pt) | mask);
73  }
74 
75  inline void
76  clearPointStatus(GA_Offset pt, uint8 mask)
77  {
78  myPointStatus.set(pt, myPointStatus.get(pt) & ~mask);
79  }
80 
81  inline void
82  setTargetDegree(GA_Offset pt, uint8 deg)
83  {
84  if (deg > 0x0F)
85  deg = 0x0F;
86 
87  uint8 val = myPointStatus.get(pt);
88  uint8 mask = deg << 4;
89  val &= 0x0F;
90  val |= mask;
91  myPointStatus.set(pt, val);
92  }
93 
94  inline int
95  getTargetDegree(GA_Offset pt)
96  {
97  return (((uint8) myPointStatus.get(pt)) >> 4);
98  }
99 
100  bool isGroupBoundaryHedge(GEO_Hedge e);
101 
102  void updateWranglers()
103  {
104  if (myWranglers)
105  delete myWranglers;
106 
107  myWranglers = new GA_ElementWranglerCache(*myGdp,
109  myWranglers->getPoint();
110  myWranglers->getVertex();
111 
112  myHdp->setWranglerCache(myWranglers);
113  }
114 
115 
116  void markHardPoints();
117  void computePointNormals(GA_Attribute * attr, bool compute_deviations = true);
118  void computePointNormalsNew(GA_Attribute *atN);
119 
120  // remeshing stages:
121  int splitLongEdges();
122  int contractShortEdges(bool use_curvature = false);
123  int equalizeValences();
124  int relaxPoints(bool use_curvature = false, fpreal smooting_level = 0.0);
125  int deleteDegree3Points();
126 
127  // The main remesh method:
128  void runIterations(int itertions, fpreal smoothing_level, bool input_pts_only = false);
129 
130  float bestQuadRidgeExtension(GA_Offset p, GA_VertexGroup *quadridge,
131  GA_RWHandleI &crossed, GA_Offset &v1,
132  GA_Offset &v2);
133  void generateQuads();
134 
135  void addEdgeToVertexGroup(GA_VertexGroup *grp, GA_Offset v);
136 
137  // ???
138  void delaunizeEdge(GEO_Hedge e);
139  int makeMeshLocallyDelaunay();
140  int delaunizeHardPointAdjacentEdges();
141 
142  // size function estimation
143  void computeInitialLfs();
144  int computeBasicLfs(GA_RWHandleF fh);
145  int computeLFS(int max_splits = -1);
146 
147  GA_Offset tryCollapseHedge(GEO_Hedge e, UT_Array < GEO_Hedge > *shortened, bool checklength = true);
148 
149  inline fpreal targetLengthMin(GEO_Hedge e);
150  inline fpreal targetLengthMax(GEO_Hedge e);
151 
152 
153  int manifoldPatchDegree(GA_Offset vtx);
154  fpreal manifoldPatchAngle(GA_Offset vtx);
155 
156  // void verifyOrientations();
157  fpreal angleAtHedge(GEO_Hedge e);
158 
159  bool isHardPoint(GA_Offset pt)
160  {
161  return myHardPoints ? myHardPoints->containsOffset(pt) : false;
162  }
163 
164  bool isHardHedge(GA_Offset vtx)
165  {
166  return myHardHedges ? myHardHedges->containsOffset(vtx) : false;
167  }
168 
169  bool isHardHedge(GEO_Hedge e)
170  {
171  return
172  myHardHedges ?
173  myHardHedges->containsOffset(myHdp->srcVertex(e)) : false;
174  }
175 
176  void hardenEdge(GEO_Hedge e);
177 
178 
179  GEO_Hedge splitHedge(GEO_Hedge e, fpreal ratio);
180 
181  fpreal getLFSUpperBound(GA_Offset x, GA_PointGroup *marked);
182 
183  bool splitOpposite(UT_Vector3 &pv, fpreal lfsp, UT_Vector3 &qv, fpreal lfsq,
184  UT_Vector3 &rv, fpreal lfsr, fpreal &ratio, bool verbose);
185 
186  void relaxLFSAtPoint(GA_Offset p, GA_PointGroup *marked, GA_PointGroup *border, GA_RWHandleI &srch,
187  GA_RWHandleF &gdsrch, GA_OffsetArray &newpts);
188 
189  GA_Offset getBestSrc(GA_Offset x, GA_PointGroup *marked, GA_RWHandleI& srch,
190  GA_RWHandleF& gdsrch, fpreal &res);
191 
192  GA_Offset splitHedgeAtBisector(GEO_Hedge e, fpreal lfsp, fpreal lfsq,
193  GA_PointGroup *marked, GA_RWHandleI& srch,
194  GA_RWHandleF& gdsrch);
195  bool splitOppositeSimple(UT_Vector3 &pv, fpreal lfsp, UT_Vector3 &qv,
196  fpreal lfsq, UT_Vector3 &rv, fpreal lfsr);
197 
198  fpreal worstLinearApprox(UT_Vector3 &pv, fpreal lfsp, UT_Vector3 &qv,
199  fpreal lfsq, UT_Vector3 &rv, fpreal lfsr);
200 
201 private:
202  GA_ElementWranglerCache *myWranglers;
203 
204  GU_Detail *myGdp;
205  GEO_HedgeInterface *myHdp;
206  GA_PrimitiveGroup *myGroup;
207 
208 
209  GA_Attribute *myAttrLfs; // local feature size (target edge length at point)
210  GA_RWHandleF myLfs;
211  GA_Attribute *myAttrN; // point normals
212  GA_RWHandleV3 myN;
213 
214  GA_Attribute *myAttrNdiv; // normal deviation at point
215  GA_RWHandleF myNdiv;
216 
217  GA_Attribute *myAttrPointStatus;
218  GA_RWHandleI myPointStatus;
219 
220  GA_EdgeGroup *myInputHardEdges; // input edge group for crease edges
221  GA_VertexGroup *myHardHedges;
222  GA_PointGroup *myHardPoints;
223  GA_PointGroup *myBoundaryPoints; // points incident to edges belonging to only one input polygon
224  GA_PointGroup *myNonManifoldPoints; // nonmanifold points
225 
226  fpreal myMinLfs, myMaxLfs;
227  fpreal myDensity;
228  fpreal myGradation;
229  fpreal myExpansion;
230  fpreal myApproxFactor;
231  fpreal myMinEdgeLength;
232  fpreal myMaxEdgeLength;
233  fpreal myTargetEdgeLength;
234 
235  bool myAdaptive;
236  bool myLimitAbove;
237  bool myLimitBelow;
238  fpreal myHigh, myLow, myLocalHigh, myLocalLow;
239 };
240 
241 
242 #endif /* GU_REMESH_H_ */
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
const GLdouble * v
Definition: glcorearb.h:836
GLint GLuint mask
Definition: glcorearb.h:123
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
GA_Size GA_Offset
Definition: GA_Types.h:617
GEO_Hedge encapsulates a half-edge (hedge) which is the restriction of.
Definition: GEO_Hedge.h:47
#define GU_API
Definition: GU_API.h:12
double fpreal
Definition: SYS_Types.h:270
GLint GLint GLsizei GLint border
Definition: glcorearb.h:107
unsigned char uint8
Definition: SYS_Types.h:32
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLuint GLfloat * val
Definition: glcorearb.h:1607
guPointStatusMask
Definition: GU_Remesh.h:22