HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GD_Curve.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 handles curves of arbitrary degree.
10  * The Face class maintains the control vertices for the curve.
11  *
12  */
13 
14 #ifndef __GD_Curve_h__
15 #define __GD_Curve_h__
16 
17 #include "GD_API.h"
18 #include <GA/GA_Basis.h>
19 #include "GD_Face.h"
20 #include "GD_PrimType.h"
21 #include <iosfwd>
22 
23 class UT_MemoryCounter;
24 
25 class GD_API GD_Curve : public GD_Face
26 {
27 public:
28  // Constructor that attaches this curve to detail "d".
30 
31  // Class destructor, virtual by inheritance. It assumes it is OK to
32  // delete the basis, so make sure you always set the basis with an object
33  // allocated from the heap.
34  ~GD_Curve() override;
35 
36  /// Report memory usage
37  int64 getMemoryUsage() const override;
38 
39  /// Count memory usage using a UT_MemoryCounter in order to count
40  /// shared memory correctly.
41  /// NOTE: This should always include sizeof(*this).
42  void countMemory(UT_MemoryCounter &counter) const override;
43 
44  const GA_PrimitiveJSON *getJSON() const override;
45 
46  /// @{
47  /// Return the basis for the face (or @c NULL if there is no basis)
48  GA_Basis *getFaceBasis() override;
49  const GA_Basis *getFaceBasis() const override;
50  /// @}
51 
52  /// @{
53  /// Load basis from a JSON value (from GD_Face)
54  bool jsonLoadBasis(UT_JSONParser &p) override;
55  bool jsonSaveBasis(UT_JSONWriter &w) const override;
57  const UT_JSONValue &v) override;
58  bool jsonSaveBasis(UT_JSONValue &v) const override;
59  /// @}
60 
61  // Overwrite this curve with the data from src. Virtual by inheritance.
62  GD_Primitive *copy(int preserve_shared_pts = 0) const override;
63  int copy(const GD_Primitive &src, int ptoffset) override;
64 
65  void copySubclassData(const GA_Primitive *source) override;
66 
67  // Return the bounds of the valid evaluation interval in domain space:
68  void validInterval(int &a, int &b) const override;
69 private:
70  void validRangeImpl(fpreal64 &ua,
71  fpreal64 &ub) const override;
72 public:
73 
74  // Evaluate one point (when du=0), or the du-th derivative.
75  // Return 0 if successful, and -1 otherwise.
76  int evaluate(float u, UT_Vector3 &pos,
77  unsigned du=0, int uOffset=-1) const override;
78 
79 
80  // Stub for now
82  fpreal u, uint du=0, int uoffset=-1
83  ) const override;
84 
85  // Given a domain value (u), store all the basis derivatives (from 0 to du
86  // inclusive) into bmatx. Return the first index of the CVs needed for the
87  // linear combination in cvoffset. The CV index may exceed the number of
88  // vertices if the curve is wrapped, so remember to use modulus (%).
89  // Return 0 if successful, and -1 otherwise.
90  virtual int evaluateBasisDerivs(fpreal u,
91  fpreal bmatx[][GA_MAXORDER],
92  int &cvoffset, unsigned du = 0,
93  int uoffset = -1) const = 0;
94 
95  // Evaluate the basis at the given point in the domain and also return
96  // the index of the first CV to linearly combine the basis with in cvoffset.
97  // The CV index may exceed the number of vertices if the curve is wrapped,
98  // so remember to use modulus (%). This method handles both rational and
99  // non-rational curves.
100  // Return 0 if successful, and -1 otherwise.
101  virtual int evaluateBasis(fpreal u, fpreal *ubvals,
102  int &cvoffset, unsigned du=0,
103  int uoffset=-1) const = 0;
104 
105  // Return the value of the i'th basis at parameter u. This method handles
106  // both rational an non-rational curves.
107  fpreal computeBValue(float u, int i) const;
108 
109  // Evaluate the curvature at (u). Return 0 if successful and -1 otherwise.
110  int curvature(float u, UT_Vector2 &curv) const;
111 
112  // Evaluate the curve betw. breakpoints by taking a start and a stop index
113  // in the valid knot domain and an lod representing number of points to
114  // be interpolated between every two breakpoints. The method ALWAYS
115  // interpolates the encountered breakpoints (aka "edit points").
116  // This returns true if successful, else false. Please save
117  // yourself headaches and pass VALID start and end indices (see the
118  // method getValidInterval() in GA_Basis).
119  bool evaluateBreakSegm(int uStartIdx, int uStopIdx,
120  int lod, UT_Vector3Array &pos,
121  unsigned du=0) const override;
122 
123  // Given a CV index figure out the min/max indicies of the knots between
124  // which the curve needs to be re-evaluated if the CV changes. If not
125  // given a valid CV index, the method returns -1. Otherwise it returns 0.
126  virtual int domainRangeOfCV(int cvidx, int &mink,
127  int &maxk) const = 0;
128 
129  // Take the weights into consideration or don't. If you do, the curve
130  // becomes a rational, and possibly different algorithms apply. If 'onOff'
131  // is true, this function first checks if any two weights are different
132  // before setting the rational flag to TRUE; if they are all the same,
133  // the curve is set to non-rational (=> faster evaluation). weights()
134  // calls normalizeWeights() to bring the weights to standard form, and
135  // invokes recordChanges() if necessary. Weights that are <= 0 are bumped
136  // up to FLT_EPSILON.
137  void weights(unsigned short onOff) override;
138 
139  // Normalize the weights of the control mesh so that edge weights are 1,
140  // and all weights are >= 0 (those that are <= 0 are bumped up to
141  // FLT_EPSILON).
142  void normalizeWeights();
143 
144  // Normalize the domain and optionally shift it to a new origin. Use the
145  // given length if greater than 0.
146  void normalizeDomain(fpreal len=0, fpreal *neworigin=0)
147  {
148  myBasis->normalize(len, neworigin);
149  }
150 
151  // Set or query the basis. The "set" function overwrites the current
152  // basis pointer, so use with care; it returns -1 if the basis is invalid.
154  {
155  if (ub && ub->checkValid((int)getVertexCount(),
156  (int)isClosed()))
157  {
158  delete myBasis;
159  myBasis = ub;
160  return 0;
161  }
162  else return -1;
163  }
164  const GA_Basis *getBasis() const { return myBasis; }
165  GA_Basis *getBasis() { return myBasis; }
166 
167  // Query the order and the dimension of the basis.
168  unsigned getOrder() const override
169  { return myBasis->getOrder(); }
170  unsigned getDim() const
171  { return myBasis->getDimension(); }
172 
173  // Inherited from the base class: just checks the validity of the basis.
174  bool isDegenerate() const override;
175 
176  // Reverses the vertices of a given face. It's virtual because some faces,
177  // such as rational splines, need to be aware of it.
178  void reverse() override;
179 
180  // Find out whether the curve is currently computed as a rational:
181  bool isRational() const { return myRational; }
182 
183 protected:
184  /// All subclasses should call this method to register the curve intrinsics.
185  /// @see GA_AttributeIntrinsic
188  { return GD_Face::registerIntrinsics(definition); }
189 
190  // Load and save functions redefined from the parent class.
191  bool savePrivateH9(std::ostream &os,
192  bool binary) const override;
193  bool loadPrivateH9(UT_IStream &is) override;
194 
195  // Get a new basis of a type that matches our type:
196  virtual GA_Basis *newBasis() const = 0;
197 
198  // Check the validity of the data. Meant to be called especially at loading
199  // time, since it also checks the weights. The method returns 1 if OK and
200  // 0 if trouble.
201  bool validate() const override;
202 
203  // Set the order of the basis:
204  void setOrder(unsigned ord) { myBasis->setOrder(ord); }
205 
206  // Build the vextex list, and optionally append points to the detail.
207  // Return 0 if OK, and -1 if error.
208  int create(GD_Curve *crv, int nelems, int closed,
209  int appendPoints = 1);
210  int breakCount() const override;
211 
212 protected:
213  /// Curve's basis
215 
216 private:
217  // Flag that indicates whether the CV weights should be taken into account
218  // when evaluating the curve or otherwise affecting its geometry.
219  bool myRational;
220 
221  friend std::ostream &operator<<(std::ostream &os, const GD_Curve &d)
222  {
223  d.saveH9(os, 0,
226  return os;
227  }
228 };
229 
230 #endif
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
virtual int evaluate(float u, UT_Vector3 &pos, unsigned du=0, int uOffset=-1) const =0
virtual bool jsonSaveBasis(UT_JSONWriter &w) const
bool isRational() const
Definition: GD_Curve.h:181
virtual bool loadPrivateH9(UT_IStream &is)=0
const GLdouble * v
Definition: glcorearb.h:837
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:508
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GA_Basis * myBasis
Curve's basis.
Definition: GD_Curve.h:214
virtual bool savePrivateH9(std::ostream &os, bool binary) const =0
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define GA_MAXORDER
Definition: GA_Defines.h:17
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
virtual int64 getMemoryUsage() const
Definition: GA_Primitive.h:209
void normalizeDomain(fpreal len=0, fpreal *neworigin=0)
Definition: GD_Curve.h:146
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
GD_Primitive * copy(int preserve_shared_pts=0) const override
const GA_Basis * getBasis() const
Definition: GD_Curve.h:164
virtual bool jsonLoadBasis(UT_JSONParser &p)
double fpreal64
Definition: SYS_Types.h:201
GA_Size GA_Offset
Definition: GA_Types.h:646
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
Definition: GD_Primitive.h:67
int setBasis(GA_Basis *ub)
Definition: GD_Curve.h:153
virtual bool checkValid(int cvLen, int bLen, bool doesWrap) const =0
GLintptr offset
Definition: glcorearb.h:665
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Curve.h:187
virtual void countMemory(UT_MemoryCounter &counter) const
virtual const GA_PrimitiveJSON * getJSON() const =0
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
Provide a JSON interface to a primitive.
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
friend std::ostream & operator<<(std::ostream &os, const GD_Curve &d)
Definition: GD_Curve.h:221
virtual void weights(unsigned short)
Definition: GD_Face.h:245
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
unsigned getOrder() const override
Definition: GD_Curve.h:168
bool isDegenerate() const override
Is the primitive degenerate.
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
virtual int breakCount() const =0
GT_Basis myBasis
Definition: GT_CurveEval.h:262
#define GD_API
Definition: GD_API.h:10
fpreal64 fpreal
Definition: SYS_Types.h:277
void setOrder(unsigned ord)
Definition: GD_Curve.h:204
unsigned getDim() const
Definition: GD_Curve.h:170
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
virtual void validInterval(int &a, int &b) const
GA_Basis * getBasis()
Definition: GD_Curve.h:165
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void reverse() override
Definition of a geometric primitive.
virtual bool validate() const
virtual GA_Basis * getFaceBasis()
unsigned int uint
Definition: SYS_Types.h:45
GLint lod
Definition: glcorearb.h:2765
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Face.h:251
SYS_FORCE_INLINE bool isClosed() const
Definition: GD_Face.h:161
GLenum src
Definition: glcorearb.h:1793
virtual bool evaluateBreakSegm(int ustartidx, int ustopidx, int lod, UT_Vector3Array &pos, unsigned du=0) const