HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GD_PrimRBezCurve() {}
32 
33  static void registerDefinition(GA_PrimitiveFactory &factory);
34 
35  virtual const GA_PrimitiveDefinition &getTypeDef() const;
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.
47  virtual int evaluateBasisDerivs(fpreal u,
48  fpreal bmatx[][GA_MAXORDER],
49  int &cvoffset, unsigned du = 0,
50  int uoffset = -1) const;
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  virtual int evaluateBasis(fpreal u, fpreal *ubvals,
59  int &cvoffset, unsigned du=0,
60  int uoffset=-1) const;
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  virtual bool evaluateBreakSegm(int uStartIdx, int uStopIdx, int lod,
70  UT_Vector3Array &pos, unsigned du=0) const;
71 
72  /// Implementation of rational bezier evaluation
73  virtual int evaluateBreakSegment(int ustart, int uend,
74  int lod, GA_Offset *vertices,
75  GA_AttributeRefMap &h, uint du=0) const;
76 
77  // Remove all repeated vertices - (only gets consecutive vertices)
78  virtual int removeRepeatedVertices(int check_order = 0);
79 
80  // Given a CV index figure out the min/max indicies of the knots between
81  // which the curve needs to be re-evaluated if the CV changes. If not
82  // given a valid CV index, the method returns -1. Otherwise it returns 0.
83  // If the curve wraps the domain we return will be rather large.
84  virtual int domainRangeOfCV(int cvidx, int &mink,int &maxk) const;
85 
86  // Close up an open curve.
87  virtual void close(int rounded = 1, int preserveShape = 0);
88 
89  // Open up a closed curve.
90  virtual void open(int preserveShape = 0, int safe = 0);
91 
92  // Insert or delete vertices. The insertion methods return the index if
93  // successful and -1 otherwise. The deletion methods return 0 if ok and
94  // -1 otherwise. The insertion methods create the point if it does not
95  // exist.
96  virtual GA_Size insertVertex(GA_Offset ptoff=GA_INVALID_OFFSET, GA_Size where=0);
98  virtual int deleteVertex(GA_Size i);
99 
100  // Reverses the vertices of the curve.
101  virtual void reverse();
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  virtual GD_TrimLoop *trimLoop(float ustart, float ustop) const;
109 
110 
111 protected:
112  // Get a new basis of a type that matches our type:
113  virtual GA_Basis *newBasis() const;
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(void);
124  void closeRounded(void);
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)
virtual GA_Size appendVertex(GA_Offset ptoff=GA_INVALID_OFFSET)
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &definition)
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)
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
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:39
virtual ~GD_PrimRBezCurve()
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:269
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
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
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