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