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