HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GD_PrimNURBCurve.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 non-uniform B-Spline curve defined by
10  * a set of knots, basis function, and CVs.
11  *
12  */
13 
14 #ifndef __GD_PrimNURBCurve_h__
15 #define __GD_PrimNURBCurve_h__
16 
17 #include "GD_API.h"
18 #include "GD_Curve.h"
19 #include "GD_PrimType.h"
20 #include <GA/GA_NUBBasis.h>
21 
23 {
24 public:
25  // Constructor that attaches this curve to detail "d".
27  : GD_Curve(d, offset) {}
28 
29  // Trivial class destructor, virtual by inheritance. Please read the
30  // comments on the parent class d-tor.
31  virtual ~GD_PrimNURBCurve() {}
32 
33  virtual const GA_PrimitiveDefinition &getTypeDef() const;
34 
35  // Build a new curve and insert it into the given detail.
36  static GD_PrimNURBCurve *build(GD_Detail *gdp, int npts,
37  int order = 4, int closed = 0,
38  int clamped = 1, int appendPts = 1);
39 
40  // Given a domain value (u), store all the basis derivatives (from 0 to du
41  // inclusive) into bmatx. Return the first index of the CVs needed for the
42  // linear combination in cvoffset. The CV index may exceed the number of
43  // vertices if the curve is wrapped, so remember to use modulus (%).
44  // Return 0 if successful, and -1 otherwise.
45  virtual int evaluateBasisDerivs(fpreal u,
46  fpreal bmatx[][GA_MAXORDER],
47  int &cvoffset, unsigned du = 0,
48  int uoffset = -1) const;
49 
50  // Evaluate the basis at the given point in the domain and also return
51  // the index of the first CV to linearly combine the basis with in cvoffset.
52  // The CV index may exceed the number of vertices if the curve is wrapped,
53  // so remember to use modulus (%). This method handles both rational and
54  // non-rational curves.
55  // Return 0 if successful, and -1 otherwise.
56  virtual int evaluateBasis(fpreal u, fpreal *ubvals,
57  int &cvoffset, unsigned du=0,
58  int uoffset=-1) const;
59 
60  // Curve evaluator that takes a start and a stop index
61  // in the valid knot domain and an lod representing number of points to
62  // be interpolated between every two breakpoints. The method ALWAYS
63  // interpolates the encountered breakpoints (aka "edit points").
64  // This returns true if successful, else false. Please save
65  // yourself headaches and pass VALID start and end indices (see the
66  // method getValidInterval() in GA_Basis).
67  virtual bool evaluateBreakSegm(int uStartIdx, int uStopIdx, int lod,
68  UT_Vector3Array &pos, unsigned du=0) const;
69 
70  /// Implementation of NURBS evaluation
71  virtual int evaluateBreakSegment(int ustart, int uend,
72  int lod, GA_Offset *vertices,
73  GA_AttributeRefMap &h, uint du=0) const;
74 
75  // Given a CV index figure out the min/max indicies of the knots between
76  // which the curve needs to be re-evaluated if the CV changes. If not
77  // given a valid CV index, the method returns -1. Otherwise it returns 0.
78  // If the curve wraps the domain we return will be rather large.
79  virtual int domainRangeOfCV(int cvidx, int &mink,int &maxk) const;
80 
81  // Convert a topologically open curve into a topologically closed one.
82  // The rounded flag is mainly for surface end caps to indicate a half cap
83  // or a full cap.
84  virtual void close(int rounded = 1, int preserveShape = 0);
85 
86  // Convert a topologically closed curve into a topologically open one.
87  virtual void open(int preserveShape = 0, int = 0);
88 
89  // Check if the basis interpolates the endpoints, or change the flag.
90  short interpolatesEnds(void) const;
91  void toggleEndCondition(void);
92 
93  // Insert or delete vertices. The insertion methods return the index if
94  // successful and -1 otherwise. The deletion methods return 0 if ok and
95  // -1 otherwise. The insertion methods create the point if it does not
96  // exist.
97  virtual GA_Size insertVertex(GA_Offset ptoff=GA_INVALID_OFFSET, GA_Size where=0);
99  virtual int deleteVertex(GA_Size i);
100 
101  // Shift the array of vertices by an offset and wrap around.
102  // Cycle a subrange if the curve is closed and cycle the basis
103  // accordingly. The offset can be either negative or positive.
104  // Optionally remap the new basis to the original length and origin
105  virtual int cycle(int amount, int keepSpan = 1);
106 
107  // Reverses the vertices of the curve.
108  virtual void reverse();
109 
110  // Build a trim loop (which will be open unless the face is closed). The
111  // loop is build every time you call this method, so it's expensive. You
112  // must free the loop yourself when you are done with it. The trim pieces
113  // are generated in the [ustart,ustop] or [ustop,ustart] interval, where
114  // ustart and ustop are parametric values.
115  virtual GD_TrimLoop *trimLoop(float ustart, float ustop) const;
116 
117 protected:
118  // Get a new basis of a type that matches our type:
119  virtual GA_Basis *newBasis() const;
120 
121  /// All subclasses should call this method to register the NURBCurve
122  /// intrinsics.
123  /// @see GA_AttributeIntrinsic
126  { return GD_Curve::registerIntrinsics(definition); }
127 
128 private:
129  // Fill the curve with data and build the basis. Return 0 if OK, and -1
130  // if error.
131  int create(int nelems, int order=4, int closed = 0,
132  int interpEnds = 1, int appendPoints = 1);
133 
134  friend class GD_PrimitiveFactory;
135 
136  static GA_PrimitiveDefinition *theDefinition;
137 };
138 
139 #endif
virtual int evaluateBasis(fpreal u, fpreal *ubvals, int &cvoffset, unsigned du=0, int uoffset=-1) const =0
virtual GA_Size appendVertex(GA_Offset ptoff=GA_INVALID_OFFSET)
virtual ~GD_PrimNURBCurve()
virtual int evaluateBasisDerivs(fpreal u, fpreal bmatx[][GA_MAXORDER], int &cvoffset, unsigned du=0, int uoffset=-1) const =0
#define GA_MAXORDER
Definition: GA_Defines.h:17
virtual GD_TrimLoop * trimLoop(float ustart, float ustop) const =0
virtual void open(int preserveShape=0, int safe=0)
static GA_IntrinsicManager::Registrar rerIntrinsics(GA_PrimitiveDefinition &definition)
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
GA_Size GA_Offset
Definition: GA_Types.h:617
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Curve.h:190
virtual void reverse()
GLintptr offset
Definition: glcorearb.h:664
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
GD_PrimNURBCurve(GD_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
virtual int evaluateBreakSegment(int ustart, int uend, int lod, GA_Offset *vertices, GA_AttributeRefMap &h, uint du=0) const
Implementation for curves.
A handle to simplify manipulation of multiple attributes.
unsigned int uint
Definition: SYS_Types.h:33
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:263
virtual void close(int rounded=1, int preserveShape=0)
#define GD_API
Definition: GD_API.h:10
virtual int deleteVertex(GA_Size i)
virtual int domainRangeOfCV(int cvidx, int &mink, int &maxk) const =0
virtual int cycle(int amount, int=1)
Definition of a geometric primitive.
virtual const GA_PrimitiveDefinition & getTypeDef() const =0
int create(GD_Curve *crv, int nelems, int closed, int appendPoints=1)
virtual GA_Size insertVertex(GA_Offset ptoff=GA_INVALID_OFFSET, GA_Size where=0)
virtual GA_Basis * newBasis() const =0
virtual bool evaluateBreakSegm(int uStartIdx, int uStopIdx, int lod, UT_Vector3Array &pos, unsigned du=0) const
GLint lod
Definition: glcorearb.h:2764