HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_PrimNURBCurve.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_PrimNURBCurve.h (C++)
7  *
8  * COMMENTS:
9  * Header file for GU_PrimNURBCurve.h class...
10  *
11  */
12 
13 #ifndef __GU_PrimNURBCurve_h__
14 #define __GU_PrimNURBCurve_h__
15 
16 #include "GU_API.h"
17 #include <GA/GA_NUBBasis.h>
18 #include <GEO/GEO_PrimNURBCurve.h>
19 #include <UT/UT_Matrix.h>
20 
22 template<bool isconst> class GA_PwHandle;
24 class GEO_ConvertParms;
25 class GU_Detail;
26 class GU_PrimPoly;
27 class GU_PrimRBezCurve;
28 class UT_MemoryCounter;
29 
30 /////////////////////////////////////////////////////////////
31 // //
32 // Class: GU_PrimNURBCurve //
33 // Descr: This class is responsible for operations //
34 // done on nurb primitives. As we need to access //
35 // the GU_Detail, the pointer is passed in the //
36 // constructor. The second constructor creates a //
37 // curve with the given parameters. //
38 // //
39 /////////////////////////////////////////////////////////////
40 
42 {
43 protected:
44  /// NOTE: Primitives should not be deleted directly. They are managed
45  /// by the GA_PrimitiveList and the stash.
46  virtual ~GU_PrimNURBCurve() {}
47 
48 public:
49  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
52  {}
53 
54  /// Report approximate memory usage.
55  virtual int64 getMemoryUsage() const;
56 
57  /// Count memory usage using a UT_MemoryCounter in order to count
58  /// shared memory correctly.
59  /// NOTE: This should always include sizeof(*this).
60  virtual void countMemory(UT_MemoryCounter &counter) const;
61 
62  virtual const GA_PrimitiveDefinition &getTypeDef() const
63  {
64  UT_ASSERT(theDefinition);
65  return *theDefinition;
66  }
67 
68  GU_PrimPoly *makeGrevillePoly(GU_Detail *dest) const;
69 
70  virtual int intersectRay(const UT_Vector3 &o, const UT_Vector3 &d,
71  float tmax = 1E17F, float tol = 1E-12F,
72  float *distance = 0, UT_Vector3 *pos = 0,
73  UT_Vector3 *nml = 0, int accurate = 0,
74  float *u = 0, float *v = 0,
75  int ignoretrim = 1) const;
76 
77  virtual int intersect(const GEO_Primitive &prim,
78  UT_Array<GU_RayInfoHit> &hitList,
79  float tol = 0.01F, int ignoretrim=1) const;
80 
81  // NOTE: For static member functions please call in the following
82  // manner. <ptrvalue> = GU_PrimNURBCurve::<functname>
83  // i.e. meshptr = GU_PrimNURBCurve::build(params...);
84 
85  // Optional Build Method. Returns 0 if it fails.
86 
87  static GU_PrimNURBCurve *build(GU_Detail *gudp, int nelems,
88  int order = 4, int closed = 0,
89  int interpEnds = 1, int appendPoints= 1);
90 
91  virtual GEO_Primitive *convert(GEO_ConvertParms &parms,
92  GA_PointGroup *usedpts = NULL);
93  virtual GEO_Primitive *convertNew(GEO_ConvertParms &parms);
94  GU_PrimRBezCurve *convertToBezNew(GA_ElementWranglerCache &wranglers,
95  GA_PointGroup *delpts=0,
96  GA_PrimitiveGroup *delprims=0);
97 
98  /// Cut a wedge of the primitive given a domain range
99  /// ind1 and ind2 are indices to the refined values
100  /// They are updated if negative on input, else used as is.
101  /// If keep is zero the curve is only refined and the indices
102  /// updated.
103  virtual GEO_Curve *cut(float u1, float u2,
104  int &ind1, int &ind2, int keep);
105 
106  /// Open the primitive at the given domain value
107  virtual void openAt(float u);
108  /// Rotate basis so specified u value becomes first visible u value.
109  virtual void rotateTo(float u);
110 
111  /// This is more powerful than convertNew. It always returns a NEW
112  /// object, so free it when you're done with it. It may return
113  /// a NURB curve or a Bezier curve depending on the type.
114  virtual GEO_Face *reconfigure(unsigned type, int order, bool open,
115  bool interpends, bool nonrational) const;
116 
117  // This version reparametrizes the curve. It does this by implementing
118  // a map of the basis from the source parameter values to the corresponding
119  // dest values. Interpolation is linear, thus new knots are inserted
120  // at each of the specified points. If the map is a uniform map,
121  // no break points are inserted.
122  virtual int matchKnots(const UT_Vector &source,
123  const UT_Vector &dest, float tol = 1e-2F);
124 
125  // Compute the location of the breakpoint. Return 0 if OK, else -1.
126  virtual int evaluateBreakpoint(int uidx, UT_Vector4 &pos,
127  int du=0) const;
128 
129  // Given a bit array representing the edges in the curve (1 meaning
130  // delete and 0 meaning keep) delete as many edges as possible
131  // if a particular edge cannot be deleted then negate the value
132  // in removededges[edgenum] DO NOT CHANGE THE MAGNITUDE!
133  // returns 0 if successful, -1 if the curve becomes degenerate, and
134  // -2 if the poly should be removed.
135  int removeEdges(const UT_BitArray &edgemap,
136  UT_IntArray &removededges);
137 
138  // Remove the interior knot at knotIdx num times if possible,
139  // where 1 <= num <= the multiplicity mult of the knot,
140  // and U[knotIdx] != U[knotIdx+1].
141  // If multiplicity mult is not given, the procedure will compute it.
142  // The tol specifies the tolerance of distance between the knot removable
143  // position and its actual position. To force knot removal, set tol = -1.0F.
144  // The deleteGroup is used to gather unused cv geo points to be deleted.
145  // (It is more efficient to delete points in a group.)
146  // The uniqueInteriorCvs flag indicates whether the interior cvs need to be
147  // uniqued before removing knots. This is because during the process of
148  // knot removal, interior cvs may changed and/or got removed.
149  // Output: the actual number of times that the knot got removed.
150  int removeKnot(int knotIdx, int num, int mult=0,
151  float tol=1e-4F,GA_PointGroup *delGroup=0,
152  int uniqueInteriorCvs=0);
153 
154  // Perform data reduction by removing possible knots (and cvs) while
155  // maintaining the errors between all the data points and the actual
156  // points on the curve corresponding to the parm to be within the tolerance
157  // tol. If num is specified, the procedure will remove at least that number
158  // of knots even when removing them may result in error > tol.
159  // The error[k] is the current error between data point corresponding
160  // to parm[k]. The parm list has to be in non-decreasing order.
161  // The deleteGroup is used to gather unused cv geo points to be deleted.
162  // Output: update the error vector, and reduce knots and cvs.
163  void reduceKnots(const UT_Vector &parm, UT_Vector &error,
164  float tol=1e-1F, int num=0,
165  GA_PointGroup *deleteGroup=0);
166 
167  // Methods for fitting.
168  // Interpolate a set of data points.
169  // Return 0 if resulted in singular matrix (ie. can not solve).
170  // 1 if ok.
171  int interpGlobal(const GA_Range &point_range,
172  int order=4, int wrapped=0,
175  const UT_Vector *parmValues = 0);
176  int interpGlobal(const UT_Vector4Array &v4Data,
177  int order=4, int wrapped=0,
180  const UT_Vector *parmValues = 0);
181 
182  int interpGlobal(const UT_MatrixF &pointData,
183  const UT_MatrixF &derivData, int order=4,
184  int wrapped = 0,
187  int interpGlobal(const UT_MatrixF &pointData,
188  const UT_MatrixF &derivData,
189  const UT_MatrixF &deriv2Data, int order=6,
190  int wrapped = 0,
193 
194  void interpLocal(const UT_Array<GA_Offset> &gpData,
195  int order=4, int wrapped=0, int corner=0);
196  void interpLocal(const UT_Vector4Array &v4Data,
197  int order=4, int wrapped=0, int corner=0);
198 
199  // Fit through the breakpoints:
200  int interpBreakpoints(
201  const GA_OffsetList &point_offsets,
202  int order=4, int wrapped=0,
204  const UT_Vector *parmValues = 0);
205  int interpBreakpoints(
206  const UT_Vector4Array &v4Data,
207  int order=4, int wrapped=0,
209  const UT_Vector *parmValues = 0);
210 
211  // This approxmation is mainly for open curve.
212  // For closed curve, it may not behave well on the closed segment.
213  // However, you can improve its behaviour by duplicating the first
214  // data point and put it at the end.
215  void approxGlobal(const UT_Vector4Array &v4Data,
216  int order=4, int wrapped=0,
217  float tol=1e-1f, float smooth=0.0F,
218  int noMultipleKnots=1);
219 
220  // Static methods for fitting.
221 
222  // Global curve interpolation through dataPts[0..n][0..Dimension-1]
223  // with parameterization param[0..n] and basis should have its knot
224  // vector and order already set up.
225  // Output: cvs[0..n][0..Dimension-1]
226  // If natural_end is set it means that we are computing the 2nd derivative
227  // at the ends.
228  static int interpGlobal(const UT_MatrixF &dataPts,
229  const UT_Vector &param,
230  const GA_NUBBasis &basis,
231  UT_MatrixF &cvs, int natural_end = 0);
232  // Takes points and/or derivatives in dataPts[0..n][0..Dimension-1]
233  // with parameterization param[0..n] and corresponding derivatives
234  // dervs[0..n]. Basis should have its knot vector and order already
235  // set up.
236  static int interpGlobal(const UT_MatrixF &dataPts,
237  const UT_Vector &param,
238  const GA_NUBBasis &basis,
239  UT_MatrixF &cvs,
240  const UT_IntArray &dervs);
241  // Takes derivitives at each point. CV matrix should be
242  // cvs[0..2n+1][0..Dimmension-1]
243  static int interpGlobal(const UT_MatrixF &dataPts,
244  const UT_MatrixF &dataTans,
245  const UT_Vector &param,
246  const GA_NUBBasis &basis,
247  UT_MatrixF &cvs);
248  // Takes derivitives at each point. CV matrix should be
249  // cvs[0..3n+2][0..Dimmension-1]
250  static int interpGlobal(const UT_MatrixF &dataPts,
251  const UT_MatrixF &dataTans,
252  const UT_MatrixF &dataCurvature,
253  const UT_Vector &param,
254  const GA_NUBBasis &basis,
255  UT_MatrixF &cvs);
256 
257  // Get the bounding box for a specific range
258  virtual void getRangeBBox(const UT_Interval &u,
259  UT_BoundingBox &bbox,
260  const GA_PwHandleRO &h) const;
261 
262 private:
263  // Private methods to translate/transform selected breakpoints and
264  // interpolate through them.
265  virtual int translateBkptsFixed(const UT_IntArray &uindices,
266  const UT_Vector3 &delta,
267  GA_PointGroup *ptgroup = NULL,
268  GEO_Delta *geodelta = 0);
269  virtual int transformBkptsFixed(const UT_IntArray &uindices,
270  const UT_Matrix4 &matx,
271  GA_PointGroup *ptgroup = NULL,
272  GEO_Delta *geodelta = 0);
273 
274  // Fill the curve with data and build the basis. Return 0 if OK, and -1
275  // if error.
276  int create(int nelems, int order=4, int closed = 0,
277  int interpEnds = 1, int appendPoints = 1);
278 
279  // Use for approximation.
280  void fit(const UT_Vector4Array &v4Data,
281  UT_Vector *data, int curOrd, int prevEnd,
282  int cvEnd, UT_Vector *coord, UT_Vector &param,
283  UT_Vector &error, float smooth);
284 
285  static GA_PrimitiveDefinition *theDefinition;
286  friend class GU_PrimitiveFactory;
287 };
288 
289 #endif
const GLdouble * v
Definition: glcorearb.h:836
virtual int intersect(const GEO_Primitive &prim, UT_Array< GU_RayInfoHit > &hitList, float tol=0.01F, int ignoretrim=1) const =0
virtual GEO_Curve * cut(float u1, float u2, int &ind1, int &ind2, int keep)=0
3D Vector class.
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:204
#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);
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_ParameterizationType
Definition: GA_Types.h:173
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
GLfloat f
Definition: glcorearb.h:1925
virtual ~GU_PrimNURBCurve()
#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
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
GLintptr offset
Definition: glcorearb.h:664
NURBS basis classes which maintain knot vectors.
Definition: GA_NUBBasis.h:44
virtual int translateBkptsFixed(const UT_IntArray &uindices, const UT_Vector3 &delta, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)
#define GU_API
Definition: GU_API.h:11
GLboolean * data
Definition: glcorearb.h:130
virtual GEO_Face * reconfigure(unsigned type, int order, bool open, bool interpends, bool nonrational) const =0
virtual int open(float queuesize)
virtual int transformBkptsFixed(const UT_IntArray &uindices, const UT_Matrix4 &matx, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)
virtual void openAt(float u)=0
Open the primitive at the given domain value.
virtual void getRangeBBox(const UT_Interval &u, UT_BoundingBox &bbox, const GA_PwHandleRO &h) const =0
virtual int evaluateBreakpoint(int uidx, UT_Vector4 &pos, int du=0) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GLenum GLfloat param
Definition: glcorearb.h:103
virtual bool smooth(GA_AttributeOperand &d, GA_AttributeOperand &min, GA_AttributeOperand &max, GA_AttributeOperand &t) const
d = SYSsmooth(min, max, t);
GA_PwHandle< true > GA_PwHandleRO
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
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Container class for all geometry.
Definition: GA_Detail.h:96
png_infop png_uint_32 int num
Definition: png.h:2158
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
Definition of a geometric primitive.
GU_PrimNURBCurve(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 const GA_PrimitiveDefinition & getTypeDef() const
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
int keep
Definition: png.h:2568