HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_PrimNURBSurf.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_PrimNURBSurf.h (C++)
7  *
8  * COMMENTS:
9  * Header file for GU_PrimNURBSurf.h class...
10  *
11  */
12 
13 #ifndef __GU_PrimNURBSurf_h__
14 #define __GU_PrimNURBSurf_h__
15 
16 #include "GU_API.h"
17 #include <GEO/GEO_PrimNURBSurf.h>
18 #include <GEO/GEO_PrimRBezSurf.h>
19 #include <GA/GA_NUBBasis.h>
20 #include <UT/UT_IntArray.h>
21 #include <UT/UT_PtrMatrix.h>
22 #include <UT/UT_Matrix.h>
23 
24 class GA_EdgeGroup;
26 template<bool isconst> class GA_PwHandle;
28 class GEO_ConvertParms;
29 class GEO_Detail;
30 class GU_PrimRBezSurf;
31 class UT_MemoryCounter;
32 
33 //////////////////////////////////////////////////////////////
34 /// //
35 /// Class: GU_PrimNURBSurf //
36 /// Descr: This class is responsible for operations //
37 /// done on nurb primitives. As we need to access //
38 /// the GEO_Detail, the pointer is passed in the //
39 /// constructor. The second constructor creates a //
40 /// mesh with the given parameters. //
41 /// //
42 //////////////////////////////////////////////////////////////
43 
45 {
46 protected:
47  /// NOTE: Primitives should not be deleted directly. They are managed
48  /// by the GA_PrimitiveList and the stash.
49  ~GU_PrimNURBSurf() override {}
50 
51 public:
52  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
54  : GEO_PrimNURBSurf(gdp, offset)
55  {}
56 
57  const GA_PrimitiveDefinition &getTypeDef() const override
58  {
59  UT_ASSERT(theDefinition);
60  return *theDefinition;
61  }
62 
63  /// Report approximate memory usage.
64  int64 getMemoryUsage() const override;
65 
66  /// Count memory usage using a UT_MemoryCounter in order to count
67  /// shared memory correctly.
68  /// NOTE: This should always include sizeof(*this).
69  void countMemory(UT_MemoryCounter &counter) const override;
70 
71  /// Conversion Method
72 
73  /// uses 'this' for surfacetype, primattribs, orderu and orderv.
74  GU_PrimRBezSurf *convertToBezNew(GA_ElementWranglerCache &wranglers,
75  GA_PointGroup *delpoints=0,
76  GA_PrimitiveGroup *delprim=0);
77 
79  GA_PointGroup *usedpts = NULL) override;
80  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
81 
82  int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d,
83  float tmax = 1E17F, float tol = 1E-12F,
84  float *distance = 0, UT_Vector3 *pos = 0,
85  UT_Vector3 *nml = 0, int accurate = 0,
86  float *u = 0, float *v = 0,
87  int ignoretrim = 1) const override;
88 
89  int intersectSurf(GEO_TPSurf &surf2,
90  GU_IsectCurveSet &curveset,
91  float worldtol = 1e-4F,
92  float domaintol = 1e-2F,
93  int steps = 100,
94  bool docompact = true) override;
95  int doesIntersect(const GEO_Primitive &prim,
96  float worldtol = 1e-4F,
97  int nontrivial = 0) const override;
98 
99  /// This is more powerful than convertNew. It always returns a NEW
100  /// object, so free it when you're done with it. It may return
101  /// a NURB surface or a Bezier surface depending on the type.
102  GEO_Hull *reconfigure(unsigned type, int orderu, int orderv,
103  bool openu, bool openv,
104  bool endsu, bool endsv) const override;
105 
106  /// Cut a wedge of the primitive given a domain range
107  /// ind1 and ind2 are indices to the refined values
108  /// They are updated if negative on input, else used as is.
109  /// If keep is zero the curve is only refined and the indices
110  /// updated.
111 
112  GEO_TPSurf *cutU(float u1, float u2,
113  int &ind1, int &ind2, int keep) override;
114 
115  GEO_TPSurf *cutV(float v1, float v2,
116  int &ind1, int &ind2, int keep) override;
117 
118 
119  /// Open the primitive at the given domain value
120  void openAtU(float u) override;
121  void openAtV(float v) override;
122 
123  /// Construct a curve that has our characteristics in u or v. The
124  /// CVs of the new curve are not set.
125  /// @{
126  GEO_Curve *buildRowCurve(bool appendPoints,
127  GEO_Detail *parent) const override;
128  GEO_Curve *buildColCurve(bool appendPoints,
129  GEO_Detail *parent) const override;
130  /// @}
131 
132  static GU_PrimNURBSurf *build(GEO_Detail *gudp,
133  int rows, int cols,
134  int orderu = 4, int orderv = 4,
135  int wrapu = 0, int wrapv = 0,
136  int interpEndsU= 1, int interpEndsV= 1,
138  int appendPoints = 1);
139 
140  /// Remove as many of the given edges of possible from this poly.
141  /// If edge #a is removed, bit a in the bit array is set to a & 1.
142  /// returns 0 if successful, -1 if the poly becomes degenerate, and
143  /// -2 if the poly should be removed.
144  int removeEdges(const GA_EdgeGroup &edges,
145  UT_BitArray *remove_edges=0);
146 
147  /// Remove the interior knot at knotIdx once if possible,
148  /// where mult is the multiplicity of the knot,
149  /// and U/V[knotIdx] != U/V[knotIdx+1].
150  /// If multiplicity mult is not given, the procedure will compute it.
151  /// The tol specifies the tolerance of distance between the knot removable
152  /// position and its actual position. To force knot removal, set tol = -1.0F.
153  /// The deleteGroup is used to gather unused cv geo points to be deleted.
154  /// (It is more efficient to delete points in a group.)
155  /// The uniqueInteriorCvs flag indicates whether the interior cvs need to be
156  /// uniqued before removing knots. This is because during the process of
157  /// knot removal, interior cvs may changed and/or got removed.
158  /// Output: 1 if the knot got removed, else 0.
159  int removeKnot(int uDir, int knotIdx, int mult=0,
160  float tol=1e-4F,
161  GA_PointGroup *deleteGroup=0,
162  int uniqueInteriorCvs=0);
163 
164  /// Perform data reduction by removing possible knots (and cvs) while
165  /// maintaining the errors between all the data points and the actual
166  /// points on the surface corresponding to the parm to be within the
167  /// tolerance tol. If u/vNum is specified, the procedure will remove
168  /// at least that number of knots in their corresponding parameters even
169  /// when removing them may result in error > tol.
170  /// The error(i,j) is the current error between data point corresponding
171  /// to uParm(i) and vParm(j). The parameter lists have to be in
172  /// non-decreasing order.
173  /// The deleteGroup is used to gather unused cv geo points to be deleted.
174  /// Output: update the error matrix, and reduce knots and cvs.
175  void reduceKnots(const UT_Vector &uParm,
176  const UT_Vector &vParm,
177  UT_MatrixF &error, float tol=1e-1F,
178  int uNum=0, int vNum=0,
179  GA_PointGroup *deleteGroup=0);
180 
181  /// Compute the location of the breakpoint. Return 0 if OK, else -1.
182  int evaluateBreakpoint(int uidx, int vidx,
183  UT_Vector4 &pos,
184  int du=0, int dv=0) const override;
185 
186  /// Methods for fitting.
187 
188  /// Interpolate the mesh of points.
189  /// Return 0 if ok.
190  /// 1 if the data resulted in a singular matrix.
191  /// 2 if interrupted.
192  int interpGlobal(const GA_OffsetMatrix &goMesh,
193  int uOrder=4, int vOrder=4,
194  bool uWrapped=false, bool vWrapped=false,
200  const UT_Vector *uParmValues = 0,
201  const UT_Vector *vParmValues = 0);
202 
203  /// Same as global interpolation, but fits to break points.
204  /// If not open or at least order four, reverts to interpGlobal.
205  int interpBreakpoints(
206  const GA_OffsetMatrix &goMesh,
207  int uOrder=4, int vOrder=4,
208  bool uWrapped=false, bool vWrapped=false,
214  const UT_Vector *uParmValues = 0,
215  const UT_Vector *vParmValues = 0);
216 
217  /// Approximate the set of data points given a tolerance.
218  /// uNoMultipleKNots and vNoMultipleKnots specify that no multiple knots is
219  /// allowed in u and v parameteric direction respectively.
220  ///
221  /// This approxmation is mainly for unwrapped surface.
222  /// For wrapped curve, it may not behave well on the wrapped patch.
223  /// However, you can improve its behaviour by duplicating the first
224  /// row/col data points and put it at the end.
225  void approxGlobal(const GA_OffsetMatrix &gpMesh,
226  int uOrder, int vOrder,
227  int uWrapped, int vWrapped,
229  float tol, float smooth=0.0F,
230  int uNoMultipleKnots=1, int vNoMultipleKnots=1);
231 
232 
233  /// Get the bounding box for a specific range of u and v
234  void getRangeBBox(const UT_Interval &u,
235  const UT_Interval &v,
236  UT_BoundingBox &bbox,
237  const GA_PwHandleRO &h) const override;
238 
239 protected:
240  GEO_Hull *getSubHull(int top, int left, int bottom, int right,
241  GEO_SubHullFlags break_flags) override;
242 
243 private:
244  // Private methods to translate/transform selected breakpoints and
245  // perform an interpolation.
246  int translateBkptsFixed(const UT_IntArray &uindices,
247  const UT_IntArray &vindices,
248  const UT_Vector3 &delta,
249  GA_PointGroup *ptgroup=NULL,
250  GEO_Delta *geodelta = 0) override;
251  int transformBkptsFixed(const UT_IntArray &uindices,
252  const UT_IntArray &vindices,
253  const UT_Matrix4 &matx,
254  GA_PointGroup *ptgroup=NULL,
255  GEO_Delta *geodelta = 0) override;
256 
257  // Helper functions for approximation.
258 
259  void fit(const GA_OffsetMatrix &gpMesh,
260  UT_Vector *data[3], UT_Vector *vData,
261  int prevUEnd, int cvUEnd,
262  int prevVEnd, int cvVEnd,
263  UT_Vector &uSol, UT_Vector &vSol,
264  UT_Vector &uParm, UT_Vector &vParm,
265  UT_MatrixF &error, float smooth);
266 
267  void makeSafeDegreeEvaluateNoMult(int uDir, int m, int n,
268  const UT_Vector &uParm, const UT_Vector &vParm,
269  UT_MatrixF &error, float tol,
270  GA_PointGroup *deleteGroup,
271  int &cvUEnd, int &cvVEnd);
272 
273  void makeSafeDegreeEvaluateWMult(int uDir, int m, int n,
274  const UT_Vector &uParm, const UT_Vector &vParm,
275  UT_MatrixF &error, float tol,
276  GA_PointGroup *deleteGroup,
277  int &cvUEnd, int &cvVEnd, int &breakCount);
278 
279  void degreeEvaluateNoMult(GA_NUBBasis *basis,
280  GA_KnotVector &knots,
281  GA_KnotVector &tmpKnots);
282 
283  void degreeEvaluateWMult(GA_NUBBasis *basis,
284  GA_KnotVector &knots,
285  GA_KnotVector &tmpKnots,
286  int breakCount);
287 
288  // Fill the surface with data and build the bases. Return 0 if OK, and -1
289  // if error.
290  int create(int rows, int cols, int orderu=4, int orderv=4,
291  int wrapu = 0, int wrapv = 0,
292  int interpEndsU = 1, int interpEndsV = 1,
294  int appendPoints = 1);
295 
296  static GA_PrimitiveDefinition *theDefinition;
297  friend class GU_PrimitiveFactory;
298 };
299 
300 #endif
virtual GEO_Hull * reconfigure(unsigned type, int orderu, int orderv, bool openu, bool openv, bool endsu, bool endsv) const =0
GLuint GLdouble u1
Definition: glew.h:3446
GLint left
Definition: glew.h:8008
virtual void openAtU(float u)=0
Open the primitive at the given domain value.
const GA_PrimitiveDefinition & getTypeDef() const override
const GLdouble * m
Definition: glew.h:9124
const GLdouble * v
Definition: glew.h:1391
4D Vector class.
Definition: UT_Vector4.h:166
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
virtual int intersectSurf(GEO_TPSurf &surf2, GU_IsectCurveSet &curveset, float worldtol=1e-4F, float domaintol=1e-2F, int steps=100, bool docompact=true)=0
virtual int doesIntersect(const GEO_Primitive &prim, float worldtol=1e-4F, int nontrivial=0) const =0
virtual void openAtV(float v)=0
#define GA_INVALID_OFFSET
Definition: GA_Types.h:676
int evaluateBreakpoint(int uidx, int vidx, UT_Vector4 &pos, int du=0, int dv=0) const override
virtual bool fit(GA_AttributeOperand &d, GA_AttributeOperand &a, GA_AttributeOperand &omin, GA_AttributeOperand &omax, GA_AttributeOperand &nmin, GA_AttributeOperand &nmax) const
d = SYSfit(a, omin, omax, nmin, nmax);
GA_ParameterizationType
Definition: GA_Types.h:195
GA_Size GA_Offset
Definition: GA_Types.h:639
GLint GLint bottom
Definition: glew.h:8008
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
virtual void getRangeBBox(const UT_Interval &u, const UT_Interval &v, UT_BoundingBox &bbox, const GA_PwHandleRO &h) const =0
virtual void countMemory(UT_MemoryCounter &counter) const
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GLfloat GLfloat GLfloat top
Definition: glew.h:15186
virtual GEO_Curve * buildRowCurve(bool appendPoints, GEO_Detail *parent) const =0
GLsizei n
Definition: glew.h:4040
GLsizei GLsizei GLfloat distance
Definition: glew.h:13640
NURBS basis classes which maintain knot vectors.
Definition: GA_NUBBasis.h:44
long long int64
Definition: SYS_Types.h:116
#define GU_API
Definition: GU_API.h:14
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
GLfloat right
Definition: glew.h:15186
virtual GEO_TPSurf * cutV(float v1, float v2, int &ind1, int &ind2, int keep)=0
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
virtual GEO_TPSurf * cutU(float u1, float u2, int &ind1, int &ind2, int keep)=0
virtual bool smooth(GA_AttributeOperand &d, GA_AttributeOperand &min, GA_AttributeOperand &max, GA_AttributeOperand &t) const
d = SYSsmooth(min, max, t);
GLuint counter
Definition: glew.h:2740
virtual int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d, float tmax=1E17F, float tol=1E-12F, float *distance=0, UT_Vector3 *pos=0, UT_Vector3 *nml=0, int accurate=0, float *u=0, float *v=0, int ignoretrim=1) const
virtual int translateBkptsFixed(const UT_IntArray &uindices, const UT_IntArray &vindices, const UT_Vector3 &delta, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)
virtual GEO_Hull * getSubHull(int top, int left, int bottom, int right, GEO_SubHullFlags break_flags)=0
GEO_SurfaceType
GLuint GLdouble GLdouble u2
Definition: glew.h:3446
Container class for all geometry.
Definition: GA_Detail.h:95
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
Definition of a geometric primitive.
GU_PrimNURBSurf(GA_Detail *gdp, GA_Offset offset=GA_INVALID_OFFSET)
NOTE: This constructor should only be called via GU_PrimitiveFactory.
GA_KnotSpaceType
Definition: GA_Types.h:188
virtual GEO_Curve * buildColCurve(bool appendPoints, GEO_Detail *parent) const =0
GLfloat GLfloat v1
Definition: glew.h:1852
~GU_PrimNURBSurf() override
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
GA_PwHandle< true > GA_PwHandleRO
GLintptr offset
Definition: glew.h:1682
virtual int transformBkptsFixed(const UT_IntArray &uindices, const UT_IntArray &vindices, const UT_Matrix4 &matx, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)