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