HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_VolumeBreak.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_VolumeBreak.h ( GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_VolumeBreak__
12 #define __GU_VolumeBreak__
13 
14 #include "GU_API.h"
15 #include <GEO/GEO_PrimList.h>
16 #include <GA/GA_Edge.h>
17 #include <GA/GA_EdgeMap.h>
18 #include <GA/GA_ElementWrangler.h>
19 #include <GA/GA_Types.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_FloatArray.h>
23 
24 class GU_Detail;
25 class GEO_PrimVolume;
26 class GEO_PrimPoly;
27 class GA_PrimitiveGroup;
28 
30 {
34 };
35 
37 {
40 };
41 
42 struct guBreakPoly;
43 
45 {
46  // The break point is either on the edge interior or on a vertex.
48 
49  // The point.
51 
52  // If status is InteriorPoint: the adjacent points.
53  // If status is VertexPoint: the same point, i.e. pt1 = pt2.
56 
57  // The adjacent break points determined while splitting.
60 
61  // 0 if pt==pt1; 1 if pt==pt2; else between 0 and 1
63 
64  // The associated polygons.
66 };
67 
69 {
70  // The poly is classified as inside or outside the SDF volume.
72 
73  // The polygon.
75 
76  // The associated break points.
78 };
79 
81 {
84 
85  bool reusable1;
86  bool reusable2;
87 };
88 
91 
93 {
98 };
99 
101 {
107 };
108 
109 
110 
112 {
113 public:
114  GU_VolumeBreak();
115  ~GU_VolumeBreak();
116 
117  void setGroups(const GA_PrimitiveGroup *agrp) { myGrp = agrp; }
118  void setSnapDistance(fpreal snapdistance) { myTol = snapdistance; }
119  void setKeepInside(bool inside) { myKeepInside = inside; }
120  void setKeepOutside(bool outside) { myKeepOutside = outside; }
121  void setCloseGeometry(bool closegeo) { myCloseGeo = closegeo; }
123  { myCloseMethod = closemethod; }
124 
125  void volumeBreak(GU_Detail &gdp, GEO_PrimVolume &volume,
126  GA_PrimitiveGroup *ingrp, GA_PrimitiveGroup *inclgrp,
127  GA_PrimitiveGroup *outgrp, GA_PrimitiveGroup *outclgrp);
128 
129 
130 private:
131  GU_Detail *myGdp;
132  GEO_PrimVolume *myVolume;
133 
134  const GA_PrimitiveGroup *myGrp;
135 
136  fpreal myTol;
137  bool myKeepInside;
138  bool myKeepOutside;
139  bool myCloseGeo;
140  guLoopCloseMethod myCloseMethod;
141 
142  // Hash of edges to be broken. Used to maintain a unique list.
143  GA_EdgeMap<guBreakPoint *> myEdgeTable;
144 
145  // List of all break points.
146  UT_Array<guBreakPoint *> myPointList;
147 
148  // List of all polygons, including those with no break points.
149  UT_Array<guBreakPoly *> myPolyList;
150 
151  // Point distances indexed by point num.
152  UT_FloatArray myPointDistances;
153 
154  GA_ElementWranglerCache *myWranglers;
155 
156  void clearPointList();
157  void clearPolyList();
158  void printPointList();
159  void printPolyList();
160 
161 
162  //
163  // -- Breakpoint finding --
164  //
165 
166  // Add zero or more breakpoints given the edge (pa, pb).
167  void addBreakPoint(guBreakPoly *poly, const GA_Edge &edge);
168 
169  // Find the break point location on the edge given two points.
170  GA_Offset makeBreakPoint(GA_Offset pt1, GA_Offset pt2,
171  fpreal &lerpbias,
172  GA_PointWrangler &ptwrangler);
173 
174  // Find the position between in1 and in2 where the SDF is 0. The initial
175  // SDF values at in1 and in2 are given in indist1 and indist2.
176  int findRoot(const GEO_PrimVolume &volume,
177  const UT_Vector3 &in1, fpreal indist1,
178  const UT_Vector3 &in2, fpreal indist2,
179  UT_Vector3 &out,
180  int maxiters = 100);
181 
182  // Find the position along the ray (origin, dir) where the SDF is 0.
183  int findRoot(const GEO_PrimVolume &volume,
184  const UT_Vector3 &origin,
185  const UT_Vector3 &dir,
186  UT_Vector3 &out,
187  int maxiters = 100);
188 
189  // Removes duplicate adjacent breakpoints on the same poly
190  void removeDuplicateBreakpoints(guBreakPoly *poly);
191 
192 
193  //
194  // -- Edge finding and splitting --
195  //
196 
197  // Iteratively call splitClosedPoly or splitOpenPoly.
198  int splitPoly(guBreakPoly *poly, GA_ElementWranglerCache &wranglers);
199 
200  // Split into one poly free of break points and a second remaining poly.
201  // The resulting polygons are either all open or all closed.
202  int splitClosedPoly(guBreakPoly *poly, bool &finished, GA_ElementWranglerCache &wranglers);
203 
204  // Split into one poly free of break points and a second remaining poly.
205  // The resulting polygons are open.
206  int splitOpenPoly(guBreakPoly *poly, bool &finished, GA_ElementWranglerCache &wranglers);
207 
208  // Sort the list of break points with respect to the given polygon.
209  // This sorts each break point internally as well as the list itself.
210  void sortBreakPoints(guBreakPoly *poly);
211 
212  // Finds a pair of break points from the polygon that defines an
213  // approximating edge of the volume surface.
214  int findSurfaceEdge(guBreakPoly *poly,
215  guBreakPointPair &outpair);
216 
217  // Determines whether or not the walk from startpt to endpt along the
218  // polygon perimeter occurs inside the volume.
219  bool isInsideWalk(guBreakPoly *poly,
220  guBreakPoint *startpt, guBreakPoint *endpt);
221 
222  // Determines whether the given edge from startpt to endpt requires that
223  // the polygon be split.
224  guNeedSplitResult needSplit(guBreakPoly *poly,
225  guBreakPoint *startpt, guBreakPoint *endpt);
226 
227  // Split the given polygon along the given edge and pass the pointer to
228  // the new polygon back. The new polygon is formed by the vertices
229  // traversed when walking from startpt to endpt.
230  int splitClosedPoly(guBreakPoly *poly,
231  guBreakPoint *startpt, guBreakPoint *endpt,
232  guBreakPoly *&outnewpoly, GA_ElementWranglerCache &wranglers);
233 
234  // Removes breakpoints according to rules in the pair.
235  int removeBreakPoints(guBreakPoly *poly,
236  guBreakPointPair &pair);
237 
238 
239  //
240  // -- Hole closing --
241  //
242 
243  // Given a list of breakpoints, extracts loops of these.
244  void findLoops(UT_Array<guBreakPointArray> &loops,
245  guBreakPointArray &breakpoints);
246 
247  // Given a list of breakpoint loops, generates geometry to fill each loop.
248  int closeLoops(UT_Array<guBreakPointArray> &loops,
249  GU_Detail &gdp, GEO_PrimVolume &sdf,
250  UT_Array<GEO_PrimPoly *> &closurepolys,
251  GA_ElementWranglerCache &wranglers);
252 
253 
254 
255 
256  // Return the insideness of the given poly when it is absolutely certain
257  // with a minimum distance tolerance. When uncertain, returns GU_UNKNOWN.
258  guBreakPolyType classifyPolyConservative(GEO_PrimPoly *poly, float tol);
259 
260  // Return the insideness of the given polygon; does not return GU_UNKNOWN.
261  guBreakPolyType classifyPoly(guBreakPoly *poly);
262 
263  GEO_PrimPoly * createPolygon(GU_Detail &gdp);
264 
265  GEO_PrimPoly * createPolygon(GU_Detail &gdp,
266  const UT_Array<GA_Offset> &vtxes,
267  bool closed,
268  GEO_PrimPoly *srcpoly,
269  GA_PrimitiveWrangler &polywrangler,
270  GA_VertexWrangler &vtxwrangler);
271 
272  // Links p1 with p2 in that order, opposite order if backward is true.
273  int linkBreakPoints(guBreakPoint *p1, guBreakPoint *p2,
274  bool backward);
275 
276  bool linkExistsInPoly(guBreakPoint *pt, guBreakPoly *p);
277 };
278 
280 {
284 };
285 
286 
287 
288 #endif
289 
guBreakPointStatus status
void setCloseGeometry(bool closegeo)
guBreakPointStatus
guBreakPolyType type
guBreakPoint * next
GA_Offset pt1
GA_Offset pt
GA_Size GA_Offset
Definition: GA_Types.h:646
UT_Array< guBreakPoly * > polys
GU_VolumeBreak * breaker
void setKeepOutside(bool outside)
void setSnapDistance(fpreal snapdistance)
UT_Array< guBreakPoint * > points
#define GU_API
Definition: GU_API.h:14
GEO_PrimPoly * poly
guLoopCloseMethod
GA_Offset pt2
UT_Array< guBreakPoint * > guBreakPointArray
void setKeepInside(bool inside)
guNeedSplitResult
fpreal64 fpreal
Definition: SYS_Types.h:277
guBreakPoly * poly
UT_Array< guBreakPoly * > guBreakPolyArray
guBreakPoint * pt1
void setCloseHoles(guLoopCloseMethod closemethod)
GA_PointWrangler * ptwrangler
guBreakPolyType
void setGroups(const GA_PrimitiveGroup *agrp)
guBreakPoint * pt2
guBreakPoint * prev