00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __GEO_Curve_h__
00023 #define __GEO_Curve_h__
00024
00025 #include "GEO_API.h"
00026 #include <UT/UT_RefArray.h>
00027
00028 #include <GB/GB_Basis.h>
00029 #include <GB/GB_Parameterization.h>
00030 #include <UT/UT_IntArray.h>
00031 #include "GEO_Face.h"
00032 #include "GEO_PrimType.h"
00033 #include "GEO_Greville.h"
00034
00035 class UT_Vector3;
00036 class UT_Vector4;
00037 class GB_AttributeData;
00038 class GB_FloatOffsets;
00039 class GEO_AttributeHandleList;
00040 class GEO_WorkVertexBuffer;
00041 class GEO_Delta;
00042
00043 class GEO_API GEO_Curve : public GEO_Face {
00044 public:
00045
00046
00047 GEO_Curve(GEO_Detail *d, int m = 0);
00048
00049
00050
00051
00052 virtual ~GEO_Curve();
00053
00054
00055 virtual void copyPrimitive(const GEO_Primitive *src,
00056 GEO_Point **ptredirect);
00057 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00058
00059 virtual void changePointRef(GB_Element *from, GB_Element *to);
00060
00061
00062
00063 virtual bool evaluate(float u, GEO_Vertex &result,
00064 GEO_AttributeHandleList &hlist,
00065 unsigned du=0, int uOffset=-1) const;
00066 virtual int evaluate(float u, UT_Vector4 &pos,
00067 unsigned du=0, int uOffset=-1) const;
00068 virtual int evaluateWAttrib(float u, UT_Vector4 &pos,
00069 GB_AttributeData &adata,
00070 const GB_FloatOffsets &foffsets,
00071 unsigned du=0, int uOffset=-1) const;
00072
00073
00074
00075
00076
00077 virtual int evaluateBasisDerivs(float u,float bmatx[][GB_MAXORDER],
00078 int &cvoffset, unsigned du = 0,
00079 int uoffset = -1) const = 0;
00080
00081
00082
00083
00084
00085
00086 virtual int evaluateBasis(float u,float *ubvals, int &cvoffset,
00087 unsigned du=0, int uoffset=-1) const = 0;
00088
00089
00090
00091 float computeBValue(float u, int i) const;
00092
00093
00094
00095
00096
00097
00098 virtual int evaluateSegm(float *uArr, unsigned uArrLen,
00099 UT_Vector4 *pos, unsigned du=0) const;
00100 virtual bool evaluateSegm(float uStart, float uStop,
00101 uint nu, GEO_Vertex **results,
00102 GEO_AttributeHandleList &hlist,
00103 uint du) const;
00104 virtual int evaluateSegm(float uStart, float uStop, unsigned nu,
00105 UT_Vector4 *pos, unsigned du=0) const;
00106 virtual int evaluateSegmWAttrib(float uStart, float uStop,
00107 unsigned nu, UT_Vector4 *pos,
00108 GB_AttributeData *adata,
00109 const GB_FloatOffsets &foffsets,
00110 unsigned du=0) const;
00111
00112
00113
00114
00115
00116
00117
00118
00119 virtual int evaluateBreakSegm(int uStartIdx, int uStopIdx,
00120 int lod, GEO_Vertex **result,
00121 GEO_AttributeHandleList &hlist,
00122 unsigned du) const;
00123 virtual int evaluateBreakSegm(int uStartIdx, int uStopIdx,
00124 int lod, UT_Vector4 *pos, unsigned du=0) const;
00125 virtual int evaluateBreakSegmWAttrib(int uStartIdx, int uStopIdx,
00126 int lod, UT_Vector4 *pos,
00127 GB_AttributeData *adata,
00128 const GB_FloatOffsets &foffsets,
00129 unsigned du=0) const;
00130
00131
00132
00133
00134
00135 virtual float breakSegmIndexToDomain(int ustartidx, int ustopidx,
00136 int lod, int index) const;
00137
00138
00139
00140
00141 virtual bool evaluatePoint( GEO_Vertex &result,
00142 GEO_AttributeHandleList &hlist,
00143 float u_unit, float=0,
00144 unsigned du=0, unsigned = 0) const;
00145 virtual int evaluatePoint( UT_Vector4 &pos, float u_unit, float=0,
00146 unsigned du=0, unsigned = 0) const;
00147 virtual int evaluatePointWAttrib(UT_Vector4 &pos,
00148 GB_AttributeData &adata,
00149 const GB_FloatOffsets &foffsets,
00150 float u_unit, float=0, unsigned du = 0,
00151 unsigned = 0) const;
00152
00153
00154
00155 int evaluateNormal(float u, UT_Vector3 &nml) const;
00156
00157
00158 int curvature(float u, UT_Vector3 &curv) const;
00159
00160
00161
00162
00163
00164
00165 float arcLength(float u0, float u1, bool use_frwd_diff = true,
00166 int divs = 10) const;
00167
00168
00169
00170
00171
00172
00173
00174 virtual float getKnotLengths(GB_ParmType ptype,
00175 UT_FloatArray &lengths) const=0;
00176
00177
00178
00179 virtual int fillCurve(int nu, UT_Vector4 *pos) const=0;
00180
00181
00182
00183 virtual int raiseOrder(int neworder, GEO_AttributeHandleList &)=0;
00184 virtual int raiseOrder (int neworder) = 0;
00185 virtual int raiseOrderWAttrib(int neworder,
00186 const GB_FloatOffsets &foffsets) = 0;
00187
00188
00189
00190
00191
00192
00193 virtual int translateBreakpoints(const UT_IntArray &uindices,
00194 const UT_Vector3 &delta,
00195 int fixbkpts = 1,
00196 GB_PointGroup *ptgroup = NULL,
00197 GEO_Delta *geodelta = 0)= 0;
00198
00199 virtual int transformBreakpoints(const UT_IntArray &uindices,
00200 const UT_Matrix4 &matx,
00201 int fixbkpts = 1,
00202 GB_PointGroup *ptgroup = NULL,
00203 GEO_Delta *geodelta = 0)= 0;
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 virtual int attach(const GEO_Face &face, int blend = 1,
00216 float bias = 0.5f, float tolerance = 1.0f,
00217 int unrefine = 1, GB_PointGroup *ptgroup=0);
00218
00219
00220
00221
00222 virtual int domainRangeOfCV(int cvidx, int &mink,
00223 int &maxk) const = 0;
00224
00225
00226
00227
00228
00229
00230 virtual int breakpointRangeOfCV(int cvidx, int &minbkp,
00231 int &maxbkp) const = 0;
00232
00233
00234
00235 virtual void reparameterize(GB_ParmType ptype) = 0;
00236
00237
00238
00239
00240 int setGreville(unsigned int r);
00241 int setGrevilles(void);
00242
00243
00244
00245
00246 int buildGreville (unsigned r);
00247 int buildGrevilles(int resize = 1);
00248
00249
00250
00251 void clearGrevilles(void) { grevArray.resize(0); }
00252
00253
00254 const GEO_Greville& getGreville(unsigned int r) const
00255 {
00256 return grevArray(r);
00257 }
00258
00259
00260
00261 unsigned hasGreville(void) const { return !grevArray.isEmpty(); }
00262
00263
00264
00265 int setCV(unsigned r, const UT_Vector4 &v);
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 void weights(unsigned short onOff);
00276
00277
00278
00279
00280 int setWeight(unsigned int r, float w);
00281
00282
00283 float getWeight(unsigned int r) const;
00284
00285
00286 int isRational(void) const { return (int) theRational; }
00287
00288
00289
00290 void makeHomogeneous(GEO_AttributeHandleList &hlist,
00291 int startcv=0, int endcv=-1)
00292 {
00293 homogenize(hlist, startcv, endcv);
00294 theRational = 0;
00295 }
00296 void makeHomogeneous(int startcv = 0, int endcv = -1)
00297 {
00298 homogenize(startcv, endcv);
00299 theRational = 0;
00300 }
00301 void makeHomogeneousWAttrib(const GB_FloatOffsets &foffsets,
00302 int startcv = 0, int endcv = -1)
00303 {
00304 homogenizeWAttrib(foffsets, startcv, endcv);
00305 theRational = 0;
00306 }
00307 void makeNonHomogeneous(GEO_AttributeHandleList &hlist,
00308 int startcv=0, int endcv=-1)
00309 {
00310 dehomogenize(hlist, startcv, endcv);
00311 theRational = 1;
00312 }
00313 void makeNonHomogeneous(int startcv = 0, int endcv = -1)
00314 {
00315 dehomogenize(startcv, endcv);
00316 theRational = 1;
00317 }
00318 void makeNonHomogeneousWAttrib(
00319 const GB_FloatOffsets &foffsets,
00320 int startcv = 0, int endcv = -1)
00321 {
00322 dehomogenizeWAttrib(foffsets, startcv, endcv);
00323 theRational = 1;
00324 }
00325
00326
00327
00328
00329 void normalizeWeights();
00330
00331
00332
00333 void normalizeDomain(float len = 0.0F, float *neworigin = 0)
00334 {
00335 uBasis->normalize(len, neworigin);
00336 }
00337
00338
00339
00340 virtual float unitToRealDomain(float u_unit) const;
00341 virtual float realToUnitDomain(float u_real) const;
00342
00343
00344
00345
00346
00347 virtual void unitToRealSequence(float *uunit, float *ureal,
00348 int ulen) const;
00349
00350
00351
00352
00353
00354 virtual float unitLengthToUnitDomain(float ulength,
00355 float tolerance = 1e-05F) const;
00356 virtual float unitToUnitLengthDomain(float uparm) const;
00357
00358
00359
00360 virtual void validInterval(int &a, int &b) const;
00361 virtual void validRange(float &ua, float &ub) const;
00362
00363
00364
00365
00366
00367 int uniformTexture (int txtoff = -1, int ptattrib = 1);
00368 int grevilleTexture(int txtoff = -1, int ptattrib = 1);
00369 int chordLenTexture(int txtoff = -1, int ptattrib = 1);
00370
00371
00372
00373 virtual void reverse();
00374
00375
00376
00377
00378
00379
00380
00381
00382 virtual int recordChange(unsigned r);
00383 virtual int recordChanges(unsigned short basisChange = 0,
00384 unsigned short sizeChange = 0);
00385
00386
00387
00388 int setBasis(GB_Basis *ub)
00389 {
00390 if (ub && ub->validate((int)getVertexCount(),(int)isClosed()))
00391 {
00392 delete uBasis; uBasis = ub;
00393 return 0;
00394 }
00395 else return -1;
00396 }
00397 GB_Basis* getBasis(void) const { return uBasis; }
00398 void setAnyBasis(GB_Basis *ub)
00399 {
00400 delete uBasis; uBasis = ub;
00401 }
00402
00403
00404 virtual unsigned getOrder(void) const;
00405 unsigned getDim(void) const { return (unsigned)uBasis->getDimension(); }
00406
00407
00408 virtual int isDegenerate(void) const;
00409
00410
00411 static void dehomogenizeData(GEO_Vertex **vertices,
00412 GEO_AttributeHandleList &hlist,
00413 int count);
00414 static void dehomogenizeData(UT_Vector4 *pos, int count);
00415 static void dehomogenizeDataWAttrib(UT_Vector4 *pos,
00416 GB_AttributeData *adata,
00417 const GB_FloatOffsets &foffsets,
00418 int count);
00419
00420
00421
00422 virtual int parametricBBox(float u, float v,
00423 float *u0, float *u1,
00424 float *v0, float *v1);
00425
00426
00427
00428
00429 virtual GEO_Curve *extract(float ustart,float ustop) const = 0;
00430 virtual int breakCount() const;
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 int solveConstraints(const UT_Vector ¶m,
00443 const UT_IntArray &dervs,
00444 UT_Matrix &soln,
00445 UT_IntArray &cv_index);
00446
00447
00448
00449 int applyConstraints(UT_Matrix &changes,
00450 const UT_Vector ¶m,
00451 const UT_IntArray &dervs,
00452 const UT_IntArray &cv_index,
00453 const UT_Matrix &soln);
00454
00455
00456
00457
00458
00459 int solveAndApplyConstraints(const UT_Vector ¶m,
00460 const UT_IntArray &dervs,
00461 UT_Matrix &changes);
00462
00463 protected:
00464
00465
00466
00467
00468 GB_Basis *uBasis;
00469
00470
00471 virtual int savePrivate(ostream &os, int binary) const;
00472 virtual bool loadPrivate(UT_IStream &is);
00473 virtual void copyBasis(const GEO_Curve *src);
00474
00475
00476 virtual void copyOffsetPrimitive(const GEO_Primitive *src, int base);
00477
00478
00479 virtual GB_Basis *newBasis(void) const = 0;
00480
00481
00482
00483
00484 virtual bool validate(void) const;
00485
00486
00487 void setOrder(unsigned ord) { uBasis->setOrder(ord); }
00488
00489
00490 float stepSize(float start, float stop, int count) const
00491 {
00492 return (count > 0) ? ((stop - start)/(float)count)
00493 : 0.0F;
00494 }
00495
00496
00497 void rational(int yesno) { theRational = (unsigned short) yesno; }
00498
00499
00500 private:
00501
00502
00503
00504
00505 UT_RefArray<GEO_Greville> grevArray;
00506
00507
00508
00509
00510 unsigned short theRational;
00511
00512
00513
00514 bool evaluateRational(float u,
00515 GEO_Vertex &result,
00516 GEO_AttributeHandleList &hl,
00517 unsigned du=0, int uOffset=-1) const;
00518 int evaluateRational(float u, UT_Vector4 &pos,
00519 unsigned du=0, int uOffset=-1) const;
00520 int evaluateRationalWAttrib(float u, UT_Vector4 &pos,
00521 GB_AttributeData &adata,
00522 const GB_FloatOffsets &foffsets,
00523 unsigned du=0, int uOffset=-1) const;
00524
00525
00526
00527
00528
00529 int linearCombine(float bmatx[][GB_MAXORDER],
00530 unsigned du, int cvoffset,
00531 GEO_WorkVertexBuffer &vbuffer,
00532 GEO_AttributeHandleList &hlist,
00533 float *wders) const;
00534 int linearCombine(float bmatx[][GB_MAXORDER],
00535 unsigned du, int cvoffset, UT_Vector4 *aders,
00536 float *wders) const;
00537 int linearCombineWAttrib(float bmatx[][GB_MAXORDER],
00538 unsigned du, int cvoffset, UT_Vector4 *aders,
00539 float *wders, GB_AttributeData *attr_aders,
00540 const GB_FloatOffsets &foffsets) const;
00541
00542 friend ostream &operator<<(ostream &os, const GEO_Curve &d)
00543 {
00544 d.save(os, 0);
00545 return os;
00546 }
00547 };
00548
00549 #endif