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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #ifndef TETRA_TYPE
00077 #pragma message("\nYou should never directly include this file\_n")
00078 #else
00079
00080 #include<vcg/space/point3.h>
00081 #include<vcg/space/tetra3.h>
00082 #include<vcg/space/sphere3.h>
00083
00084 namespace vcg {
00093 template < class VTYPE, class TTYPE >
00094 class TETRA_TYPE{
00095
00096 public:
00097
00099 typedef TETRA_TYPE BaseTetraType;
00101 typedef VTYPE VertexType;
00103 typedef typename VertexType::CoordType CoordType;
00105 typedef typename VertexType::ScalarType ScalarType;
00107 typedef Tetra3<ScalarType> GeometricType;
00108
00109
00110
00120
00122 int _flags;
00123
00124 enum {
00125 DELETED = 0x00000001,
00126 SELECTED = 0x00000002,
00127 BORDERF0 = 0x00000004,
00128 BORDERF1 = 0x00000008,
00129 BORDERF2 = 0x00000010,
00130 BORDERF3 = 0x00000020,
00131 BORDERE0 = 0x00000040,
00132 BORDERE1 = 0x00000080,
00133 BORDERE2 = 0x00000100,
00134 BORDERE3 = 0x00000200,
00135 BORDERE4 = 0x00000400,
00136 BORDERE5 = 0x00000800,
00137 USER0 = 0x00001000,
00138 };
00139
00140 public:
00142 inline int & Flags ()
00143 {
00144 assert( (_flags & DELETED) == 0 );
00145 return _flags;
00146 }
00147
00148 static int &LastBitFlag()
00149 {
00150 static int b =USER0;
00151 return b;
00152 }
00153 static inline int NewBitFlag()
00154 {
00155 LastBitFlag()=LastBitFlag()<<1;
00156 return LastBitFlag();
00157 }
00158 static inline bool DeleteBitFlag(int bitval)
00159 {
00160 if(LastBitFlag()==bitval) {
00161 LastBitFlag()= LastBitFlag()>>1;
00162 return true;
00163 }
00164 assert(0);
00165 return false;
00166 }
00167
00169 inline int & UberFlags()
00170 {
00171 return _flags;
00172 }
00173
00175 bool IsUserBit(int userBit){return (_flags & userBit) != 0;}
00177 void SetUserBit(int userBit){_flags |=userBit;}
00179 void ClearUserBit(int userBit){_flags &= (~userBit);}
00181 bool IsD() const {return (_flags & DELETED) != 0;}
00183 void SetD() {_flags |=DELETED;}
00185 void ClearD() {_flags &=~DELETED;}
00187 bool IsS() const {return (_flags & SELECTED) != 0;}
00189 void SetS() {_flags |=SELECTED;}
00191 void ClearS() {_flags &=~SELECTED;}
00193 bool HaveBorderF() {return ((_flags & (BORDERF0 | BORDERF1 | BORDERF2 | BORDERF3)) != 0);}
00195 bool IsBorderF(int face) {
00196 assert ((face<4)&&(face>-1));
00197 return (this->TTp(face) == this);
00198 }
00200
00201
00206
00207 protected:
00208 VertexType *_v[4];
00209 public:
00210
00214 inline VertexType * & V( const int j )
00215 {
00216 assert( (_flags & DELETED) == 0 );
00217 assert(j >= 0);
00218 assert(j < 4);
00219 return _v[j];
00220 }
00221
00222 inline const VertexType * const & V( const int j ) const
00223 {
00224 assert( (_flags & DELETED) == 0 );
00225 assert(j>=0);
00226 assert(j<4);
00227 return _v[j];
00228 }
00229
00230 inline const VertexType * const & cV( const int j ) const
00231 {
00232 assert( (_flags & DELETED) == 0 );
00233 assert(j>=0);
00234 assert(j<4);
00235 return _v[j];
00236 }
00237
00238 inline CoordType & P( const int j ) { return V(j)->P();}
00239 inline const CoordType & cP( const int j ) const { return V(j)->cP();}
00240
00241
00242
00248
00249
00250 #ifdef __VCGLIB_TETRA_AT
00251 protected:
00253 TTYPE *_ttp[4];
00255 int _tti[4];
00256 public:
00258 TTYPE *&TTp(const int &index)
00259 {
00260 return _ttp[index];
00261 }
00263 int &TTi(const int &index)
00264 {
00265 return _tti[index];
00266 }
00267 #endif
00268
00269 #ifdef __VCGLIB_TETRA_AV
00270 protected:
00272 TTYPE *_tvp[4];
00274 short int _tvi[4];
00275 public:
00277 TTYPE *&TVp(const int &index)
00278 {
00279 return _tvp[index];
00280 }
00282 short int &TVi(const int &index)
00283 {
00284 return _tvi[index];
00285 }
00286 #endif
00287
00288
00289
00292 public:
00293
00295 TETRA_TYPE()
00296 {
00297 _flags=0;
00298 }
00300 virtual void Init(VertexType * p0,VertexType * p1,VertexType * p2,VertexType * p3)
00301 {
00302 _flags = 0;
00303 _v[0]=p0;
00304 _v[1]=p1;
00305 _v[2]=p2;
00306 _v[3]=p3;
00307
00308 if(vcg::ComputeVolume(*this)<0 )
00309 std::swap(_v[1],_v[2]);
00310
00311 #ifdef __VCGLIB_TETRA_TA
00312 _z[0]=_z[1]=_z[2]=_z[3]=-1;
00313 _t[0]=_t[1]=_t[2]=_t[3]=NULL;
00314 #endif
00315 #ifdef __VCGLIB_TETRA_TV
00316 _zv[0]=_zv[1]=_zv[2]=_zv[3]=-1;
00317 _tv[0]=_tv[1]=_tv[2]=_tv[3]=NULL;
00318 #endif
00319
00320 #ifdef __VCGLIB_TETRA_TQ
00321 ComputeAspectRatio();
00322 #endif
00323
00324 }
00326 #ifdef __VCGLIB_TETRA_AT
00327 void setBorderV()
00328 {
00329 int i;
00330 for (i=0;i<4;i++)
00331 if (TTp(i)==this)
00332 {
00333 V(Tetra::VofF(i,0))->SetB();
00334 V(Tetra::VofF(i,1))->SetB();
00335 V(Tetra::VofF(i,2))->SetB();
00336 }
00337 }
00338 #endif
00339
00340
00341
00344 #ifdef __VCGLIB_TETRA_TN
00345 private:
00346 CoordType _n[4];
00347 public:
00348 #endif
00349
00351 CoordType N(const int &i){
00352 assert((i>=0)&&(i<4));
00353 #ifdef __VCGLIB_TETRA_TN
00354 return _n[i];
00355 #else
00356
00357
00358
00359
00360
00361
00362 return (Normal(*this,i));
00363 #endif
00364 }
00365
00367 void ComputeNormal()
00368 {
00369 #ifdef __VCGLIB_TETRA_TN
00370 Tetra3<ScalarType> T=Tetra3<ScalarType>();
00371 T.P0(0)=V(0)->P();
00372 T.P1(0)=V(1)->P();
00373 T.P2(0)=V(2)->P();
00374 T.P3(0)=V(3)->P();
00375
00376 for (int i=0;i<4;i++)
00377 _n[i]=(Normal<Tetra3<ScalarType> >(T,i));
00378 #else
00379 assert(0);
00380 #endif
00381 }
00383
00384
00387
00388 #ifdef __VCGLIB_TETRA_TQ
00389 ScalarType _volume;
00390 ScalarType _aspect_ratio;
00391 ScalarType _q;
00392 #endif
00393
00394 ScalarType & Q(){
00395 #ifdef __VCGLIB_TETRA_TQ
00396 return _q;
00397 #else
00398 assert(0);
00399 return *(ScalarType*)(&_flags);
00400 #endif
00401 }
00402
00403 const ScalarType & Q()const{
00404 #ifdef __VCGLIB_TETRA_TQ
00405 return _q;
00406 #else
00407 assert(0);
00408 return *(ScalarType*)(&_flags);
00409 #endif
00410 }
00411
00412 ScalarType ComputeVolume(){
00413 #ifdef __VCGLIB_TETRA_TQ
00414 _volume = vcg::ComputeVolume<BaseTetraType>(*this);
00415 return _volume;
00416 #else
00417 return vcg::ComputeVolume<BaseTetraType>(*this);
00418 #endif
00419 }
00420
00422 const ScalarType & Volume(){
00423 #ifdef __VCGLIB_TETRA_TQ
00424 return _volume;
00425 #else
00426 return (( V(2)->cP()-V(0)->cP())^(V(1)->cP()-V(0)->cP() ))*(V(3)->cP()-V(0)->cP())/6.0;
00427 #endif
00428 }
00430 ScalarType AspectRatio(){
00431 #ifdef __VCGLIB_TETRA_TQ
00432 return _aspect_ratio;
00433 #else
00434 return ComputeAspectRatio();
00435 #endif
00436 }
00437
00439 ScalarType ComputeAspectRatio(){
00440
00441
00442
00443
00444
00445
00446
00447
00448 #ifdef __VCGLIB_TETRA_TQ
00449 _aspect_ratio= ( (Tetra3<ScalarType>* ) this) -> ComputeAspectRatio();
00450 return(_aspect_ratio);
00451 #else
00452 return (( (Tetra3<ScalarType> *) this) -> ComputeAspectRatio());
00453 #endif
00454 }
00455
00456 CoordType Barycenter() const
00457 {
00458 return (V(0)->cP()+V(1)->cP()+V(2)->cP()+V(3)->cP())/ScalarType(4.0);
00459 }
00460
00461 Sphere3<ScalarType> SmallestEnclosingSphere()const
00462 {
00463 return SmallestEnclosing::SphereOfTetra(*this);
00464 }
00465
00467
00468
00469
00473 #ifdef __VCGLIB_TETRA_TC
00474 Color4b c;
00475 #endif
00476
00477 Color4b & C(){
00478 #ifdef __VCGLIB_TETRA_TC
00479 return _c;
00480 #else
00481 assert(0);
00482 return (*new Color4b());
00483 #endif
00484 }
00486
00487
00488
00494
00495 static bool HasTetraNormal() {
00496 #ifdef __VCGLIB_TETRA_TN
00497 return true;
00498 #else
00499 return false;
00500 #endif
00501 }
00502 static bool HasTetraMark() {
00503 #ifdef __VCGLIB_TETRA_TM
00504 return true;
00505 #else
00506 return false;
00507 #endif
00508 }
00509 static bool HasTetraQuality() {
00510 #ifdef __VCGLIB_TETRA_TQ
00511 return true;
00512 #else
00513 return false;
00514 #endif
00515 }
00516
00517 static bool HasTetraColor() {
00518 #ifdef __VCGLIB_TETRA_TC
00519 return true;
00520 #else
00521 return false;
00522 #endif
00523 }
00524
00525 static bool HasTTAdjacency() {
00526 #if (defined(__VCGLIB_TETRA_AT) || defined(__VCGLIB_TETRA_SAT))
00527 return true;
00528 #else
00529 return false;
00530 #endif
00531 }
00532 static bool HasVTAdjacency() {
00533 #if (defined(__VCGLIB_TETRA_AV) || defined(__VCGLIB_TETRA_SAT))
00534 return true;
00535 #else
00536 return false;
00537 #endif
00538 }
00539
00541 };
00542
00543 }
00544 #endif