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 
70  bool operator==(const GU_SplitLoc &src) const;
71  bool operator!=(const GU_SplitLoc &src) const
72  {
73  return !(operator==(src));
74  }
75 
76  UT_Vector3 getPos3() const;
77  void print() const; // TODO: debug only
78 
81  float myT; //
82  float myT2; // second uv value for face vertices
83  bool myInsidePrim; // the point is not a vertex/edge cut
85  GEO_PrimPoly *myOldPoly; // used to store references to old polygons
86  // for in-polygon cuts to save recalculating
87  // u, v values
89 };
91 
92 
93 
94 // The UpdatePrimList is the list kept of all the prims that must be
95 // updated once the split is over. These prims are not involved in any
96 // split, but have been affected by a split (probably because they share
97 // an edge that was split.)
99 {
100 public:
102 
104 
105  void updatePrims(GU_SplitHistory &hist, GU_Detail &gdp,
106  float tolerance,
107  GA_ElementWranglerCache &wranglers,
108  bool createDuplicate = false);
109 
110  GEO_PrimPoly * createDuplicatePoly(GEO_PrimPoly &poly,
111  GU_SplitHistory &hist,
112  GU_Detail &gdp,
113  GA_ElementWranglerCache &wranglers);
114 
115  // Adds to list primlist the polygons that will be getting point pt
116  void getPrimsUsingPoint(GA_Offset pt, UT_IntArray &primlist);
117 };
118 
119 class gu_PrimDistance;
120 
121 
122 // EdgeSplit workhorse.
124 {
125 public:
126  GU_EdgeSplit(GU_Detail &gdp, GA_EdgeGroup *outedges = 0,
127  bool modifyGdp = true, UT_Fpreal32Array *outPositions = NULL);
128  ~GU_EdgeSplit();
129 
130  void doSplit(const GU_SplitLocArray &splitlocs, bool force,
131  bool quadcut, float tolerance, bool quadcomplete,
132  bool fixends);
133 
134 private:
135 
136  // This method takes both inputs, converts them to an edge split location,
137  // if necessary, and calls splitEdge
138  // The parameters:
139  // from - from location
140  // to - to location
141  // path - current path so far
142  // quadcut - true if we are quadcuttin', false otherwise
143  // findingtail - true if we are looking for our tail
144  // pointpass - serial number of passing the responsibility to
145  // other primitives and avoid infinite recursion.
146  void split(const GU_SplitLoc &from, const GU_SplitLoc &to,
147  GU_SplitPath *&path, bool quadcut, bool findingtail,
148  int pointpass);
149  bool simplify(GU_SplitLoc &from, GU_SplitLoc &to);
150 
151  void splitPoly(GEO_PrimPoly &poly, int fromedge, int toedge,
152  float fromt, float tot,
153  GA_Offset newpt0, GA_Offset newpt1);
154 
155  void addEdgeToPoly(GEO_PrimPoly &poly, int fromedge, float fromt,
156  GA_Offset newpt0, GA_Offset newpt1,
157  GEO_PrimPoly &oldPoly,
158  float u, float v);
159 
160  // Returns true if the node was added to the path
161  bool addPathNode(const GU_SplitLoc &from, const GU_SplitLoc &to,
162  GU_SplitPath &path, bool quadcut);
163 
164  void updateNeighbourPrims(const GU_SplitLoc &splitloc);
165 
166  bool restructureSplit(GU_SplitHistoryNode *stn, GU_SplitLoc &loc);
167 
168  void executePath(GU_SplitPath &path);
169  void getTransferCandidates(const GU_SplitLoc &from,
170  GA_PrimitiveGroup &grp);
171  bool transferLoc(GU_SplitLoc &loc, GEO_PrimPoly *poly);
172  bool inPath(GEO_PrimPoly *poly, const GU_SplitPath &path);
173  void pruneGroup(const GU_SplitLoc &fromloc, const GU_SplitLoc &toloc,
174  UT_IntArray &primlist, bool quadcut);
175 
176  void getEdgeCandidates(const GU_SplitLoc &loc,
177  const UT_Vector3 &src, const UT_Vector3 &dest,
179  bool quadcut);
180 
181  void sortEdgeCandidates(const GU_SplitLoc &loc,
182  const UT_Vector3 &dest,
184 
185  void getPrimCandidates(const GEO_PrimPoly *poly, GA_Offset pt0,
186  GA_Offset pt1,const GU_SplitPath &path,
187  UT_IntArray &candidates, bool quadcut);
188 
189  GA_Offset getNewPoint(GA_Offset pt0, GA_Offset pt1, fpreal t);
190  GA_Offset getNewPoint(const GEO_PrimPoly &p, const UT_Vector3 &pos,
191  float u, float v);
192 
193  int buildFromPrimArray(const GU_SplitLoc &fromloc,
194  const GU_SplitLoc &toloc,
195  UT_IntArray &fromlist,
196  UT_Array<gu_PrimDistance *> &primarray,
197  bool quadcut);
198 
199  // Takes the path and fills it with the correctly interpolated biases for
200  // quad cuts. The quadclosed flag indicates whether or not the path is
201  // a closed loop. The findingtail flag indicates whether or not we were
202  // trying to find our tail (single-click quadcut).
203  void quadProcessPath(GU_SplitPath &path, bool quadclosed,
204  bool findingtail);
205 
206  void getParticipatingPolys(const GU_SplitLoc &loc,
207  GEO_Closure &closure, UT_IntArray &prims);
208 
209  void interpolateInteriorPoint(GA_Offset &result,
210  GA_AttributeRefMap &map,
211  const GEO_PrimPoly &poly,
212  fpreal u, fpreal v);
213 
214  // ensures that the first and last split locations in the given array are
215  // not on faces, as the algorithm requires that they are. If they are not,
216  // add the closest vertex to the first/last point appropriately
217  void fixFirstLastPoints(GU_SplitLocArray &splitlocs);
218 
219  // returns a split location that is a vertex closest to the given splitloc
220  // skip is a point that will not be considered. Use this if for example you
221  // just came from a point and don't want to return there
222  GU_SplitLoc *closestPoint(const GU_SplitLoc &splitpt,
224 
225  // attempts to fix any quads on the original geometry which have been split
226  // into polygons that are not quads. It only works when the polygon has been
227  // split into exactly two parts, one of which is a quad or a triangle
228  void completeQuads();
229 
230  // adds the point specified to myOutPositions
231  void addToMyOutPositions(GA_Offset pt0, GA_Offset pt1, float t);
232 
233  // Data Members
234  GA_PrimitiveGroup *myTempPrimGrp;
235 
236  // This group will keep track of the new points we add to the geometry
237  // so that we don't add duplicate points (keeps things consolidated
238  GA_PointGroup *myNewPointsGrp;
239  gu_UpdatePrimList myUpdatePrimList;
240  GEO_PrimPoly *lastPoly;
241  GU_SplitHistory *myHistory;
242  GU_Detail &myGdp;
243  GU_SplitPathManager *mySplitPathMan;
244  GA_EdgeGroup *myOutEdges;
245  GA_ElementWranglerCache *myWranglers;
246  bool myForceCut;
247  float myTolerance;
248  bool myHasInsideCut;
249  // this prevents myGdp from being changed. It is used when we want to find
250  // the split path for rendering purposes, but don't want to actually change
251  // the given GU_Detail
252  bool myModifyGdp;
253  // we typically don't want to modify the gdp when we just want a list of
254  // edges being modified/add for rendering purposes. We can't use myOutEdges
255  // because that requires the points to be added to the gdp, so instead we
256  // just use a UT_Fpreal32Array
257  UT_Fpreal32Array *myOutPositions;
258 
259 };
260 
261 #endif
GA_Offset myP0Off
Definition: GU_EdgeSplit.h:79
void skip(T &in, int n)
Definition: ImfXdr.h:613
const GLdouble * v
Definition: glcorearb.h:837
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:3341
GA_Offset myP1Off
Definition: GU_EdgeSplit.h:80
GEO_PrimPoly * myOldPoly
Definition: GU_EdgeSplit.h:85
**But if you need a result
Definition: thread.h:613
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
GA_Size GA_Offset
Definition: GA_Types.h:646
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
bool myInsidePrim
Definition: GU_EdgeSplit.h:83
A handle to simplify manipulation of multiple attributes.
GA_Detail * myGdp
Definition: GU_EdgeSplit.h:88
bool operator!=(const GU_SplitLoc &src) const
Definition: GU_EdgeSplit.h:71
#define GU_API
Definition: GU_API.h:14
GLdouble t
Definition: glad.h:2397
UT_Array< GU_SplitLoc * > GU_SplitLocArray
Definition: GU_EdgeSplit.h:90
GU_SplitLoc(float u, float v, GEO_PrimPoly *poly)
Definition: GU_EdgeSplit.h:59
SIM_API const UT_StringHolder force
fpreal64 fpreal
Definition: SYS_Types.h:277
OPENVDB_API SharedPtr< MapBase > simplify(SharedPtr< AffineMap > affine)
reduces an AffineMap to a ScaleMap or a ScaleTranslateMap when it can
Container class for all geometry.
Definition: GA_Detail.h:96
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
GEO_PrimPoly * myPoly
Definition: GU_EdgeSplit.h:84
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
UT_Array< gu_PrimToUpdate * > myList
Definition: GU_EdgeSplit.h:103
GLenum src
Definition: glcorearb.h:1793