HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GU_PrimNURBSurf() {}
50 
51 public:
52  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
54  : GEO_PrimNURBSurf(gdp, offset)
55  {}
56 
57  virtual const GA_PrimitiveDefinition &getTypeDef() const
58  {
59  UT_ASSERT(theDefinition);
60  return *theDefinition;
61  }
62 
63  /// Report approximate memory usage.
64  virtual int64 getMemoryUsage() const;
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  virtual void countMemory(UT_MemoryCounter &counter) const;
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 
78  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
79  GA_PointGroup *usedpts = NULL);
80  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
81 
82  virtual 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;
88 
89  virtual 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);
95  virtual int doesIntersect(const GEO_Primitive &prim,
96  float worldtol = 1e-4F, int nontrivial = 0) const;
97 
98  /// This is more powerful than convertNew. It always returns a NEW
99  /// object, so free it when you're done with it. It may return
100  /// a NURB surface or a Bezier surface depending on the type.
101  virtual GEO_Hull *reconfigure(unsigned type, int orderu, int orderv,
102  bool openu, bool openv,
103  bool endsu, bool endsv) const;
104 
105  /// Cut a wedge of the primitive given a domain range
106  /// ind1 and ind2 are indices to the refined values
107  /// They are updated if negative on input, else used as is.
108  /// If keep is zero the curve is only refined and the indices
109  /// updated.
110 
111  virtual GEO_TPSurf *cutU(float u1, float u2,
112  int &ind1, int &ind2, int keep);
113 
114  virtual GEO_TPSurf *cutV(float v1, float v2,
115  int &ind1, int &ind2, int keep);
116 
117 
118  /// Open the primitive at the given domain value
119  virtual void openAtU(float u);
120  virtual void openAtV(float v);
121 
122  /// Construct a curve that has our characteristics in u or v. The
123  /// CVs of the new curve are not set.
124  /// @{
125  virtual GEO_Curve *buildRowCurve(bool appendPoints,
126  GEO_Detail *parent) const;
127  virtual GEO_Curve *buildColCurve(bool appendPoints,
128  GEO_Detail *parent) const;
129  /// @}
130 
131  static GU_PrimNURBSurf *build(GEO_Detail *gudp,
132  int rows, int cols,
133  int orderu = 4, int orderv = 4,
134  int wrapu = 0, int wrapv = 0,
135  int interpEndsU= 1, int interpEndsV= 1,
137  int appendPoints = 1);
138 
139  /// Remove as many of the given edges of possible from this poly.
140  /// If edge #a is removed, bit a in the bit array is set to a & 1.
141  /// returns 0 if successful, -1 if the poly becomes degenerate, and
142  /// -2 if the poly should be removed.
143  int removeEdges(const GA_EdgeGroup &edges,
144  UT_BitArray *remove_edges=0);
145 
146  /// Remove the interior knot at knotIdx once if possible,
147  /// where mult is the multiplicity of the knot,
148  /// and U/V[knotIdx] != U/V[knotIdx+1].
149  /// If multiplicity mult is not given, the procedure will compute it.
150  /// The tol specifies the tolerance of distance between the knot removable
151  /// position and its actual position. To force knot removal, set tol = -1.0F.
152  /// The deleteGroup is used to gather unused cv geo points to be deleted.
153  /// (It is more efficient to delete points in a group.)
154  /// The uniqueInteriorCvs flag indicates whether the interior cvs need to be
155  /// uniqued before removing knots. This is because during the process of
156  /// knot removal, interior cvs may changed and/or got removed.
157  /// Output: 1 if the knot got removed, else 0.
158  int removeKnot(int uDir, int knotIdx, int mult=0,
159  float tol=1e-4F,
160  GA_PointGroup *deleteGroup=0,
161  int uniqueInteriorCvs=0);
162 
163  /// Perform data reduction by removing possible knots (and cvs) while
164  /// maintaining the errors between all the data points and the actual
165  /// points on the surface corresponding to the parm to be within the
166  /// tolerance tol. If u/vNum is specified, the procedure will remove
167  /// at least that number of knots in their corresponding parameters even
168  /// when removing them may result in error > tol.
169  /// The error(i,j) is the current error between data point corresponding
170  /// to uParm(i) and vParm(j). The parameter lists have to be in
171  /// non-decreasing order.
172  /// The deleteGroup is used to gather unused cv geo points to be deleted.
173  /// Output: update the error matrix, and reduce knots and cvs.
174  void reduceKnots(const UT_Vector &uParm,
175  const UT_Vector &vParm,
176  UT_MatrixF &error, float tol=1e-1F,
177  int uNum=0, int vNum=0,
178  GA_PointGroup *deleteGroup=0);
179 
180  /// Compute the location of the breakpoint. Return 0 if OK, else -1.
181  virtual int evaluateBreakpoint(int uidx, int vidx,
182  UT_Vector4 &pos,
183  int du=0, int dv=0) const;
184 
185  /// Methods for fitting.
186 
187  /// Interpolate the mesh of points.
188  /// Return 0 if ok.
189  /// 1 if the data resulted in a singular matrix.
190  /// 2 if interrupted.
191  int interpGlobal(const GA_OffsetMatrix &goMesh,
192  int uOrder=4, int vOrder=4,
193  bool uWrapped=false, bool vWrapped=false,
199  const UT_Vector *uParmValues = 0,
200  const UT_Vector *vParmValues = 0);
201 
202  /// Same as global interpolation, but fits to break points.
203  /// If not open or at least order four, reverts to interpGlobal.
204  int interpBreakpoints(
205  const GA_OffsetMatrix &goMesh,
206  int uOrder=4, int vOrder=4,
207  bool uWrapped=false, bool vWrapped=false,
213  const UT_Vector *uParmValues = 0,
214  const UT_Vector *vParmValues = 0);
215 
216  /// Approximate the set of data points given a tolerance.
217  /// uNoMultipleKNots and vNoMultipleKnots specify that no multiple knots is
218  /// allowed in u and v parameteric direction respectively.
219  ///
220  /// This approxmation is mainly for unwrapped surface.
221  /// For wrapped curve, it may not behave well on the wrapped patch.
222  /// However, you can improve its behaviour by duplicating the first
223  /// row/col data points and put it at the end.
224  void approxGlobal(const GA_OffsetMatrix &gpMesh,
225  int uOrder, int vOrder,
226  int uWrapped, int vWrapped,
228  float tol, float smooth=0.0F,
229  int uNoMultipleKnots=1, int vNoMultipleKnots=1);
230 
231 
232  /// Get the bounding box for a specific range of u and v
233  virtual void getRangeBBox(const UT_Interval &u,
234  const UT_Interval &v,
235  UT_BoundingBox &bbox,
236  const GA_PwHandleRO &h) const;
237 
238 protected:
239  virtual GEO_Hull *getSubHull(int top, int left, int bottom, int right,
240  GEO_SubHullFlags break_flags);
241 
242 private:
243  // Private methods to translate/transform selected breakpoints and
244  // perform an interpolation.
245  virtual int translateBkptsFixed(const UT_IntArray &uindices,
246  const UT_IntArray &vindices,
247  const UT_Vector3 &delta,
248  GA_PointGroup *ptgroup=NULL,
249  GEO_Delta *geodelta = 0);
250  virtual int transformBkptsFixed(const UT_IntArray &uindices,
251  const UT_IntArray &vindices,
252  const UT_Matrix4 &matx,
253  GA_PointGroup *ptgroup=NULL,
254  GEO_Delta *geodelta = 0);
255 
256  // Helper functions for approximation.
257 
258  void fit(const GA_OffsetMatrix &gpMesh,
259  UT_Vector *data[3], UT_Vector *vData,
260  int prevUEnd, int cvUEnd,
261  int prevVEnd, int cvVEnd,
262  UT_Vector &uSol, UT_Vector &vSol,
263  UT_Vector &uParm, UT_Vector &vParm,
264  UT_MatrixF &error, float smooth);
265 
266  void makeSafeDegreeEvaluateNoMult(int uDir, int m, int n,
267  const UT_Vector &uParm, const UT_Vector &vParm,
268  UT_MatrixF &error, float tol,
269  GA_PointGroup *deleteGroup,
270  int &cvUEnd, int &cvVEnd);
271 
272  void makeSafeDegreeEvaluateWMult(int uDir, int m, int n,
273  const UT_Vector &uParm, const UT_Vector &vParm,
274  UT_MatrixF &error, float tol,
275  GA_PointGroup *deleteGroup,
276  int &cvUEnd, int &cvVEnd, int &breakCount);
277 
278  void degreeEvaluateNoMult(GA_NUBBasis *basis,
279  GA_KnotVector &knots,
280  GA_KnotVector &tmpKnots);
281 
282  void degreeEvaluateWMult(GA_NUBBasis *basis,
283  GA_KnotVector &knots,
284  GA_KnotVector &tmpKnots,
285  int breakCount);
286 
287  // Fill the surface with data and build the bases. Return 0 if OK, and -1
288  // if error.
289  int create(int rows, int cols, int orderu=4, int orderv=4,
290  int wrapu = 0, int wrapv = 0,
291  int interpEndsU = 1, int interpEndsV = 1,
293  int appendPoints = 1);
294 
295  static GA_PrimitiveDefinition *theDefinition;
296  friend class GU_PrimitiveFactory;
297 };
298 
299 #endif
virtual GEO_Hull * reconfigure(unsigned type, int orderu, int orderv, bool openu, bool openv, bool endsu, bool endsv) const =0
GLint left
Definition: glcorearb.h:2004
const GLdouble * v
Definition: glcorearb.h:836
virtual void openAtU(float u)=0
Open the primitive at the given domain value.
virtual int evaluateBreakpoint(int uidx, int vidx, UT_Vector4 &pos, int du=0, int dv=0) const
virtual const GA_PrimitiveDefinition & getTypeDef() const
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
3D Vector class.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:204
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:654
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:173
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:100
GLdouble n
Definition: glcorearb.h:2007
virtual void getRangeBBox(const UT_Interval &u, const UT_Interval &v, UT_BoundingBox &bbox, const GA_PwHandleRO &h) const =0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
virtual void countMemory(UT_MemoryCounter &counter) const
virtual ~GU_PrimNURBSurf()
GLintptr offset
Definition: glcorearb.h:664
virtual GEO_Curve * buildRowCurve(bool appendPoints, GEO_Detail *parent) const =0
NURBS basis classes which maintain knot vectors.
Definition: GA_NUBBasis.h:44
#define GU_API
Definition: GU_API.h:11
GLboolean * data
Definition: glcorearb.h:130
virtual GEO_TPSurf * cutV(float v1, float v2, int &ind1, int &ind2, int keep)=0
GLint GLint bottom
Definition: glcorearb.h:2004
virtual GEO_TPSurf * cutU(float u1, float u2, int &ind1, int &ind2, int keep)=0
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
virtual bool smooth(GA_AttributeOperand &d, GA_AttributeOperand &min, GA_AttributeOperand &max, GA_AttributeOperand &t) const
d = SYSsmooth(min, max, t);
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)
GLfloat GLfloat v1
Definition: glcorearb.h:816
virtual GEO_Hull * getSubHull(int top, int left, int bottom, int right, GEO_SubHullFlags break_flags)=0
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GEO_SurfaceType
Container class for all geometry.
Definition: GA_Detail.h:96
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
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:166
virtual GEO_Curve * buildColCurve(bool appendPoints, GEO_Detail *parent) const =0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
GA_PwHandle< true > GA_PwHandleRO
int keep
Definition: png.h:2568
virtual int transformBkptsFixed(const UT_IntArray &uindices, const UT_IntArray &vindices, const UT_Matrix4 &matx, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)