HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_TPSurf.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 handles tensor product (TP) surfaces of arbitrary degree.
10  * The Hull class maintains the hull for the surface.
11  *
12  *
13  */
14 
15 #ifndef __GEO_TPSurf_h__
16 #define __GEO_TPSurf_h__
17 
18 #include "GEO_API.h"
19 #include <UT/UT_BoundingRect.h>
20 #include <UT/UT_RefMatrix.h>
21 #include <UT/UT_IntArray.h>
22 #include <UT/UT_Interval.h>
23 #include <UT/UT_Matrix.h>
24 #include <GA/GA_Basis.h>
25 #include <GA/GA_GenericHandle.h>
26 #include "GEO_Hull.h"
27 #include "GEO_PrimType.h"
28 
29 class GU_IsectCurveSet;
30 class GEO_Curve;
31 class GEO_Delta;
32 class GEO_Face;
33 class GEO_Greville;
34 class GEO_PasteSurf;
35 class GEO_Profiles;
37 class GA_Detail;
38 template<bool isconst> class GA_PwHandle;
41 class UT_MemoryCounter;
42 
43 class GEO_API GEO_TPSurf : public GEO_Hull
44 {
45 protected:
46  /// NOTE: The constructor should only be called from subclass
47  /// constructors.
48  // You can optionally specify the number of rows and columns.
50  : GEO_Hull(d, offset)
51  , myUBasis(NULL)
52  , myVBasis(NULL)
53  , theProfiles(NULL)
54  , thePasteSurf(NULL)
55  {}
56 
57  /// NOTE: The destructor should only be called from subclass
58  /// destructors.
59  // It assumes it is OK to delete the bases, so make sure you always
60  // set the bases with objects allocated from the heap.
61  virtual ~GEO_TPSurf();
62 
63 public:
64  // Return any dependent details (GEO_Profiles)
65  virtual unsigned getNumSecondaryDetails() const;
66  virtual const GA_Detail *getSecondaryDetail(GA_Index i) const;
68 
69  // Overwrite this surface with the data from src. Virtual by inheritance.
70  virtual void copyPrimitive( const GEO_Primitive *src);
71  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
72 
73  virtual void copySubclassData(const GA_Primitive *source);
74 
75  virtual void clearForDeletion();
76 
77  // Merge tpsurf's profiles into ours. Skin invisible ones if you want.
78  void mergeProfiles(const GEO_TPSurf &tpsurf,
79  int onlyvisible = 0);
80 
81 
82  // Evaluate one point (when du=dv=0), or the du-th dv-th derivative.
83  // Return 0 if successful, and -1 otherwise.
84  bool evaluate(fpreal u, fpreal v, GA_Offset result_vtx,
85  GA_AttributeRefMap &hlist,
86  unsigned du=0, unsigned dv=0,
87  int uoffset=-1, int voffset=-1) const;
88  int evaluateHomogeneous(float u, float v, UT_Vector4 &pos,
89  unsigned du=0, unsigned dv=0,
90  int uoffset=-1, int voffset=-1) const;
91  int evaluate(float u, float v, UT_Vector4 &pos,
92  unsigned du=0, unsigned dv=0,
93  int uoffset=-1, int voffset=-1) const;
94  virtual void computeInteriorPointWeights(
95  UT_Array<GA_Offset> &vtxlist,
96  UT_Array<float> &weightlist,
97  fpreal u, fpreal v, fpreal w) const;
98 
99  template <typename T>
100  bool evaluateHomogeneous(fpreal u, fpreal v,
101  const GA_ROGenericHandleVertex<T> &h, T &pos,
102  unsigned du=0, unsigned dv=0,
103  int uoffset=-1, int voffset=-1) const;
104 
105  // Given a domain value (u,v), store all the basis derivatives
106  // (from 0 to du and from 0 to dv inclusive) into ubmatx and vbmatx
107  // respectively. Return the min indices of the CVs needed
108  // for the linear combination. The indices may exceed the number of
109  // vertices if the surface is wrapped, so remember to use modulus (%).
110  virtual int evaluateBasisDerivs(float u, float v,
111  float ubmatx[][GA_MAXORDER],
112  float vbmatx[][GA_MAXORDER],
113  int &rowoffset, int &coloffset,
114  unsigned du=0, unsigned dv=0,
115  int uoffset=-1, int voffset=-1) const = 0;
116 
117  // Evaluate the basis at the given point in the domain and also return
118  // the index of the first CV to linearly combine the basis with. The CV
119  // indices may exceed the number of vertices if the surface is wrapped,
120  // so remember to use modulus (%).
121  virtual int evaluateBasis(float u, float v, float *ubvals,
122  float *vbvals, int &rowoffset,
123  int &coloffset,
124  unsigned du=0, unsigned dv=0,
125  int uoffset=-1, int voffset=-1) const = 0;
126  virtual int evaluateUBasis(float u, float *ubvals, int &coloffset,
127  unsigned du=0, int uoffset=-1) const = 0;
128  virtual int evaluateVBasis(float v, float *vbvals, int &rowoffset,
129  unsigned dv=0, int voffset=-1) const = 0;
130 
131  // Return the value of the i'th u/vbasis at parameter u or v, or both.
132  // This method handles both rational an non-rational surfaces. You need
133  // to specify the row and column index only if the surface is rational,
134  // so that we know whose weights to use.
135  float computeUBValue(float u, int uoff) const;
136  float computeVBValue(float v, int voff) const;
137  float computeBValue (float u,float v,int uoff,int voff)const;
138 
139  // Fill in parameter values that interpolate breakpoints. The start
140  // and stop indices are breakpoint indices. lod specifies the number
141  // of isoparms to insert between breakpoints in each dimension.
142  void fillBreakParameters(UT_FloatArray &uvals,
143  UT_FloatArray &vvals,
144  int ustartidx, int ustopidx,
145  int vstartidx, int vstopidx,
146  int ulod, int vlod) const;
147 
148  // Evaluate the surface for the given parameter arrays. The provided
149  // result array should provide storage for
150  // uvals.entries()*vvals.entries() values.
151  bool evaluateMesh(const UT_FloatArray &uvals,
152  const UT_FloatArray &vvals,
153  UT_Vector4 *pos,
154  bool transpose = false,
155  unsigned du = 0, unsigned dv = 0) const;
156  bool evaluateMesh(const UT_FloatArray &uvals,
157  const UT_FloatArray &vvals,
158  GEO_WorkVertexArray &verts,
160  bool transpose = false,
161  unsigned du = 0, unsigned dv = 0) const;
162  bool evaluateMesh(const UT_FloatArray &uvals,
163  const UT_FloatArray &vvals,
164  GA_WorkVertexBuffer &verts,
165  GA_AttributeRefMap &map,
166  bool transpose = false,
167  unsigned du = 0, unsigned dv = 0) const;
168 
169  // Explicit instantiations are provided for float, UT_Vector3,
170  // UT_Vector4, UT_Matrix3, UT_Matrix4, GA_Offset
171  template <typename T>
172  bool evaluateMesh(const UT_FloatArray &uvals,
173  const UT_FloatArray &vvals,
175  T *pos,
176  bool transpose = false,
177  unsigned du = 0, unsigned dv = 0) const;
178 
179  // Compute the CVs of the U or V isoparametric curve running through
180  // the given parametric value. The number of resulting CVs equals the
181  // number or rows (if v = const.) or cols (if u = const.) respectively.
182  // We return 0 if successful and -1 otherwise. Use these methods to
183  // extract isoparms.
184  int computeUConstCVs(float u, GEO_Face *results,
185  const GA_AttributeRefMap &map,
186  int uoffset=-1) const;
187 
188  int computeUConstCVs(float u, UT_Vector4 *cvs,
189  int uoffset=-1) const;
190 
191  int computeVConstCVs(float v, GEO_Face *results,
192  const GA_AttributeRefMap &map,
193  int voffset=-1) const;
194  int computeVConstCVs(float v, UT_Vector4 *cvs,
195  int voffset=-1) const;
196 
197  // Create a profile curve (curve on surface) at the given isopam value:
198  // Return 0 if successful and -1 otherwise. growtip is a value by which
199  // we grow the tips of the iso line. It's useful to have it non-zero
200  // when trimming.
201  int createUConstProfile(float u, float growtip = 0.0f);
202  int createVConstProfile(float v, float growtip = 0.0f);
203 
204  // Map the given value, defined in our domain, to a value in a chord/arc
205  // length domain computed from our columns (u) or rows (v). Return -1 if
206  // failed and 0 if successful. u and v must live in the valid interval.
207  // Compute the chord-length parameterized basis in U or V for a given
208  // location in our valid interval. Return 0 if OK and -1 otherwise. ubasis
209  // and vbasis will be resized inside these methods if necessary.
210  int chordUBasis(float v, GA_Basis &ub, int voff=-1) const;
211  int chordVBasis(float u, GA_Basis &vb, int uoff=-1) const;
212 
213  // Evaluate the unit normal at (u,v) or at basis indices (iu,iv).
214  // Return 0 if successful, and -1 otherwise.
215  virtual int evaluateNormal(float u,float v, UT_Vector3 &nml) const;
216  virtual int normalIndex(float iu, float iv, UT_Vector3 &nml) const;
217 
218  // Evaluate the curvature at (u,v).
219  // Return 0 if successful, and -1 otherwise.
220  int curvature(float u, float v, float &curv) const;
221 
222  // Evaluate the arc length of the surface within a range. If the
223  // values are invalid, return -1. divs means divisions per span.
224  float arcLength(float u0, float v0, float u1, float v1,
225  int divs = 10) const;
226 
227  // Given a CV index figure out the min/max indicies of the knots between
228  // which the curve needs to be re-evaluated if the CV changes. If not
229  // given a valid CV index, the method returns -1. Otherwise it returns 0.
230  virtual int domainRangeOfCV(int i, int j, int &minuk,int &maxuk,
231  int &minvk,int &maxvk) const=0;
232 
233  // Given a CV index figure out the min/max breakpoints which are
234  // affected if the CV changes. If not given a valid CV index, the
235  // method returns -1. Otherwise it returns 0. Also returns -1 if
236  // no breakpoints are affected.
237  // NOTE: use % breakCount since maxbkp may be >= breakCount
238  virtual int breakpointRangeOfCV(int i, int j, int &minbkpu,
239  int &maxbkpu, int &minbkpv,
240  int &maxbkpv) const = 0;
241 
242  // Reparameterize the surface by changing its basis. This type of
243  // reparameterization is generally NOT shape preserving:
244  virtual void reparameterizeU(GA_ParameterizationType ptype) = 0;
245  virtual void reparameterizeV(GA_ParameterizationType ptype) = 0;
246 
247  // Reverse rows (V) or columns (U). Reversing in either direction will
248  // flip the normal.
249  virtual void reverseU(void);
250  virtual void reverseV(void);
251 
252  // Remap the basis and possibly the profiles too. The origin and length
253  // apply to the whole length of the basis, not just to the valid interval.
254  void mapUBasis(float orig, float len);
255  void mapVBasis(float orig, float len);
256 
257  // Return the bounds of the valid evaluation interval in domain space:
258  // For meshes this refers to cv indices.
259  virtual void validURange(float &ua, float &ub) const;
260  virtual void validVRange(float &va, float &vb) const;
261  virtual void validUInterval(int &a, int &b) const;
262  virtual void validVInterval(int &a, int &b) const;
263 
264  /// Compute the texture coordinates either uniformly of chord length.
265  /// If ptattrib is true we deal with points, else with vertices.
266  /// Returns false iff problems.
267  bool uniformTexture (const GA_RWHandleV3 &txth, bool ptattrib);
268  bool grevilleTexture(const GA_RWHandleV3 &txth, bool ptattrib);
269  bool chordLenTexture(const GA_RWHandleV3 &txth, bool ptattrib);
270 
271  // Compute the UV anc CV images of each Greville point.
272  // resize is expensive: try to avoid it if possible.
273  // Returns true if success
274  bool buildGrevilles(UT_RefMatrix<GEO_Greville> &dest) const;
275 
276  // Compute the _approximate_ first order derivative at
277  // greville[uIdx,vIdx]. None of these methods checks the boundary
278  // conditions on the two indices, so be careful.
279  // They return true iff successful.
280  bool duApprox(const UT_RefMatrix<GEO_Greville> &grevilles,
281  int uIdx, int vIdx, UT_Vector3 &du,
282  int normalize=1, float precision=0.008F) const;
283  bool dvApprox(const UT_RefMatrix<GEO_Greville> &grevilles,
284  int uIdx, int vIdx, UT_Vector3 &du,
285  int normalize=1, float precision=0.008F) const;
286 
287  // Set the coordinates of cv[r,c].
288  // The method returns 0 if OK and -1 if the indices are wrong.
289  int setCV(unsigned r, unsigned c, const UT_Vector4 &v);
290 
291  // Take the weights into consideration or don't. If you do, the surface
292  // becomes a rational, and possibly different algorithms apply. If 'onOff'
293  // is true, this function first checks if any two weights are different
294  // before setting the rational flag to TRUE; if they are all the same,
295  // the surface is set to non-rational (=> faster evaluation). weights()
296  // calls normalizeWeights() to bring the weights to standard form.
297  // Weights that are <= 0 are bumped up to FLT_EPSILON.
298  void weights(unsigned short onOff);
299 
300  // Set the weight of cv[r,c] to w. If the indices are out of bounds, it
301  // returns -1; otherwise it returns 0. Weights that are <= 0 are bumped
302  // up to FLT_EPSILON.
303  int setWeight(unsigned int r, unsigned int c, float w);
304 
305  // Get the weight of cv[r,c]. Return -1 if indices are wrong.
306  float getWeight(unsigned int r, unsigned int c) const;
307 
308  // Find out whether the surface is currently computed as a rational:
309  int isRational() const;
310 
311  // Go from a normalized domain ([0,1]) to the real domain or vice versa.
312  // We look only at the valid interval.
313  virtual void unitToRealDomain(float u_unit, float v_unit,
314  float &u_real, float &v_real) const;
315  virtual void realToUnitDomain(float u_real, float v_real,
316  float &u_unit, float &v_unit) const;
317 
318  // Calculate the real domains for n consecutive operations on the domain
319  // given n normalized domains and the operation
320  virtual void unitToRealSequenceU(float *uunit, float *ureal,
321  int ulen) const;
322 
323  virtual void unitToRealSequenceV(float *vunit, float *vreal,
324  int vlen) const;
325 
326  // Normalize the weights of the control mesh so that edge weights are 1,
327  // and all weights are >= 0 (those that are <= 0 are bumped up to
328  // FLT_EPSILON).
329  void normalizeWeights();
330 
331  // Normalize the domain and optionally shift it to a new origin. Use the
332  // given length if greater than 0.
333  void normalizeDomain(float len = 0.F,float *newuorigin = 0,
334  float *newvorigin = 0);
335 
336  // This function will refine the area bounded by "rect" to have divisions
337  // at least the size of "tol". "rect" passes in the boundary of the
338  // surface that contains the curve to be deformed, and it passes out the
339  // boundary that was actually defined (the latter is slightly bigger).
340  // It returns (via reference parameters uunits, vunits, udivs, vdivs) the
341  // float arrays and the size of the float array. Please delete the
342  // array pointed to by uunits and vunits after use. It also returns an
343  // array of original breakpoints (via uunrefineranges and vunrefineranges)
344  // where all the original breakpoints with some newly inserted nodes between
345  // them are returned.
346  void refineRange(const UT_BoundingRect &rect, float tol,
347  float *&uunits, float *&vunits,
348  int &udivs, int &vdivs,
349  UT_FloatArray &uunrefineranges,
350  UT_FloatArray &vunrefineranges);
351 
352  // Refine an area around the boundary of the surface, called the "belt".
353  void refineBelt(float ubwidth = 0.4F, float vbwidth = 0.4F,
354  int ubdivs = 2, int vbdivs = 2);
355 
356  // Set or query the U and V bases respectively. The "set" functions
357  // overwrite the current basis pointer, so use with care; they return
358  // -1 if the bases are invalid.
360  {
361  if (ub && ub->checkValid((int)getNumCols(), (int)isWrappedU()))
362  {
363  delete myUBasis; myUBasis = ub;
364  return 0;
365  }
366  else return -1;
367  }
369  {
370  if (vb && vb->checkValid((int)getNumRows(), (int)isWrappedV()))
371  {
372  delete myVBasis; myVBasis = vb;
373  return 0;
374  }
375  else return -1;
376  }
377  GA_Basis* getUBasis(void) const { return myUBasis; }
378  GA_Basis* getVBasis(void) const { return myVBasis; }
379 
380  // Query the order of the u and respectively v bases.
381  unsigned getUOrder(void) const { return (unsigned)myUBasis->getOrder(); }
382  unsigned getVOrder(void) const { return (unsigned)myVBasis->getOrder(); }
383 
384  // Query the dimension of the u and respectively v bases.
385  unsigned getUDim(void) const { return (unsigned)myUBasis->getDimension(); }
386  unsigned getVDim(void) const { return (unsigned)myVBasis->getDimension(); }
387 
388  // Gets the current U and V grevilles of the surface
389  // User Beware: If the surface is subsequently changed, i.e. if the basis
390  // changed, refined, etc., the results from this method
391  // will be useless.
392  void getUGrevilles(UT_FloatArray &ugrevilles) const;
393  void getVGrevilles(UT_FloatArray &vgrevilles) const;
394 
395  // Inherited from the base class: just checks the validity of the bases.
396  virtual bool isDegenerate(void) const;
397 
398  // Get the bounding box for a specific range of u and v
399  virtual void getRangeBBox(const UT_Interval &u,
400  const UT_Interval &v,
401  UT_BoundingBox &bbox,
402  const GA_PwHandleRO &h) const = 0;
403 
404  // Dehomogenize data (with attributes):
405  static void dehomogenizeData(GA_Offset *vertices,
406  GA_AttributeRefMap &hlist,
407  int count);
408  static void dehomogenizeData(UT_Vector4 *pos, int count);
409 
410  // Increase the order. Return 0 if successful, -1 otherwise (eg.
411  // order cannot be increased because it's >= MAXORDER).
412  int raiseOrderU (int neworder)
413  { return raiseOrderUInt(neworder); }
414  int raiseOrderV (int neworder)
415  { return raiseOrderVInt(neworder); }
416  int raiseOrderU(int neworder,
417  GA_AttributeRefMap &map)
418  { return raiseOrderURefMap(neworder, map); }
419  int raiseOrderV(int neworder,
420  GA_AttributeRefMap &map)
421  { return raiseOrderVRefMap(neworder, map); }
422 
423 
424  // Translate the CVs such that the given breakpoint change positions by
425  // the given delta. Return -1 if something goes wrong, 0 if translation
426  // was successful.
427  // NOTE: Cannot contain any duplicates. If the surface is wrapped,
428  // the first and last breakpoint are considered the same.
429  virtual int translateBreakpoints(const UT_IntArray &uindices,
430  const UT_IntArray &vindices,
431  const UT_Vector3 &delta,
432  int fixbkpts = 1,
433  GA_PointGroup *ptgroup=NULL,
434  GEO_Delta *geodelta = 0) = 0;
435 
436  virtual int transformBreakpoints(const UT_IntArray &uindices,
437  const UT_IntArray &vindices,
438  const UT_Matrix4 &matx,
439  int fixbkpts = 1,
440  GA_PointGroup *ptgroup=NULL,
441  GEO_Delta *geodelta = 0) = 0;
442 
443  // Append another hull to us in one of two ways: blend the two endpoints
444  // or connect them straight or rounded. The bias ranges from 0 to 1 and is
445  // relevant only to blending. The tolerance for blending: if 0, the two
446  // endpoints will merge into one point with a discontinuity; if less than
447  // 1, we insert knots into the hulls to minimize the affected areas; if 1,
448  // no refinement is done. For the non-blend case, the tolerance will
449  // generate a span whose shape goes from round to straight; 0 tolerance
450  // means straight connection. If unrefine is on, we'll try to reduce the
451  // complexity of the hull if we're connecting rounded. We return 0 if OK
452  // and -1 if error. Both hulls must be open and have the same order.
453  virtual int attachU(const GEO_Hull &hull, int blend = 1,
454  float bias = 0.5f, float tolerance = 1.0f,
455  int unrefine = 1, GA_PointGroup *ptgroup=0);
456  virtual int attachV(const GEO_Hull &hull, int blend = 1,
457  float bias = 0.5f, float tolerance = 1.0f,
458  int unrefine = 1, GA_PointGroup *ptgroup=0);
459 
460  // If [ustart,ustop] and [vstart,vstop] are in the valid interval, return
461  // the part of the surface delimited by those values in a new primitive.
462  // Return 0 if a problem is encountered.
463  virtual GEO_TPSurf *extract(float ustart, float ustop,
464  float vstart, float vstop) const = 0;
465 
466  // Derived from the base class. Here we just want to preserve our basis.
467  virtual void subdivide(int numdivs, GA_PointGroup *ptgroup=0);
468 
469  // Return the surrounding values of the real-space u,v parameters.
470  // Returns 1 if succesful, 0 if out-of-range.
471  virtual int parametricBBox(float u, float v,
472  float *u0, float *u1,
473  float *v0, float *v1);
474 
475  // Find out if the surface has any profiles in its domain:
476  int hasProfiles(void) const;
477 
478  // Get the profiles detail. Create the detail if not there if the create
479  // option is true.
480  GEO_Profiles *profiles(int create = 1);
481  GEO_Profiles *profiles(void) const { return theProfiles; }
482 
483  // find out if the surface is pasted:
484  int isPasted(void) const { return thePasteSurf != 0; }
485 
486  // Get or set the pasted image of this surface:
487  GEO_PasteSurf *pastedSurface(void) const { return thePasteSurf; }
488  void pastedSurface(GEO_PasteSurf *p) { thePasteSurf = p; }
489 
490  // Update the displacement of the CV(s) whose point is ptoff if the
491  // surface is pasted. This method wil not update the pasted dependents
492  // unless you want it to. Return 1 of found and 0 otherwise.
493  int updateDisplacement(GA_Offset ptoff,
494  int updatekids = 1);
495 
496  virtual void isolate(void);
497 
498  /// Stash (deactivate) or unstash (reactivate) the primitive.
499  virtual void stashed(bool beingstashed,
501 
502  /// @{
503  /// Method to load/save basis values.
504  bool jsonSaveUBasis(UT_JSONWriter &w) const;
505  bool jsonSaveUBasis(UT_JSONValue &v) const;
506  bool jsonSaveVBasis(UT_JSONWriter &w) const;
507  bool jsonSaveVBasis(UT_JSONValue &v) const;
508  bool jsonLoadUBasis(UT_JSONParser &p);
509  bool jsonLoadUBasis(UT_JSONParser &p, const UT_JSONValue &v);
510  bool jsonLoadVBasis(UT_JSONParser &p);
511  bool jsonLoadVBasis(UT_JSONParser &p, const UT_JSONValue &v);
512  /// @}
513 
514  // Constraint based manipulation.
515  // If the parameterization and derivative constraints do not change and
516  // the curve's basis and order don't change, then the system only needs to
517  // be solved once. The solution can then be applied multiple times,
518  // with different changes at the given parameters.
519 
520  // Return 0 if the resulting system is overdetermined (or otherwise
521  // unsolvable).
522  // 1 if ok.
523  int solveConstraints(const UT_Vector &uparam,
524  const UT_Vector &vparam,
525  const UT_IntArray &udervs,
526  const UT_IntArray &vdervs,
527  UT_MatrixF &soln,
528  UT_IntArray &cv_idx);
529 
530  // Return 0 if the given data is invalid (incorrect dimensions or indices).
531  // 1 if ok.
532  // The changes matrix is an n x 3 matrix, with each of the columns
533  // corresponding to the x, y, and z coordinates.
534  // If the surface is rational, the changes matrix will be modified.
535  int applyConstraints(UT_MatrixF &changes,
536  const UT_Vector &uparam,
537  const UT_Vector &vparam,
538  const UT_IntArray &udervs,
539  const UT_IntArray &vdervs,
540  const UT_IntArray &cv_index,
541  const UT_MatrixF &soln);
542 
543  // Return 0 if the resulting system is overdetermined.
544  // 1 if ok.
545  // Only call this method when the solution cannot be reused.
546  // If the surface is rational, the changes matrix will be modified.
547  int solveAndApplyConstraints(const UT_Vector &uparam,
548  const UT_Vector &vparam,
549  const UT_IntArray &udervs,
550  const UT_IntArray &vdervs,
551  UT_MatrixF &changes);
552 
553  /// Elevate the curve to the given order. Return 0 if OK and -1 otherwise.
554  int elevateOrderU(int order);
555  int elevateOrderV(int order);
556 
557  virtual int intersectSurf(GEO_TPSurf &surf2,
558  GU_IsectCurveSet &curveset,
559  float worldtol = 1e-4F,
560  float domaintol = 1e-2F,
561  int steps = 100,
562  bool docompact = true) = 0;
563  virtual int doesIntersect(const GEO_Primitive &prim,
564  float worldtol = 1e-4F, int nontrivial = 0) const = 0;
565 
566  /// This is more powerful than convertNew. It always returns a NEW
567  /// object, so free it when you're done with it. It may return a mesh,
568  /// a NURB surface or a Bezier surface depending on the type.
569  virtual GEO_Hull *reconfigure(unsigned type, int orderu, int orderv,
570  bool openu, bool openv,
571  bool endsu, bool endsv) const = 0;
572 
573  /// Construct a curve that has our characteristics in u or v. The
574  /// CVs of the new curve are not set.
575  /// @{
576  virtual GEO_Curve *buildRowCurve(bool appendPoints,
577  GEO_Detail *parent) const = 0;
578  virtual GEO_Curve *buildColCurve(bool appendPoints,
579  GEO_Detail *parent) const = 0;
580  /// @}
581 
582  /// Cut a wedge of the primitive given a domain range
583  /// ind1 and ind2 are indices to the refined values
584  /// They are updated if negative on input, else used as is.
585  /// If keep is zero the curve is only refined and the indices
586  /// updated.
587  virtual GEO_TPSurf *cutU(float u1, float u2, int &ind1, int &ind2,
588  int keep) = 0;
589 
590  virtual GEO_TPSurf *cutV(float v1, float v2, int &ind1, int &ind2,
591  int keep) = 0;
592 
593  /// Open the primitive at the given domain value
594  virtual void openAtU(float u) = 0;
595  virtual void openAtV(float v) = 0;
596 
597  /// Puts the position of the breakpoint at (uidx, vidx) in p
598  /// Returns 1 if uidx and vidx are both valid, 0 otherwise.
599  bool interpretBreakpoint(int uidx, int vidx, UT_Vector3 &p) const;
600 
601  /// Compute the CVs of the U or V isoparametric curve running through
602  /// the given parametric value. The number of resulting CVs equals the
603  /// number or rows (if v = const.) or cols (if u = const.) respectively.
604  /// We return the extracted curve if successful and 0 otherwise.
605  /// @{
606  GEO_Curve *extractUIsoparm(float u, int uoffset=-1)
607  { return extractUIsoparm(u, uoffset, getParent()); }
608  GEO_Curve *extractUIsoparm(float u, int uoffset,
609  GEO_Detail *parent) const;
611  int uoffset=-1)
612  { return extractUIsoparm(u, map, uoffset, getParent()); }
613  GEO_Curve *extractUIsoparm(float u, const GA_AttributeRefMap &map,
614  int uoffset, GEO_Detail *parent) const;
615  GEO_Curve *extractVIsoparm(float v, int voffset=-1)
616  { return extractVIsoparm(v, voffset, getParent()); }
617  GEO_Curve *extractVIsoparm(float v, int voffset,
618  GEO_Detail *parent) const;
620  int voffset=-1)
621  { return extractUIsoparm(v, map, voffset, getParent()); }
622  GEO_Curve *extractVIsoparm(float v, const GA_AttributeRefMap &map,
623  int voffset, GEO_Detail *parent) const;
624  /// @}
625 
626  /// remove a single curve in the domain of the hull
627  /// @{
628  GEO_Curve *extractU(float unitu)
629  { return extractU(unitu, getParent()); }
630  GEO_Curve *extractU(float unitu, GEO_Detail *parent) const;
631  GEO_Curve *extractV(float unitv)
632  { return extractV(unitv, getParent()); }
633  GEO_Curve *extractV(float unitv, GEO_Detail *parent) const;
634  /// @}
635 
636 protected:
637  // The bases in each parametric direction. Not const because we want
638  // to be able to (re)set them at initialization time or elsewhere.
639  // They must be set with objects allocated from the heap so that we can
640  // delete them when calling this class's destructor.
643 
644  // PROTECTED METHODS:
646  {
647  return static_cast<GA_PrimitiveFamilyMask>(
650  );
651  }
652 
653  // Declare intrinsic attribute functions
655 
656  // Load and save functions redefined from the parent class.
657  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
658  virtual bool saveExtraH9 (std::ostream &, bool binary) const;
659  virtual bool loadPrivateH9(UT_IStream &is);
660  virtual bool loadExtraH9 (UT_IStream &);
661 
662  // Check the validity of the data. Meant to be called especially at loading
663  // time. The method returns 1 if OK and 0 if trouble.
664  virtual bool validate(void) const;
665 
666  // Used by the derived classes in their attach() methods.
667  void mergeAttachProfilesU(const GEO_TPSurf &tpsurf);
668  void mergeAttachProfilesV(const GEO_TPSurf &tpsurf);
669 
670  // Compute an evalution stepsize that is surely valid.
671  float stepSize(float start, float stop, int count) const
672  {
673  return (count > 0) ? ((stop - start)/(float)count)
674  : 0.0F;
675  }
676 
677  // Get a new basis of a type that matches our type:
678  virtual GA_Basis *newBasis(void) const = 0;
679 
680  // Evaluate the position or the derivative at domain point (u,v), where
681  // u and v MUST be in [0,1]. "v" and "dv" will be ignored when dealing
682  // with one-dimensional types such as circles and polygons. Return 0 if
683  // OK and -1 otherwise.
684  virtual bool evaluatePointRefMap( GA_Offset result_vtx,
685  GA_AttributeRefMap &hlist,
686  fpreal u, fpreal v, uint du, uint dv) const;
687  virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
688  unsigned du=0, unsigned dv=0) const;
689 
690  // Evaluate one point (when du=dv=0), or the du-th dv-th derivative.
691  // Return 0 if successful, and -1 otherwise.
692  // The difference between this method and evaluate() is that this one
693  // treats u and v as values between 2 knot indices, while evaluate()
694  // sees them as actual domain values.
695  virtual bool evaluateIndexRefMap(fpreal u, fpreal v, GA_Offset result_vtx,
696  GA_AttributeRefMap &hlist,
697  unsigned du, unsigned dv) const;
698  virtual int evaluateIndexV4(float iu, float iv, UT_Vector4 &pos,
699  unsigned du=0, unsigned dv=0) const;
700 
701  // Refine for all spans with specified number of divisions per span.
702  virtual void spanRefineURefMap(GA_AttributeRefMap &map, int ndivs=1);
703  virtual void spanRefineUInt(int numdivs=1);
704  virtual void spanRefineVRefMap(GA_AttributeRefMap &map, int ndivs=1);
705  virtual void spanRefineVInt(int numdivs=1);
706 
707  virtual int raiseOrderUInt (int neworder) = 0;
708  virtual int raiseOrderVInt (int neworder) = 0;
709  virtual int raiseOrderURefMap(int neworder,
710  GA_AttributeRefMap &map) = 0;
711  virtual int raiseOrderVRefMap(int neworder,
712  GA_AttributeRefMap &map) = 0;
713 
714  /// Report approximate memory usage for myUBasis, myVBasis,
715  /// theProfiles, since the subclasses don't have access to some.
716  int64 getBaseMemoryUsage() const;
717 
718  // This is called by the subclasses to count the
719  // memory used by myUBasis, myVBasis, theProfiles
721 
722 private:
723  // Method to copy the basis of the source to me
724  void copyBasisAndProfiles(const GEO_TPSurf *src);
725 
726  // Detail of (trimming) profiles:
727  GEO_Profiles *theProfiles;
728 
729  // The pasted image:
730  GEO_PasteSurf *thePasteSurf;
731 
732  friend std::ostream &operator<<(std::ostream &os, const GEO_TPSurf &d)
733  {
734  d.saveH9(os, 0,
737  return os;
738  }
739 };
740 
741 #endif
bool isWrappedU() const
Definition: GEO_Hull.h:484
virtual void realToUnitDomain(float u_real, float v_real, float &u_unit, float &v_unit) const
int setUBasis(GA_Basis *ub)
Definition: GEO_TPSurf.h:359
GLenum src
Definition: glew.h:2410
bool isWrappedV() const
Definition: GEO_Hull.h:485
int raiseOrderV(int neworder, GA_AttributeRefMap &map)
Definition: GEO_TPSurf.h:419
int isPasted(void) const
Definition: GEO_TPSurf.h:484
int setVBasis(GA_Basis *vb)
Definition: GEO_TPSurf.h:368
GEO_Primitive * copy(int preserve_shared_pts=0) const override
#define GEO_FAMILY_TPSURF
Definition: GEO_PrimType.h:75
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)=0
virtual void validVRange(float &va, float &vb) const
unsigned getUOrder(void) const
Definition: GEO_TPSurf.h:381
virtual void subdivide(int numdivs, GA_PointGroup *ptgroup=0)
GLuint GLdouble u1
Definition: glew.h:3446
GEO_Profiles * profiles(void) const
Definition: GEO_TPSurf.h:481
virtual bool evaluateIndexRefMap(fpreal u, fpreal v, GA_Offset result_vtx, GA_AttributeRefMap &hlist, unsigned du, unsigned dv) const
int raiseOrderU(int neworder)
Definition: GEO_TPSurf.h:412
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
virtual int evaluateNormal(float u, float v, UT_Vector3 &nml) const
virtual void validVInterval(int &a, int &b) const
GEO_Curve * extractU(float unitu)
Definition: GEO_TPSurf.h:628
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_Hull.h:682
virtual void validUInterval(int &a, int &b) const
unsigned getUDim(void) const
Definition: GEO_TPSurf.h:385
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
#define GA_MAXORDER
Definition: GA_Defines.h:17
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
SYS_FORCE_INLINE GEO_Detail * getParent() const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
const GLdouble * v
Definition: glew.h:1391
virtual void unitToRealSequenceU(float *uunit, float *ureal, int ulen) const
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
4D Vector class.
Definition: UT_Vector4.h:163
virtual void spanRefineURefMap(GA_AttributeRefMap &map, int numdivs=1)=0
GA_PrimitiveFamilyMask
GLuint GLdouble GLdouble GLint GLint order
Definition: glew.h:3446
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
#define GA_INVALID_OFFSET
Definition: GA_Types.h:674
GA_Basis * myVBasis
Definition: GEO_TPSurf.h:642
GA_ParameterizationType
Definition: GA_Types.h:193
GA_PwHandle< true > GA_PwHandleRO
Definition: GEO_TPSurf.h:38
int divs(int x, int y)
Definition: ImathFun.h:180
GA_Size GA_Offset
Definition: GA_Types.h:637
virtual void unitToRealSequenceV(float *vunit, float *vreal, int vlen) const
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4648
long long int64
Definition: SYS_Types.h:111
virtual void copySubclassData(const GA_Primitive *source) override
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
virtual void validURange(float &ua, float &ub) const
unsigned getVOrder(void) const
Definition: GEO_TPSurf.h:382
GEO_PasteSurf * pastedSurface(void) const
Definition: GEO_TPSurf.h:487
virtual bool checkValid(int cvLen, int bLen, bool doesWrap) const =0
GLclampf f
Definition: glew.h:3499
virtual int normalIndex(float iu, float iv, UT_Vector3 &nml) const
virtual void reverseU()
const GLuint GLenum const void * binary
Definition: glew.h:3502
GA_Basis * getVBasis(void) const
Definition: GEO_TPSurf.h:378
virtual void unitToRealDomain(float u_unit, float v_unit, float &u_real, float &v_real) const
bool extract(const vbool4 &a)
Definition: simd.h:3330
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexMatx (exclusive)
const GLfloat * c
Definition: glew.h:16296
#define GEO_API
Definition: GEO_API.h:14
Bezier or NURBS basis classes which maintain knot vectors.
Definition: GA_Basis.h:49
A handle to simplify manipulation of multiple attributes.
GEO_Curve * extractVIsoparm(float v, const GA_AttributeRefMap &map, int voffset=-1)
Definition: GEO_TPSurf.h:619
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
GLfloat bias
Definition: glew.h:10274
virtual void weights(unsigned short onOff)
bool isDegenerate() const override
Is the primitive degenerate.
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
unsigned int uint
Definition: SYS_Types.h:44
GLuint start
Definition: glew.h:1253
GA_DECLARE_INTRINSICS(override)
GEO_Curve * extractV(float unitv)
Definition: GEO_TPSurf.h:631
int parametricBBox(float u, float v, float *u0, float *u1, float *v0, float *v1) override
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
double fpreal
Definition: SYS_Types.h:276
virtual void spanRefineUInt(int numdivs=1)=0
unsigned getVDim(void) const
Definition: GEO_TPSurf.h:386
int raiseOrderV(int neworder)
Definition: GEO_TPSurf.h:414
GLuint counter
Definition: glew.h:2740
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
virtual bool loadExtraH9(UT_IStream &is)=0
GEO_Curve * extractVIsoparm(float v, int voffset=-1)
Definition: GEO_TPSurf.h:615
void copyPrimitive(const GEO_Primitive *src) override
virtual void reverseV()
int raiseOrderU(int neworder, GA_AttributeRefMap &map)
Definition: GEO_TPSurf.h:416
virtual int evaluateIndexV4(float iu, float iv, UT_Vector4 &pos, unsigned du=0, unsigned dv=0) const
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
GLuint GLuint GLsizei count
Definition: glew.h:1253
GEO_Curve * extractUIsoparm(float u, const GA_AttributeRefMap &map, int uoffset=-1)
Definition: GEO_TPSurf.h:610
GA_Basis * myUBasis
Definition: GEO_TPSurf.h:641
GLfloat v0
Definition: glew.h:1848
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:76
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
virtual bool loadPrivateH9(UT_IStream &is)=0
GLuint GLdouble GLdouble u2
Definition: glew.h:3446
Container class for all geometry.
Definition: GA_Detail.h:95
friend std::ostream & operator<<(std::ostream &os, const GEO_TPSurf &d)
Definition: GEO_TPSurf.h:732
virtual void spanRefineVRefMap(GA_AttributeRefMap &map, int numdivs=1)=0
Specialization of GA_ROGenericHandle for GA_ATTRIB_VERTEX offsets.
void countBaseMemory(UT_MemoryCounter &counter) const
float stepSize(float start, float stop, int count) const
Definition: GEO_TPSurf.h:671
virtual void computeInteriorPointWeights(UT_Array< GA_Offset > &vtxlist, UT_Array< float > &weightlist, fpreal u, fpreal v, fpreal w) const override
GEO_Curve * extractUIsoparm(float u, int uoffset=-1)
Definition: GEO_TPSurf.h:606
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)=0
GA_Basis * getUBasis(void) const
Definition: GEO_TPSurf.h:377
GLenum GLint GLint * precision
Definition: glew.h:3500
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_TPSurf.h:645
virtual bool saveExtraH9(std::ostream &os, bool binary) const =0
virtual unsigned getNumSecondaryDetails() const
A primitive may support any number of secondary details.
virtual bool savePrivateH9(std::ostream &os, bool binary) const =0
virtual void spanRefineVInt(int numdivs=1)=0
virtual void isolate()
Method to isolate a pasted surface.
GLfloat GLfloat v1
Definition: glew.h:1852
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
void pastedSurface(GEO_PasteSurf *p)
Definition: GEO_TPSurf.h:488
virtual bool validate(void) const =0
void clearForDeletion() override
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET) override
GEO_TPSurf(GA_Detail *d, GA_Offset offset=GA_INVALID_OFFSET)
Definition: GEO_TPSurf.h:49
GLsizei GLboolean transpose
Definition: glew.h:1864
virtual const GA_Detail * getSecondaryDetail(GA_Index i) const
GLenum GLsizei len
Definition: glew.h:7752
GLintptr offset
Definition: glew.h:1682