HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_PrimRBezSurf.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 RBezier defined by
10  * a set of breakpoints, basis functions, and CVs.
11  *
12  *
13  */
14 
15 #ifndef __GEO_PrimRBezSurf_h__
16 #define __GEO_PrimRBezSurf_h__
17 
18 #include "GEO_API.h"
19 #include "GEO_TPSurf.h"
20 #include "GEO_PrimType.h"
21 
23 {
24 protected:
25  /// NOTE: The constructor should only be called from subclass
26  /// constructors.
28  : GEO_TPSurf(d, offset)
29  {}
30 
31  /// NOTE: The destructor should only be called from subclass
32  /// destructors.
33  /// Please read the comments on the parent class destructor.
34  virtual ~GEO_PrimRBezSurf() {}
35 
36 public:
37  // Given a domain value (u,v), store all the basis derivatives
38  // (from 0 to du and from 0 to dv inclusive) into ubmatx and vbmatx
39  // respectively. Return the min indices of the CVs needed
40  // for the linear combination. The indices may exceed the number of
41  // vertices if the surface is wrapped, so remember to use modulus (%).
42  virtual int evaluateBasisDerivs(float u, float v,
43  float ubmatx[][GA_MAXORDER],
44  float vbmatx[][GA_MAXORDER],
45  int &rowoffset, int &coloffset,
46  unsigned du=0, unsigned dv=0,
47  int uoffset=-1, int voffset=-1) const;
48 
49  // Evaluate the basis at the given point in the domain and also return
50  // the index of the first CV to linearly combine the basis with. The CV
51  // indices may exceed the number of vertices if the surface is wrapped,
52  // so remember to use modulus (%).
53  virtual int evaluateBasis(float u, float v, float *ubvals,
54  float *vbvals, int &rowoffset,
55  int &coloffset,
56  unsigned du=0, unsigned dv=0,
57  int uoffset=-1, int voffset=-1) const;
58  virtual int evaluateUBasis(float u, float *ubvals, int &coloffset,
59  unsigned du=0, int uoffset=-1) const;
60  virtual int evaluateVBasis(float v, float *vbvals, int &rowoffset,
61  unsigned dv=0, int voffset=-1) const;
62 
63  // Compute the location of the breakpoint. Return 0 if OK, else -1.
64  virtual int evaluateBreakpoint(int uidx, int vidx,
65  UT_Vector4 &pos,
66  int du=0, int dv=0) const;
67 
68  // Given a CV index figure out the min/max indicies of the knots between
69  // which the curve needs to be re-evaluated if the CV changes. If not
70  // given a valid CV index, the method returns -1. Otherwise it returns 0.
71  virtual int domainRangeOfCV(int i, int j, int &minuk,int &maxuk,
72  int &minvk,int &maxvk) const;
73 
74  // Given a CV index figure out the min/max breakpoints which are
75  // affected if the CV changes. If not given a valid CV index, the
76  // method returns -1. Otherwise it returns 0. Also returns -1 if
77  // no breakpoints are affected.
78  // NOTE: use % breakCount since maxbkp may be >= breakCount
79  virtual int breakpointRangeOfCV(int i, int j, int &minbkpu,
80  int &maxbkpu, int &minbkpv,
81  int &maxbkpv) const;
82 
83  // Reparameterize the surface by changing its basis. The first breakpoint
84  // is not changed.
85  virtual void reparameterizeU(GA_ParameterizationType ptype);
86  virtual void reparameterizeV(GA_ParameterizationType ptype);
87 
88  // Insert a breakpoint at the given point in the domain and return its
89  // index if successful. Return -1 in case of failure (eg. if outside the
90  // valid domain or equal to an existing breakpoint).
91  virtual int refineU(float k, GA_AttributeRefMap &hlist, int=1);
92  virtual int refineU (float k, int=1);
93 
94  virtual int refineV(float k, GA_AttributeRefMap &hlist, int=1);
95  virtual int refineV (float k, int=1);
96 
97  // To gain access to the GEO_AttributeHandleList versions of refine()
98  using GEO_Hull::refineU;
99  using GEO_Hull::refineV;
100 
101  // Set the wrap or open flag, and make sure the basis knot vectors are
102  // consistent with the change. These functions are virtual by inheritance.
103  // TODO-CB: increase the size of the knot vector if necessary.
104 
105  // Wrap in the specified U/V direction.
106  //
107  // If preserveShape = 1:
108  // add extra row/col cvs at the end to define the last span.
109  // if rounded,
110  // the new cvs just added will be arranged to give a
111  // rounded appearance in the specified U/V direction.
112  // else
113  // the new cvs just added will form a plane
114  // between the first and last row/col endpoint.
115  // If preserveShape = 0:
116  // just grow the U/V basis by one span, without adding any
117  // new cvs and ignore the rounded flag.
118  virtual void wrapU(int rounded = 1, int preserveShape = 0);
119  virtual void wrapV(int rounded = 1, int preserveShape = 0);
120 
121  // Open in the specified U/V direction.
122  //
123  // If preserveShape = 1:
124  // the open surface will have exactly the same geometry
125  // (ie. still look closed) with the first row/col point
126  // duplicated.
127  // If preserveShape = 0:
128  // the open surface will remove the last span in the basis,
129  // thus open up a gap in the surface.
130  // last few row/col cvs are dangling which do not form a valid
131  // surface patch, if the safe flag = 0.
132  // The safe flag is to remove unneed cvs for ensuring the resulting
133  // surface is a valid bezier surface.
134  virtual void openU(int preserveShape = 0, int safe = 0);
135  virtual void openV(int preserveShape = 0, int safe = 0);
136 
137  // Insert or remove rows and columns. The insertion returns the index if
138  // successful. The deletion methods return 0 if ok. If failure, return -1.
139  virtual int insertRow(unsigned int beforeWhich, bool appendPts=true);
140  virtual int insertCol(unsigned int beforeWhich, bool appendPts=true);
141  virtual int deleteRow(unsigned int which);
142  virtual int deleteCol(unsigned int which);
143 
144  // Find the max u and v indices of the bases:
145  virtual int uMaxValidIndex(void) const;
146  virtual int vMaxValidIndex(void) const;
147 
148  // Raise the number of CVs to match the newcount. The shape of the curve
149  // (especially if parametric) should NOT change. Return 0 upon success
150  // and -1 otherwise. start and stop define which indices to examine
151  // if newcount is negative it is taken as a relative value.
152  virtual int loftU(int newcount, int start=-1, int stop=-1);
153  virtual int loftV(int newcount, int start=-1, int stop=-1);
154 
155  // Warp the mesh at u,v by the given delta. Change 1 or 4 Cvs and possibly
156  // insert a knot once or more as well. If a knot is inserted or we happen
157  // to land exactly on a knot, we change only one CV. The bias makes sense
158  // only when changing 4 CVs, and will be ignored altogether if < 0.
159  // We return the CV index in warpU/V and 0 in warp() if OK; -1 otherwise.
160  virtual int warpU(float u, const UT_Vector3 &delta,
161  GA_AttributeRefMap &map,
162  float sharpness = 0.0f, float bias = -1.0f);
163  virtual int warpV(float v, const UT_Vector3 &delta,
164  GA_AttributeRefMap &map,
165  float sharpness = 0.0f, float bias = -1.0f);
166  virtual int warp (float u, float v, const UT_Vector3 &delta,
167  GA_AttributeRefMap &map,
168  float usharpness = 0.f, float vsharpness = 0.f,
169  float ubias = -1.0f, float vbias = -1.0f);
170 
171  virtual int unrollU(int append_pts = 1);
172  virtual int unrollV(int append_pts = 1);
173 
174  // Reverse rows (V) or columns (U). Reversing in either direction will
175  // flip the normal.
176  virtual void reverseU(void);
177  virtual void reverseV(void);
178 
179  // Translate the CVs such that the given breakpoint change positions by
180  // the given delta. Return -1 if something goes wrong, 0 if translation
181  // was successful.
182  // NOTE: Cannot contain any duplicates. If the surface is wrapped,
183  // the first and last breakpoint are considered the same.
184  virtual int translateBreakpoints(const UT_IntArray &uindices,
185  const UT_IntArray &vindices,
186  const UT_Vector3 &delta,
187  int fixbpkts = 1,
188  GA_PointGroup *ptgroup=NULL,
189  GEO_Delta *geodelta = 0);
190 
191  virtual int transformBreakpoints(const UT_IntArray &uindices,
192  const UT_IntArray &vindices,
193  const UT_Matrix4 &matx,
194  int fixbpkts = 1,
195  GA_PointGroup *ptgroup=NULL,
196  GEO_Delta *geodelta = 0);
197 
198  // Append another hull to us in one of two ways: blend the two endpoints
199  // or connect them straight or rounded. The bias ranges from 0 to 1 and is
200  // relevant only to blending. The tolerance for blending: if 0, the two
201  // endpoints will merge into one point with a discontinuity; if less than
202  // 1, we insert knots into the hulls to minimize the affected areas; if 1,
203  // no refinement is done. For the non-blend case, the tolerance will
204  // generate a span whose shape goes from round to straight; 0 tolerance
205  // means straight connection. If unrefine is on, we'll try to reduce the
206  // complexity of the hull if we're connecting rounded. We return 0 if OK
207  // and -1 if error. Both hulls must be open and have the same order.
208  virtual int attachU(const GEO_Hull &hull, int blend = 1,
209  float bias = 0.5f, float tolerance = 1.0f,
210  int = 1, GA_PointGroup *ptgroup=0);
211  virtual int attachV(const GEO_Hull &hull, int blend = 1,
212  float bias = 0.5f, float tolerance = 1.0f,
213  int = 1, GA_PointGroup *ptgroup=0);
214 
215  // If [ustart,ustop] and [vstart,vstop] are in the valid interval, return
216  // the part of the surface delimited by those values in a new primitive.
217  // Return 0 if a problem is encountered.
218  virtual GEO_TPSurf *extract(float ustart, float ustop,
219  float vstart, float vstop) const;
220 
221  // Reverse the roles of rows and columns
222  virtual void transpose();
223 
224  virtual const GA_PrimitiveJSON *getJSON() const;
225 
226 protected:
228  { return GEO_TPSurf::buildFamilyMask(); }
229 
230  /// All subclasses should call this method to register the curve intrinsics.
231  /// @see GA_IntrinsicManager
234  { return GEO_TPSurf::registerIntrinsics(defn); }
235 
236  // Get a new basis of a type that matches our type:
237  virtual GA_Basis *newBasis(void) const;
238 
239  // increase order by 1.
240  void incrementOrderU(void);
241  void incrementOrderU(GA_AttributeRefMap &map);
242 
243  void incrementOrderV(void);
244  void incrementOrderV(GA_AttributeRefMap &map);
245 
246  // Increase the order. Return 0 if successful, -1 otherwise (eg.
247  // order cannot be increased because it's >= MAXORDER).
248  virtual int raiseOrderURefMap(int neworder, GA_AttributeRefMap &m);
249  virtual int raiseOrderUInt (int neworder);
250  virtual int raiseOrderVRefMap(int neworder, GA_AttributeRefMap &m);
251  virtual int raiseOrderVInt (int neworder);
252 
253 private:
254  // Nothing.
255 };
256 #endif
virtual int loftV(int newcount, int start=-1, int stop=-1)=0
virtual int insertRow(unsigned int beforeWhich, bool appendPts=true)
virtual int refineU(float k, GA_AttributeRefMap &hlist, int i=1)
virtual int unrollU(int append_pts=1)
virtual ~GEO_PrimRBezSurf()
virtual int raiseOrderVInt(int neworder)=0
virtual void openU(int preserveShape=0, int safe=0)
virtual int evaluateBreakpoint(int uidx, int vidx, UT_Vector4 &pos, int du=0, int dv=0) const =0
virtual void reverseV(void)
virtual void reverseU(void)
virtual int evaluateBasisDerivs(float u, float v, float ubmatx[][GA_MAXORDER], float vbmatx[][GA_MAXORDER], int &rowoffset, int &coloffset, unsigned du=0, unsigned dv=0, int uoffset=-1, int voffset=-1) const =0
const GLdouble * v
Definition: glcorearb.h:836
GLuint start
Definition: glcorearb.h:474
virtual int attachV(const GEO_Hull &hull, int blend=1, float bias=0.5f, float tolerance=1.0f, int unrefine=1, GA_PointGroup *ptgroup=0)
virtual int warp(float u, float v, const UT_Vector3 &delta, GA_AttributeRefMap &map, float usharpness=0.0f, float vsharpness=0.f, float ubias=-1.0f, float vbias=-1.0f)=0
virtual GA_Basis * newBasis(void) const =0
#define GA_MAXORDER
Definition: GA_Defines.h:17
virtual int deleteCol(unsigned int which)
virtual int warpU(float u, const UT_Vector3 &delta, GA_AttributeRefMap &map, float sharpness=0.0f, float bias=-1.0f)=0
virtual void wrapU(int rounded=1, int preserveShape=0)
virtual int raiseOrderUInt(int neworder)=0
virtual int refineV(float k, GA_AttributeRefMap &hlist, int i=1)
3D Vector class.
png_uint_32 i
Definition: png.h:2877
virtual int domainRangeOfCV(int i, int j, int &minuk, int &maxuk, int &minvk, int &maxvk) const =0
GA_PrimitiveFamilyMask
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
virtual int insertCol(unsigned int beforeWhich, bool appendPts=true)
virtual int warpV(float v, const UT_Vector3 &delta, GA_AttributeRefMap &map, float sharpness=0.0f, float bias=-1.0f)=0
GA_ParameterizationType
Definition: GA_Types.h:173
virtual int vMaxValidIndex() const
GA_Size GA_Offset
Definition: GA_Types.h:617
GLfloat f
Definition: glcorearb.h:1925
virtual int breakpointRangeOfCV(int i, int j, int &minbkpu, int &maxbkpu, int &minbkpv, int &maxbkpv) const =0
virtual int evaluateUBasis(float u, float *ubvals, int &coloffset, unsigned du=0, int uoffset=-1) const =0
virtual const GA_PrimitiveJSON * getJSON() const =0
GLintptr offset
Definition: glcorearb.h:664
virtual void openV(int preserveShape=0, int safe=0)
Provide a JSON interface to a primitive.
#define GEO_API
Definition: GEO_API.h:10
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
virtual void reparameterizeV(GA_ParameterizationType ptype)=0
A handle to simplify manipulation of multiple attributes.
virtual int evaluateBasis(float u, float v, float *ubvals, float *vbvals, int &rowoffset, int &coloffset, unsigned du=0, unsigned dv=0, int uoffset=-1, int voffset=-1) const =0
virtual void reparameterizeU(GA_ParameterizationType ptype)=0
virtual GEO_TPSurf * extract(float ustart, float ustop, float vstart, float vstop) const =0
virtual void wrapV(int rounded=1, int preserveShape=0)
virtual int translateBreakpoints(const UT_IntArray &uindices, const UT_IntArray &vindices, const UT_Vector3 &delta, int fixbkpts=1, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)=0
virtual int loftU(int newcount, int start=-1, int stop=-1)=0
static GA_PrimitiveFamilyMask buildFamilyMask()
virtual void transpose()
virtual int uMaxValidIndex() const
virtual int evaluateVBasis(float v, float *vbvals, int &rowoffset, unsigned dv=0, int voffset=-1) const =0
Container class for all geometry.
Definition: GA_Detail.h:96
Definition of a geometric primitive.
GEO_PrimRBezSurf(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
virtual int deleteRow(unsigned int which)
static GA_IntrinsicManager::Registrar registerIntrinsics(GA_PrimitiveDefinition &defn)
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_TPSurf.h:643
virtual int raiseOrderVRefMap(int neworder, GA_AttributeRefMap &map)=0
virtual int raiseOrderURefMap(int neworder, GA_AttributeRefMap &map)=0
virtual int attachU(const GEO_Hull &hull, int blend=1, float bias=0.5f, float tolerance=1.0f, int unrefine=1, GA_PointGroup *ptgroup=0)
virtual int transformBreakpoints(const UT_IntArray &uindices, const UT_IntArray &vindices, const UT_Matrix4 &matx, int fixbkpts=1, GA_PointGroup *ptgroup=NULL, GEO_Delta *geodelta=0)=0
virtual int unrollV(int append_pts=1)