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