00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 #include <vcg/complex/complex.h> 00024 00025 #ifndef __VCG_HEDGE_COMPONENT 00026 #define __VCG_HEDGE_COMPONENT 00027 00028 namespace vcg { 00029 namespace hedge { 00030 /* 00031 Some naming Rules 00032 All the Components that can be added to a vertex should be defined in the namespace hedge: 00033 00034 */ 00035 // 00037 //template <class T> class EmptyVertexRef: public T { 00038 //public: 00039 // // typedef typename T::VertexType VertexType; 00040 // // typedef typename T::CoordType CoordType; 00041 // inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; } 00042 // inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } 00043 // inline typename T::VertexType * cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } 00044 // inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00045 // inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00046 // inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00047 // template <class LeftF> 00048 // void ImportData(const LeftF & leftF) {T::ImportData(leftF);} 00049 // static bool HasVertexRef() { return false; } 00050 // static void Name(std::vector<std::string> & name){T::Name(name);} 00051 // 00052 //}; 00053 //template <class T> class VertexRef: public T { 00054 //public: 00055 // VertexRef(){ 00056 // v[0]=0; 00057 // v[1]=0; 00058 // } 00059 // 00060 // inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<2); return v[j]; } 00061 // inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<2); return v[j]; } 00062 // inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<2); return v[j]; } 00063 // 00064 // // Shortcut per accedere ai punti delle facce 00065 // inline typename T::CoordType & P( const int j ) { assert(j>=0 && j<2); return v[j]->P(); } 00066 // inline const typename T::CoordType &cP( const int j ) const { assert(j>=0 && j<2); return v[j]->cP(); } 00067 // 00068 // /** Return the pointer to the ((j+1)%3)-th vertex of the face. 00069 // @param j Index of the face vertex. 00070 // */ 00071 // inline typename T::VertexType * & V0( const int j ) { return V(j);} 00072 // inline typename T::VertexType * & V1( const int j ) { return V((j+1)%2);} 00073 // inline const typename T::VertexType * const & V0( const int j ) const { return V(j);} 00074 // inline const typename T::VertexType * const & V1( const int j ) const { return V((j+1)%2);} 00075 // inline const typename T::VertexType * const & cV0( const int j ) const { return cV(j);} 00076 // inline const typename T::VertexType * const & cV1( const int j ) const { return cV((j+1)%2);} 00077 // 00078 // /// Shortcut per accedere ai punti delle facce 00079 // inline typename T::CoordType & P0( const int j ) { return V(j)->P();} 00080 // inline typename T::CoordType & P1( const int j ) { return V((j+1)%2)->P();} 00081 // inline const typename T::CoordType & P0( const int j ) const { return V(j)->P();} 00082 // inline const typename T::CoordType & P1( const int j ) const { return V((j+1)%2)->P();} 00083 // inline const typename T::CoordType & cP0( const int j ) const { return cV(j)->P();} 00084 // inline const typename T::CoordType & cP1( const int j ) const { return cV((j+1)%2)->P();} 00085 // 00086 // template <class LeftF> 00087 // void ImportData(const LeftF & leftF){ V(0) = NULL; V(1) = NULL; V(2) = NULL; T::ImportData(leftF);} 00088 // 00089 // static bool HasVertexRef() { return true; } 00090 // static void Name(std::vector<std::string> & name){name.push_back(std::string("VertexRef"));T::Name(name);} 00091 // 00092 // 00093 // private: 00094 // typename T::VertexType *v[2]; 00095 //}; 00096 00097 00098 00099 /*-------------------------- INCREMENTAL MARK ----------------------------------------*/ 00100 00101 template <class T> class EmptyMark: public T { 00102 public: 00103 static bool HasMark() { return false; } 00104 static bool HasMarkOcc() { return false; } 00105 inline void InitIMark() { } 00106 inline int & IMark() { assert(0); static int tmp=-1; return tmp;} 00107 inline int IMark() const {return 0;} 00108 template < class LeftV> 00109 void ImportData(const LeftV & left ) { T::ImportData( left); } 00110 static void Name(std::vector<std::string> & name){T::Name(name);} 00111 00112 }; 00113 template <class T> class Mark: public T { 00114 public: 00115 static bool HasMark() { return true; } 00116 static bool HasMarkOcc() { return true; } 00117 inline void InitIMark() { _imark = 0; } 00118 inline int & IMark() { return _imark;} 00119 inline const int & IMark() const {return _imark;} 00120 template < class LeftV> 00121 void ImportData(const LeftV & left ) { IMark() = left.IMark(); T::ImportData( left); } 00122 static void Name(std::vector<std::string> & name){name.push_back(std::string("Mark"));T::Name(name);} 00123 00124 private: 00125 int _imark; 00126 }; 00127 00128 /*------------------------- FLAGS -----------------------------------------*/ 00129 template <class T> class EmptyBitFlags: public T { 00130 public: 00131 typedef int FlagType; 00133 int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } 00134 int Flags() const { return 0; } 00135 template < class LeftV> 00136 void ImportData(const LeftV & left ) { T::ImportData( left); } 00137 static bool HasFlags() { return false; } 00138 static void Name(std::vector<std::string> & name){T::Name(name);} 00139 00140 }; 00141 00142 template <class T> class BitFlags: public T { 00143 public: 00144 BitFlags(){_flags=0;} 00145 typedef int FlagType; 00146 int &Flags() {return _flags; } 00147 int Flags() const {return _flags; } 00148 template < class LeftV> 00149 void ImportData(const LeftV & left ) { Flags() = left.Flags(); T::ImportData( left); } 00150 static bool HasFlags() { return true; } 00151 static void Name(std::vector<std::string> & name){name.push_back(std::string("BitFlags"));T::Name(name);} 00152 00153 private: 00154 int _flags; 00155 }; 00156 00157 /*----------------------------- HVADJ ------------------------------*/ 00158 template <class T> class EmptyHVAdj: public T { 00159 public: 00160 typename T::VertexPointer &HVp() { static typename T::VertexPointer ep=0; assert(0); return ep; } 00161 const typename T::VertexPointer cHVp() const { static typename T::VertexPointer ep=0; assert(0); return ep; } 00162 int &HVi(){static int z=0; return z;} 00163 template < class LeftV> 00164 void ImportData(const LeftV & left ) { T::ImportData( left); } 00165 static bool HasHVAdjacency() { return false; } 00166 static bool HasHVAdjacencyOcc() { return false; } 00167 static void Name(std::vector<std::string> & name){ T::Name(name);} 00168 }; 00169 00170 template <class T> class HVAdj: public T { 00171 public: 00172 HVAdj(){_vp =0;} 00173 typename T::VertexPointer & HVp() {return _vp ; } 00174 const typename T::VertexPointer cHVp() const {return _vp ; } 00175 template < class LeftV> 00176 void ImportData(const LeftV & left ) { this->V() = NULL; T::ImportData( left); } 00177 static bool HasHVAdjacency() { return true; } 00178 static bool HasHVAdjacencyOcc() { return true; } 00179 static void Name(std::vector<std::string> & name){name.push_back(std::string("HVAdj"));T::Name(name);} 00180 00181 private: 00182 typename T::VertexPointer _vp ; 00183 }; 00184 00185 /*----------------------------- HEADJ ------------------------------*/ 00186 template <class T> class EmptyHEAdj: public T { 00187 public: 00188 typename T::EdgePointer &HEp() { static typename T::EdgePointer ep=0; assert(0); return ep; } 00189 const typename T::EdgePointer cHEp() const { static typename T::EdgePointer ep=0; assert(0); return ep; } 00190 template < class LeftV> 00191 void ImportData(const LeftV & left ) { T::ImportData( left); } 00192 static bool HasHEAdjacency() { return false; } 00193 static bool HasHEAdjacencyOcc() { return false; } 00194 static void Name(std::vector<std::string> & name){ T::Name(name);} 00195 }; 00196 00197 template <class T> class HEAdj: public T { 00198 public: 00199 HEAdj(){_ep =0;} 00200 typename T::EdgePointer &HEp() {return _ep ; } 00201 const typename T::EdgePointer cHEp() const {return _ep ; } 00202 template < class LeftV> 00203 void ImportData(const LeftV & left ) { this->V() = NULL; T::ImportData( left); } 00204 static bool HasHEAdjacency() { return true; } 00205 static bool HasHEAdjacencyOcc() { return true; } 00206 static void Name(std::vector<std::string> & name){name.push_back(std::string("HEAdj"));T::Name(name);} 00207 00208 private: 00209 typename T::EdgePointer _ep ; 00210 }; 00211 00212 00213 /*----------------------------- HHADJ ------------------------------*/ 00214 template <class T> class EmptyHHAdj: public T { 00215 public: 00216 typename T::HEdgePointer &HHp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; } 00217 typename T::HEdgePointer cHHp(const int & ) { static typename T::EdgePointer ep=0; assert(0); return ep; } 00218 int &HHi(){static int z=0; return z;} 00219 template < class LeftV> 00220 void ImportData(const LeftV & left ) { T::ImportData( left); } 00221 static bool HasHHAdjacency() { return false; } 00222 static bool HasHHAdjacencyOcc() { return false; } 00223 static void Name(std::vector<std::string> & name){ T::Name(name);} 00224 }; 00225 00226 template <class T> class HHAdj: public T { 00227 public: 00228 HHAdj(){_ep=0;} 00229 typename T::EdgePointer &HHp(const int & i) {return _ep[i]; } 00230 typename T::EdgePointer cHHp(const int & i) {return _ep[i]; } 00231 int &HHi(const int & i) {return _zp[i]; } 00232 template < class LeftV> 00233 void ImportData(const LeftV & left ) { HHp() = NULL; T::ImportData( left); } 00234 static bool HasHHAdjacency() { return true; } 00235 static bool HasHHAdjacencyOcc() { return true; } 00236 static void Name(std::vector<std::string> & name){name.push_back(std::string("HHAdj"));T::Name(name);} 00237 00238 private: 00239 typename T::HEdgePointer _ep[2] ; 00240 int _zp[2] ; 00241 }; 00242 00243 00244 00245 00246 /*----------------------------- HENextADJ ------------------------------*/ 00247 template <class T> class EmptyHNextAdj: public T { 00248 public: 00249 typename T::HEdgePointer &HNp( ) { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00250 typename T::HEdgePointer const cHNp( ) const { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00251 template < class LeftV> 00252 void ImportData(const LeftV & left ) { T::ImportData( left); } 00253 static bool HasHNextAdjacency() { return false; } 00254 static bool HasHNextAdjacencyOcc() { return false; } 00255 static void Name(std::vector<std::string> & name){ T::Name(name);} 00256 }; 00257 00258 template <class T> class HNextAdj: public T { 00259 public: 00260 HNextAdj(){_nep=0;} 00261 typename T::HEdgePointer &HNp() {return _nep; } 00262 typename T::HEdgePointer const cHNp() const {return _nep; } 00263 template < class LeftV> 00264 void ImportData(const LeftV & left ) { this->EEp() = NULL; T::ImportData( left); } 00265 static bool HasHNextAdjacency() { return true; } 00266 static void Name(std::vector<std::string> & name){name.push_back(std::string("HNextAdj"));T::Name(name);} 00267 00268 private: 00269 typename T::HEdgePointer _nep ; 00270 }; 00271 00272 /*----------------------------- HEOppADJ ------------------------------*/ 00273 template <class T> class EmptyHOppAdj: public T { 00274 public: 00275 typename T::HEdgePointer &HOp() { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00276 typename T::HEdgePointer const cHOp() const { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00277 int &EEi(){static int z=0; return z;} 00278 template < class LeftV> 00279 void ImportData(const LeftV & left ) { T::ImportData( left); } 00280 static bool HasHOppAdjacency() { return false; } 00281 static bool HasHOpptAdjacencyOcc() { return false; } 00282 static void Name(std::vector<std::string> & name){ T::Name(name);} 00283 }; 00284 00285 template <class T> class HOppAdj: public T { 00286 public: 00287 HOppAdj(){_oep=0;} 00288 typename T::HEdgePointer &HOp() {return _oep; } 00289 typename T::HEdgePointer cHOp() {return _oep; } 00290 template < class LeftV> 00291 void ImportData(const LeftV & left ) { this->HOp() = NULL; T::ImportData( left); } 00292 static bool HasHOppAdjacency() { return true; } 00293 static void Name(std::vector<std::string> & name){name.push_back(std::string("HOppAdj"));T::Name(name);} 00294 00295 private: 00296 typename T::HEdgePointer _oep ; 00297 00298 }; 00299 /*----------------------------- HPrevADJ ------------------------------*/ 00300 template <class T> class EmptyHPrevAdj: public T { 00301 public: 00302 typename T::HEdgePointer &HPp() { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00303 typename T::HEdgePointer const cHPp() const { static typename T::HEdgePointer ep=0; assert(0); return ep; } 00304 int &EEi(){static int z=0; return z;} 00305 template < class LeftV> 00306 void ImportData(const LeftV & left ) { T::ImportData( left); } 00307 static bool HasHPrevAdjacency() { return false; } 00308 static bool HasHPrevAdjacencyOcc() { return false; } 00309 static void Name(std::vector<std::string> & name){ T::Name(name);} 00310 }; 00311 00312 template <class T> class HPrevAdj: public T { 00313 public: 00314 HPrevAdj(){_pep=0;} 00315 typename T::HEdgePointer &HPp() {return _pep; } 00316 typename T::HEdgePointer cHPp() {return _pep; } 00317 int &EEi(const int & i) {return this->_nei[i]; } 00318 template < class LeftV> 00319 void ImportData(const LeftV & left ) { this->EEp() = NULL; T::ImportData( left); } 00320 static bool HasHPrevAdjacency() { return true; } 00321 static void Name(std::vector<std::string> & name){name.push_back(std::string("HPrevAdj"));T::Name(name);} 00322 00323 private: 00324 typename T::HEdgePointer _pep ; 00325 }; 00326 /*----------------------------- HFADJ ------------------------------*/ 00327 00328 template <class T> class EmptyHFAdj: public T { 00329 public: 00330 typename T::FacePointer &HFp() { static typename T::FacePointer fp=0; assert(0); return fp; } 00331 typename T::FacePointer const cHFp() const { static typename T::FacePointer fp=0; assert(0); return fp; } 00332 int &EFi(){static int z=0; return z;} 00333 template < class LeftV> 00334 void ImportData(const LeftV & left ) { T::ImportData( left); } 00335 static bool HasHFAdjacency() { return false; } 00336 static bool HasHFAdjacencyOcc() { return false; } 00337 static void Name(std::vector<std::string> & name){ T::Name(name);} 00338 }; 00339 00340 template <class T> class HFAdj: public T { 00341 public: 00342 HFAdj(){_fp=0;} 00343 typename T::FacePointer &HFp() {return _fp; } 00344 typename T::FacePointer cHFp() {return _fp; } 00345 int &EFi() {return _zp; } 00346 template < class LeftV> 00347 void ImportData(const LeftV & left ) { this->EFp() = NULL; T::ImportData( left); } 00348 static bool HasHFAdjacency() { return true; } 00349 static bool HasHFAdjacencyOcc() { return true; } 00350 static void Name(std::vector<std::string> & name){name.push_back(std::string("HFAdj"));T::Name(name);} 00351 00352 private: 00353 typename T::FacePointer _fp ; 00354 int _zp ; 00355 }; 00356 00357 00358 /*----------------------------- HFADJ ------------------------------*/ 00362 template <class T> 00363 class EmptyHEdgeData : public EmptyHFAdj< // pointer to the face 00364 EmptyHOppAdj < // pointer to the opposite half edge 00365 EmptyHNextAdj < // pointer to the next half edge along the face 00366 EmptyHVAdj < // pointer to the vertex 00367 EmptyHEAdj < // pointer to the edge 00368 EmptyHPrevAdj< 00369 T > > > > > > {}; 00370 00371 00372 template <class T> 00373 class HEdgeData : public HFAdj< // pointer to the face 00374 HOppAdj < // pointer to the opposite half edge 00375 HNextAdj < // pointer to the next half edge along the face 00376 HVAdj < // pointer to the vertex 00377 HEAdj < // pointer to the edge 00378 T > > > > > { 00379 00380 public: 00381 // functions to make the half edge user confortable 00382 typename T::VertexPointer & Vertex() { return this->HVp();} 00383 const typename T::VertexPointer & cVertex() const { return this->cHVp();} 00384 typename T::HEdgePointer Opposite() { return this->HOp();} 00385 const typename T::HEdgePointer & cOpposite() const { return this->cHOp();} 00386 typename T::HEdgePointer & Next() { return this->HNp();} 00387 const typename T::HEdgePointer & cNext() const { return this->HNp();} 00388 00389 }; 00390 00391 } // end namespace edge 00392 }// end namespace vcg 00393 #endif