HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GD_TrimPiece.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: Geometry Library (C++)
7  *
8  * COMMENTS:
9  * This handles trimming primitives, which are a linked list of
10  * trimming curves.
11  *
12  */
13 
14 #ifndef __GD_TrimPiece_h_
15 #define __GD_TrimPiece_h_
16 
17 #include "GD_API.h"
18 #include <UT/UT_BoundingRect.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Vector3Array.h>
21 #include <UT/UT_Matrix.h>
22 #include "GD_PrimType.h"
23 
24 class GD_Face;
25 class GD_Detail;
26 
27 class gdTrimIntersection;
28 
29 // Holds the info for a hit:
31 {
32 public:
33  int operator==(const GD_TrimHitInfo &x) const
34  {
35  return (t==x.t && u==x.u && d2==x.d2);
36  }
37  float t, u;
38  float d2; // How close hit is, squared.
39  int boundary; // GD_DomainBoundary value.
40  gdTrimIntersection *isect;
41 };
42 
43 
44 // Piece of a trimming curve
46 {
47 public:
48  GD_TrimPiece();
49  // Deletes self and all siblings.
50  virtual ~GD_TrimPiece();
51 
52  virtual int64 getMemoryUsage(bool inclusive) const
53  {
54  int64 mem = inclusive ? sizeof(*this) : 0;
55  mem += myCV.getMemoryUsage(false);
56  // We own our next, so count it (uses virtual calls)
57  if (myNext)
58  mem += myNext->getMemoryUsage(true);
59  return mem;
60  }
61 
62  void init(int order, float ustart, float ulength,
63  int rational = 1);
64 
65  // Copies this piece, does not copy siblings.
66  virtual GD_TrimPiece *copy() = 0;
67 
68  // Reverses this piece, does not reverse siblings. The U start remains
69  // unchanged but can be accessed externally.
70  virtual void reverse();
71 
72  // Remove a piece from this curve
73  virtual GD_TrimPiece *cut(float u1, float u2) const = 0;
74 
75  // Find length of curve: Rough estimate, uses the length of the
76  // hull.
77  float length() const;
78 
79  // Intersects with another piece, adding all intersections blindly
80  // to the refarray (Caller should remove any duplicates)
81  virtual int intersect(GD_TrimPiece &curve,
82  UT_Array<GD_TrimHitInfo> &hitlist,
83  float tol = 0.0001F) = 0;
84 
85  // Intersects with an isoparm.
86  virtual int intersectIsoparm(float val, int isoparm,
87  UT_Array<GD_TrimHitInfo> &hitlist,
88  float tol = 1E-4F, int depth = 4) = 0;
89 
90  virtual GD_Face *createFace(GD_Detail *gdp) = 0;
91 
92  // Find what type this piece is.
93  virtual unsigned getPrimitiveTypeId() const = 0;
94 
95  virtual int evaluate(float u, UT_Vector2 &pos) const;
96  virtual int evaluate(float u, UT_Vector2 &pos,
97  UT_Vector2 &der) const;
98  // Req's u to be in [0,1] parameterization.
99  virtual int evaluateUnit(float u, UT_Vector2 &pos) const=0;
100  virtual int evaluateUnit(float u, UT_Vector2 &pos,
101  UT_Vector2 &der, UT_Vector2 &der2)
102  const = 0;
103 
104  // Check if the piece is straight, and if so reduce it to its two
105  // end points. Returns one if straight.
106  int checkStraight(void);
107 
108  virtual void buildBBox();
109 
110  void print() const;
111 
112 // Data:
113 public:
115  float myUStart, myULength;
119 
121  UT_MatrixF myXCoeff, myYCoeff, myWCoeff;
122 };
123 
125 {
126 public:
128  // Deletes self and all siblings.
129  virtual ~GD_TrimPieceRBezCurve();
130 
131  void buildCoeff(UT_MatrixF &A, int index1, int index2);
132 
133  // Copies this piece, does not copy siblings.
134  virtual GD_TrimPiece *copy();
135 
136  // Remove a piece from this curve
137  virtual GD_TrimPiece *cut(float u1, float u2) const;
138 
139  // Intersects with another piece, adding all intersections blindly
140  // to the refarray (Caller should remove any duplicates)
141  virtual int intersect(GD_TrimPiece &curve,
142  UT_Array<GD_TrimHitInfo> &hitlist,
143  float tol = 0.0001F);
144  // Actual workhorse function:
145  int intersect(GD_TrimPieceRBezCurve &curve,
146  UT_Array<GD_TrimHitInfo> &hitlist,
147  int depth,
148  float tol = 0.0001F);
149  // Another version, uses eigenvalue methods:
150  int intersectQR(GD_TrimPieceRBezCurve &curve,
151  UT_Array<GD_TrimHitInfo> &hitlist,
152  float tol = 0.0001F);
153 
154  // Intersects with an isoparm.
155  virtual int intersectIsoparm(float val, int isoparm,
156  UT_Array<GD_TrimHitInfo> &hitlist,
157  float tol = 1E-4F, int depth = 4);
158 
159  // Req's u to be in [0,1] parameterization.
160  virtual int evaluateUnit(float u, UT_Vector2 &pos) const;
161  virtual int evaluateUnit(float u, UT_Vector2 &pos,
162  UT_Vector2 &der, UT_Vector2 &der2)
163  const;
164 
165  virtual GD_Face *createFace(GD_Detail *gdp);
166 
167  // Find what type this piece is.
168  virtual unsigned getPrimitiveTypeId() const
169  { return GD_PRIMBEZCURVE; }
170  // Requires both left & right to exist
171  void splitInHalf(GD_TrimPieceRBezCurve *left,
172  GD_TrimPieceRBezCurve *right,
173  float tol = 1E-4F) const;
174  // If left or right NULL, does not evaluate it.
175  int splitAt(GD_TrimPieceRBezCurve *left,
176  GD_TrimPieceRBezCurve *right,
177  float ucut, float tol = 1E-4F) const;
178 
179 };
180 
181 
183 {
184 public:
186  // Deletes self and all siblings.
187  virtual ~GD_TrimPiecePoly();
188 
189  virtual int64 getMemoryUsage(bool inclusive) const
190  {
191  int64 mem = inclusive ? sizeof(*this) : 0;
192  mem += GD_TrimPiece::getMemoryUsage(false);
193  mem += myCurve.getMemoryUsage(false);
194  return mem;
195  }
196 
197  // Copies this piece, does not copy siblings.
198  virtual GD_TrimPiece *copy();
199 
200  // Remove a piece from this curve
201  virtual GD_TrimPiece *cut(float u1, float u2) const;
202 
203  // Intersects with another piece, adding all intersections blindly
204  // to the refarray (Caller should remove any duplicates)
205  virtual int intersect(GD_TrimPiece &curve,
206  UT_Array<GD_TrimHitInfo> &hitlist,
207  float tol = 0.0001F);
208 
209  // Intersects with an isoparm.
210  virtual int intersectIsoparm(float val, int isoparm,
211  UT_Array<GD_TrimHitInfo> &hitlist,
212  float tol = 1E-4F, int depth = 4);
213 
214  // Req's u to be in [0,1] parameterization.
215  virtual int evaluateUnit(float u, UT_Vector2 &pos) const;
216  virtual int evaluateUnit(float u, UT_Vector2 &pos,
217  UT_Vector2 &der, UT_Vector2 &der2)
218  const;
219 
220  virtual GD_Face *createFace(GD_Detail *gdp);
221 
222  // Find what type this piece is.
223  virtual unsigned getPrimitiveTypeId() const
224  { return GD_PRIMPOLY; }
225 
226  void buildCurve(int idx);
227  void appendPoint(float x, float y);
228 public:
230 };
231 
232 #endif
virtual int evaluateUnit(float u, UT_Vector2 &pos) const =0
GLint left
Definition: glcorearb.h:2004
virtual GD_TrimPiece * cut(float u1, float u2) const =0
GLint y
Definition: glcorearb.h:102
long long int64
Definition: SYS_Types.h:107
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:475
bool intersect(const Line3< T > &line, const Vec3< T > &v0, const Vec3< T > &v1, const Vec3< T > &v2, Vec3< T > &pt, Vec3< T > &barycentric, bool &front)
virtual GD_Face * createFace(GD_Detail *gdp)=0
virtual int intersectIsoparm(float val, int isoparm, UT_Array< GD_TrimHitInfo > &hitlist, float tol=1E-4F, int depth=4)=0
int operator==(const GD_TrimHitInfo &x) const
Definition: GD_TrimPiece.h:33
GD_TrimPieceRBezCurve myCurve
Definition: GD_TrimPiece.h:229
#define GD_API
Definition: GD_API.h:10
UT_MatrixF myYCoeff
Definition: GD_TrimPiece.h:121
GLint GLenum GLint x
Definition: glcorearb.h:408
GLuint GLfloat * val
Definition: glcorearb.h:1607
UT_Vector3Array myCV
Definition: GD_TrimPiece.h:116
GD_TrimPiece * myNext
Definition: GD_TrimPiece.h:114
virtual unsigned getPrimitiveTypeId() const
Definition: GD_TrimPiece.h:223
UT_BoundingRect myBBox
Definition: GD_TrimPiece.h:117
virtual GD_TrimPiece * copy()=0
virtual int64 getMemoryUsage(bool inclusive) const
Definition: GD_TrimPiece.h:189
virtual unsigned getPrimitiveTypeId() const
Definition: GD_TrimPiece.h:168
virtual int64 getMemoryUsage(bool inclusive) const
Definition: GD_TrimPiece.h:52
virtual int intersect(GD_TrimPiece &curve, UT_Array< GD_TrimHitInfo > &hitlist, float tol=0.0001F)=0
gdTrimIntersection * isect
Definition: GD_TrimPiece.h:40
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794