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
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 #ifndef VERTEX_TYPE
00180 #pragma message("\nYou should never directly include this file\_n")
00181 #else
00182
00183 #pragma message("VCGLIB Warning: this way to define the simplex vertex is DEPRECATED and no more SUPPORTED")
00184 #pragma message("VCGLIB Warning: use vcg/simplex/vertexplus instead ")
00185
00186 #include<vcg/space/point3.h>
00187 #include<vcg/space/color4.h>
00188 #include<vcg/space/texcoord2.h>
00189 #include<vcg/simplex/face/pos.h>
00190 #include<vcg/space/box3.h>
00191
00192
00193 namespace vcg {
00194
00195 class DUMMYFACETYPE;
00196 class DUMMYEDGETYPE;
00197 class DUMMYTETRATYPE;
00207 template <class FLTYPE, class VETYPE = DUMMYEDGETYPE, class VFTYPE = DUMMYFACETYPE, class VTTYPE = DUMMYTETRATYPE,class TCTYPE = TexCoord2<float,1>, class CoordTYPE= Point3<FLTYPE> >
00208 class VERTEX_TYPE
00209 {
00210 public:
00211
00213 typedef FLTYPE ScalarType;
00215 typedef CoordTYPE CoordType;
00216 typedef Point3<ScalarType> NormalType;
00218 typedef VERTEX_TYPE BaseVertexType;
00220 typedef VETYPE EdgeType;
00222 typedef VFTYPE FaceType;
00224 typedef ScalarType QualityType;
00225
00226
00227
00233 protected:
00235 CoordType _p;
00236
00237 public:
00239 inline CoordType & P()
00240 {
00241 assert( (_flags & DELETED) == 0 );
00242 assert( (_flags & NOTREAD) == 0 );
00243 assert( (_flags & NOTWRITE) == 0 );
00244 return _p;
00245 }
00246
00248 inline const CoordType & P() const
00249 {
00250 assert( (_flags & DELETED) == 0 );
00251 assert( (_flags & NOTREAD) == 0 );
00252 return _p;
00253 }
00254
00256 inline const CoordType & cP() const
00257 {
00258 assert( (_flags & DELETED) == 0 );
00259 assert( (_flags & NOTREAD) == 0 );
00260 return _p;
00261 }
00262
00264 inline CoordType & UberP()
00265 {
00266 return _p;
00267 }
00268
00270 inline const CoordType & UberP() const
00271 {
00272 return _p;
00273 }
00274
00276
00277
00287
00288 protected:
00290 int _flags;
00291
00292 public:
00294 inline int & Flags ()
00295 {
00296 assert( (_flags & DELETED) == 0 );
00297 assert( (_flags & NOTREAD) == 0 );
00298 return _flags;
00299 }
00300
00302 inline int & UberFlags ()
00303 {
00304 return _flags;
00305 }
00306 inline const int UberFlags() const
00307 {
00308 return _flags;
00309 }
00310
00312 bool IsD() const {return (_flags & DELETED) != 0;}
00314 bool IsR() const {return (_flags & NOTREAD) == 0;}
00316 bool IsW() const {return (_flags & NOTWRITE)== 0;}
00318 bool IsRW() const {return (_flags & (NOTREAD | NOTWRITE)) == 0;}
00320 bool IsS() const {return (_flags & SELECTED) != 0;}
00322 bool IsB() const {return (_flags & BORDER) != 0;}
00324 bool IsV() const {return (_flags & VISITED) != 0;}
00325
00326
00330 void SetFlags(int flagp) {_flags=flagp;}
00331
00335 void ClearFlags() {_flags=0;}
00336
00338 void SetD() {_flags |=DELETED;}
00340 void ClearD() {_flags &=(~DELETED);}
00342 void SetR() {_flags &=(~NOTREAD);}
00344 void ClearR() {_flags |=NOTREAD;}
00346 void ClearW() {_flags |=NOTWRITE;}
00348 void SetW() {_flags &=(~NOTWRITE);}
00350 void SetS() {_flags |=SELECTED;}
00352 void ClearS() {_flags &= ~SELECTED;}
00354 void SetB() {_flags |=BORDER;}
00355 void ClearB() {_flags &=~BORDER;}
00357 void ClearV() {_flags &= ~VISITED;}
00359 void SetV() {_flags |=VISITED;}
00361 static int &LastBitFlag()
00362 {
00363 static int b =USER0;
00364 return b;
00365 }
00366
00368 static inline int NewBitFlag()
00369 {
00370 LastBitFlag()=LastBitFlag()<<1;
00371 return LastBitFlag();
00372 }
00373
00374 static inline bool DeleteBitFlag(int bitval)
00375 {
00376 if(LastBitFlag()==bitval) {
00377 LastBitFlag()= LastBitFlag()>>1;
00378 return true;
00379 }
00380 assert(0);
00381 return false;
00382 }
00384 bool IsUserBit(int userBit){return (_flags & userBit) != 0;}
00386 void SetUserBit(int userBit){_flags |=userBit;}
00388 void ClearUserBit(int userBit){_flags &= (~userBit);}
00389
00390
00392
00393
00394
00395
00396
00397
00398 void GetBBox( Box3<ScalarType> & bb ) const
00399 {
00400 bb.Set( cP() );
00401 }
00402
00403
00409
00410 #ifdef __VCGLIB_VERTEX_VT
00411 protected:
00412 TCTYPE _t;
00413 #endif
00414
00415 public:
00416 TCTYPE & T()
00417 {
00418 #ifdef __VCGLIB_VERTEX_VT
00419 return _t;
00420 #else
00421 assert(0);
00422 return *(TCTYPE*)(&_flags);
00423 #endif
00424 }
00425
00426 const TCTYPE & T() const
00427 {
00428 #ifdef __VCGLIB_VERTEX_VT
00429 return _t;
00430 #else
00431 assert(0);
00432 return *(TCTYPE*)(&_flags);
00433 #endif
00434 }
00435
00437
00438
00444
00445 #ifdef __VCGLIB_VERTEX_VC
00446 protected:
00447 Color4b _c;
00448 #endif
00449
00450 public:
00451 Color4b & C()
00452 {
00453 #ifdef __VCGLIB_VERTEX_VC
00454 return _c;
00455 #else
00456 assert(0);
00457 return *(Color4b*)(&_flags);
00458 #endif
00459 }
00460
00461 const Color4b & C() const
00462 {
00463 #ifdef __VCGLIB_VERTEX_VC
00464 return _c;
00465 #else
00466 return Color4b(Color4b::White);
00467 #endif
00468 }
00470
00471
00477
00478 #ifdef __VCGLIB_VERTEX_VQ
00479 protected:
00480 float _q;
00481 #endif
00482
00483 public:
00484 float & Q()
00485 {
00486 #ifdef __VCGLIB_VERTEX_VQ
00487 return _q;
00488 #else
00489 assert(0);
00490 return *(float*)(&_flags);
00491 #endif
00492 }
00493
00494 const float & Q() const
00495 {
00496 #ifdef __VCGLIB_VERTEX_VQ
00497 return _q;
00498 #else
00499 return 1;
00500 #endif
00501 }
00503
00508
00509 #if ((defined __VCGLIB_VERTEX_EA) || (defined __VCGLIB_VERTEX_EAS))
00510
00511 protected:
00512 EdgeType *_ep;
00513 int _ei;
00514 #endif
00515
00516 public:
00517 inline EdgeType * & VEp()
00518 {
00519 #if ((defined __VCGLIB_VERTEX_EA) || (defined __VCGLIB_VERTEX_EAS))
00520 return _ep;
00521 #else
00522 assert(0);
00523 return *((EdgeType **)(_flags));
00524 #endif
00525 }
00526
00527 inline const EdgeType * & VEp() const
00528 {
00529 #if ((defined __VCGLIB_VERTEX_EA) || (defined __VCGLIB_VERTEX_EAS))
00530 return _ep;
00531 #else
00532 assert(0);
00533 return (EdgeType *)this;
00534 #endif
00535 }
00536
00537 inline int & VEi()
00538 {
00539 #if ((defined __VCGLIB_VERTEX_EA) || (defined __VCGLIB_VERTEX_EAS))
00540
00541 return _ei;
00542 #else
00543 assert(0);
00544 return _flags;
00545 #endif
00546 }
00547
00548 inline const int & VEi() const
00549 {
00550 #if ((defined __VCGLIB_VERTEX_EA) || (defined __VCGLIB_VERTEX_EAS))
00551 return _ei;
00552 #else
00553 assert(0);
00554 return (void *)this;
00555 #endif
00556 }
00558
00564
00565 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00566
00567 protected:
00568 VFTYPE *_vfb;
00569 int _vfi;
00570 #endif
00571
00572 public:
00573 inline VFTYPE * & VFp()
00574 {
00575 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00576 return _vfb;
00577 #else
00578 assert(0);
00579 static VFTYPE *dum;
00580 return dum;
00581 #endif
00582 }
00583
00584 inline const VFTYPE * & VFp() const
00585 {
00586 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00587 return _vfb;
00588 #else
00589 assert(0);
00590 return (VFTYPE *)0;
00591 #endif
00592 }
00593
00594 inline const VFTYPE * cVFp() const
00595 {
00596 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00597 return _vfb;
00598 #else
00599 assert(0);
00600 return (VFTYPE *)0;
00601 #endif
00602 }
00603
00604 inline int & VFi()
00605 {
00606 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00607
00608 return _vfi;
00609 #else
00610 assert(0);
00611 return _flags;
00612 #endif
00613 }
00614
00615 inline const int & VFi() const
00616 {
00617 #if ((defined __VCGLIB_VERTEX_AF) || (defined __VCGLIB_VERTEX_AFS))
00618 return _vfi;
00619 #else
00620 assert(0);
00621 return (void *)this;
00622 #endif
00623 }
00624
00625
00626
00628
00629
00635
00636 #if ((defined __VCGLIB_VERTEX_AT) || (defined __VCGLIB_VERTEX_ATS))
00637
00638 protected:
00639 VTTYPE *_vtp;
00640 int _vti;
00641 #endif
00642
00643 public:
00644 inline VTTYPE * & VTp()
00645 {
00646 #if ((defined __VCGLIB_VERTEX_AT) || (defined __VCGLIB_VERTEX_ATS))
00647 return _vtp;
00648 #else
00649 assert(0);
00650 return *((VTTYPE **)(_flags));
00651 #endif
00652 }
00653
00654 inline const VTTYPE * & VTp() const
00655 {
00656 #if ((defined __VCGLIB_VERTEX_AT) || (defined __VCGLIB_VERTEX_ATS))
00657 return _vtp;
00658 #else
00659 assert(0);
00660 return (VTTYPE *)this;
00661 #endif
00662 }
00663
00664 inline int & VTi()
00665 {
00666 #if ((defined __VCGLIB_VERTEX_AT) || (defined __VCGLIB_VERTEX_ATS))
00667
00668 return _vti;
00669 #else
00670 assert(0);
00671 return _flags;
00672 #endif
00673 }
00674
00675 inline const int & VTi() const
00676 {
00677 #if ((defined __VCGLIB_VERTEX_AT) || (defined __VCGLIB_VERTEX_ATS))
00678 return _vti;
00679 #else
00680 assert(0);
00681 return (void *)this;
00682 #endif
00683 }
00684
00685
00686
00688
00689
00695
00696 #ifdef __VCGLIB_VERTEX_VM
00697 protected:
00699 int _imark;
00700 #endif // Mark
00701 public:
00702 #ifdef __VCGLIB_VERTEX_VM
00703
00704 inline int & IMark()
00705 {
00706 assert( (_flags & DELETED) == 0 );
00707 assert( (_flags & NOTREAD) == 0 );
00708 assert( (_flags & NOTWRITE) == 0 );
00709 return _imark;
00710 }
00711
00713 inline const int & IMark() const
00714 {
00715 assert( (_flags & DELETED) == 0 );
00716 assert( (_flags & NOTREAD) == 0 );
00717 return _imark;
00718 }
00719 #endif
00720
00722 inline void InitIMark()
00723 {
00724 #ifdef __VCGLIB_VERTEX_VM
00725 _imark = 0;
00726 #endif
00727 }
00728
00730
00731
00737
00738 #ifdef __VCGLIB_VERTEX_VN
00739 protected:
00740 CoordType _n;
00741 #endif
00742
00743 public:
00745 inline CoordType & N()
00746 {
00747 assert( (_flags & DELETED) == 0 );
00748 assert( (_flags & NOTREAD) == 0 );
00749 assert( (_flags & NOTWRITE) == 0 );
00750 #ifdef __VCGLIB_VERTEX_VN
00751 return _n;
00752 #else
00753 assert(0);
00754 return *(CoordType *)this;
00755 #endif
00756 }
00757
00759 inline const CoordType & N() const
00760 {
00761 assert( (_flags & DELETED) == 0 );
00762 assert( (_flags & NOTREAD) == 0 );
00763 #ifdef __VCGLIB_VERTEX_VN
00764 return _n;
00765 #else
00766 assert(0);
00767 return *(CoordType *)this;
00768 #endif
00769 }
00770
00771 inline const CoordType cN() const
00772 {
00773 assert( (_flags & DELETED) == 0 );
00774 assert( (_flags & NOTREAD) == 0 );
00775 #ifdef __VCGLIB_VERTEX_VN
00776 return _n;
00777 #else
00778 return CoordType(0,0,0);
00779 #endif
00780 }
00782 inline CoordType & UberN()
00783 {
00784 #ifdef __VCGLIB_VERTEX_VN
00785 return _n;
00786 #else
00787 assert(0);
00788 return *(CoordType *)this;
00789 #endif
00790 }
00791
00793 inline const CoordType & UberN() const
00794 {
00795 #ifdef __VCGLIB_VERTEX_VN
00796 return _n;
00797 #else
00798 assert(0);
00799 return *(CoordType *)this;
00800 #endif
00801 }
00802
00803 template <bool NormalizeFlag>
00804 const CoordType GenericNormal()
00805 {
00806 if (!HasVFAdjacency())
00807 {
00808 assert(0);
00809 return (VERTEX_TYPE::CoordType (0,0,0));
00810 }
00811 else
00812 {
00813 vcg::face::VFIterator<typename VERTEX_TYPE::FaceType> VFi=vcg::face::VFIterator<typename VERTEX_TYPE::FaceType>();
00814 VFi.f=VFp();
00815 VFi.z=VFi();
00816 typename VERTEX_TYPE::CoordType N= typename VERTEX_TYPE::CoordType(0,0,0);
00817 while (!VFi.End())
00818 {
00819 N+=VFi.f->Normal();
00820 VFi++;
00821 }
00822 if(NormalizeFlag) N.Normalize();
00823 return N;
00824 }
00825 }
00826
00830 const CoordType Normal() { return GenericNormal<false>(); }
00831
00835 const CoordType NormalizedNormal() { return GenericNormal<true>(); }
00836
00837
00839
00840
00846
00847 static bool HasFlags() {
00848 return true;
00849 }
00850
00851 static bool HasNormal() {
00852 #ifdef __VCGLIB_VERTEX_VN
00853 return true;
00854 #else
00855 return false;
00856 #endif
00857 }
00858 static bool HasColor() {
00859 #ifdef __VCGLIB_VERTEX_VC
00860 return true;
00861 #else
00862 return false;
00863 #endif
00864 }
00865 static bool HasMark() {
00866 #ifdef __VCGLIB_VERTEX_VM
00867 return true;
00868 #else
00869 return false;
00870 #endif
00871 }
00872 static bool HasQuality() {
00873 #ifdef __VCGLIB_VERTEX_VQ
00874 return true;
00875 #else
00876 return false;
00877 #endif
00878 }
00879 static bool HasTexCoord() {
00880 #ifdef __VCGLIB_VERTEX_VT
00881 return true;
00882 #else
00883 return false;
00884 #endif
00885 }
00886 static bool HasVFAdjacency() {
00887 #ifdef __VCGLIB_VERTEX_AF
00888 return true;
00889 #else
00890 return false;
00891 #endif
00892 }
00893 static bool HasVTAdjacency() {
00894 #ifdef __VCGLIB_VERTEX_AT
00895 return true;
00896 #else
00897 return false;
00898 #endif
00899 }
00900
00901 static bool HasVEAdjacency() {
00902 #ifdef __VCGLIB_VERTEX_EA
00903 return true;
00904 #else
00905 return false;
00906 #endif
00907 }
00909
00910
00914
00915 template <class VERT_TYPE>
00916 inline void Convert( VERT_TYPE &v )
00917 {
00918 P()=v.P();
00919 Flags()=v.Flags();
00920 if ((HasNormal())&&(v.HasNormal()))
00921 N()=v.N();
00922 if ((HasColor())&&(v.HasColor()))
00923 C()=v.C();
00924 #ifdef __VCGLIB_VERTEX_VM
00925 if ((HasMark())&&(v.HasMark()))
00926 IMark()=v.IMark();
00927 #endif
00928 if ((HasQuality())&&(v.HasQuality()))
00929 Q()=v.Q();
00930 if ((HasTexCoord())&&(v.HasTexCoord()))
00931 T()=v.T();
00932 }
00933
00935
00936 enum {
00937
00938 DELETED = 0x0001,
00939
00940 NOTREAD = 0x0002,
00941
00942 NOTWRITE = 0x0004,
00943
00944 MODIFIED = 0x0008,
00945
00946 VISITED = 0x0010,
00947
00948 SELECTED = 0x0020,
00949
00950 BORDER = 0x0100,
00951
00952 USER0 = 0x0200
00953 };
00954
00955
00959 inline ScalarType & operator [] ( const int i ){
00960 assert(i>=0 && i<3);
00961 return P().V(i);
00962 }
00966 inline const FLTYPE & operator [] ( const int i ) const {
00967 assert(i>=0 && i<3);
00968 return P().V(i);
00969 }
00971 inline bool operator < ( const VERTEX_TYPE & ve) const {
00972 return _p < ve._p;
00973 }
00974 inline VERTEX_TYPE() {
00975
00976 _flags=0;
00977
00978 };
00979
00980 };
00981
00983 }
00984 #endif
00985