HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~GD_PrimNURBCurve() override {}
32 
33  const GA_PrimitiveDefinition &getTypeDef() const override;
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.
46  fpreal bmatx[][GA_MAXORDER],
47  int &cvoffset, unsigned du = 0,
48  int uoffset = -1) const override;
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  int evaluateBasis(fpreal u, fpreal *ubvals,
57  int &cvoffset, unsigned du=0,
58  int uoffset=-1) const override;
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  bool evaluateBreakSegm(int uStartIdx, int uStopIdx,
68  int lod, UT_Vector3Array &pos,
69  unsigned du=0) const override;
70 
71  // Given a CV index figure out the min/max indicies of the knots between
72  // which the curve needs to be re-evaluated if the CV changes. If not
73  // given a valid CV index, the method returns -1. Otherwise it returns 0.
74  // If the curve wraps the domain we return will be rather large.
75  int domainRangeOfCV(int cvidx,
76  int &mink,int &maxk) const override;
77 
78  // Convert a topologically open curve into a topologically closed one.
79  // The rounded flag is mainly for surface end caps to indicate a half cap
80  // or a full cap.
81  void close(int rounded = 1, int preserveShape = 0) override;
82 
83  // Convert a topologically closed curve into a topologically open one.
84  void open(int preserveShape = 0, int = 0) override;
85 
86  // Check if the basis interpolates the endpoints, or change the flag.
87  short interpolatesEnds() const;
88  void toggleEndCondition();
89 
90  // Insert or delete vertices. The insertion methods return the index if
91  // successful and -1 otherwise. The deletion methods return 0 if ok and
92  // -1 otherwise. The insertion methods create the point if it does not
93  // exist.
96  GA_Size where=0) override;
98  GA_Offset ptoff=GA_INVALID_OFFSET) override;
99  int deleteVertex(GA_Size i) override;
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  int cycle(int amount, int keepSpan = 1) override;
106 
107  // Reverses the vertices of the curve.
108  void reverse() override;
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  GD_TrimLoop *trimLoop(float ustart, float ustop) const override;
116 
117 protected:
118  // Get a new basis of a type that matches our type:
119  GA_Basis *newBasis() const override;
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)
bool evaluateBreakSegm(int uStartIdx, int uStopIdx, int lod, UT_Vector3Array &pos, unsigned du=0) const override
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)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
#define GA_INVALID_OFFSET
Definition: GA_Types.h:678
GA_Size GA_Offset
Definition: GA_Types.h:641
GLintptr offset
Definition: glcorearb.h:665
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
Definition: GD_Curve.h:187
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)
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
virtual void close(int rounded=1, int preserveShape=0)
#define GD_API
Definition: GD_API.h:10
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual int deleteVertex(GA_Size i)
virtual int domainRangeOfCV(int cvidx, int &mink, int &maxk) const =0
virtual int cycle(int amount, int=1)
~GD_PrimNURBCurve() override
Definition of a geometric primitive.
virtual const GA_PrimitiveDefinition & getTypeDef() const =0
void reverse() override
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
GLint lod
Definition: glcorearb.h:2765