HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_BezBasis.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: GA_BezBasis.h ( GA Library, C++)
7  *
8  * COMMENTS: Stores an array of knots for a Bezier patch
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_BezBasis__
14 #define __GA_BezBasis__
15 
16 #include "GA_API.h"
17 #include "GA_Basis.h"
18 #include "GA_Defines.h" // for GA_MAXORDER
19 #include "GA_KnotVector.h" // for GA_KnotVector
20 
21 #include <UT/UT_VectorTypes.h> // for UT_FloatArray, etc
22 
23 #include <SYS/SYS_Types.h> // for fpreal, etc
24 
25 #include <iosfwd>
26 
27 
28 class UT_IStream;
29 
30 
31 /// @brief Bezier basis classes which maintain knot vectors
32 ///
33 /// The GA_BezBasis class maintains the knot vectors for Bezier
34 /// splines. The basis consists of:
35 /// -# The order of the basis (degree+1)
36 /// -# The knot vector (an array of doubles)
37 class GA_API GA_BezBasis : public GA_Basis
38 {
39 public:
40  /// The default constructor will choose length/order based on the defaults
41  /// for the basis type.
42  /// default: order=4, length=2
43  GA_BezBasis(int length=-1, int order=-1);
44  GA_BezBasis(fpreal start, fpreal step, int length, int order=-1);
45  GA_BezBasis(const GA_BezBasis &src);
46 
47  /// Test to see if two bases are equal
48  virtual bool isEqual(const GA_Basis &basis) const;
49  bool operator==(const GA_BezBasis &a) const;
50  bool operator!=(const GA_BezBasis &a) const
51  { return !(*this == a); }
52 
53  /// Re-initializes the basis to default values
54  virtual void reset();
55 
56  /// Return the type of the basis
57  virtual GA_BASIS_TYPE getType() const;
58 
59  /// Return the name of the basis
60  virtual const char *getTypeName() const;
61 
62  /// Return the dimension of the basis. For Beziers the dimension is
63  /// equivalent to the length of the knot vector.
64  virtual int getDimension() const;
65 
66  /// Get the boundaries of the valid evaluation interval (as indices)
67  virtual bool getValidInterval(int &a, int &b) const;
68 
69  /// Evaluate on a specific domain interval, on which at least one
70  /// basis function is non-zero given domain point u.
71  virtual void evalInterval(fpreal u, int offset, int deriv,
72  fpreal64 *vals) const;
73  virtual void evalInterval(fpreal u, int offset, int deriv,
74  fpreal32 *vals) const;
75 
76  /// Evaluate all the derivatives of the basis from 0 to deriv (inclusive).
77  virtual void evalDerivativeMatrix(fpreal u, int offset, int deriv,
78  fpreal64 bmatx[][GA_MAXORDER]) const;
79  virtual void evalDerivativeMatrix(fpreal u, int offset, int deriv,
80  fpreal32 bmatx[][GA_MAXORDER]) const;
81 
82  /// Return the first break-point. Returns -1 on an error.
83  virtual int findStartOffset(fpreal u, int uoffset) const;
84 
85  /// Compute one basis function (ie. the one with the given index)
86  /// value at u.
87  virtual fpreal computeBValue(int index, fpreal u) const;
88 
89  /// Return the number of breakpoints (ie. unique knots) in the knot
90  /// vector, in the valid interval.
91  virtual int getBreakCount() const;
92 
93  /// Given the index of a knot (kidx) and two bounds in the knot sequence
94  /// (a and b) find out the index of the breakpoint that the knot represents,
95  /// and possibly adjust kidx so that knot[kidx+1] > knot[kidx]. Return -1
96  /// if not found.
97  virtual int knotToBreakpoint(int &kidx, int a, int b) const;
98 
99  /// Compute an array of breakpoints (i.e. unique knots) in the valid
100  /// interval and return their number. The tolerance is used to
101  /// differentiate between close knots.
102  virtual int getBreakpoints(GA_KnotVector &a,
103  fpreal tol=theBasisTolerance) const;
104 
105  /// Return the multiplicity of a domain point or -1 if outside the domain.
106  /// "uidx" is the index of the largest breakpoint <= u.
107  virtual int getMultiplicity(fpreal u, int &uidx) const;
108 
109  /// Return the expected multiplicity of the end knots (1 by default):
110  virtual int getEndMultiplicity() const;
111 
112  /// Given a domain range in the valid interval, compute the range of CVs
113  /// that will be involved in the evaluation of the curve in that range.
114  /// Since the basis doesn't know about wrapping, the endcv index might
115  /// be higher than the spline's number of CVs.
116  virtual void getCvRangeOfDomain(int ustartidx, int ustopidx,
117  int &start_cv, int &end_cv) const;
118  virtual void getCvRangeOfDomain(fpreal ustart, fpreal ustop,
119  int &start_cv, int &end_cv) const;
120 
121  /// Given valid breakpoint index, compute the range of CVs that have a
122  /// non-zero influence at the knot of the breakpoint. Since the basis
123  /// doesn't know about wrapping, the endcv index might be higher than the
124  /// spline's number of CVs.
125  virtual void getCvRangeOfBreakpoint(int bkp,
126  int &startcv, int &stopcv) const;
127 
128  /// I/O functions for houdini9 format
129  virtual bool saveH9(std::ostream &os, bool wrapped, bool binary) const;
130  virtual bool loadH9(UT_IStream &is, int cvs, bool wrapped);
131 
132  /// Transitional method while we might need to import data from a GB_Basis.
133  /// Be careful calling this method as the order must be appropriate for the
134  /// number of knots.
135  /// TODO: Remove when no longer necessary.
136  bool import(int order, const UT_FloatArray &knots);
137 
138  /// The validate() method will force the basis to be valid (if possible).
139  /// The adapt enum can be used to control the behaviour of this method.
140  virtual bool validate(int adapt=GA_Basis::GA_BASIS_ADAPT_NONE);
141 
142  /// The checkValid() methods test to see whether th basis is valid given
143  /// a curve with
144  /// -# cvLen vertices
145  /// -# A basis length of bLen
146  /// -# Periodicity determined by doesWrap
147  virtual bool checkValid(int cvLen, int bLen, bool doesWrap) const;
148 
149  /// Compute the idx'th greville abscissa of the domain vector. Clamping
150  /// to the valid interval is optional and might not make any difference
151  /// for some spline types.
152  virtual fpreal getGreville(int idx, bool clamp=true,
153  bool wrap=false) const;
154 
155  /// Grow the length of the basis by one, and set the value of the new entry
156  /// to last knot+1. The method returns the index of the appended element.
157  virtual int grow(bool wrapped=false);
158 
159  /// Shrink the basis by one. The basis should not shrink beyond a valid
160  /// length. Return the new length.
161  virtual int shrink(bool wrapped=false);
162 
163  /// Attach another basis to us and grow our basis as a result. The bases
164  /// must have the same type and order.
165  /// If "overlap" is true, we overlap the beginning of b with
166  /// our end.
167  /// Spreading makes sense when you can have multiple knots in the basis, and
168  /// causes identical knots to be spread within range of the neighbouring
169  /// knots.
170  virtual bool attach(const GA_Basis &b, bool overlap=true,
171  bool spread=false);
172 
173  /// Change the size of the basis (and maybe some of its values too) to
174  /// make it a valid basis for wrapped splines.
175  virtual void setWrapping(bool wrap);
176 
177  /// Reverse the breakpoints in the basis.
178  virtual void reverse(bool wrapped);
179 
180  /// Find index in the knot vector for the break point corresponding to k.
181  virtual int findOffset(fpreal k, int startIdx=0) const;
182 
183  /// Rebuild the basis as a uniform sequence with a given step.
184  virtual void rebuild(fpreal ustart=0, fpreal ustep=1);
185 
186  /// Make the basis uniform of just find out if it is uniform:
187  virtual void makeUniform(fpreal ustep=1);
188 
189  /// Reparameterize the basis using the chord-length method, and clamp it
190  /// to the valid interval. The origin and length of the valid domain remains
191  /// unchanged.
192  virtual void chord(UT_Vector4Array &cvs);
193 
194  /// Slide the knots found in the given range left or right by an amount at
195  /// most as large as the distance to the nearest knot outside the range.
196  /// The bias is a percentage value of the left-right distance, its default
197  /// value is 0.5 (i.e. don't change anything), and is clamped to [0,1].
198  virtual bool slideRange(fpreal umin, fpreal umax,
199  fpreal ubias=0.5);
200 
201 private:
202  void initialize(fpreal start, fpreal step, int length, int order);
203 
204  /// Test whether the basis is a uniform basis.
205  bool isUniform() const;
206 
207  /// Return -1 if v is less than the 0th breakpoint or the index of the
208  /// last bkp + 1 if v is greater than the last breakpoint. Otherwise
209  /// returns the index of the last breakpoint less than or equal to v.
210  int findBezierBreakpoint(fpreal v) const;
211 };
212 
213 #endif
virtual int shrink(bool wrapped=false)=0
virtual void makeUniform(fpreal ustep=1)=0
Make the basis uniform of just find out if it is uniform:
virtual fpreal getGreville(int idx, bool clamp=true, bool wrap=false) const =0
virtual int getMultiplicity(fpreal u, int &uidx) const =0
virtual int findOffset(fpreal k, int startIdx=0) const =0
Find index in the knot vector for the break point corresponding to k.
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
virtual int getBreakpoints(GA_KnotVector &a, fpreal tol=theBasisTolerance) const =0
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
#define GA_MAXORDER
Definition: GA_Defines.h:17
virtual void evalInterval(fpreal u, int offset, int deriv, fpreal64 *vals) const =0
virtual fpreal computeBValue(int index, fpreal u) const =0
#define GA_API
Definition: GA_API.h:12
bool operator!=(const GA_BezBasis &a) const
Definition: GA_BezBasis.h:50
virtual bool slideRange(fpreal umin, fpreal umax, fpreal ubias=0.5)=0
virtual int findStartOffset(fpreal u, int uoffset) const =0
virtual int getBreakCount() const =0
virtual void reset()=0
Re-initializes the basis to default values.
virtual int grow(bool wrapped=false)=0
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
virtual bool checkValid(int cvLen, int bLen, bool doesWrap) const =0
virtual int knotToBreakpoint(int &kidx, int a, int b) const =0
double fpreal64
Definition: SYS_Types.h:191
virtual GA_BASIS_TYPE getType() const =0
Return the type of the basis.
GLintptr offset
Definition: glcorearb.h:664
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
virtual void setWrapping(bool wrap)=0
virtual int getDimension() const =0
virtual void rebuild(fpreal ustart=0, fpreal ustep=1)=0
Rebuild the basis as a uniform sequence with a given step.
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:316
virtual bool validate(int adapt=GA_Basis::GA_BASIS_ADAPT_NONE)=0
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual void chord(UT_Vector4Array &cvs)=0
virtual bool attach(const GA_Basis &b, bool overlap=true, bool spread=false)=0
double fpreal
Definition: SYS_Types.h:269
virtual bool loadH9(UT_IStream &is, int cvs, bool wrapped)=0
GA_BASIS_TYPE
Definition: GA_Basis.h:33
GLuint index
Definition: glcorearb.h:785
virtual bool saveH9(std::ostream &os, bool wrapped, bool binary) const =0
I/O functions for houdini9 format.
virtual const char * getTypeName() const =0
Return the name of the basis.
virtual void reverse(bool wrapped)=0
Reverse the breakpoints in the basis.
Bezier basis classes which maintain knot vectors.
Definition: GA_BezBasis.h:37
float fpreal32
Definition: SYS_Types.h:190
virtual int getEndMultiplicity() const
Return the expected multiplicity of the end knots (1 by default):
virtual void getCvRangeOfDomain(int ustartidx, int ustopidx, int &start_cv, int &end_cv) const =0
virtual void getCvRangeOfBreakpoint(int bkp, int &startcv, int &stopcv) const =0
virtual bool getValidInterval(int &a, int &b) const =0
Get the boundaries of the valid evaluation interval (as indices)
virtual void evalDerivativeMatrix(fpreal u, int offset, int deriv, fpreal64 bmatx[][GA_MAXORDER]) const =0
Evaluate all the derivatives of the basis from 0 to deriv (inclusive).
GLenum clamp
Definition: glcorearb.h:1233
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
virtual bool isEqual(const GA_Basis &basis) const =0
Compare to see whether the basis is equal.
GLenum src
Definition: glcorearb.h:1792