HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_EdgeSplit.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: Splits edges.
9  *
10  */
11 
12 #ifndef __GU_EdgeSplit_h__
13 #define __GU_EdgeSplit_h__
14 
15 #include "GU_API.h"
16 #include <GEO/GEO_PrimPoly.h>
17 #include <UT/UT_IntArray.h>
18 #include <UT/UT_Array.h>
19 #include <UT/UT_VectorTypes.h>
20 
21 class GA_EdgeGroup;
22 class GA_PointGroup;
23 class GA_PrimitiveGroup;
25 class GA_AttributeRefMap;
26 class GEO_Closure;
27 class GU_Detail;
28 class GU_SplitHistory;
29 class GU_SplitHistoryNode;
30 class GU_SplitLoc;
31 class GU_SplitPath;
32 class GU_SplitPathNode;
33 class GU_SplitPathManager;
34 class gu_PrimToUpdate;
35 class gu_CrossEdge;
36 
37 
38 // This class defines a split location. It represents a place where a split
39 // will occur. A list of these things is what we need to make a complete
40 // cut.
42 {
43 public:
44  GU_SplitLoc(GA_Detail *gdp = NULL,
47  float t = 0,
48  GEO_PrimPoly *poly = NULL)
49  : myP0Off(p0off)
50  , myP1Off(p1off)
51  , myT(t)
52  , myT2(-1)
53  , myPoly(poly)
54  , myOldPoly(0)
55  , myInsidePrim(false)
56  , myGdp(gdp)
57  { }
58 
59  GU_SplitLoc(float u, float v, GEO_PrimPoly *poly)
60  : myP0Off(GA_INVALID_OFFSET)
61  , myP1Off(GA_INVALID_OFFSET)
62  , myT(u)
63  , myT2(v)
64  , myPoly(poly)
65  , myInsidePrim(true)
66  , myOldPoly(poly)
67  , myGdp(&poly->getDetail())
68  { }
69 
71  {
72  myP0Off= src.myP0Off;
73  myP1Off= src.myP1Off;
74  myT = src.myT;
75  myT2 = src.myT2;
76  myPoly = src.myPoly;
77  myOldPoly = src.myOldPoly;
78  myGdp = src.myGdp;
79  myInsidePrim = src.myInsidePrim;
80  return *this;
81  }
82  bool operator==(const GU_SplitLoc &src) const;
83  bool operator!=(const GU_SplitLoc &src) const
84  {
85  return !(operator==(src));
86  }
87 
88  UT_Vector3 getPos3() const;
89  void print() const; // TODO: debug only
90 
93  float myT; //
94  float myT2; // second uv value for face vertices
95  bool myInsidePrim; // the point is not a vertex/edge cut
97  GEO_PrimPoly *myOldPoly; // used to store references to old polygons
98  // for in-polygon cuts to save recalculating
99  // u, v values
101 };
103 
104 
105 
106 // The UpdatePrimList is the list kept of all the prims that must be
107 // updated once the split is over. These prims are not involved in any
108 // split, but have been affected by a split (probably because they share
109 // an edge that was split.)
111 {
112 public:
114 
116 
117  void updatePrims(GU_SplitHistory &hist, GU_Detail &gdp,
118  float tolerance,
119  GA_ElementWranglerCache &wranglers,
120  bool createDuplicate = false);
121 
122  GEO_PrimPoly * createDuplicatePoly(GEO_PrimPoly &poly,
123  GU_SplitHistory &hist,
124  GU_Detail &gdp,
125  GA_ElementWranglerCache &wranglers);
126 
127  // Adds to list primlist the polygons that will be getting point pt
128  void getPrimsUsingPoint(GA_Offset pt, UT_IntArray &primlist);
129 };
130 
131 class gu_PrimDistance;
132 
133 
134 // EdgeSplit workhorse.
136 {
137 public:
138  GU_EdgeSplit(GU_Detail &gdp, GA_EdgeGroup *outedges = 0,
139  bool modifyGdp = true, UT_Fpreal32Array *outPositions = NULL);
140  ~GU_EdgeSplit();
141 
142  void doSplit(const GU_SplitLocArray &splitlocs, bool force,
143  bool quadcut, float tolerance, bool quadcomplete,
144  bool fixends);
145 
146 private:
147 
148  // This method takes both inputs, converts them to an edge split location,
149  // if necessary, and calls splitEdge
150  // The parameters:
151  // from - from location
152  // to - to location
153  // path - current path so far
154  // quadcut - true if we are quadcuttin', false otherwise
155  // findingtail - true if we are looking for our tail
156  // pointpass - serial number of passing the responsibility to
157  // other primitives and avoid infinite recursion.
158  void split(const GU_SplitLoc &from, const GU_SplitLoc &to,
159  GU_SplitPath *&path, bool quadcut, bool findingtail,
160  int pointpass);
161  bool simplify(GU_SplitLoc &from, GU_SplitLoc &to);
162 
163  void splitPoly(GEO_PrimPoly &poly, int fromedge, int toedge,
164  float fromt, float tot,
165  GA_Offset newpt0, GA_Offset newpt1);
166 
167  void addEdgeToPoly(GEO_PrimPoly &poly, int fromedge, float fromt,
168  GA_Offset newpt0, GA_Offset newpt1,
169  GEO_PrimPoly &oldPoly,
170  float u, float v);
171 
172  // Returns true if the node was added to the path
173  bool addPathNode(const GU_SplitLoc &from, const GU_SplitLoc &to,
174  GU_SplitPath &path, bool quadcut);
175 
176  void updateNeighbourPrims(const GU_SplitLoc &splitloc);
177 
178  bool restructureSplit(GU_SplitHistoryNode *stn, GU_SplitLoc &loc);
179 
180  void executePath(GU_SplitPath &path);
181  void getTransferCandidates(const GU_SplitLoc &from,
182  GA_PrimitiveGroup &grp);
183  bool transferLoc(GU_SplitLoc &loc, GEO_PrimPoly *poly);
184  bool inPath(GEO_PrimPoly *poly, const GU_SplitPath &path);
185  void pruneGroup(const GU_SplitLoc &fromloc, const GU_SplitLoc &toloc,
186  UT_IntArray &primlist, bool quadcut);
187 
188  void getEdgeCandidates(const GU_SplitLoc &loc,
189  const UT_Vector3 &src, const UT_Vector3 &dest,
191  bool quadcut);
192 
193  void sortEdgeCandidates(const GU_SplitLoc &loc,
194  const UT_Vector3 &dest,
196 
197  void getPrimCandidates(const GEO_PrimPoly *poly, GA_Offset pt0,
198  GA_Offset pt1,const GU_SplitPath &path,
199  UT_IntArray &candidates, bool quadcut);
200 
201  GA_Offset getNewPoint(GA_Offset pt0, GA_Offset pt1, fpreal t);
202  GA_Offset getNewPoint(const GEO_PrimPoly &p, const UT_Vector3 &pos,
203  float u, float v);
204 
205  int buildFromPrimArray(const GU_SplitLoc &fromloc,
206  const GU_SplitLoc &toloc,
207  UT_IntArray &fromlist,
208  UT_Array<gu_PrimDistance *> &primarray,
209  bool quadcut);
210 
211  // Takes the path and fills it with the correctly interpolated biases for
212  // quad cuts. The quadclosed flag indicates whether or not the path is
213  // a closed loop. The findingtail flag indicates whether or not we were
214  // trying to find our tail (single-click quadcut).
215  void quadProcessPath(GU_SplitPath &path, bool quadclosed,
216  bool findingtail);
217 
218  void getParticipatingPolys(const GU_SplitLoc &loc,
219  GEO_Closure &closure, UT_IntArray &prims);
220 
221  void interpolateInteriorPoint(GA_Offset &result,
222  GA_AttributeRefMap &map,
223  const GEO_PrimPoly &poly,
224  fpreal u, fpreal v);
225 
226  // ensures that the first and last split locations in the given array are
227  // not on faces, as the algorithm requires that they are. If they are not,
228  // add the closest vertex to the first/last point appropriately
229  void fixFirstLastPoints(GU_SplitLocArray &splitlocs);
230 
231  // returns a split location that is a vertex closest to the given splitloc
232  // skip is a point that will not be considered. Use this if for example you
233  // just came from a point and don't want to return there
234  GU_SplitLoc *closestPoint(const GU_SplitLoc &splitpt,
236 
237  // attempts to fix any quads on the original geometry which have been split
238  // into polygons that are not quads. It only works when the polygon has been
239  // split into exactly two parts, one of which is a quad or a triangle
240  void completeQuads();
241 
242  // adds the point specified to myOutPositions
243  void addToMyOutPositions(GA_Offset pt0, GA_Offset pt1, float t);
244 
245  // Data Members
246  GA_PrimitiveGroup *myTempPrimGrp;
247 
248  // This group will keep track of the new points we add to the geometry
249  // so that we don't add duplicate points (keeps things consolidated
250  GA_PointGroup *myNewPointsGrp;
251  gu_UpdatePrimList myUpdatePrimList;
252  GEO_PrimPoly *lastPoly;
253  GU_SplitHistory *myHistory;
254  GU_Detail &myGdp;
255  GU_SplitPathManager *mySplitPathMan;
256  GA_EdgeGroup *myOutEdges;
257  GA_ElementWranglerCache *myWranglers;
258  bool myForceCut;
259  float myTolerance;
260  bool myHasInsideCut;
261  // this prevents myGdp from being changed. It is used when we want to find
262  // the split path for rendering purposes, but don't want to actually change
263  // the given GU_Detail
264  bool myModifyGdp;
265  // we typically don't want to modify the gdp when we just want a list of
266  // edges being modified/add for rendering purposes. We can't use myOutEdges
267  // because that requires the points to be added to the gdp, so instead we
268  // just use a UT_Fpreal32Array
269  UT_Fpreal32Array *myOutPositions;
270 
271 };
272 
273 #endif
GA_Offset myP0Off
Definition: GU_EdgeSplit.h:91
void skip(T &in, int n)
Definition: ImfXdr.h:885
const GLdouble * v
Definition: glcorearb.h:836
GU_SplitLoc(GA_Detail *gdp=NULL, GA_Offset p0off=GA_INVALID_OFFSET, GA_Offset p1off=GA_INVALID_OFFSET, float t=0, GEO_PrimPoly *poly=NULL)
Definition: GU_EdgeSplit.h:44
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
GA_Offset myP1Off
Definition: GU_EdgeSplit.h:92
GEO_PrimPoly * myOldPoly
Definition: GU_EdgeSplit.h:97
3D Vector class.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_Size GA_Offset
Definition: GA_Types.h:617
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
png_infop png_uint_16p * hist
Definition: png.h:2385
bool myInsidePrim
Definition: GU_EdgeSplit.h:95
A handle to simplify manipulation of multiple attributes.
GA_Detail * myGdp
Definition: GU_EdgeSplit.h:100
bool operator!=(const GU_SplitLoc &src) const
Definition: GU_EdgeSplit.h:83
#define GU_API
Definition: GU_API.h:12
UT_Array< GU_SplitLoc * > GU_SplitLocArray
Definition: GU_EdgeSplit.h:102
GU_SplitLoc(float u, float v, GEO_PrimPoly *poly)
Definition: GU_EdgeSplit.h:59
double fpreal
Definition: SYS_Types.h:270
OPENVDB_API SharedPtr< MapBase > simplify(SharedPtr< AffineMap > affine)
reduces an AffineMap to a ScaleMap or a ScaleTranslateMap when it can
GU_SplitLoc & operator=(const GU_SplitLoc &src)
Definition: GU_EdgeSplit.h:70
Container class for all geometry.
Definition: GA_Detail.h:95
GEO_PrimPoly * myPoly
Definition: GU_EdgeSplit.h:96
UT_Array< gu_PrimToUpdate * > myList
Definition: GU_EdgeSplit.h:115
GLenum src
Definition: glcorearb.h:1792