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
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 #pragma message("[VCGLIB Warning] this way to define the simplex face is DEPRECATED and no more SUPPORTED")
00158 #pragma message("[VCGLIB Warning] use vcg/simplex/faceplus instead ")
00159
00160 #ifndef FACE_TYPE
00161 #pragma error message("\nYou should never directly include this file\n")
00162 #else
00163
00164
00165 #include <vcg/math/base.h>
00166 #include <vcg/space/box3.h>
00167 #include <vcg/space/texcoord2.h>
00168 #include <vcg/space/triangle3.h>
00169 #include <vcg/space/sphere3.h>
00170 #include <vcg/space/color4.h>
00171 #include <vcg/space/plane3.h>
00172 #include <vcg/space/smallest_enclosing.h>
00173 #include <vcg/simplex/face/topology.h>
00174
00175 namespace vcg {
00176 class DUMMYEDGETYPE;
00177 class DUMMYFACETYPE;
00178 class DUMMYTETRATYPE;
00179
00189 template <class FVTYPE, class FETYPE, class FFTYPE, class TCTYPE = TexCoord2<float,1> > class FACE_TYPE
00190 {
00191 public:
00193 typedef FACE_TYPE BaseFaceType;
00195 typedef FFTYPE FaceType;
00197 typedef FVTYPE VertexType;
00199 typedef FETYPE EdgeType;
00201 typedef TCTYPE TexCoordType;
00203 typedef typename VertexType::ScalarType ScalarType;
00205 typedef Point3< ScalarType > CoordType;
00206 typedef Point3< ScalarType > NormalType;
00208 typedef Triangle3<ScalarType> GeometricType;
00210 typedef ScalarType QualityType;
00211
00212 typedef typename FVTYPE::FaceType FaceFromVertType;
00214 typedef Box3<ScalarType> BoxType;
00215
00217 inline FACE_TYPE(){_flags=0;}
00218
00220 int _flags;
00221
00222
00227 protected:
00229 VertexType *v[3];
00230 public:
00234 inline VertexType * & V( const int j )
00235 {
00236 assert( (_flags & DELETED) == 0 );
00237 assert( (_flags & NOTREAD) == 0 );
00238 assert( (_flags & NOTWRITE) == 0 );
00239 assert(j >= 0);
00240 assert(j < 3);
00241 return v[j];
00242 }
00243
00244 inline VertexType * const & V( const int j ) const
00245 {
00246 assert( (_flags & DELETED) == 0 );
00247 assert( (_flags & NOTREAD) == 0 );
00248 assert(j>=0);
00249 assert(j<3);
00250 return v[j];
00251 }
00252 inline VertexType * const cV( const int j ) const
00253 {
00254 assert( (_flags & DELETED) == 0 );
00255 assert( (_flags & NOTREAD) == 0 );
00256 assert(j>=0);
00257 assert(j<3);
00258 return v[j];
00259 }
00260
00261
00262 inline CoordType & P( const int j )
00263 {
00264 assert( (_flags & DELETED) == 0 );
00265 assert( (_flags & NOTREAD) == 0 );
00266 assert( (_flags & NOTWRITE) == 0 );
00267 assert(j>=0);
00268 assert(j<3);
00269 return v[j]->P();
00270 }
00271
00272 inline const CoordType & P( const int j ) const
00273 {
00274 assert( (_flags & DELETED) == 0 );
00275 assert( (_flags & NOTREAD) == 0 );
00276 assert(j>=0);
00277 assert(j<3);
00278 return v[j]->cP();
00279 }
00280 inline const CoordType & cP( const int j ) const
00281 {
00282 assert( (_flags & DELETED) == 0 );
00283 assert( (_flags & NOTREAD) == 0 );
00284 assert(j>=0);
00285 assert(j<3);
00286 return v[j]->cP();
00287 }
00288
00292 inline VertexType * & V0( const int j ) { return V(j);}
00293 inline VertexType * & V1( const int j ) { return V((j+1)%3);}
00294 inline VertexType * & V2( const int j ) { return V((j+2)%3);}
00295 inline const VertexType * const & V0( const int j ) const { return V(j);}
00296 inline const VertexType * const & V1( const int j ) const { return V((j+1)%3);}
00297 inline const VertexType * const & V2( const int j ) const { return V((j+2)%3);}
00298 inline const VertexType * const & cV0( const int j ) const { return cV(j);}
00299 inline const VertexType * const & cV1( const int j ) const { return cV((j+1)%3);}
00300 inline const VertexType * const & cV2( const int j ) const { return cV((j+2)%3);}
00301
00303 inline CoordType & P0( const int j ) { return V(j)->P();}
00304 inline CoordType & P1( const int j ) { return V((j+1)%3)->P();}
00305 inline CoordType & P2( const int j ) { return V((j+2)%3)->P();}
00306 inline const CoordType & P0( const int j ) const { return V(j)->P();}
00307 inline const CoordType & P1( const int j ) const { return V((j+1)%3)->P();}
00308 inline const CoordType & P2( const int j ) const { return V((j+2)%3)->P();}
00309 inline const CoordType & cP0( const int j ) const { return cV(j)->P();}
00310 inline const CoordType & cP1( const int j ) const { return cV((j+1)%3)->P();}
00311 inline const CoordType & cP2( const int j ) const { return cV((j+2)%3)->P();}
00312
00313 inline VertexType * & UberV( const int j )
00314 {
00315 assert(j>=0);
00316 assert(j<3);
00317 return v[j];
00318 }
00319
00320 inline const VertexType * const & UberV( const int j ) const
00321 {
00322 assert(j>=0);
00323 assert(j<3);
00324 return v[j];
00325 }
00326
00327
00329
00330
00336
00337 #ifdef __VCGLIB_FACE_FN
00338
00339 protected:
00340 CoordType _n;
00341 public:
00342 #endif
00343
00345 inline CoordType & N()
00346 {
00347 #ifdef __VCGLIB_FACE_FN
00348 return _n;
00349 #else
00350 assert(0);
00351 return *(CoordType *)0;
00352 #endif
00353 }
00355 inline const CoordType & N() const
00356 {
00357 #ifdef __VCGLIB_FACE_FN
00358 return _n;
00359 #else
00360 return *(CoordType *)0;
00361 #endif
00362 }
00364 inline const CoordType cN() const
00365 {
00366 #ifdef __VCGLIB_FACE_FN
00367 return _n;
00368 #else
00369 return *(CoordType *)0;
00370 #endif
00371 }
00372
00375 const CoordType Normal() const
00376 {
00377 return vcg::Normal(*this);
00378 }
00379
00382 const CoordType NormalizedNormal() const
00383 {
00384 return vcg::NormalizedNormal(*this);
00385 }
00386
00387 #ifdef __VCGLIB_FACE_WN
00388
00389 CoordType _wn[3];
00390 #endif
00391
00392 public:
00393 CoordType & WN(const int i)
00394 {
00395 #ifdef __VCGLIB_FACE_WN
00396 return _wn[i];
00397 #else
00398 assert(0);
00399 return *(CoordType *)(&_flags);
00400 #endif
00401 }
00402
00403 const CoordType & WN(const int i) const
00404 {
00405 #ifdef __VCGLIB_FACE_WN
00406 return _wn[i];
00407 #else
00408 return CoordType();
00409 #endif
00410 }
00411
00413
00414
00420
00421 #ifdef __VCGLIB_FACE_FQ
00422 protected:
00423 float _q;
00424 #endif
00425 public:
00426 float & Q()
00427 {
00428 #ifdef __VCGLIB_FACE_FQ
00429 return _q;
00430 #else
00431 assert(0);
00432 return *(float*)(&_flags);
00433 #endif
00434 }
00435
00436 const float & Q() const
00437 {
00438 #ifdef __VCGLIB_FACE_FQ
00439 return _q;
00440 #else
00441 assert(0);
00442 return *(float*)(&_flags);
00443 #endif
00444 }
00445
00447
00448
00454
00455
00456 protected:
00457 #ifdef __VCGLIB_FACE_WT
00458 TCTYPE _wt[3];
00459 #endif
00460 public:
00461 TCTYPE & WT(const int i)
00462 {
00463 #ifdef __VCGLIB_FACE_WT
00464 return _wt[i];
00465 #else
00466 assert(0);
00467 return *(TCTYPE*)(&_flags +i) ;
00468 #endif
00469 }
00470
00471 const TCTYPE & WT(const int i) const
00472 {
00473 #ifdef __VCGLIB_FACE_WT
00474 return _wt[i];
00475 #else
00476 assert(0);
00477 return *(TCTYPE*)(&_flags);
00478 #endif
00479 }
00480
00481
00483
00484
00490 protected:
00491 #ifdef __VCGLIB_FACE_FC
00492 Color4b _c;
00493 #endif
00494
00495 public:
00496 Color4b & C()
00497 {
00498 #ifdef __VCGLIB_FACE_FC
00499 return _c;
00500 #else
00501 assert(0);
00502 return *(Color4b*)(&_flags);
00503 #endif
00504 }
00505
00506 const Color4b C() const
00507 {
00508 #ifdef __VCGLIB_FACE_FC
00509 return _c;
00510 #else
00511 return Color4b(Color4b::White);
00512 #endif
00513 }
00514
00515 protected:
00516 #ifdef __VCGLIB_FACE_WC
00517 Color4b _wc[3];
00518 #endif
00519 public:
00520 Color4b & WC(const int i)
00521 {
00522 #ifdef __VCGLIB_FACE_WC
00523 return _wc[i];
00524 #else
00525 assert(0);
00526 return *(Color4b*)(&_flags + i);
00527 #endif
00528 }
00529
00530 const Color4b WC(const int i) const
00531 {
00532 #ifdef __VCGLIB_FACE_WC
00533 return _wc[i];
00534 #else
00535 assert(0);
00536 return Color4b(Color4b::White);
00537 #endif
00538 }
00539
00540
00541
00542
00544
00545
00551
00552 #if (defined(__VCGLIB_FACE_AF) && defined(__VCGLIB_FACE_AS))
00553 #error Error: You cannot specify face-to-face and shared topology together
00554 #endif
00555
00556 #if (defined(__VCGLIB_FACE_AV) && defined(__VCGLIB_FACE_AS))
00557 #error Error: You cannot specify vertex-face and shared topology together
00558 #endif
00559
00560 protected:
00561 #if defined(__VCGLIB_FACE_AF)
00562
00563 FFTYPE *_ffp[3];
00565 char _ffi[3];
00566 #endif
00567
00568 #ifdef __VCGLIB_FACE_AV
00569
00570 FFTYPE *_fvp[3];
00571 char _fvi[3];
00572 #endif
00573
00574 #ifdef __VCGLIB_FACE_AS
00575
00576 FFTYPE *fs[3];
00577 char zs[3];
00578 #endif
00579 public:
00580
00581
00582
00583
00587 inline FFTYPE * & FFp( const int j )
00588 {
00589 assert( (_flags & DELETED) == 0 );
00590 assert( (_flags & NOTREAD) == 0 );
00591 assert( (_flags & NOTWRITE) == 0 );
00592 assert(j>=0);
00593 assert(j<3);
00594 #if defined(__VCGLIB_FACE_AF)
00595 return _ffp[j];
00596 #elif defined(__VCGLIB_FACE_AS)
00597 return fs[j];
00598 #else
00599 assert(0);
00600 static FFTYPE *dum=0; dum+=j;
00601 return dum;
00602
00603 #endif
00604 }
00605
00606 inline const FFTYPE * FFp( const int j ) const
00607 {
00608 assert( (_flags & DELETED) == 0 );
00609 assert( (_flags & NOTREAD) == 0 );
00610 assert(j>=0 && j<3);
00611
00612 #if defined(__VCGLIB_FACE_AF)
00613 return _ffp[j];
00614 #elif defined(__VCGLIB_FACE_AS)
00615 return fs[j];
00616 #else
00617 assert(0);
00618 static FFTYPE *dum=0; dum+=j;
00619 return dum;
00620 #endif
00621 }
00622 inline const FFTYPE * cFFp( const int j ) const {return FFp(j);}
00623
00624 inline FFTYPE * & FFp1( const int j ) { return FFp((j+1)%3);}
00625 inline FFTYPE * & FFp2( const int j ) { return FFp((j+2)%3);}
00626 inline const FFTYPE * const& FFp1( const int j ) const { return FFp((j+1)%3);}
00627 inline const FFTYPE * const& FFp2( const int j ) const { return FFp((j+2)%3);}
00628
00629
00630
00634 inline FFTYPE * & UberF( const int j )
00635 {
00636 assert(j>=0);
00637 assert(j<3);
00638 #if defined(__VCGLIB_FACE_AF)
00639 return _ffp[j];
00640 #elif defined(__VCGLIB_FACE_AS)
00641 return fs[j];
00642 #else
00643 assert(0);
00644 return *((FFTYPE **)(_flags));
00645 #endif
00646 }
00647
00648 inline const FFTYPE * const & UberF( const int j ) const
00649 {
00650 assert(j>=0);
00651 assert(j<3);
00652 #if defined(__VCGLIB_FACE_AF)
00653 return _ffp[j];
00654 #elif defined(__VCGLIB_FACE_AS)
00655 return fs[j];
00656 #else
00657 assert(0);
00658 return *((FFTYPE **)(_flags));
00659 #endif
00660 }
00661
00662
00663 inline FFTYPE * & VFp( const int j )
00664 {
00665 assert( (_flags & DELETED) == 0 );
00666 assert( (_flags & NOTREAD) == 0 );
00667 assert( (_flags & NOTWRITE) == 0 );
00668 assert(j>=0);
00669 assert(j<3);
00670 #ifdef __VCGLIB_FACE_AV
00671 return _fvp[j];
00672 #elif defined(__VCGLIB_FACE_AS)
00673 return fs[j];
00674 #else
00675 assert(0);
00676 return *((FFTYPE **)(_flags));
00677 #endif
00678 }
00679
00680 inline const FFTYPE * const VFp( const int j ) const
00681 {
00682 assert( (_flags & DELETED) == 0 );
00683 assert( (_flags & NOTREAD) == 0 );
00684 assert(j>=0);
00685 assert(j<3);
00686 #ifdef __VCGLIB_FACE_AV
00687 return _fvp[j];
00688 #elif defined(__VCGLIB_FACE_AS)
00689 return fs[j];
00690 #else
00691 assert(0);
00692 static FFTYPE * const DummyVal=0;
00693 return DummyVal;
00694 #endif
00695 }
00696 inline const FFTYPE * cVFp( const int j ) const {return VFp(j);}
00697
00698
00702 inline char & FFi( const int j )
00703 {
00704 assert( (_flags & DELETED) == 0 );
00705 assert( (_flags & NOTREAD) == 0 );
00706 assert( (_flags & NOTWRITE) == 0 );
00707 assert(j>=0);
00708 assert(j<3);
00709 #if defined(__VCGLIB_FACE_AF)
00710 return _ffi[j];
00711 #elif defined(__VCGLIB_FACE_AS)
00712 return zs[j];
00713 #else
00714 assert(0);
00715 return *(char *)&_flags;
00716 #endif
00717 }
00718
00719 inline const char & FFi( const int j ) const
00720 {
00721 assert( (_flags & DELETED) == 0 );
00722 assert( (_flags & NOTREAD) == 0 );
00723 assert(j>=0);
00724 assert(j<3);
00725 #if defined(__VCGLIB_FACE_AF)
00726 return _ffi[j];
00727 #elif defined(__VCGLIB_FACE_AS)
00728 return zs[j];
00729 #else
00730 assert(0);
00731 return *(char *)&_flags;
00732 #endif
00733 }
00734
00735 inline const char & cFFi( const int j ) const {return FFi(j);}
00736
00740 inline char & UberZ( const int j )
00741 {
00742 assert(j>=0);
00743 assert(j<3);
00744 #if defined(__VCGLIB_FACE_AF)
00745 return _ffi[j];
00746 #elif defined(__VCGLIB_FACE_AS)
00747 return zs[j];
00748 #else
00749 assert(0);
00750 return *(char *)&_flags;
00751 #endif
00752 }
00753
00754 inline const char & UberZ( const int j ) const
00755 {
00756 assert(j>=0);
00757 assert(j<3);
00758 #if defined(__VCGLIB_FACE_AF)
00759 return _ffi[j];
00760 #elif defined(__VCGLIB_FACE_AS)
00761 return zs[j];
00762 #else
00763 assert(0);
00764 return *(char *)&_flags;
00765 #endif
00766 }
00767
00768
00769 inline char & VFi( const int j )
00770 {
00771 assert( (_flags & DELETED) == 0 );
00772 assert( (_flags & NOTREAD) == 0 );
00773 assert( (_flags & NOTWRITE) == 0 );
00774 assert(j>=0);
00775 assert(j<3);
00776 #ifdef __VCGLIB_FACE_AV
00777 return _fvi[j];
00778 #elif defined(__VCGLIB_FACE_AS)
00779 return zs[j];
00780 #else
00781 assert(0);
00782 return *(char *)&_flags;
00783 #endif
00784 }
00785
00786 inline const char & VFi( const int j ) const
00787 {
00788 assert( (_flags & DELETED) == 0 );
00789 assert( (_flags & NOTREAD) == 0 );
00790 assert(j>=0);
00791 assert(j<3);
00792 #ifdef __VCGLIB_FACE_AV
00793 return _fvi[j];
00794 #elif defined(__VCGLIB_FACE_AS)
00795 return zs[j];
00796 #else
00797 assert(0);
00798 return *(char *)&_flags;
00799 #endif
00800 }
00801
00803
00804
00810
00811
00812 #ifdef __VCGLIB_FACE_FM
00813
00814 int imark;
00815 inline int & IMark()
00816 {
00817 assert( (_flags & DELETED) == 0 );
00818 assert( (_flags & NOTREAD) == 0 );
00819 assert( (_flags & NOTWRITE) == 0 );
00820 return imark;
00821 }
00822
00823 inline const int & IMark() const
00824 {
00825 assert( (_flags & DELETED) == 0 );
00826 assert( (_flags & NOTREAD) == 0 );
00827 return imark;
00828 }
00829 #endif // Mark
00830
00832 inline void InitIMark()
00833 {
00834 #ifdef __VCGLIB_FACE_FM
00835 imark = 0;
00836 #endif
00837 }
00838
00839
00841
00847
00848
00849 enum {
00850
00851 DELETED = 0x00000001,
00852
00853 NOTREAD = 0x00000002,
00854
00855 NOTWRITE = 0x00000004,
00856
00857 SELECTED = 0x00000020,
00858
00859 BORDER0 = 0x00000040,
00860 BORDER1 = 0x00000080,
00861 BORDER2 = 0x00000100,
00862
00863 NORMX = 0x00000200,
00864 NORMY = 0x00000400,
00865 NORMZ = 0x00000800,
00866
00867 FEATURE0 = 0x00008000,
00868 FEATURE1 = 0x00010000,
00869 FEATURE2 = 0x00020000,
00870
00871 USER0 = 0x00040000,
00872 USER1 = 0x00080000,
00873 USER2 = 0x00100000,
00874 USER3 = 0x00200000
00875 };
00876 public:
00877 static int &LastBitFlag()
00878 {
00879 static int b =USER0;
00880 return b;
00881 }
00882 static inline int NewBitFlag()
00883 {
00884 LastBitFlag()=LastBitFlag()<<1;
00885 return LastBitFlag();
00886 }
00887 static inline bool DeleteBitFlag(int bitval)
00888 {
00889 if(LastBitFlag()==bitval) {
00890 LastBitFlag()= LastBitFlag()>>1;
00891 return true;
00892 }
00893 assert(0);
00894 return false;
00895 }
00896
00897 void ClearFlags() {_flags=0;}
00898
00900 inline int & Flags ()
00901 {
00902 assert( (_flags & DELETED) == 0 );
00903 assert( (_flags & NOTREAD) == 0 );
00904 return _flags;
00905 }
00906
00907 inline const int & Flags () const
00908 {
00909 assert( (_flags & DELETED) == 0 );
00910 assert( (_flags & NOTREAD) == 0 );
00911 return _flags;
00912 }
00914 inline int & UberFlags()
00915 {
00916 return _flags;
00917 }
00918
00919 inline const int UberFlags() const
00920 {
00921 return _flags;
00922 }
00923
00925 bool IsD() const {return (_flags & DELETED) != 0;}
00927 void SetD() {_flags |=DELETED;}
00929 void ClearD() {_flags &= (~DELETED);}
00931 bool IsDeleted() const {return IsD();}
00932
00934 bool IsR() const {return (_flags & NOTREAD) == 0;}
00936 void SetR() {_flags &= (~NOTREAD);}
00938 void ClearR() {_flags |=NOTREAD;}
00939
00941 bool IsW() const {return (_flags & NOTWRITE)== 0;}
00943 void SetW() {_flags &=(~NOTWRITE);}
00945 void ClearW() {_flags |=NOTWRITE;}
00946
00948 bool IsRW() const {return (_flags & (NOTREAD | NOTWRITE)) == 0;}
00949
00950
00952 bool IsS() const {return (_flags & SELECTED) != 0;}
00954 void SetS() {_flags |=SELECTED;}
00956 void ClearS() {_flags &= (~SELECTED);}
00957
00959 bool IsB(int i) const {return (_flags & (BORDER0<<i)) != 0;}
00961 void SetB(int i) {_flags |=(BORDER0<<i);}
00963 void ClearB(int i) {_flags &= (~(BORDER0<<i));}
00964
00966 bool IsF(int i) const {return (_flags & (FEATURE0<<i)) != 0;}
00968 void SetF(int i) {_flags |=(FEATURE0<<i);}
00970 void ClearF(int i) {_flags &= (~(FEATURE0<<i));}
00971
00973 bool IsUserBit(int userBit){return (_flags & userBit) != 0;}
00975 void SetUserBit(int userBit){_flags |=userBit;}
00977 void ClearUserBit(int userBit){_flags &= (~userBit);}
00978
00979
00981
00982
00983
00984
00985 void GetBBox( BoxType & bb ) const
00986 {
00987 bb.Set( v[0]->P() );
00988 bb.Add( v[1]->P() );
00989 bb.Add( v[2]->P() );
00990 }
00991
00992
00998 static bool HasFlags() {
00999 return true;
01000 }
01001 static bool HasFaceNormal() {
01002 #ifdef __VCGLIB_FACE_FN
01003 return true;
01004 #else
01005 return false;
01006 #endif
01007 }
01008 static bool HasFaceQuality() {
01009 #ifdef __VCGLIB_FACE_FQ
01010 return true;
01011 #else
01012 return false;
01013 #endif
01014 }
01015 static bool HasFaceColor() {
01016 #ifdef __VCGLIB_FACE_FC
01017 return true;
01018 #else
01019 return false;
01020 #endif
01021 }
01022 static bool HasEdgePlane() {
01023 #ifdef __VCGLIB_FACE_RT
01024 return true;
01025 #else
01026 return false;
01027 #endif
01028 }
01029 static bool HasFFAdjacency() {
01030 #if (defined(__VCGLIB_FACE_AF) || defined(__VCGLIB_FACE_AS))
01031 return true;
01032 #else
01033 return false;
01034 #endif
01035 }
01036 static bool HasVFAdjacency() {
01037 #if (defined(__VCGLIB_FACE_AV) || defined(__VCGLIB_FACE_AS))
01038 return true;
01039 #else
01040 return false;
01041 #endif
01042 }
01043 static bool HasSharedAdjacency() {
01044 #if defined(__VCGLIB_FACE_AS)
01045 return true;
01046 #else
01047 return false;
01048 #endif
01049 }
01050 static bool HasFaceMark() {
01051 #ifdef __VCGLIB_FACE_FC
01052 return true;
01053 #else
01054 return false;
01055 #endif
01056 }
01057 static bool HasWedgeColor() {
01058 #ifdef __VCGLIB_FACE_WC
01059 return true;
01060 #else
01061 return false;
01062 #endif
01063 }
01064 static bool HasWedgeTexCoord() {
01065 #ifdef __VCGLIB_FACE_WT
01066 return true;
01067 #else
01068 return false;
01069 #endif
01070 }
01071 static bool HasWedgeNormal() {
01072 #ifdef __VCGLIB_FACE_WN
01073 return true;
01074 #else
01075 return false;
01076 #endif
01077 }
01078
01080
01082 inline bool operator == ( const FFTYPE & f ) const {
01083 for(int i=0; i<3; ++i)
01084 if( (V(i) != f.V(0)) && (V(i) != f.V(1)) && (V(i) != f.V(2)) )
01085 return false;
01086 return true;
01087 }
01088
01096 bool InterpolationParameters(const CoordType & bq, ScalarType &a, ScalarType &b, ScalarType &_c ) const
01097 {
01098 const ScalarType EPSILON = ScalarType(0.000001);
01099
01100
01101 #define x1 (cV(0)->P()[0])
01102 #define y1 (cV(0)->P()[1])
01103 #define z1 (cV(0)->P()[2])
01104 #define x2 (cV(1)->P()[0])
01105 #define y2 (cV(1)->P()[1])
01106 #define z2 (cV(1)->P()[2])
01107 #define x3 (cV(2)->P()[0])
01108 #define y3 (cV(2)->P()[1])
01109 #define z3 (cV(2)->P()[2])
01110 #define px (bq[0])
01111 #define py (bq[1])
01112 #define pz (bq[2])
01113
01114 ScalarType t1 = px*y2;
01115 ScalarType t2 = px*y3;
01116 ScalarType t3 = py*x2;
01117 ScalarType t4 = py*x3;
01118 ScalarType t5 = x2*y3;
01119 ScalarType t6 = x3*y2;
01120 ScalarType t8 = x1*y2;
01121 ScalarType t9 = x1*y3;
01122 ScalarType t10 = y1*x2;
01123 ScalarType t11 = y1*x3;
01124 ScalarType t13 = t8-t9-t10+t11+t5-t6;
01125 if(fabs(t13)>=EPSILON)
01126 {
01127 ScalarType t15 = px*y1;
01128 ScalarType t16 = py*x1;
01129 a = (t1 -t2-t3 +t4+t5-t6 )/t13;
01130 b = -(t15-t2-t16+t4+t9-t11)/t13;
01131 _c = (t15-t1-t16+t3+t8-t10)/t13;
01132 return true;
01133 }
01134
01135 t1 = px*z2;
01136 t2 = px*z3;
01137 t3 = pz*x2;
01138 t4 = pz*x3;
01139 t5 = x2*z3;
01140 t6 = x3*z2;
01141 t8 = x1*z2;
01142 t9 = x1*z3;
01143 t10 = z1*x2;
01144 t11 = z1*x3;
01145 t13 = t8-t9-t10+t11+t5-t6;
01146 if(fabs(t13)>=EPSILON)
01147 {
01148 ScalarType t15 = px*z1;
01149 ScalarType t16 = pz*x1;
01150 a = (t1 -t2-t3 +t4+t5-t6 )/t13;
01151 b = -(t15-t2-t16+t4+t9-t11)/t13;
01152 _c = (t15-t1-t16+t3+t8-t10)/t13;
01153 return true;
01154 }
01155
01156 t1 = pz*y2; t2 = pz*y3;
01157 t3 = py*z2; t4 = py*z3;
01158 t5 = z2*y3; t6 = z3*y2;
01159 t8 = z1*y2; t9 = z1*y3;
01160 t10 = y1*z2; t11 = y1*z3;
01161 t13 = t8-t9-t10+t11+t5-t6;
01162 if(fabs(t13)>=EPSILON)
01163 {
01164 ScalarType t15 = pz*y1;
01165 ScalarType t16 = py*z1;
01166 a = (t1 -t2-t3 +t4+t5-t6 )/t13;
01167 b = -(t15-t2-t16+t4+t9-t11)/t13;
01168 _c = (t15-t1-t16+t3+t8-t10)/t13;
01169 return true;
01170 }
01171
01172 #undef x1
01173 #undef y1
01174 #undef z1
01175 #undef x2
01176 #undef y2
01177 #undef z2
01178 #undef x3
01179 #undef y3
01180 #undef z3
01181 #undef px
01182 #undef py
01183 #undef pz
01184
01185 return false;
01186 }
01187
01188
01189
01191
01192
01193
01194
01195
01196 ScalarType DoubleArea() const
01197 {
01198 return ( (V(1)->cP() - V(0)->cP()) ^ (V(2)->cP() - V(0)->P()) ).Norm();
01199 }
01200
01201 CoordType Barycenter() const
01202 {
01203 return (V(0)->P()+V(1)->P()+V(2)->P())/ScalarType(3.0);
01204 }
01205
01206 Sphere3<ScalarType> SmallestEnclosingSphere() const
01207 {
01208 return SmallestEnclosing::SphereOfTriangle<ScalarType>(*this);
01209 }
01210
01211 ScalarType Perimeter() const
01212 {
01213 return Distance(V(0)->P(),V(1)->P())+
01214 Distance(V(1)->P(),V(2)->P())+
01215 Distance(V(2)->P(),V(0)->P());
01216 }
01217
01219 ScalarType QualityFace( ) const
01220 {
01221
01222 return Quality(V(0)->cP(), V(1)->cP(), V(2)->cP());
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242 }
01243
01244
01245 inline void Nexts( BaseFaceType *&f,int &z )
01246 {
01247 int t;
01248 t = z;
01249 z = (*f).Z(z);
01250 f = (*f).F(t);
01251 }
01252
01253
01254 #ifdef __VCGLIB_FACE_RT
01255
01256 CoordType & Edge(const int& i){return edges[i];};
01257 CoordType cEdge(const int& i)const{return edges[i];};
01258
01259 Plane3<ScalarType> & Plane(){return plane;};
01260 Plane3<ScalarType> cPlane()const{return plane;};
01261
01262
01263 CoordType edges[3];;
01264 Plane3<ScalarType> plane;
01265 #endif
01266
01268 inline int VertexIndex( const VertexType * w ) const
01269 {
01270 if( v[0]==w ) return 0;
01271 else if( v[1]==w ) return 1;
01272 else if( v[2]==w ) return 2;
01273 else return -1;
01274 }
01275
01276
01277 };
01278
01279
01280 #ifndef __VCG_FACE_BASE_SINGLE
01281 #define __VCG_FACE_BASE_SINGLE
01282
01283
01285 namespace face
01286 {
01287
01288 template <class FaceType>
01289 void ComputeNormal(FaceType &f) { f.N() = vcg::Normal< FaceType >(f); }
01290
01291 template <class FaceType>
01292 void ComputeNormalizedNormal(FaceType &f) { f.N() = vcg::NormalizedNormal< FaceType >(f); }
01293
01294 }
01296 #endif
01297
01298 }
01299
01300
01301 #endif
01302