HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~GU_PrimNURBCurve() override {}
47 
48 public:
49  /// NOTE: This constructor should only be called via GU_PrimitiveFactory.
52  {}
53 
54  /// Report approximate memory usage.
55  int64 getMemoryUsage() const override;
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  void countMemory(UT_MemoryCounter &counter) const override;
61 
62  const GA_PrimitiveDefinition &getTypeDef() const override
63  {
64  UT_ASSERT(theDefinition);
65  return *theDefinition;
66  }
67 
68  GU_PrimPoly *makeGrevillePoly(GU_Detail *dest) const;
69 
70  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 override;
76 
77  int intersect(const GEO_Primitive &prim,
78  UT_Array<GU_RayInfoHit> &hitList,
79  float tol = 0.01F, int ignoretrim=1) const override;
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 
92  GA_PointGroup *usedpts = NULL) override;
93  GEO_Primitive *convertNew(GEO_ConvertParms &parms) override;
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  GEO_Curve *cut(float u1, float u2,
104  int &ind1, int &ind2, int keep) override;
105 
106  /// Open the primitive at the given domain value
107  void openAt(float u) override;
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  GEO_Face *reconfigure(unsigned type, int order, bool open,
115  bool interpends,
116  bool nonrational) const override;
117 
118  // This version reparametrizes the curve. It does this by implementing
119  // a map of the basis from the source parameter values to the corresponding
120  // dest values. Interpolation is linear, thus new knots are inserted
121  // at each of the specified points. If the map is a uniform map,
122  // no break points are inserted.
123  virtual int matchKnots(const UT_Vector &source,
124  const UT_Vector &dest, float tol = 1e-2F);
125 
126  // Compute the location of the breakpoint. Return 0 if OK, else -1.
127  int evaluateBreakpoint(int uidx, UT_Vector4 &pos,
128  int du=0) const override;
129 
130  // Given a bit array representing the edges in the curve (1 meaning
131  // delete and 0 meaning keep) delete as many edges as possible
132  // if a particular edge cannot be deleted then negate the value
133  // in removededges[edgenum] DO NOT CHANGE THE MAGNITUDE!
134  // returns 0 if successful, -1 if the curve becomes degenerate, and
135  // -2 if the poly should be removed.
136  int removeEdges(const UT_BitArray &edgemap,
137  UT_IntArray &removededges);
138 
139  // Remove the interior knot at knotIdx num times if possible,
140  // where 1 <= num <= the multiplicity mult of the knot,
141  // and U[knotIdx] != U[knotIdx+1].
142  // If multiplicity mult is not given, the procedure will compute it.
143  // The tol specifies the tolerance of distance between the knot removable
144  // position and its actual position. To force knot removal, set tol = -1.0F.
145  // The deleteGroup is used to gather unused cv geo points to be deleted.
146  // (It is more efficient to delete points in a group.)
147  // The uniqueInteriorCvs flag indicates whether the interior cvs need to be
148  // uniqued before removing knots. This is because during the process of
149  // knot removal, interior cvs may changed and/or got removed.
150  // Output: the actual number of times that the knot got removed.
151  int removeKnot(int knotIdx, int num, int mult=0,
152  float tol=1e-4F,GA_PointGroup *delGroup=0,
153  int uniqueInteriorCvs=0);
154 
155  // Perform data reduction by removing possible knots (and cvs) while
156  // maintaining the errors between all the data points and the actual
157  // points on the curve corresponding to the parm to be within the tolerance
158  // tol. If num is specified, the procedure will remove at least that number
159  // of knots even when removing them may result in error > tol.
160  // The error[k] is the current error between data point corresponding
161  // to parm[k]. The parm list has to be in non-decreasing order.
162  // The deleteGroup is used to gather unused cv geo points to be deleted.
163  // Output: update the error vector, and reduce knots and cvs.
164  void reduceKnots(const UT_Vector &parm, UT_Vector &error,
165  float tol=1e-1F, int num=0,
166  GA_PointGroup *deleteGroup=0);
167 
168  // Methods for fitting.
169  // Interpolate a set of data points.
170  // Return 0 if resulted in singular matrix (ie. can not solve).
171  // 1 if ok.
172  int interpGlobal(const GA_Range &point_range,
173  int order=4, int wrapped=0,
176  const UT_Vector *parmValues = 0,
177  const bool elevate_order_if_required = true);
178  int interpGlobal(const UT_Vector4Array &v4Data,
179  int order=4, int wrapped=0,
182  const UT_Vector *parmValues = 0,
183  const bool elevate_order_if_required = true);
184 
185  int interpGlobal(const UT_MatrixF &pointData,
186  const UT_MatrixF &derivData, int order=4,
187  int wrapped = 0,
190  const bool elevate_order_if_required = true);
191 
192  int interpGlobal(const UT_MatrixF &pointData,
193  const UT_MatrixF &derivData,
194  const UT_MatrixF &deriv2Data, int order=6,
195  int wrapped = 0,
198  const bool elevate_order_if_required = true);
199 
200  void interpLocal(const UT_Array<GA_Offset> &gpData,
201  int order=4, int wrapped=0, int corner=0);
202  void interpLocal(const UT_Vector4Array &v4Data,
203  int order=4, int wrapped=0, int corner=0);
204 
205  // Fit through the breakpoints:
206  int interpBreakpoints(
207  const GA_OffsetList &point_offsets,
208  int order=4, int wrapped=0,
210  const UT_Vector *parmValues = 0,
211  const bool elevate_order_if_required = true);
212  int interpBreakpoints(
213  const UT_Vector4Array &v4Data,
214  int order=4, int wrapped=0,
216  const UT_Vector *parmValues = 0,
217  const bool elevate_order_if_required = true);
218 
219  // This approxmation is mainly for open curve.
220  // For closed curve, it may not behave well on the closed segment.
221  // However, you can improve its behaviour by duplicating the first
222  // data point and put it at the end.
223  void approxGlobal(const UT_Vector4Array &v4Data,
224  int order=4, int wrapped=0,
225  float tol=1e-1f, float smooth=0.0F,
226  int noMultipleKnots=1);
227 
228  // Static methods for fitting.
229 
230  // Global curve interpolation through dataPts[0..n][0..Dimension-1]
231  // with parameterization param[0..n] and basis should have its knot
232  // vector and order already set up.
233  // Output: cvs[0..n][0..Dimension-1]
234  // If natural_end is set it means that we are computing the 2nd derivative
235  // at the ends.
236  static int interpGlobal(const UT_MatrixF &dataPts,
237  const UT_Vector &param,
238  const GA_NUBBasis &basis,
239  UT_MatrixF &cvs, int natural_end = 0);
240  // Takes points and/or derivatives in dataPts[0..n][0..Dimension-1]
241  // with parameterization param[0..n] and corresponding derivatives
242  // dervs[0..n]. Basis should have its knot vector and order already
243  // set up.
244  static int interpGlobal(const UT_MatrixF &dataPts,
245  const UT_Vector &param,
246  const GA_NUBBasis &basis,
247  UT_MatrixF &cvs,
248  const UT_IntArray &dervs);
249  // Takes derivitives at each point. CV matrix should be
250  // cvs[0..2n+1][0..Dimmension-1]
251  static int interpGlobal(const UT_MatrixF &dataPts,
252  const UT_MatrixF &dataTans,
253  const UT_Vector &param,
254  const GA_NUBBasis &basis,
255  UT_MatrixF &cvs);
256  // Takes derivitives at each point. CV matrix should be
257  // cvs[0..3n+2][0..Dimmension-1]
258  static int interpGlobal(const UT_MatrixF &dataPts,
259  const UT_MatrixF &dataTans,
260  const UT_MatrixF &dataCurvature,
261  const UT_Vector &param,
262  const GA_NUBBasis &basis,
263  UT_MatrixF &cvs);
264 
265  // Get the bounding box for a specific range
266  void getRangeBBox(const UT_Interval &u,
267  UT_BoundingBox &bbox,
268  const GA_PwHandleRO &h) const override;
269 
270 private:
271  // Private methods to translate/transform selected breakpoints and
272  // interpolate through them.
273  int translateBkptsFixed(const UT_IntArray &uindices,
274  const UT_Vector3 &delta,
275  GA_PointGroup *ptgroup = NULL,
276  GEO_Delta *geodelta = 0) override;
277  int transformBkptsFixed(const UT_IntArray &uindices,
278  const UT_Matrix4 &matx,
279  GA_PointGroup *ptgroup = NULL,
280  GEO_Delta *geodelta = 0) override;
281 
282  // Fill the curve with data and build the basis. Return 0 if OK, and -1
283  // if error.
284  int create(int nelems, int order=4, int closed = 0,
285  int interpEnds = 1, int appendPoints = 1);
286 
287  // Use for approximation.
288  void fit(const UT_Vector4Array &v4Data,
289  UT_Vector *data, int curOrd, int prevEnd,
290  int cvEnd, UT_Vector *coord, UT_Vector &param,
291  UT_Vector &error, float smooth);
292 
293  static GA_PrimitiveDefinition *theDefinition;
294  friend class GU_PrimitiveFactory;
295 };
296 
297 #endif
const GLdouble * v
Definition: glcorearb.h:837
virtual GEO_Curve * cut(float u1, float u2, int &ind1, int &ind2, int keep)=0
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
GLdouble u1
Definition: glad.h:2676
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
int evaluateBreakpoint(int uidx, UT_Vector4 &pos, int du=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);
A range of elements in an index-map.
Definition: GA_Range.h:42
< returns > If no error
Definition: snippets.dox:2
GA_ParameterizationType
Definition: GA_Types.h:197
GA_Size GA_Offset
Definition: GA_Types.h:646
GLfloat f
Definition: glcorearb.h:1926
GLintptr offset
Definition: glcorearb.h:665
int open(float queuesize) override
virtual void countMemory(UT_MemoryCounter &counter) const
~GU_PrimNURBCurve() override
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
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)
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
long long int64
Definition: SYS_Types.h:116
#define GU_API
Definition: GU_API.h:14
GLdouble GLdouble u2
Definition: glad.h:2676
virtual GEO_Face * reconfigure(unsigned type, int order, bool open, bool interpends, bool nonrational) const =0
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
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLenum GLfloat param
Definition: glcorearb.h:104
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
Container class for all geometry.
Definition: GA_Detail.h:96
virtual GEO_Primitive * convert(GEO_ConvertParms &parms, GA_PointGroup *usedpts=0)=0
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
Definition of a geometric primitive.
SIM_API const UT_StringHolder distance
const GA_PrimitiveDefinition & getTypeDef() const override
type
Definition: core.h:1059
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:190
virtual int intersect(const GEO_Primitive &prim, UT_Array< GU_RayInfoHit > &hit_list, float tol=0.01F, int ignoretrim=1) const =0
virtual GEO_Primitive * convertNew(GEO_ConvertParms &parms)=0
Definition: format.h:895