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();
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  ~GD_TrimPieceRBezCurve() override;
130 
131  void buildCoeff(UT_MatrixF &A, int index1, int index2);
132 
133  // Copies this piece, does not copy siblings.
134  GD_TrimPiece *copy() override;
135 
136  // Remove a piece from this curve
137  GD_TrimPiece *cut(float u1, float u2) const override;
138 
139  // Intersects with another piece, adding all intersections blindly
140  // to the refarray (Caller should remove any duplicates)
141  int intersect(GD_TrimPiece &curve,
142  UT_Array<GD_TrimHitInfo> &hitlist,
143  float tol = 0.0001F) override;
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  int intersectIsoparm(float val, int isoparm,
156  UT_Array<GD_TrimHitInfo> &hitlist,
157  float tol = 1E-4F, int depth = 4) override;
158 
159  // Req's u to be in [0,1] parameterization.
160  int evaluateUnit(float u, UT_Vector2 &pos) const override;
161  int evaluateUnit(float u,
162  UT_Vector2 &pos,
163  UT_Vector2 &der,
164  UT_Vector2 &der2) const override;
165 
166  GD_Face *createFace(GD_Detail *gdp) override;
167 
168  // Find what type this piece is.
169  unsigned getPrimitiveTypeId() const override
170  { return GD_PRIMBEZCURVE; }
171  // Requires both left & right to exist
172  void splitInHalf(GD_TrimPieceRBezCurve *left,
174  float tol = 1E-4F) const;
175  // If left or right NULL, does not evaluate it.
176  int splitAt(GD_TrimPieceRBezCurve *left,
178  float ucut, float tol = 1E-4F) const;
179 
180 };
181 
182 
184 {
185 public:
187  // Deletes self and all siblings.
188  ~GD_TrimPiecePoly() override;
189 
190  int64 getMemoryUsage(bool inclusive) const override
191  {
192  int64 mem = inclusive ? sizeof(*this) : 0;
193  mem += GD_TrimPiece::getMemoryUsage(false);
194  mem += myCurve.getMemoryUsage(false);
195  return mem;
196  }
197 
198  // Copies this piece, does not copy siblings.
199  GD_TrimPiece *copy() override;
200 
201  // Remove a piece from this curve
202  GD_TrimPiece *cut(float u1, float u2) const override;
203 
204  // Intersects with another piece, adding all intersections blindly
205  // to the refarray (Caller should remove any duplicates)
206  int intersect(GD_TrimPiece &curve,
207  UT_Array<GD_TrimHitInfo> &hitlist,
208  float tol = 0.0001F) override;
209 
210  // Intersects with an isoparm.
211  int intersectIsoparm(float val, int isoparm,
212  UT_Array<GD_TrimHitInfo> &hitlist,
213  float tol = 1E-4F, int depth = 4) override;
214 
215  // Req's u to be in [0,1] parameterization.
216  int evaluateUnit(float u, UT_Vector2 &pos) const override;
217  int evaluateUnit(float u,
218  UT_Vector2 &pos,
219  UT_Vector2 &der,
220  UT_Vector2 &der2) const override;
221 
222  GD_Face *createFace(GD_Detail *gdp) override;
223 
224  // Find what type this piece is.
225  unsigned getPrimitiveTypeId() const override { return GD_PRIMPOLY; }
226 
227  void buildCurve(int idx);
228  void appendPoint(float x, float y);
229 public:
231 };
232 
233 #endif
virtual int evaluateUnit(float u, UT_Vector2 &pos) const =0
GLuint GLdouble u1
Definition: glew.h:3446
GLint left
Definition: glew.h:8008
GLuint const GLfloat * val
Definition: glew.h:2794
void reverse(I begin, I end)
Definition: pugixml.cpp:7190
virtual GD_TrimPiece * cut(float u1, float u2) const =0
int64 getMemoryUsage(bool inclusive) const override
Definition: GD_TrimPiece.h:190
GLuint GLdouble GLdouble GLint GLint order
Definition: glew.h:3446
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)
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
virtual GD_Face * createFace(GD_Detail *gdp)=0
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
unsigned getPrimitiveTypeId() const override
Definition: GD_TrimPiece.h:225
long long int64
Definition: SYS_Types.h:116
virtual int intersectIsoparm(float val, int isoparm, UT_Array< GD_TrimHitInfo > &hitlist, float tol=1E-4F, int depth=4)=0
GLfloat right
Definition: glew.h:15186
unsigned getPrimitiveTypeId() const override
Definition: GD_TrimPiece.h:169
int operator==(const GD_TrimHitInfo &x) const
Definition: GD_TrimPiece.h:33
ImageBuf OIIO_API cut(const ImageBuf &src, ROI roi={}, int nthreads=0)
GD_TrimPieceRBezCurve myCurve
Definition: GD_TrimPiece.h:230
#define GD_API
Definition: GD_API.h:10
UT_MatrixF myYCoeff
Definition: GD_TrimPiece.h:121
OIIO_API bool copy(string_view from, string_view to, std::string &err)
UT_Vector3Array myCV
Definition: GD_TrimPiece.h:116
GD_TrimPiece * myNext
Definition: GD_TrimPiece.h:114
GLuint GLdouble GLdouble u2
Definition: glew.h:3446
UT_BoundingRect myBBox
Definition: GD_TrimPiece.h:117
virtual GD_TrimPiece * copy()=0
GLdouble GLdouble t
Definition: glew.h:1398
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glew.h:1254
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
std::enable_if< internal::is_string< S >::value >::type print(std::basic_ostream< FMT_CHAR(S)> &os, const S &format_str, const Args &...args)
Definition: ostream.h:146