HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GD_PrimRBezCurve.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 piecewise Bezier curve defined by
10  * a set of breakpoints, basis function, and CVs.
11  *
12  */
13 
14 #ifndef __GD_PrimRBezCurve_h__
15 #define __GD_PrimRBezCurve_h__
16 
17 #include "GD_API.h"
18 #include "GD_Curve.h"
19 #include "GD_PrimType.h"
20 #include <GA/GA_BezBasis.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_PrimRBezCurve() override {}
32 
33  static void registerDefinition(GA_PrimitiveFactory &factory);
34 
35  const GA_PrimitiveDefinition &getTypeDef() const override;
36 
37  // Build a new curve and insert it into the given detail.
38  static GD_PrimRBezCurve *build(GD_Detail *gudp,
39  int nelems, int order = 4, int closed=0,
40  int appendPoints = 1);
41 
42  // Given a domain value (u), store all the basis derivatives (from 0 to du
43  // inclusive) into bmatx. Return the first index of the CVs needed for the
44  // linear combination in cvoffset. The CV index may exceed the number of
45  // vertices if the curve is wrapped, so remember to use modulus (%).
46  // Return 0 if successful, and -1 otherwise.
48  fpreal bmatx[][GA_MAXORDER],
49  int &cvoffset, unsigned du = 0,
50  int uoffset = -1) const override;
51 
52  // Evaluate the basis at the given point in the domain and also return
53  // the index of the first CV to linearly combine the basis with in cvoffset.
54  // The CV index may exceed the number of vertices if the curve is wrapped,
55  // so remember to use modulus (%). This method handles both rational and
56  // non-rational curves.
57  // Return 0 if successful, and -1 otherwise.
58  int evaluateBasis(fpreal u, fpreal *ubvals,
59  int &cvoffset, unsigned du=0,
60  int uoffset=-1) const override;
61 
62  // Curve evaluator that takes a start and a stop index
63  // in the valid knot domain and an lod representing number of points to
64  // be interpolated between every two breakpoints. The method ALWAYS
65  // interpolates the encountered breakpoints (aka "edit points").
66  // This returns true if successful, else false. Please save
67  // yourself headaches and pass VALID start and end indices (see the
68  // method getValidInterval() in GA_Basis).
69  bool evaluateBreakSegm(int uStartIdx, int uStopIdx,
70  int lod, UT_Vector3Array &pos,
71  unsigned du=0) const override;
72 
73  // Remove all repeated vertices - (only gets consecutive vertices)
74  int removeRepeatedVertices(int check_order = 0) override;
75 
76  // Given a CV index figure out the min/max indicies of the knots between
77  // which the curve needs to be re-evaluated if the CV changes. If not
78  // given a valid CV index, the method returns -1. Otherwise it returns 0.
79  // If the curve wraps the domain we return will be rather large.
80  int domainRangeOfCV(int cvidx,
81  int &mink,int &maxk) const override;
82 
83  // Close up an open curve.
84  void close(int rounded = 1, int preserveShape = 0) override;
85 
86  // Open up a closed curve.
87  void open(int preserveShape = 0, int safe = 0) override;
88 
89  // Insert or delete vertices. The insertion methods return the index if
90  // successful and -1 otherwise. The deletion methods return 0 if ok and
91  // -1 otherwise. The insertion methods create the point if it does not
92  // exist.
95  GA_Size where=0) override;
97  GA_Offset ptoff=GA_INVALID_OFFSET) override;
98  int deleteVertex(GA_Size i) override;
99 
100  // Reverses the vertices of the curve.
101  void reverse() override;
102 
103  // Build a trim loop (which will be open unless the face is closed). The
104  // loop is build every time you call this method, so it's expensive. You
105  // must free the loop yourself when you are done with it. The trim pieces
106  // are generated in the [ustart,ustop] or [ustop,ustart] interval, where
107  // ustart and ustop are parametric values.
108  GD_TrimLoop *trimLoop(float ustart, float ustop) const override;
109 
110 
111 protected:
112  // Get a new basis of a type that matches our type:
113  GA_Basis *newBasis() const override;
114 
115  /// All subclasses should call this method to register the BezierCurve
116  /// intrinsics.
117  /// @see GA_AttributeIntrinsic
120  { return GD_Curve::registerIntrinsics(definition); }
121 
122  // Two different closing methods:
123  void closeSharp();
124  void closeRounded();
125 
126 
127 private:
128  // Fill the curve with data and build the basis. Return 0 if OK, and -1
129  // if error.
130  int create(int nelems, int order = 4, int closed = 0,
131  int appendPoints = 1);
132 
133  // Find out if a curve segment is straight:
134  int isSegmentCollinear(int i) const;
135 
136  friend class GD_PrimitiveFactory;
137 
138  static GA_PrimitiveDefinition *theDefinition;
139 };
140 
141 #endif
virtual int evaluateBasis(fpreal u, fpreal *ubvals, int &cvoffset, unsigned du=0, int uoffset=-1) const =0
virtual int removeRepeatedVertices(int check_order=0)
~GD_PrimRBezCurve() override
virtual GA_Size appendVertex(GA_Offset ptoff=GA_INVALID_OFFSET)
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
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)
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
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
virtual void close(int rounded=1, int preserveShape=0)
GD_PrimRBezCurve(GD_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
#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
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