HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_IsectCurveSet.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 library (C++)
7  *
8  * COMMENTS: Describes a set of intersection curves on surfaces.
9  * Handles additions of new curves, points to curves, etc.
10  * Standard type is UT_Vector4, where:
11  * (x, y, z, w) ~ (u1, v1, u2, v2)
12  *
13  */
14 
15 #ifndef __GU_IsectCurveSet_h__
16 #define __GU_IsectCurveSet_h__
17 
18 #include "GU_API.h"
19 #include <UT/UT_ValArray.h>
20 #include <UT/UT_Vector4.h>
21 #include <UT/UT_BoundingRect.h>
22 
23 class GA_PrimitiveGroup;
24 class GEO_Face;
25 class GEO_Profiles;
26 class GEO_TPSurf;
27 class GD_TrimLoop;
28 class GU_IsectNode;
29 class GU_IsectCurveSet;
30 class GU_IsectPoint;
31 class GU_Detail;
32 
34 {
35 public:
36  GU_IsectCurve();
37  GU_IsectCurve(int surface, GD_TrimLoop *loop);
38  ~GU_IsectCurve();
39 
40  // Add a point to the curve.
41  void append(const UT_Vector4 &point);
42  // Append another curve:
43  // These all steal the poinstfrom the provided curve!!!
44  void append(GU_IsectCurve &curve);
45  void appendReverse(GU_IsectCurve &curve);
46  // Same, but prepend:
47  void prepend(GU_IsectCurve &curve);
48  void prependReverse(GU_IsectCurve &curve);
49  // Adds curve, but copies points.
50  void appendCopy(GU_IsectCurve &curve);
51 
52  // Reparameterizes all the points in the curve from 0,1 into
53  // start, start+length:
54  void reparameterize(const UT_Vector4 &start,
55  const UT_Vector4 &length);
56 
57  // Accumulates into area based upon dir.
58  void getArea(float &areaxy, float &areazw, int dir) const;
59 
60  // Accumulates into length based upon euclidean length
61  void getLength(float &lengthxy, float &lengthzw) const;
62 
63  // Returns euclidean length of curve along specified surface
64  // (In terms of domain space though!)
65  float getLength(int surface) const;
66 
67  int numPoints() const { return myNumPts; }
68 
69  // Adds this curve to the set, making the appropriate nodes, etc.
70  void linkInto(GU_IsectCurveSet &curveset, const UT_Vector4 &tol);
71  // Removes links to nodes.
72  void unLink() { myNodes[0] = myNodes[1] = 0; }
73 
74  // Empties the curve.
75  // Deletes all points in the curve.
76  void empty();
77 
78  // Only works if compact has been called on the curveset.
79  int isClosed() const
80  { return (myNodes[0] && (myNodes[0] == myNodes[1])); }
81 
82  UT_Vector4 &operator()(int i);
83  UT_Vector4 operator()(int i) const;
84 
85  // Not a very intelligent == operator, something is required for
86  // NT build though.
87  int operator==(const GU_IsectCurve &curve)
88  { return myPoints[0] == curve.myPoints[0]; }
89 
90  GU_IsectNode *getNode(int idx) const { return myNodes[idx]; }
91  void setNode(int idx, GU_IsectNode *node) {myNodes[idx] = node;}
92  int getEndPoint(int idx, UT_Vector4 &pt) const;
93  int setEndPoint(int idx, const UT_Vector4 &pt);
94 
95  // Finds which direction this curve should be.
96  void findDirection(const GEO_TPSurf &surfxy,
97  const GEO_TPSurf &surfzw,
98  int signxy = 1, int signzw = 1);
99 
100  // surfside is 0 for XY, 1 for ZW surface. Result is 1 if
101  // surface should be generated in forward direction, else
102  // -1.
103  int getDirection(int surfside) const
104  { return myDirection[surfside]; }
105  void setDirection(int surfside, int dir)
106  { myDirection[surfside] = dir; }
107 
108  // Creates a space curve from the curve, on the specified surface.
109  // The given surface is assumed to be correct.
110  GEO_Face *createSpaceCurve(GU_Detail *gdp, int surface,
111  GEO_TPSurf *surf,
112  GEO_TPSurf *base1, GEO_TPSurf *base2,
113  GEO_Face *&edge1, GEO_Face *&edge2,
114  GEO_Face *&prof1, GEO_Face *&prof2,
115  float tol = 1e-3F) const;
116 
117  // Creates a profile out of this curve, in the direction specified
118  // by myDirection[surface]. Generates it into the specified profile
119  // set.
120  void createProfile(int surface, int direction,
121  GEO_Profiles &profs,
122  GA_PrimitiveGroup *profgroup = 0,
123  float tol = 1e-3F) const;
124 
125  // Creates a profile, and generates trim regions from it
126  GD_TrimLoop *createTrimmedProfile(int surface, int direction,
127  GEO_Profiles &profs,
128  GA_PrimitiveGroup *profgroup = 0,
129  float tol = 1e-3F) const;
130 
131  // Create a trim loop:
132  GD_TrimLoop *createTrimLoop(int surface, int direction, int parameter,
133  float tol = 1e-3F) const;
134 
135 private:
136  // 0 is start of point list, 1 is end.
137  GU_IsectPoint *myPoints[2];
138  GU_IsectPoint *myLastPoint;
139  // Start and end nodes, indexed 0 and 1 resp.
140  GU_IsectNode *myNodes[2];
141  // Direction of curve along two surfaces.
142  // 0 is for XY, 1 is for ZW.
143  int myDirection[2];
144  int myNumPts;
145 };
146 
148 {
149 protected:
150  // A sanity test on the curve net work. Useful for tracking down
151  // orphaned curves, etc. Returns 1 if all is fine, writes an error
152  // to stderr and returns 0 otherwise.
153  int verifyNetwork() const;
154 public:
156  ~GU_IsectCurveSet();
157 
158  // Add in a new curve, searching this set for any existant
159  // curves that could be merged in:
160  // Both of these STEAL the points/curves from the source set/curve.
161  void merge(GU_IsectCurve *curve);
162  // Add in another curveset, again merging nearby curves:
163  void merge(GU_IsectCurveSet &curveset);
164  // And this one will duplicate the curve, but not the points.
165  void merge(GU_IsectCurve &curve);
166  // This constructs copies of the requested curves, and does not steal
167  void mergeCopy(GU_IsectCurve *curve);
168  void mergeCopy(const GU_IsectCurveSet &curveset);
169 
170  int isEmpty() const
171  { return (myCurves.entries()) ? 0 : 1; }
172  int numCurves() const { return (int)myCurves.entries(); }
173 
174  // Clears all local information without destroying the refarray.
175  void reset();
176  void setSurfaces(GEO_TPSurf *surfxy, GEO_TPSurf *surfzw)
177  { mySurfXY = surfxy; mySurfZW = surfzw; }
178 
179  // Reparameterizes all the points in the curve from 0,1 into
180  // start, start+length:
181  void reparameterize(const UT_Vector4 &start, const UT_Vector4 &length);
182 
183  // NB: This CAN be NULL, in which case the curve should be ignored
184  // as it was eliminated in a collapse.
185  GU_IsectCurve *&operator()(int i) { return myCurves((unsigned)i); }
186  GU_IsectCurve *operator()(int i) const { return myCurves((unsigned)i); }
187 
188  // Not a very intelligent == operator, something is required for
189  // NT build though.
190  int operator==(const GU_IsectCurveSet &curveSet)
191  { return myCurves == curveSet.myCurves; }
192 
193  GU_IsectNode *findNode(const UT_Vector4 &p,
194  const UT_Vector4 &tol) const;
195  GU_IsectNode *findNearestNode(const UT_Vector4 &p, int surface,
196  float tol, GU_IsectNode *ignore) const;
197  GU_IsectNode *createNode(const UT_Vector4 &p);
198 
199  // Reduces number of curves in curveset by generating vertex list
200  // and merging all the adjacent curves. Uses tol to judge identical
201  // points, and looptol to decide if a loop is degenerate and should
202  // be replaced by a line.
203  // xtol & ytol are the tolerances for identicalness on the
204  // base curve, likely MUCH larger than tol.
205  // If ignroe dir is false, only connect pieces whose directions
206  // are copacetic.
207  void compact(const UT_Vector4 &tol, float looptolxy,
208  float looptolzw, int ignoredir=1);
209 
210  // Takes compacted curveset & handles brachiations & tachnodes,
211  // creating closed curves where possible.
212  // Returns 0 if curveset unchanged.
213  int resolveTachnodes(int surface, float tol);
214 
215  // Sets the direction fields of all curves:
216  void findCurveDirections(int signxy = 1, int signzw = 1);
217 
218  // Generates profile curves on the specified surface.
219  // 0 will generate profile on XY surface, 1 on ZW surface.
220  // trim determines if profiles will be generated along entire isect
221  // curve, or only those not already trimmed out on the cutting
222  // surface
223  // Direction = 1 will generate according to results of
224  // findCurveDirections, -1 will do so oppositely.
225  void generateProfiles(int surface, int trim = 0,
226  int direction = 1,
227  GA_PrimitiveGroup *profgroup = 0,
228  float tol = 1e-3F,
229  bool *buildloop = 0) const;
230 
231 #if 0
232  void generateTrimProfs(const UT_BoundingRect &brect,
233  int surface, int direction,
234  float tol = 1e-3F) const;
235 #endif
236 
237  // Stretches all points to the domain all the way over.
238  void stretchToDomain(int surface,
239  const UT_BoundingRect &rect, float tol);
240 
241  // Cuts all our curves by the specified trim loop
242  void cutByTrimLoops(int surface, const GD_TrimLoop *cutter,
243  int inside = 1);
244 private:
245  // Eliminates topological information of set.
246  void clearNodeList();
247 
248  // Builds topological info of set.
249  void buildNodeList(const UT_Vector4 &tol);
250 
251  // Collapses degenerate loops
252  int mergeLoops(float looptolxy, float looptolzw);
253 
254  // Joins adjacent edges
255  int joinAdjacent(int ignoredir);
256 
257  // List of all curves that are present.
259  // Head of node list.
260  GU_IsectNode *myNodes;
261  // "Owner" surfaces:
262  GEO_TPSurf *mySurfXY, *mySurfZW;
263 };
264 
265 #endif
GU_IsectNode * getNode(int idx) const
void setDirection(int surfside, int dir)
GU_IsectCurve *& operator()(int i)
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLuint start
Definition: glcorearb.h:474
void setNode(int idx, GU_IsectNode *node)
int isEmpty() const
png_uint_32 i
Definition: png.h:2877
int isClosed() const
void setSurfaces(GEO_TPSurf *surfxy, GEO_TPSurf *surfzw)
#define GU_API
Definition: GU_API.h:11
int operator==(const GU_IsectCurve &curve)
int getDirection(int surfside) const
int numPoints() const
GU_IsectCurve * operator()(int i) const
int numCurves() const
int operator==(const GU_IsectCurveSet &curveSet)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794