HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  bool isEqual(const GA_Basis &basis) const override;
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  void reset() override;
55 
56  /// Return the type of the basis
57  GA_BASIS_TYPE getType() const override;
58 
59  /// Return the name of the basis
60  const char *getTypeName() const override;
61 
62  /// Return the dimension of the basis. For Beziers the dimension is
63  /// equivalent to the length of the knot vector.
64  int getDimension() const override;
65 
66  /// Get the boundaries of the valid evaluation interval (as indices)
67  bool getValidInterval(int &a, int &b) const override;
68 
69  /// Evaluate on a specific domain interval, on which at least one
70  /// basis function is non-zero given domain point u.
71  void evalInterval(fpreal u, int offset, int deriv,
72  fpreal64 *vals) const override;
73  void evalInterval(fpreal u, int offset, int deriv,
74  fpreal32 *vals) const override;
75 
76  /// Evaluate all the derivatives of the basis from 0 to deriv (inclusive).
77  void evalDerivativeMatrix(fpreal u, int offset, int deriv,
78  fpreal64 bmatx[][GA_MAXORDER]) const override;
79  void evalDerivativeMatrix(fpreal u, int offset, int deriv,
80  fpreal32 bmatx[][GA_MAXORDER]) const override;
81 
82  /// Return the first break-point. Returns -1 on an error.
83  int findStartOffset(fpreal u, int uoffset) const override;
84 
85  /// Compute one basis function (ie. the one with the given index)
86  /// value at u.
87  fpreal computeBValue(int index, fpreal u) const override;
88 
89  /// Return the number of breakpoints (ie. unique knots) in the knot
90  /// vector, in the valid interval.
91  int getBreakCount() const override;
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  int knotToBreakpoint(int &kidx, int a, int b) const override;
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.
103  fpreal tol=theBasisTolerance) const override;
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  int getMultiplicity(fpreal u, int &uidx) const override;
108 
109  /// Return the expected multiplicity of the end knots (1 by default):
110  int getEndMultiplicity() const override;
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  void getCvRangeOfDomain(int ustartidx, int ustopidx,
117  int &start_cv, int &end_cv) const override;
118  void getCvRangeOfDomain(fpreal ustart, fpreal ustop,
119  int &start_cv, int &end_cv) const override;
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  void getCvRangeOfBreakpoint(int bkp,
126  int &startcv, int &stopcv) const override;
127 
128  /// I/O functions for houdini9 format
129  bool saveH9(std::ostream &os, bool wrapped,
130  bool binary) const override;
131  bool loadH9(UT_IStream &is, int cvs, bool wrapped) override;
132 
133  /// Transitional method while we might need to import data from a GB_Basis.
134  /// Be careful calling this method as the order must be appropriate for the
135  /// number of knots.
136  /// TODO: Remove when no longer necessary.
137  bool import(int order, const UT_FloatArray &knots);
138 
139  /// The validate() method will force the basis to be valid (if possible).
140  /// The adapt enum can be used to control the behaviour of this method.
141  bool validate(int adapt=GA_Basis::GA_BASIS_ADAPT_NONE) override;
142 
143  /// The checkValid() methods test to see whether th basis is valid given
144  /// a curve with
145  /// -# cvLen vertices
146  /// -# A basis length of b_len
147  /// -# Periodicity determined by doesWrap
148  bool checkValid(int cv_len, int b_len, bool does_wrap) const override;
149 
150  /// Compute the idx'th greville abscissa of the domain vector. Clamping
151  /// to the valid interval is optional and might not make any difference
152  /// for some spline types.
153  fpreal getGreville(int idx, bool clamp=true,
154  bool wrap=false) const override;
155 
156  /// Grow the length of the basis by one, and set the value of the new entry
157  /// to last knot+1. The method returns the index of the appended element.
158  int grow(bool wrapped=false) override;
159 
160  /// Shrink the basis by one. The basis should not shrink beyond a valid
161  /// length. Return the new length.
162  int shrink(bool wrapped=false) override;
163 
164  /// Attach another basis to us and grow our basis as a result. The bases
165  /// must have the same type and order.
166  /// If "overlap" is true, we overlap the beginning of b with
167  /// our end.
168  /// Spreading makes sense when you can have multiple knots in the basis, and
169  /// causes identical knots to be spread within range of the neighbouring
170  /// knots.
171  bool attach(const GA_Basis &b, bool overlap=true,
172  bool spread=false) override;
173 
174  /// Change the size of the basis (and maybe some of its values too) to
175  /// make it a valid basis for wrapped splines.
176  void setWrapping(bool wrap) override;
177 
178  /// Reverse the breakpoints in the basis.
179  void reverse(bool wrapped) override;
180 
181  /// Find index in the knot vector for the break point corresponding to k.
182  int findOffset(fpreal k, int start_idx=0) const override;
183 
184  /// Rebuild the basis as a uniform sequence with a given step.
185  void rebuild(fpreal ustart=0, fpreal ustep=1) override;
186 
187  /// Make the basis uniform of just find out if it is uniform:
188  void makeUniform(fpreal ustep=1) override;
189 
190  /// Reparameterize the basis using the chord-length method, and clamp it
191  /// to the valid interval. The origin and length of the valid domain remains
192  /// unchanged.
193  void chord(UT_Vector4Array &cvs) override;
194 
195  /// Slide the knots found in the given range left or right by an amount at
196  /// most as large as the distance to the nearest knot outside the range.
197  /// The bias is a percentage value of the left-right distance, its default
198  /// value is 0.5 (i.e. don't change anything), and is clamped to [0,1].
199  bool slideRange(fpreal umin, fpreal umax, fpreal ubias=0.5) override;
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
GLenum clamp
Definition: glcorearb.h:1234
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:837
GLuint start
Definition: glcorearb.h:475
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
virtual int getBreakpoints(GA_KnotVector &a, fpreal tol=theBasisTolerance) const =0
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
#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:14
bool operator!=(const GA_BezBasis &a) const
Definition: GA_BezBasis.h:50
virtual bool slideRange(fpreal umin, fpreal umax, fpreal ubias=0.5)=0
float fpreal32
Definition: SYS_Types.h:200
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.
double fpreal64
Definition: SYS_Types.h:201
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
GLintptr offset
Definition: glcorearb.h:665
virtual int knotToBreakpoint(int &kidx, int a, int b) const =0
virtual GA_BASIS_TYPE getType() const =0
Return the type of the basis.
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
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 native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
virtual bool validate(int adapt=GA_Basis::GA_BASIS_ADAPT_NONE)=0
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
virtual void chord(UT_Vector4Array &cvs)=0
virtual bool attach(const GA_Basis &b, bool overlap=true, bool spread=false)=0
virtual bool loadH9(UT_IStream &is, int cvs, bool wrapped)=0
fpreal64 fpreal
Definition: SYS_Types.h:277
GA_BASIS_TYPE
Definition: GA_Basis.h:33
GLuint index
Definition: glcorearb.h:786
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
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).
virtual bool isEqual(const GA_Basis &basis) const =0
Compare to see whether the basis is equal.
GLenum src
Definition: glcorearb.h:1793