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 #ifndef __VCGLIB__EDGE_TYPE_BASE
00063 #define __VCGLIB__EDGE_TYPE_BASE
00064
00065 #pragma message("[VCGLIB Warning] this way to define the simplex edge is DEPRECATED and no more SUPPORTED")
00066 #pragma message("[VCGLIB Warning] use vcg/simplex/edgeplus instead ")
00067
00068
00069 #include <vcg/space/box3.h>
00070 #include <vcg/space/texcoord2.h>
00071
00072 namespace vcg {
00073
00081 template <class EDGENAME, class SVTYPE, class TCTYPE = TexCoord2<float,1> > class EDGE_TYPE
00082 {
00083 public:
00085 typedef EDGE_TYPE BaseEdgeType;
00087 typedef typename SVTYPE::ScalarType ScalarType;
00089 typedef SVTYPE VertexType;
00091 typedef Point3< ScalarType > CoordType;
00092
00094 typedef Box3<ScalarType> BoxType;
00095
00097 inline EDGE_TYPE(){}
00098
00099 inline EDGE_TYPE(VertexType* v0,VertexType* v1){v[0]=v0;v[1]=v1;}
00100
00101 static inline EDGE_TYPE OrderedEdge(VertexType* v0,VertexType* v1){
00102 if(v0<v1) return EDGE_TYPE(v0,v1);
00103 else return EDGE_TYPE(v1,v0);
00104 }
00105
00106
00107
00109 inline void Set(VertexType* v0,VertexType* v1){v[0]=v0;v[1]=v1;}
00110
00111
00112
00118 protected:
00120 VertexType *v[2];
00121 public:
00125 inline SVTYPE * & V( const int j )
00126 {
00127 assert( !IsD() );
00128 assert(j >= 0 && j < 2);
00129 return v[j];
00130 }
00131
00132 inline const SVTYPE * const & V( const int j ) const
00133 {
00134 assert( !IsD() );
00135 assert(j>=0 && j<2);
00136 return v[j];
00137 }
00138 inline const SVTYPE * const & cV( const int j ) const
00139 {
00140 assert( !IsD() );
00141 assert(j>=0 && j<2);
00142 return v[j];
00143 }
00144
00145
00146 inline CoordType & P( const int j )
00147 {
00148 assert( !IsD() );
00149 assert(j>=0 && j<2);
00150 return v[j]->P();
00151 }
00152
00153 inline const CoordType & P( const int j ) const
00154 {
00155 assert( !IsD() );
00156 assert(j>=0 && j<2);
00157 return v[j]->cP();
00158 }
00159 inline const CoordType & cP( const int j ) const
00160 {
00161 assert( !IsD() );
00162 assert(j>=0 && j<2);
00163 return v[j]->cP();
00164 }
00165
00169 inline SVTYPE * & V0( const int j ) { return V(j);}
00170 inline SVTYPE * & V1( const int j ) { return V((j+1)%2);}
00171 inline const SVTYPE * const & V0( const int j ) const { return V(j);}
00172 inline const SVTYPE * const & V1( const int j ) const { return V((j+1)%2);}
00173 inline const SVTYPE * const & cV0( const int j ) const { return cV(j);}
00174 inline const SVTYPE * const & cV1( const int j ) const { return cV((j+1)%2);}
00175
00177 inline CoordType & P0( const int j ) { return V(j)->P();}
00178 inline CoordType & P1( const int j ) { return V((j+1)%2)->P();}
00179 inline const CoordType & P0( const int j ) const { return V(j)->P();}
00180 inline const CoordType & P1( const int j ) const { return V((j+1)%2)->P();}
00181 inline const CoordType & cP0( const int j ) const { return cV(j)->P();}
00182 inline const CoordType & cP1( const int j ) const { return cV((j+1)%2)->P();}
00183
00184 inline SVTYPE * & UberV( const int j )
00185 {
00186 assert(j>=0 && j<2);
00187 return v[j];
00188 }
00189
00190 inline const SVTYPE * const & UberV( const int j ) const
00191 {
00192 assert(j>=0 && j<2);
00193 return v[j];
00194 }
00195
00196
00198
00199
00205
00206 #ifdef __VCGLIB_EDGE_EN
00207
00208 protected:
00209 CoordType _n;
00210 public:
00211 #endif
00212
00214 inline CoordType & N()
00215 {
00216 #ifdef __VCGLIB_EDGE_EN
00217 return _n;
00218 #else
00219 assert(0);
00220 return *(CoordType *)0;
00221 #endif
00222 }
00224 inline const CoordType & N() const
00225 {
00226 #ifdef __VCGLIB_EDGE_EN
00227 return _n;
00228 #else
00229 return *(CoordType *)0;
00230 #endif
00231 }
00233 inline const CoordType cN() const
00234 {
00235 #ifdef __VCGLIB_EDGE_EN
00236 return _n;
00237 #else
00238 return *(CoordType *)0;
00239 #endif
00240 }
00241
00243
00244
00250
00251 #ifdef __VCGLIB_EDGE_EQ
00252 protected:
00253 float _q;
00254 #endif
00255 public:
00256 float & Q()
00257 {
00258 #ifdef __VCGLIB_EDGE_EQ
00259 return _q;
00260 #else
00261 assert(0);
00262 return *(float*)(0);
00263 #endif
00264 }
00265
00266 const float & Q() const
00267 {
00268 #ifdef __VCGLIB_EDGE_EQ
00269 return _q;
00270 #else
00271 assert(0);
00272 return *(float*)(0);
00273 #endif
00274 }
00275
00277
00278
00284 protected:
00285 #ifdef __VCGLIB_EDGE_EC
00286 Color4b _c;
00287 #endif
00288
00289 public:
00290 Color4b & C()
00291 {
00292 #ifdef __VCGLIB_EDGE_EC
00293 return _c;
00294 #else
00295 assert(0);
00296 return *(Color4b*)(0);
00297 #endif
00298 }
00299
00300 const Color4b C() const
00301 {
00302 #ifdef __VCGLIB_EDGE_EC
00303 return _c;
00304 #else
00305 return Color4b(Color4b::White);
00306 #endif
00307 }
00308
00309
00310
00312
00313
00319
00320 protected:
00321 #if defined(__VCGLIB_EDGE_AE)
00322
00323 EDGENAME *ee[2];
00325 char zs[2];
00326 #endif
00327
00328 #ifdef __VCGLIB_EDGE_AV
00329
00330 EDGENAME *ev[2];
00331 char zv[2];
00332 #endif
00333
00334 public:
00335
00336
00337
00338
00342 inline EDGENAME * & EEp( const int j )
00343 {
00344 assert( !IsD() );
00345 assert(j>=0 && j<2);
00346 #if defined(__VCGLIB_EDGE_AE)
00347 return ee[j];
00348 #else
00349 assert(0);
00350 return *(EDGENAME **)(0);;
00351 #endif
00352 }
00353
00354 inline const EDGENAME * const & EEp( const int j ) const
00355 {
00356 assert( !IsD() );
00357 assert(j>=0 && j<2);
00358 #if defined(__VCGLIB_EDGE_AE)
00359 return ee[j];
00360 #else
00361 assert(0);
00362 return (EDGENAME *)0;
00363 #endif
00364 }
00365 inline EDGENAME * & EEp1( const int j ) { return EEp((j+1)%2);}
00366 inline const EDGENAME * const& EEp1( const int j ) const { return EEp((j+1)%2);}
00367
00371 inline EDGENAME * & UberEEp( const int j )
00372 {
00373 assert(j>=0 && j<2);
00374 #if defined(__VCGLIB_EDGE_AE)
00375 return ee[j];
00376 #else
00377 assert(0);
00378 return *(EDGENAME **)(0);
00379 #endif
00380 }
00381
00382 inline const EDGENAME * const & UberEEp( const int j ) const
00383 {
00384 assert(j>=0 && j<2);
00385 #if defined(__VCGLIB_EDGE_AE)
00386 return ee[j];
00387 #else
00388 assert(0);
00389 return *(EDGENAME **)(0);
00390 #endif
00391 }
00392
00393
00394 inline EDGENAME * & VEp( const int j )
00395 {
00396 assert( !IsD() );
00397 assert(j>=0 && j<2);
00398 #ifdef __VCGLIB_EDGE_AV
00399 return ev[j];
00400 #else
00401 assert(0);
00402 return *(EDGENAME **)(0);
00403 #endif
00404 }
00405
00406 inline const EDGENAME * const & VEp( const int j ) const
00407 {
00408 assert( !IsD() );
00409 assert(j>=0 && j<2);
00410 #ifdef __VCGLIB_EDGE_AV
00411 return ev[j];
00412 #else
00413 assert(0);
00414 return *(EDGENAME **)(0);
00415 #endif
00416 }
00417
00418
00422 inline char & EEi( const int j )
00423 {
00424 assert( !IsD() );
00425 assert(j>=0 && j<2);
00426 #if defined(__VCGLIB_EDGE_AE)
00427 return zs[j];
00428 #else
00429 assert(0);
00430 return *(char *)0;
00431 #endif
00432 }
00433
00434 inline const char & EEi( const int j ) const
00435 {
00436 assert( !IsD() );
00437 assert(j>=0 && j<2);
00438 #if defined(__VCGLIB_EDGE_AE)
00439 return zs[j];
00440 #else
00441 assert(0);
00442 return *(char *)0;
00443 #endif
00444 }
00445
00449 inline char & UberZ( const int j )
00450 {
00451 assert(j>=0 && j<2);
00452 #if defined(__VCGLIB_EDGE_AE)
00453 return zs[j];
00454 #elif defined(__VCGLIB_EDGE_SA)
00455 return zs[j];
00456 #else
00457 assert(0);
00458 static char dummy = 0;
00459 return dummy;
00460 #endif
00461 }
00462
00463 inline const char & UberZ( const int j ) const
00464 {
00465 assert(j>=0 & j<2);
00466 #if defined(__VCGLIB_EDGE_AE)
00467 return zs[j];
00468 #elif defined(__VCGLIB_EDGE_SA)
00469 return zs[j];
00470 #else
00471 assert(0);
00472 static int dummy = 0;
00473 return dummy;
00474 #endif
00475 }
00476
00477
00478 inline char & VEi( const int j )
00479 {
00480 assert( !IsD() );
00481 assert(j>=0 & j<2);
00482 #ifdef __VCGLIB_EDGE_VA
00483 return zv[j];
00484 #elif defined(__VCGLIB_EDGE_SA)
00485 return zs[j];
00486 #else
00487 assert(0);
00488 static char dummy = 0;
00489 return dummy;
00490 #endif
00491 }
00492
00493 inline const char & VEi( const int j ) const
00494 {
00495 assert( !IsD() );
00496 assert(j>=0 & j<2);
00497 #ifdef __VCGLIB_EDGE_VA
00498 return zv[j];
00499 #elif defined(__VCGLIB_EDGE_SA)
00500 return zs[j];
00501 #else
00502 assert(0);
00503 static char dummy = 0;
00504 return dummy;
00505 #endif
00506 }
00507
00509
00510
00516
00517
00518 #ifdef __VCGLIB_EDGE_EM
00519
00520 int imark;
00521 #endif // Mark
00522
00523 inline int & IMark()
00524 {
00525 #ifdef __VCGLIB_EDGE_EM
00526 assert( !IsD() );
00527 assert( (_flags & NOTREAD) == 0 );
00528 assert( (_flags & NOTWRITE) == 0 );
00529 return imark;
00530 #else
00531 return 0;
00532 #endif // Mark
00533 }
00534
00535 inline const int & IMark() const
00536 {
00537 assert( !IsD() );
00538 #ifdef __VCGLIB_EDGE_EM
00539 assert( (_flags & NOTREAD) == 0 );
00540 return imark;
00541 #else
00542 static int dummy = 0;
00543 return dummy;
00544 #endif
00545 }
00546
00548 inline void InitIMark()
00549 {
00550 #ifdef __VCGLIB_EDGE_EM
00551 imark = 0;
00552 #endif
00553 }
00554
00555
00557
00563
00565 #ifdef __VCGLIB_EDGE_EF
00566 int _flags;
00567 #endif
00568 enum {
00569
00570 DELETED = 0x00000001,
00571
00572 NOTREAD = 0x00000002,
00573
00574 NOTWRITE = 0x00000004,
00575
00576 SELECTED = 0x00000020,
00577
00578 BORDER0 = 0x00000040,
00579 BORDER1 = 0x00000080,
00580
00581 USER0 = 0x00040000
00582 };
00583 public:
00584 static int &LastBitFlag()
00585 {
00586 static int b =USER0;
00587 return b;
00588 }
00589 static inline int NewBitFlag()
00590 {
00591 LastBitFlag()=LastBitFlag()<<1;
00592 return LastBitFlag();
00593 }
00594 static inline bool DeleteBitFlag(int bitval)
00595 {
00596 if(LastBitFlag()==bitval) {
00597 LastBitFlag()= LastBitFlag()>>1;
00598 return true;
00599 }
00600 assert(0);
00601 return false;
00602 }
00603
00604 void ClearFlags() {
00605 #ifdef __VCGLIB_EDGE_EF
00606 _flags=0;
00607 #endif
00608 }
00609
00611 inline int & Flags ()
00612 {
00613 #ifdef __VCGLIB_EDGE_EF
00614 assert( !IsD() );
00615 return _flags;
00616 #else
00617 return *(int *)0;
00618 #endif
00619 }
00620
00621 inline const int & Flags () const
00622 {
00623 #ifdef __VCGLIB_EDGE_EF
00624 assert( !IsD() );
00625 return _flags;
00626 #else
00627 return 0;
00628 #endif
00629 }
00631 inline int & UberFlags()
00632 {
00633 #ifdef __VCGLIB_EDGE_EF
00634 return _flags;
00635 #else
00636 assert(0);
00637 return *(int *)0;
00638 #endif
00639 }
00640
00641 inline const int UberFlags() const
00642 {
00643 #ifdef __VCGLIB_EDGE_EF
00644 return _flags;
00645 #else
00646 return 0;
00647 #endif
00648 }
00649
00651 bool IsD() const {
00652 #ifdef __VCGLIB_EDGE_EF
00653 return (_flags & DELETED) != 0;
00654 #else
00655 return false;
00656 #endif
00657 }
00659 void SetD() {
00660 #ifdef __VCGLIB_EDGE_EF
00661 _flags |=DELETED;
00662 #endif
00663 }
00665 void ClearD() {
00666 #ifdef __VCGLIB_EDGE_EF
00667 _flags &= (~DELETED);
00668 #endif
00669 }
00670
00671
00673 bool IsS() const {
00674 #ifdef __VCGLIB_EDGE_EF
00675 return (_flags & SELECTED) != 0;
00676 #else
00677 return false;
00678 #endif
00679 }
00681 void SetS() {
00682 #ifdef __VCGLIB_EDGE_EF
00683 _flags |=SELECTED;
00684 #endif
00685 }
00687 void ClearS() {
00688 #ifdef __VCGLIB_EDGE_EF
00689 _flags &= (~SELECTED);
00690 #endif
00691 }
00692
00694 bool IsB(int i) const {
00695 #ifdef __VCGLIB_EDGE_EF
00696 return (_flags & (BORDER0<<i)) != 0;
00697 #else
00698 return false;
00699 #endif
00700 }
00702 void SetB(int i) {
00703 #ifdef __VCGLIB_EDGE_EF
00704 _flags |=(BORDER0<<i);
00705 #endif
00706 }
00708 void ClearB(int i) {
00709 #ifdef __VCGLIB_EDGE_EF
00710 _flags &= (~(BORDER0<<i));
00711 #endif
00712 }
00713
00715 bool IsUserBit(int userBit){
00716 #ifdef __VCGLIB_EDGE_EF
00717 return (_flags & userBit) != 0;
00718 #else
00719 return false;
00720 #endif
00721 }
00723 void SetUserBit(int userBit){
00724 #ifdef __VCGLIB_EDGE_EF
00725 _flags |=userBit;
00726 #endif
00727 }
00729 void ClearUserBit(int userBit){
00730 #ifdef __VCGLIB_EDGE_EF
00731 _flags &= (~userBit);
00732 #endif
00733 }
00734
00735
00737
00738
00739
00740
00741 void GetBBox( BoxType & bb )
00742 {
00743 bb.Set( v[0]->P() );
00744 bb.Add( v[1]->P() );
00745 }
00746
00747
00753
00754 static bool HasEdgeNormal() {
00755 #ifdef __VCGLIB_EDGE_FN
00756 return true;
00757 #else
00758 return false;
00759 #endif
00760 }
00761 static bool HasEdgeQuality() {
00762 #ifdef __VCGLIB_EDGE_FQ
00763 return true;
00764 #else
00765 return false;
00766 #endif
00767 }
00768 static bool HasEdgeColor() {
00769 #ifdef __VCGLIB_EDGE_FC
00770 return true;
00771 #else
00772 return false;
00773 #endif
00774 }
00775 static bool HasEEAdjacency() {
00776 #if (defined(__VCGLIB_EDGE_AE) )
00777 return true;
00778 #else
00779 return false;
00780 #endif
00781 }
00782 static bool HasVEAdjacency() {
00783 #if (defined(__VCGLIB_EDGE_AV) )
00784 return true;
00785 #else
00786 return false;
00787 #endif
00788 }
00789 static bool HasEdgeMark() {
00790 #ifdef __VCGLIB_EDGE_FC
00791 return true;
00792 #else
00793 return false;
00794 #endif
00795 }
00796
00798
00800 inline bool operator == ( const EDGENAME & f ) const {
00801 if( (V(0) != f.V(0)) && (V(0) != f.V(1)) ) return false;
00802 if( (V(1) != f.V(0)) && (V(1) != f.V(1)) ) return false;
00803 return true;
00804 }
00805
00813 bool InterpolationParameters(const CoordType & bq, typename VertexType::ScalarType &a, ScalarType &_b) const
00814 {
00815 typedef typename VertexType::ScalarType ScalarType;
00816 const ScalarType EPSILON = ScalarType(0.000001);
00817 ScalarType l;
00818
00819 #define x1 (cV(0)->P().x())
00820 #define y1 (cV(0)->P().y())
00821 #define z1 (cV(0)->P().z())
00822 #define x2 (cV(1)->P().x())
00823 #define y2 (cV(1)->P().y())
00824 #define z2 (cV(1)->P().z())
00825 #define px (bq.x())
00826 #define py (bq.y())
00827 #define pz (bq.z())
00828 a = (px-x1)/(x2-x1);
00829 l = (py-y1)/(y2-y1);
00830 if( ( l < a -EPSILON) || ( l > a +EPSILON))
00831 return false;
00832
00833 l = (pz-z1)/(z2-z1);
00834 if( ( l < a -EPSILON) || ( l > a +EPSILON))
00835 return false;
00836
00837 _b = 1-a;
00838 return true;
00839
00840 #undef x1
00841 #undef y1
00842 #undef z1
00843 #undef x2
00844 #undef y2
00845 #undef z2
00846 #undef px
00847 #undef py
00848 #undef pz
00849 }
00850
00851
00852
00854 ScalarType Length() const
00855 {
00856 return Norm( (V(1)->P() - V(0)->P()).Norm());
00857 }
00858
00859 CoordType Barycenter() const
00860 {
00861 return (V(0)->P()+V(1)->P())/ScalarType(2.0);
00862 }
00863
00864 };
00865
00866
00867
00868
00869 }
00870
00871 #endif
00872
00873
00874