HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimRBezCurve.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 class implements a piecewise Bezier curve defined by
10  * a set of breakpoints, basis function, and CVs.
11  *
12  *
13  */
14 
15 #pragma once
16 
17 #ifndef __GEO_PrimRBezCurve_h__
18 #define __GEO_PrimRBezCurve_h__
19 
20 #include "GEO_API.h"
21 #include "GEO_Curve.h"
22 #include "GEO_PrimType.h"
23 
24 class GA_Detail;
25 
27 {
28 public:
29  using GEO_Face::refine;
30 
31 protected:
32  /// NOTE: The constructor should only be called from subclass
33  /// constructors.
35  : GEO_Curve(d, offset)
36  {}
37 
38  /// NOTE: The destructor should only be called from subclass
39  /// destructors.
40  /// Please read the comments on the parent class destructor.
41  virtual ~GEO_PrimRBezCurve() {}
42 
43 public:
44  /// Increases div to the first valid number of divisions, given
45  /// the order and closed flag. For NURBs, this is a straightforward
46  /// minimum.
47  /// Returns true if the divisions changed.
48  static bool forceValidDivisions(int &div, int order, bool closed);
49 
50  // Given a domain value (u), store all the basis derivatives (from 0 to du
51  // inclusive) into bmatx. Return the min index of the CVs needed
52  // for the linear combination. The indices may exceed the number of
53  // vertices if the curve is wrapped, so remember to use % getVertexCount().
54  virtual int evaluateBasisDerivs(float u,float bmatx[][GA_MAXORDER],
55  int &cvoffset, unsigned du = 0,
56  int uoffset = -1) const;
57 
58  // Evaluate the basis at the given point in the domain and also return
59  // the index of the first CV to linearly combine the basis with. The CV
60  // index may exceed the number of vertices if the curve is wrapped,
61  // so remember to use modulus (%). This method handles both rational and
62  // non-rational curves.
63  virtual int evaluateBasis(float u,float *ubvals, int &cvoffset,
64  unsigned du=0, int uoffset=-1) const;
65 
66  // Compute the location of the breakpoint. Return 0 if OK, else -1.
67  virtual int evaluateBreakpoint(int uidx, UT_Vector4 &pos,
68  int du = 0) const;
69 
70  // Remove all repeated vertices - (only gets consecutive vertices)
71  virtual GA_Size removeRepeatedVertices(bool check_order = false,
72  bool count_only = false,
73  bool deleteOrphanedPoints = false);
74 
75  // compute the un-normalized lengths corresponding to points on the curve
76  // evaluated at the valid knots parameter values
77  // (ones with which lie within curve paramer domain) and store them
78  // in the 'lengths' array. Returns the curve "length" (same as last knot).
79  // The meaning of "length" depends on ptype, and can mean chord length,
80  // square chord length, approximate arc length.
81  virtual float getKnotLengths(GA_ParameterizationType ptype,
82  UT_FloatArray &lengths) const;
83 
84  // Given a CV index figure out the min/max indicies of the knots between
85  // which the curve needs to be re-evaluated if the CV changes. If not
86  // given a valid CV index, the method returns -1. Otherwise it returns 0.
87  // If the curve wraps the domain we return will be rather large.
88  virtual int domainRangeOfCV(int cvidx, int &mink,int &maxk) const;
89 
90  // Given a CV index figure out the min/max breakpoints which are
91  // affected if the CV changes. If not given a valid CV index, the
92  // method returns -1. Otherwise it returns 0. Also returns -1 if
93  // no breakpoints are affected.
94  // NOTE: use % breakCount since maxbkp may be >= breakCount
95  virtual int breakpointRangeOfCV(int cvidx, int &minbkp,
96  int &maxbkp) const;
97 
98  // Reparameterize the curve by changing its basis. The first breakpoint
99  // remains unchanged.
100  virtual void reparameterize(GA_ParameterizationType ptype);
101 
102  // Set the closed or open flag, and make sure the basis knot vector is
103  // consistent with the change. These functions are virtual by inheritance.
104  // They change the number of CVs, so use them with care. Also, they do
105  // not keep a history of changes: if you start with a closed curve
106  // and then you open and close it again, the re-closed curve uses
107  // 'degree-2' new CVs that have been generated for this purpose.
108 
109  // Close up an open curve.
110  //
111  // If preserveShape = 1:
112  // add extra cvs at the end to define the last span.
113  // if rounded,
114  // the new cvs just added will be arranged to
115  // give a rounded appearance.
116  // else
117  // the new cvs just added will form a straight
118  // line between the first and last endpoint.
119  // If preserveShape = 0:
120  // just grow the basis by one span, without adding any new cvs.
121  // ignore the rounded flag.
122  virtual void close(int rounded = 1, int preserveShape = 0);
123 
124  // Open up a closed curve.
125  //
126  // If preserveShape = 1:
127  // the open curve will have exactly the same geometry
128  // (ie. still look closed) with the first point duplicated.
129  // If preserveShape = 0:
130  // the open curve will remove the last span in the basis,
131  // thus open up a gap in the curve.
132  // last few cvs are dangling which do not form a valid
133  // curve segment, if the safe flag = 0.
134  // The safe flag is to remove unneed cvs for ensuring the resulting
135  // curve is a valid bezier curve.
136  virtual void open(int preserveShape = 0, int safe = 0);
137 
138  // Insert or delete vertices. The insertion methods return the index if
139  // successful and -1 otherwise. The deletion methods return 0 if ok and
140  // -1 otherwise. The insertion methods create the point if it does not
141  // exist.
144  virtual int deleteVertex(GA_Size num);
145 
146  // Assuming the curve is closed, "unroll" it so that the CVs that are
147  // shared to form a wrapped curve are made unique. Also, the curve becomes
148  // open. The base class method only flips the open flag. If the curve is
149  // not closed, the method returns -1. Otherwise it returns 0.
150  virtual int unroll(int append_pts = 1);
151 
152  // Raise the number of CVs to match the newcount. The shape of the curve
153  // (especially if parametric) should NOT change. Return 0 upon success
154  // and -1 otherwise. start and stop define which indices to examine
155  // if newcount is negative it is taken as a relative value.
156  virtual int loft(int newcount, int start=-1, int stop=-1);
157 
158  // Warp the curve at u by the given delta. Change 1 or 2 Cvs and possibly
159  // insert a knot once or more as well. If a knot is inserted or we happen
160  // to land exactly on a knot, we change only one CV. The bias makes sense
161  // only when changing 2 CVs, and will be ignored altogether if < 0.
162  // We return the index of the affected knot in the sequence, or -1 if
163  // there's an error.
164  virtual int warp(float u, const UT_Vector3 &delta,
165  GA_AttributeRefMap &map,
166  float sharpness = 0.0f, float bias = -1.0f);
167 
168  // Translate the CVs such that the given breakpoint change positions by
169  // the given delta. Return -1 if something goes wrong, 0 if translation
170  // was successful.
171  // NOTE: uindices cannot contain any duplicates. If the curve is closed,
172  // the first and last breakpoint are considered the same.
173  virtual int translateBreakpoints(const UT_IntArray &uindices,
174  const UT_Vector3 &delta,
175  int fixbkpts = 1,
176  GA_PointGroup *ptgroup = NULL,
177  GEO_Delta *geodelta = 0);
178 
179  virtual int transformBreakpoints(const UT_IntArray &uindices,
180  const UT_Matrix4 &matx,
181  int fixbkpts = 1,
182  GA_PointGroup *ptgroup = NULL,
183  GEO_Delta *geodelta = 0);
184 
185  // Append another face to us in one of two ways: blend the two endpoints
186  // or connect them straight or rounded. The bias ranges from 0 to 1 and is
187  // relevant only to blending. The tolerance for blending: if 0, the two
188  // endpoints will merge into one point with a discontinuity; if less than
189  // 1, we insert knots into the curves to minimize the affected areas; if 1,
190  // no refinement is done. For the non-blend case, the tolerance will
191  // generate a span whose shape goes from round to straight; 0 tolerance
192  // means straight connection. We return 0 if OK and -1 if error. Both
193  // curves must be open and have the same order.
194  virtual int attach(const GEO_Face &face, int blend = 1,
195  float bias = .5f, float tolerance = 1.f, int=0,
196  GA_PointGroup *ptgroup=0);
197 
198  // Build a planar (domain) face of the same type as us and with the same
199  // number of vertices. Copying the (x,y) values of our points to the planar
200  // face is optional.
201  virtual GD_Face *planar(GD_Detail &dgdp, int copyxy = 0) const;
202 
203  // reverse the vertices of the curve, preserving shape
204  virtual void reverse(void);
205 
206  // If ustart and ustop are two values in the valid interval,ustart < ustop,
207  // return the part of curve defined by ustart and ustop in a new primitive.
208  // Return 0 if a problem is encountered.
209  virtual GEO_Curve *extract(float ustart,float ustop) const;
210 
211  virtual const GA_PrimitiveJSON *getJSON() const;
212 
213  /// Builds Bezier curves using the specified range of point offsets,
214  /// as dictated by curvesizelist and curvepointnumbers, in parallel.
215  /// curvepointnumbers lists the *offsets* of the points used by
216  /// each curve *MINUS* startpt, i.e. they are offsets relative to startpt,
217  /// *not* indices relative to startpt. The offset of the first curve is
218  /// returned, and the rest are at consecutive offsets. All
219  /// curvepointnumbers must be between 0 (inclusive) and
220  /// npoints (exclusive).
221  ///
222  /// NOTE: Existing primitives *are* allowed to be using the points in
223  /// the specified range already, and the curves being created do not
224  /// need to use all of the points in the range. However,
225  /// these cases may impact performance.
226  /// @{
227  static GA_Offset buildBlock(GA_Detail *detail,
228  const GA_Offset startpt,
229  const GA_Size npoints,
230  const GEO_PolyCounts &curvesizelist,
231  const int *curvepointnumbers,
232  const UT_Array<int> &porders,
233  const int uorder = 4,
234  const bool closed = false);
235  static GA_Offset buildBlock(GA_Detail *detail,
236  const GA_Offset startpt,
237  const GA_Size npoints,
238  const GA_PolyCounts &curvesizelist,
239  const int *curvepointnumbers,
240  const UT_Array<int> &porders,
241  const int uorder = 4,
242  const bool closed = false);
243  /// @}
244 
245 protected:
247  { return GEO_Curve::buildFamilyMask(); }
248 
249  /// All subclasses should call this method to register the curve intrinsics.
250  /// @see GA_IntrinsicManager
253  { return GEO_Curve::registerIntrinsics(defn); }
254 
255  // Get a new basis of a type that matches our type:
256  virtual GA_Basis *newBasis(void) const;
257 
258  /// Set the basis to a copy of the passed-in basis.
259  /// NOTE: basis *must* be valid for this curve!
260  virtual void setBasisCopy(const GA_Basis *basis);
261 
262  // Two different closing methods:
263  void closeSharp(void);
264  void closeRounded(void);
265 
266  // increase order by 1.
267  void incrementOrder(GA_AttributeRefMap &map);
268  void incrementOrder(void);
269 
270  // Increase the order. Return 0 if successful, -1 otherwise (eg.
271  // order cannot be increased because it's >= MAXORDER).
272  virtual int raiseOrderRefMap(int neworder,
273  GA_AttributeRefMap &map);
274  virtual int raiseOrderInt (int neworder);
275 
276  // Insert a breakpoint at the given point in the domain and return its
277  // index if successful. Return -1 in case of failure (eg. if outside the
278  // valid domain or equal to an existing breakpoint).
279  virtual int refineRefMap(float k, GA_AttributeRefMap &hlist, int=0);
280  virtual int refineInt(float k, int=0);
281 
282 private:
283  // Nothing.
285 };
287 #endif
virtual void open(int preserveShape=0, int safe=0)
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
Definition: GEO_TriMesh.h:258
virtual float getKnotLengths(GA_ParameterizationType ptype, UT_FloatArray &lengths) const =0
virtual int refineInt(float k, int r=1)
GA_API const UT_StringHolder div
virtual GA_Size removeRepeatedVertices(bool check_order=false, bool count_only=false, bool deleteOrphanedPoints=false)
virtual int attach(const GEO_Face &face, int blend=1, float bias=0.5f, float tolerance=1.0f, int unrefine=1, GA_PointGroup *ptgroup=0)
virtual int domainRangeOfCV(int cvidx, int &mink, int &maxk) const =0
virtual int breakpointRangeOfCV(int cvidx, int &minbkp, int &maxbkp) const =0
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
GLuint start
Definition: glcorearb.h:474
#define GA_MAXORDER
Definition: GA_Defines.h:17
3D Vector class.
virtual int loft(int newcount, int start=-1, int stop=-1)=0
virtual int warp(float u, const UT_Vector3 &delta, GA_AttributeRefMap &map, float sharpness=0.0f, float bias=-1.0f)=0
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GA_PrimitiveFamilyMask
virtual int transformBreakpoints(const UT_IntArray &uindices, const UT_Matrix4 &matx, int fixbkpts=1, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)=0
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
static GA_PrimitiveFamilyMask buildFamilyMask()
GA_ParameterizationType
Definition: GA_Types.h:173
GA_Size GA_Offset
Definition: GA_Types.h:617
GLfloat f
Definition: glcorearb.h:1925
virtual GA_Size appendVertex(GA_Offset ppt)
virtual int translateBreakpoints(const UT_IntArray &uindices, const UT_Vector3 &delta, int fixbkpts=1, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)=0
virtual GEO_Curve * extract(float ustart, float ustop) const =0
int refine(float k, GA_AttributeRefMap &gah, int r=1)
Definition: GEO_Face.h:302
virtual GD_Face * planar(GD_Detail &dgdp, int copyxy=0) const =0
virtual const GA_PrimitiveJSON * getJSON() const =0
GLintptr offset
Definition: glcorearb.h:664
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:10
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
virtual GA_Basis * newBasis(void) const =0
virtual ~GEO_PrimRBezCurve()
A handle to simplify manipulation of multiple attributes.
virtual int raiseOrderRefMap(int neworder, GA_AttributeRefMap &map)=0
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
virtual void close(int rounded=1, int preserveShape=0)
virtual void reverse()
Reverse the order of vertices.
virtual int raiseOrderInt(int neworder)=0
GEO_PrimRBezCurve(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
virtual int refineRefMap(float k, GA_AttributeRefMap &gah, int r=1)
Container class for all geometry.
Definition: GA_Detail.h:95
png_infop png_uint_32 int num
Definition: png.h:2158
virtual GA_Size insertVertex(GA_Offset ppt, GA_Size where=0)
Definition of a geometric primitive.
virtual void reparameterize(GA_ParameterizationType ptype)=0
virtual int evaluateBasis(float u, float *ubvals, int &cvoffset, unsigned du=0, int uoffset=-1) const =0
virtual int evaluateBreakpoint(int uidx, UT_Vector4 &pos, int du=0) const =0
virtual int deleteVertex(GA_Size num)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_Curve.h:415
virtual int unroll(int append_pts=1)
virtual int evaluateBasisDerivs(float u, float bmatx[][GA_MAXORDER], int &cvoffset, unsigned du=0, int uoffset=-1) const =0
GLsizei GLenum GLenum GLuint GLenum GLsizei * lengths
Definition: glcorearb.h:2541
virtual void setBasisCopy(const GA_Basis *basis)=0
static GA_Offset buildBlock(GA_PrimitiveTypeId type, GA_Detail *detail, const GA_Offset startpt, const GA_Size npoints, const GEO_PolyCounts &facesizelist, const int *facepointnumbers, const bool closed=true)