00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __GEO_Hull_H__
00027 #define __GEO_Hull_H__
00028
00029 #include "GEO_API.h"
00030 #include <UT/UT_RefMatrix.h>
00031 #include "GEO_Primitive.h"
00032 #include "GEO_SurfaceType.h"
00033 #include "GEO_Vertex.h"
00034
00035 class UT_BitArray;
00036 class GEO_Point;
00037 class GEO_Detail;
00038 class GB_Edge;
00039 class GB_EdgeGroup;
00040
00041 class GEO_API GEO_HullFlags {
00042 public:
00043 GEO_HullFlags()
00044 {
00045 wrapu = 0;
00046 wrapv = 0;
00047 }
00048 unsigned wrapu:1,
00049 wrapv:1;
00050 bool loadBinary( UT_IStream &is );
00051 int saveBinary( ostream &os ) const;
00052 };
00053
00054 class GEO_API GEO_SubHullFlags {
00055 public:
00056 GEO_SubHullFlags()
00057 {
00058 wrapu = 0; wrapv = 0;
00059 dupTop = 0; dupLeft = 0;
00060 dupBottom = 0; dupRight = 0;
00061 breakThread = 0; breakBridge = 0;
00062 recurse = 1;
00063 }
00064
00065 unsigned wrapu:1,
00066 wrapv:1,
00067 dupTop:1,
00068 dupLeft:1,
00069 dupBottom:1,
00070 dupRight:1,
00071 breakThread:1,
00072 breakBridge:1,
00073 recurse:1;
00074 };
00075
00076 class GEO_API GEO_SubHullPart
00077 {
00078 public:
00079 GEO_SubHullPart() { h_edge = v_edge = d_edge = flags = 0; }
00080
00081 int h_edge;
00082 int v_edge;
00083 int d_edge;
00084 int flags;
00085
00086
00087
00088
00089
00090 unsigned operator==(const GEO_SubHullPart &p) const
00091 { return( (h_edge==p.h_edge) &&
00092 (v_edge==p.v_edge) &&
00093 (d_edge==p.d_edge) &&
00094 (flags ==p.flags ) );
00095 }
00096 };
00097
00098 class GEO_API GEO_SubHull
00099 {
00100 public:
00101 GEO_SubHull() : mat() {}
00102
00103 UT_RefMatrix<GEO_SubHullPart> mat;
00104 int v_rows, v_cols;
00105 int h_rows, h_cols;
00106 int d_rows, d_cols;
00107 };
00108
00109 class GEO_API GEO_Hull : public GEO_Primitive {
00110 public:
00111 GEO_Hull(GEO_Detail *d);
00112 virtual ~GEO_Hull();
00113
00114 virtual unsigned getPrimitiveId() const = 0;
00115
00116
00117 virtual int evaluateBreakpoint(int uidx, int vidx,
00118 UT_Vector4 &pos,
00119 int du=0, int dv=0) const = 0;
00120
00121
00122
00123 virtual bool evaluateIndex(fpreal u, fpreal v, GEO_Vertex &result,
00124 GEO_AttributeHandleList &hlist,
00125 unsigned du, unsigned dv) const;
00126 virtual int evaluateIndex(float iu, float iv, UT_Vector4 &pos,
00127 unsigned du=0, unsigned dv=0) const;
00128 virtual int evaluateIndexWAttrib(float iu, float iv,
00129 UT_Vector4 &pos, GB_AttributeData &adata,
00130 const GB_FloatOffsets &foffsets,
00131 unsigned du=0, unsigned dv=0) const;
00132
00133
00134
00135
00136 virtual int evaluateNormalVector(UT_Vector3 &nml, float u,
00137 float v = 0) const;
00138
00139
00140
00141 virtual int evaluateNormal(float u,float v, UT_Vector3 &nml) const;
00142 virtual int normalIndex(float iu, float iv, UT_Vector3 &nml) const;
00143
00144 virtual int uMinValidIndex(void) const;
00145 virtual int uMaxValidIndex(void) const;
00146 virtual int vMinValidIndex(void) const;
00147 virtual int vMaxValidIndex(void) const;
00148
00149 virtual int save(ostream &os, int binary) const;
00150 virtual bool load(UT_IStream &is);
00151 virtual int getBBox(UT_BoundingBox *bbox) const;
00152 virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
00153 virtual UT_Vector3 baryCenter() const;
00154 virtual UT_Vector3 computeNormal() const;
00155 virtual void copyPrimitive(const GEO_Primitive *src,
00156 GEO_Point **ptredirect);
00157 virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
00158
00159 virtual void addPointRefToGroup(GB_PointGroup &grp) const;
00160
00161 virtual void changePointRef(GB_Element *from, GB_Element *to);
00162
00163
00164 virtual void reverse (void);
00165 virtual void reverseU(void);
00166 virtual void reverseV(void);
00167
00168
00169
00170 virtual int cycleU(int amount, int = 1);
00171 virtual int cycleV(int amount, int = 1);
00172
00173
00174 int setRowCol(unsigned int r, unsigned int c);
00175 virtual int insertRow(unsigned int beforeWhich, int appendPts=1);
00176 int appendRow(int appendPts=1)
00177 {
00178 return insertRow(vtxMatx.usedRows(), appendPts);
00179 }
00180 virtual int insertCol(unsigned int beforeWhich, int appendPts=1);
00181 int appendCol(int appendPts=1)
00182 {
00183 return insertCol(vtxMatx.usedCols(), appendPts);
00184 }
00185
00186 virtual int deleteRow(unsigned int which);
00187 virtual int deleteCol(unsigned int which);
00188
00189
00190
00191
00192
00193
00194 virtual int detachPoints (GB_PointGroup &grp);
00195
00196
00197
00198
00199
00200 virtual int subdivideU(fpreal u, GEO_AttributeHandleList &hlist);
00201 virtual int subdivideU(float u);
00202 virtual int subdivideUWAttrib(float u,
00203 const GB_FloatOffsets &foffsets);
00204 virtual int subdivideV(float u, GEO_AttributeHandleList &hlist);
00205 virtual int subdivideV(float u);
00206 virtual int subdivideVWAttrib(float u,
00207 const GB_FloatOffsets &foffsets);
00208
00209 virtual void subdivide(int numdivs, GB_PointGroup *ptgroup=0);
00210
00211
00212
00213
00214
00215
00216 virtual int warpU(float u, const UT_Vector3 &delta,
00217 GEO_AttributeHandleList &hlist,
00218 float sharpness = 0.0f, float bias = -1.0f) = 0;
00219 virtual int warpV(float v, const UT_Vector3 &delta,
00220 GEO_AttributeHandleList &hlist,
00221 float sharpness = 0.0f, float bias = -1.0f) = 0;
00222 virtual int warp (float u, float v, const UT_Vector3 &delta,
00223 GEO_AttributeHandleList &hlist,
00224 float usharpness = 0.0f, float vsharpness = 0.f,
00225 float ubias = -1.0f, float vbias = -1.0f) = 0;
00226
00227 virtual int warpU(float u, const UT_Vector3 &delta,
00228 GB_FloatOffsets *foffsets = 0,
00229 float sharpness = 0.0f, float bias = -1.0f) = 0;
00230 virtual int warpV(float v, const UT_Vector3 &delta,
00231 GB_FloatOffsets *foffsets = 0,
00232 float sharpness = 0.0f, float bias = -1.0f) = 0;
00233 virtual int warp (float u, float v, const UT_Vector3 &delta,
00234 GB_FloatOffsets *foffsets = 0,
00235 float usharpness = 0.0f, float vsharpness = 0.f,
00236 float ubias = -1.0f, float vbias = -1.0f) = 0;
00237
00238
00239
00240
00241 int warpAlongNormal (float u, float v, float distance,
00242 GEO_AttributeHandleList &hlist,
00243 float usharpness, float vsharpness,
00244 float ubias, float vbias,
00245 int u_v_both);
00246 int warpAlongNormal (float u, float v, float distance,
00247 GB_FloatOffsets *foffsets,
00248 float usharpness, float vsharpness,
00249 float ubias, float vbias,
00250 int u_v_both);
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 virtual int attachU(const GEO_Hull &hull, int blend = 1,
00263 float bias = 0.5f, float tolerance = 1.0f,
00264 int unrefine=1, GB_PointGroup *ptgroup=0) = 0;
00265 virtual int attachV(const GEO_Hull &hull, int blend = 1,
00266 float bias = 0.5f, float tolerance = 1.0f,
00267 int unrefine=1, GB_PointGroup *ptgroup=0) = 0;
00268
00269
00270
00271
00272
00273 virtual int refineU(float k,
00274 GEO_AttributeHandleList &hlist,
00275 int i=0);
00276
00277 virtual int refineU ( float k, int=0);
00278 virtual int refineUWAttrib ( float k,
00279 const GB_FloatOffsets &foffsets, int=0);
00280 virtual int refineUWAttrib ( float k,
00281 const GB_FloatOffsets *ptoffsets,
00282 const GB_FloatOffsets *vtxoffsets,
00283 int=0);
00284 virtual int refineV(float k,
00285 GEO_AttributeHandleList &hlist,
00286 int i=0);
00287 virtual int refineV ( float k, int=0);
00288 virtual int refineVWAttrib ( float k,
00289 const GB_FloatOffsets &foffsets, int=0);
00290 virtual int refineVWAttrib ( float k,
00291 const GB_FloatOffsets *ptoffsets,
00292 const GB_FloatOffsets *vtxoffsets,
00293 int=0);
00294
00295
00296 virtual void spanRefineU(GEO_AttributeHandleList &hlist,
00297 int numdivs=1) = 0;
00298 virtual void spanRefineU ( int numdivs=1) = 0;
00299 virtual void spanRefineUWAttrib ( const GB_FloatOffsets
00300 &foffsets, int numdivs=1) = 0;
00301 virtual void spanRefineV(GEO_AttributeHandleList &hlist,
00302 int numdivs=1) = 0;
00303 virtual void spanRefineV ( int numdivs=1) = 0;
00304 virtual void spanRefineVWAttrib ( const GB_FloatOffsets
00305 &foffsets, int numdivs=1) = 0;
00306
00307
00308
00309 virtual int unrefineU(int kidx, GEO_AttributeHandleList &h,
00310 int mult=0, fpreal tol=1e-4f,
00311 GB_PointGroup *delgroup=0);
00312 virtual int unrefineU (int kidx, int mult = 0,
00313 float tol = 1e-4F,
00314 GB_PointGroup *delgroup = 0);
00315 virtual int unrefineUWAttrib(int kidx,
00316 const GB_FloatOffsets &foffets,
00317 int mult=0, float tol = 1e-4F,
00318 GB_PointGroup *delgroup = 0);
00319 virtual int unrefineV(int kidx, GEO_AttributeHandleList &h,
00320 int mult=0, fpreal tol=1e-4f,
00321 GB_PointGroup *delgroup=0);
00322 virtual int unrefineV (int kidx, int mult = 0,
00323 float tol = 1e-4F,
00324 GB_PointGroup *delgroup = 0);
00325 virtual int unrefineVWAttrib(int kidx,
00326 const GB_FloatOffsets &foffets,
00327 int mult=0, float tol = 1e-4F,
00328 GB_PointGroup *delgroup = 0);
00329
00330
00331
00332 virtual void fixSeamsU(void);
00333 virtual void fixSeamsV(void);
00334
00335
00336
00337
00338 int rowColTexture(int txtoff = -1, int ptattrib = 1);
00339
00340 int getNumRows() const { return (int)vtxMatx.usedRows(); }
00341 int getNumCols() const { return (int)vtxMatx.usedCols(); }
00342
00343
00344
00345 const GEO_Vertex &operator()(unsigned int r, unsigned int c) const
00346 {
00347 return vtxMatx(r, c);
00348 }
00349 GEO_Vertex &operator()(unsigned int r, unsigned int c)
00350 {
00351 return vtxMatx(r, c);
00352 }
00353
00354 const GEO_Vertex &getVertex(unsigned int r, unsigned int c) const;
00355 void setVertex(unsigned int r, unsigned int c, GEO_Point *pt)
00356 {
00357 if(r < vtxMatx.usedRows() && c < vtxMatx.usedCols())
00358 vtxMatx(r, c).setPt(pt);
00359 }
00360
00361 GEO_SurfaceType getSurfaceType() const { return surfaceType; }
00362 void setSurfaceType(GEO_SurfaceType t) { surfaceType = t; }
00363
00364 unsigned isWrappedU() const { return flags.wrapu; }
00365 unsigned isWrappedV() const { return flags.wrapv; }
00366
00367 virtual void wrapU(int rounded = 1, int preserveShape = 0);
00368 virtual void openU(int preserveShape = 0, int safe = 0);
00369 virtual void wrapV(int rounded = 1, int preserveShape = 0);
00370 virtual void openV(int preserveShape = 0, int safe = 0);
00371
00372 virtual short isClampedU(void) const;
00373 virtual short isClampedV(void) const;
00374
00375
00376
00377
00378
00379 virtual int unrollU(int append_pts = 1);
00380 virtual int unrollV(int append_pts = 1);
00381
00382 virtual int isPointUsed(GB_Element *pt) const;
00383 virtual int isPointGroupUsed(const GB_PointGroup &grp) const;
00384 virtual int hasEdge(const GEO_Point &a, const GEO_Point &b) const;
00385 virtual int hasEdge(const GB_Edge &edge) const;
00386
00387
00388 virtual int isDegenerate() const;
00389
00390
00391 virtual int ifDetachPoint(GB_Element *ppt) const;
00392
00393
00394
00395
00396 virtual int vertexApply(int (*apply)(GB_Vertex &vtx, void *),
00397 void *data = 0);
00398 virtual int vertexApply(int (*apply)(const GB_Vertex &vtx, void *),
00399 void *data = 0) const;
00400 virtual void edgeApply(GEO_EdgeApplyFunc apply, void *data = 0);
00401 virtual void edgeApplyIndex(GEO_EdgeApplyIndexFunc apply,
00402 void *data = 0);
00403
00404 virtual unsigned getVertexCount() const;
00405 virtual const GEO_Vertex &getVertex(unsigned idx) const;
00406 virtual GEO_Vertex &getVertex(unsigned idx);
00407
00408
00409
00410
00411
00412 virtual int loftU(int newcount, int start=-1, int stop=-1) = 0;
00413 virtual int loftV(int newcount, int start=-1, int stop=-1) = 0;
00414
00415
00416
00417
00418 virtual void realToUnitPair(float ureal, float vreal,
00419 float &uunit, float &vunit) const;
00420
00421 virtual void unitToRealPair(float uunit, float vunit,
00422 float &ureal, float &vreal) const;
00423
00424
00425
00426
00427 virtual void unitToRealDomain(float u_unit, float v_unit,
00428 float &u_real, float &v_real) const;
00429 virtual void realToUnitDomain(float u_real, float v_real,
00430 float &u_unit, float &v_unit) const;
00431
00432
00433
00434
00435 virtual void unitToRealSequenceU(float *uunit, float *ureal,
00436 int ulen) const;
00437 virtual void unitToRealSequenceV(float *vunit, float *vreal,
00438 int vlen) const;
00439
00440
00441
00442 virtual int findEdgePoints(const GB_Edge &edge,
00443 int *pr0, int *pc0,
00444 int *pr1, int *pc1) const;
00445
00446 virtual int findEdgePoints(const GEO_Point &a, const GEO_Point &b,
00447 int *pr0, int *pc0,
00448 int *pr1, int *pc1) const;
00449
00450
00451
00452
00453
00454
00455 int makeEdgeMatrix(const GB_EdgeGroup &edges,
00456 GEO_SubHull &subhull);
00457
00458
00459
00460
00461 void homogenize(GEO_AttributeHandleList &hlist,
00462 int startrow=0, int endrow=-1,
00463 int startcol=0, int endcol=-1);
00464 void dehomogenize(GEO_AttributeHandleList &hlist,
00465 int startrow=0, int endrow=-1,
00466 int startcol=0, int endcol=-1);
00467
00468 void homogenize (int startrow = 0, int endrow = -1,
00469 int startcol = 0, int endcol = -1);
00470 void dehomogenize(int startrow = 0, int endrow = -1,
00471 int startcol = 0, int endcol = -1);
00472 void homogenizeWAttrib(const GB_FloatOffsets &foffsets,
00473 int startrow = 0, int endrow = -1,
00474 int startcol = 0, int endcol = -1);
00475 void dehomogenizeWAttrib(const GB_FloatOffsets &foffsets,
00476 int startrow = 0, int endrow = -1,
00477 int startcol = 0, int endcol = -1);
00478 void homogenizeWAttrib(const GB_FloatOffsets *ptoffsets,
00479 const GB_FloatOffsets *vtxoffsets,
00480 int startrow = 0, int endrow = -1,
00481 int startcol = 0, int endcol = -1);
00482 void dehomogenizeWAttrib(const GB_FloatOffsets *foffsets,
00483 const GB_FloatOffsets *vtxoffsets,
00484 int startrow = 0, int endrow = -1,
00485 int startcol = 0, int endcol = -1);
00486
00487
00488 void sampleEndsU(int n);
00489 void sampleEndsV(int n);
00490
00491
00492
00493 virtual void validURange(float &ua, float &ub) const;
00494 virtual void validVRange(float &va, float &vb) const;
00495 virtual void validUInterval(int &a, int &b) const;
00496 virtual void validVInterval(int &a, int &b) const;
00497
00498
00499
00500 float getIndices(float c, int &c1, int &c2,
00501 int maxIndex, int wrap) const;
00502
00503
00504 virtual void transpose();
00505
00506
00507
00508 virtual int parametricBBox(float u, float v,
00509 float *u0, float *u1,
00510 float *v0, float *v1);
00511
00512
00513 virtual float uvDist(float u1, float v1, float u2, float v2) const;
00514
00515 virtual void weights(unsigned short onOff);
00516
00517 virtual float calcVolume(UT_Vector3 &refpt) const;
00518 virtual float calcArea() const;
00519 virtual float calcPerimeter() const;
00520
00521 protected:
00522 virtual void copyOffsetPrimitive(const GEO_Primitive *src, int base);
00523
00524
00525
00526
00527
00528
00529
00530
00531 int breakHull(GEO_SubHull &subhull,
00532 int top, int left, int bottom, int right,
00533 GEO_SubHullFlags break_flags);
00534
00535
00536
00537 int checkUsedEdges(UT_BitArray *remove_edges,
00538 const GEO_SubHull &subhull);
00539
00540
00541
00542 virtual GEO_Hull *getSubHull(int top, int left, int bottom, int right,
00543 GEO_SubHullFlags break_flags) = 0;
00544
00545
00546 virtual int savePrivate(ostream &os, int binary) const = 0;
00547 virtual bool loadPrivate(UT_IStream &is) = 0;
00548 virtual int saveExtra (ostream &os, int binary) const = 0;
00549 virtual bool loadExtra (UT_IStream &is) = 0;
00550
00551
00552 virtual int pointCanDelete(GB_Element *pt) const;
00553 virtual void pointDeleted(GB_Element *pt);
00554
00555
00556
00557 virtual bool validate(void) const = 0;
00558
00559
00560
00561 float getLRIndex(float c, int &c1, int &c2,
00562 int minIndex, int maxIndex, int wrap) const;
00563
00564
00565 UT_RefMatrix<GEO_Vertex> vtxMatx;
00566 GEO_HullFlags flags;
00567 GEO_SurfaceType surfaceType;
00568
00569
00570 private:
00571
00572 friend ostream &operator<<(ostream &os, const GEO_Hull &d)
00573 {
00574 d.save(os, 0);
00575 return os;
00576 }
00577 void increaseDensityInRows(GEO_AttributeHandleList &h,
00578 int numdivs, GB_PointGroup *pgp);
00579 void increaseDensityInCols(GEO_AttributeHandleList &h,
00580 int numdivs, GB_PointGroup *pgp);
00581 };
00582 #endif