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_POLYGON_COMPONENT 00025 #define __VCG_POLYGON_COMPONENT 00026 00027 //#include <vector> 00028 //#include <vcg/space/triangle3.h> 00029 //#include <vcg/space/texcoord2.h> 00030 //#include <vcg/space/color4.h> 00031 00032 namespace vcg { 00033 namespace face { 00034 /* 00035 Some naming Rules 00036 All the Components that can be added to a vertex should be defined in the namespace vert: 00037 00038 */ 00039 00040 /*-------------------------- PolInfo -------------------------------------------*/ 00041 template <class T> class EmptyPolyInfo: public T { 00042 protected: 00043 inline void SetVN(const int & n) {assert(0);} 00044 public: 00045 typedef typename T::HEdgeType HEdgeType; 00046 typedef typename T::HEdgePointer HEdgePointer; 00047 00048 /* Note: the destructor will not be called in general because there are no virtual destructors. 00049 Instead, the job of deallocating the memory will be done bu the edge allocator. 00050 This destructor is only done for those who istance a face alone (outside a mesh) 00051 */ 00052 static bool HasPolyInfo() { return false; } 00053 inline void Alloc(const int & ns){T::Alloc(ns);};// it should be useless 00054 inline void Dealloc(){T::Dealloc();};// it should be useless 00055 00056 // EmptyPFHAdj 00057 HEdgePointer &FHp( ) { static typename T::HEdgePointer fp=0; assert(0); return fp; } 00058 HEdgePointer const cFHp( ) const { static typename T::HEdgePointer const fp=0; return fp; } 00059 static bool HasFHAdjacency() { return false; } 00060 }; 00061 00062 00063 00064 00065 template <class T> class PolyInfo: public T { 00066 protected: 00067 inline void SetVN(const int & n) {_ns = n;} 00068 public: 00069 PolyInfo(){ _ns = -1; } 00070 /* Note: the destructor will not be called in general because there are no virtual destructors. 00071 Instead, the job of deallocating the memory will be done bu the face allocator. 00072 This destructor is only done for those who istance a face alone (outside a mesh) 00073 */ 00074 static bool HasPolyInfo() { return true; } 00075 inline const int & VN() const { return _ns;} 00076 inline int Prev(const int & i){ return (i+(VN()-1))%VN();} 00077 inline int Next(const int & i){ return (i+1)%VN();} 00078 inline void Alloc(const int & ns){}; 00079 inline void Dealloc(){}; 00080 00081 // EmptyPFHAdj 00082 typename T::HEdgePointer &FHp(const int & ) { static typename T::HEdgePointer fp=0; assert(0); return fp; } 00083 typename T::HEdgePointer const cFHp(const int & ) const { static typename T::HEdgePointer const fp=0; return fp; } 00084 static bool HasFHAdjacency() { return false; } 00085 private: 00086 int _ns; 00087 }; 00088 00089 /*-------------------------- VERTEX ----------------------------------------*/ 00090 template <class T> class PEmptyFVAdj: public T { 00091 public: 00092 typedef typename T::VertexType::CoordType CoordType; 00093 typedef typename T::VertexType::ScalarType ScalarType; 00094 // typedef typename T::CoordType CoordType; 00095 inline typename T::VertexType * & V( const int j ) { assert(0); static typename T::VertexType *vp=0; return vp; } 00096 inline typename T::VertexType * const & V( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } 00097 inline typename T::VertexType * cV( const int j ) const { assert(0); static typename T::VertexType *vp=0; return vp; } 00098 inline typename T::CoordType & P( const int j ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00099 inline const typename T::CoordType & P( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00100 inline const typename T::CoordType &cP( const int j ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } 00101 template <class LeftF> 00102 void ImportLocal(const LeftF & leftF) {T::ImportLocal(leftF);} 00103 static bool HasFVAdjN() { return false; } 00104 static void Name(std::vector<std::string> & name){T::Name(name);} 00105 inline void Alloc(const int & ns){T::Alloc();}; 00106 inline void Dealloc(){T::Dealloc();} 00107 00108 }; 00109 template <class T> class PFVAdj: public T { 00110 public: 00111 typedef typename T::VertexType::CoordType CoordType; 00112 typedef typename T::VertexType::ScalarType ScalarType; 00113 typedef typename T::VertexType VertexType; 00114 00115 PFVAdj(){_vpoly = NULL;} 00116 inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<this->VN()); return _vpoly[j]; } 00117 inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]; } 00118 inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]; } 00119 00120 00124 inline VertexType * & V0( const int j ) { return V(j);} 00125 inline VertexType * & V1( const int j ) { return V((j+1)%this->VN());} 00126 inline VertexType * & V2( const int j ) { return V((j+2)%this->VN());} 00127 inline const VertexType * const & V0( const int j ) const { return V(j);} 00128 inline const VertexType * const & V1( const int j ) const { return V((j+1)%this->VN());} 00129 inline const VertexType * const & V2( const int j ) const { return V((j+2)%this->VN());} 00130 inline const VertexType * const & cV0( const int j ) const { return cV(j);} 00131 inline const VertexType * const & cV1( const int j ) const { return cV((j+1)%this->VN());} 00132 inline const VertexType * const & cV2( const int j ) const { return cV((j+2)%this->VN());} 00133 00134 // Shortcut per accedere ai punti delle facce 00135 inline CoordType & P( const int j ) { assert(j>=0 && j<this->VN()); return _vpoly[j]->P(); } 00136 inline const CoordType & P( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]->cP(); } 00137 inline const CoordType &cP( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]->cP(); } 00138 00140 inline CoordType & P0( const int j ) { return V(j)->P();} 00141 inline CoordType & P1( const int j ) { return V((j+1)%this->VN())->P();} 00142 inline CoordType & P2( const int j ) { return V((j+2)%this->VN())->P();} 00143 inline const CoordType & P0( const int j ) const { return V(j)->P();} 00144 inline const CoordType & P1( const int j ) const { return V((j+1)%this->VN())->P();} 00145 inline const CoordType & P2( const int j ) const { return V((j+2)%this->VN())->P();} 00146 inline const CoordType & cP0( const int j ) const { return cV(j)->P();} 00147 inline const CoordType & cP1( const int j ) const { return cV((j+1)%this->VN())->P();} 00148 inline const CoordType & cP2( const int j ) const { return cV((j+2)%this->VN())->P();} 00149 00150 template <class LeftF> 00151 void ImportLocal(const LeftF & leftF){ for(int i =0; i < this->VN(); ++i) V(i) = NULL; T::ImportLocal(leftF);} 00152 inline void Alloc(const int & ns) { 00153 if(_vpoly == NULL){this->SetVN(ns); 00154 _vpoly = new typename T::VertexType*[this->VN()]; 00155 for(int i = 0; i < this->VN(); ++i) _vpoly[i] = 0; 00156 } 00157 T::Alloc(ns); 00158 } 00159 inline void Dealloc() { if(_vpoly!=NULL){ 00160 delete [] _vpoly; 00161 _vpoly = NULL; 00162 } 00163 T::Dealloc(); 00164 } 00165 00166 static bool HasFVAdjacency() { return true; } 00167 static void Name(std::vector<std::string> & name){name.push_back(std::string("PFVAdj"));T::Name(name);} 00168 00169 private: 00170 typename T::VertexPointer *_vpoly; 00171 }; 00172 00173 /*----------------------------- PVFADJ ------------------------------*/ 00174 template <class T> class EmptyPVFAdj: public T { 00175 public: 00176 typedef typename T::VertexType VertexType; 00177 typedef int VFAdjType; 00178 typename T::FacePointer &VFp(const int) { static typename T::FacePointer fp=0; assert(0); return fp; } 00179 typename T::FacePointer const cVFp(const int) const { static typename T::FacePointer const fp=0; return fp; } 00180 typename T::FacePointer &FFp(const int) { static typename T::FacePointer fp=0; assert(0); return fp; } 00181 typename T::FacePointer const cFFp(const int) const { static typename T::FacePointer const fp=0; return fp; } 00182 char &VFi(const int j){static char z=0; assert(0); return z;}; 00183 char &FFi(const int j){static char z=0; assert(0); return z;}; 00184 const char &cVFi(const int j){static char z=0; return z;}; 00185 const char &cFFi(const int j) const {static char z=0; return z;}; 00186 template <class LeftF> 00187 void ImportLocal(const LeftF & leftF){ T::ImportLocal(leftF);} 00188 void Alloc(const int & ns){T::Alloc(ns);} 00189 void Dealloc(){T::Dealloc();} 00190 static bool HasVFAdjacency() { return false; } 00191 static bool HasFFAdjacency() { return false; } 00192 static bool HasFFAdjacencyOcc() { return false; } 00193 static bool HasVFAdjacencyOcc() { return false; } 00194 static void Name(std::vector<std::string> & name){T::Name(name);} 00195 00196 }; 00197 00198 template <class T> class PVFAdj: public T { 00199 public: 00200 00201 PVFAdj(){_vfiP = NULL; _vfiP = NULL;} 00202 /* Note: the destructor will not be called in general because there are no virtual destructors. 00203 Instead, the job of deallocating the memory will be done bu the edge allocator. 00204 This destructor is only done for those who istance a face alone (outside a mesh) 00205 */ 00206 typedef typename T::VertexType VertexType; 00207 typedef typename T::FaceType FaceType; 00208 typename T::FacePointer &VFp(const int j) { assert(j>=0 && j<this->VN()); return _vfpP[j]; } 00209 typename T::FacePointer const VFp(const int j) const { assert(j>=0 && j<this->VN()); return _vfpP[j]; } 00210 typename T::FacePointer const cVFp(const int j) const { assert(j>=0 && j<this->VN()); return _vfpP[j]; } 00211 char &VFi(const int j) {return _vfiP[j]; } 00212 template <class LeftF> 00213 void ImportLocal(const LeftF & leftF){T::ImportLocal(leftF);} 00214 inline void Alloc(const int & ns) { 00215 if(_vfpP == NULL){ 00216 this->SetVN(ns); 00217 _vfpP = new FaceType*[this->VN()]; 00218 _vfiP = new char[this->VN()]; 00219 for(int i = 0; i < this->VN(); ++i) {_vfpP[i] = 0;_vfiP = -1;} 00220 } 00221 T::Alloc(ns); 00222 00223 } 00224 inline void Dealloc() { if(_vfpP!=NULL){ 00225 delete [] _vfpP; _vfpP = NULL; 00226 delete [] _vfiP; _vfiP = NULL; 00227 } 00228 T::Dealloc(); 00229 } 00230 00231 static bool HasVFAdjacency() { return true; } 00232 static bool HasVFAdjacencyOcc() { return false; } 00233 static void Name(std::vector<std::string> & name){name.push_back(std::string("PVFAdj"));T::Name(name);} 00234 00235 private: 00236 typename T::FacePointer *_vfpP ; 00237 char *_vfiP ; 00238 }; 00239 00240 /*----------------------------- FFADJ ------------------------------*/ 00241 00242 template <class T> class PFFAdj: public T { 00243 public: 00244 typedef typename T::FaceType FaceType; 00245 PFFAdj(){_ffpP = NULL; _ffiP = NULL; } 00246 typename T::FacePointer &FFp(const int j) { assert(j>=0 && j<this->VN()); return _ffpP[j]; } 00247 typename T::FacePointer const FFp(const int j) const { assert(j>=0 && j<this->VN()); return _ffpP[j]; } 00248 typename T::FacePointer const cFFp(const int j) const { assert(j>=0 && j<this->VN()); return _ffpP[j]; } 00249 char &FFi(const int j) { return _ffiP[j]; } 00250 const char &cFFi(const int j) const { return _ffiP[j]; } 00251 00252 template <class LeftF> 00253 void ImportLocal(const LeftF & leftF){T::ImportLocal(leftF);} 00254 inline void Alloc(const int & ns) { 00255 if( _ffpP == NULL){ 00256 this->SetVN(ns); 00257 _ffpP = new FaceType*[this->VN()]; 00258 _ffiP = new char[this->VN()]; 00259 for(int i = 0; i < this->VN(); ++i) {_ffpP[i] = 0;_ffiP[i] = 0;} 00260 } 00261 T::Alloc(ns); 00262 } 00263 inline void Dealloc() { if(_ffpP!=NULL){ 00264 delete [] _ffpP; _ffpP = NULL; 00265 delete [] _ffiP; _ffiP = NULL; 00266 } 00267 T::Dealloc(); 00268 } 00269 00270 static bool HasFFAdjacency() { return true; } 00271 static bool HasFFAdjacencyOcc() { return false; } 00272 static void Name(std::vector<std::string> & name){name.push_back(std::string("PFFAdj"));T::Name(name);} 00273 00274 //private: 00275 typename T::FacePointer *_ffpP ; 00276 char *_ffiP ; 00277 }; 00278 00279 /*----------------------------- PFEADJ ------------------------------*/ 00280 00281 template <class T> class PFEAdj: public T { 00282 public: 00283 typedef typename T::EdgeType EdgeType; 00284 PFEAdj(){_fepP = NULL; } 00285 typename T::EdgePointer &FEp(const int j) { assert(j>=0 && j<this->VN()); return _fepP[j]; } 00286 typename T::EdgePointer const FEp(const int j) const { assert(j>=0 && j<this->VN()); return _fepP[j]; } 00287 typename T::EdgePointer const cFEp(const int j) const { assert(j>=0 && j<this->VN()); return _fepP[j]; } 00288 00289 template <class LeftF> 00290 void ImportLocal(const LeftF & leftF){T::ImportLocal(leftF);} 00291 inline void Alloc(const int & ns) { 00292 if( _fepP == NULL){ 00293 this->SetVN(ns); 00294 _fepP = new EdgeType *[this->VN()]; 00295 for(int i = 0; i < this->VN(); ++i) {_fepP[i] = 0;} 00296 } 00297 T::Alloc(ns); 00298 } 00299 inline void Dealloc() { if(_fepP!=NULL) {delete [] _fepP; _fepP = NULL;} T::Dealloc();} 00300 00301 static bool HasFEAdjacency() { return true; } 00302 static bool HasFEAdjacencyOcc() { return false; } 00303 static void Name(std::vector<std::string> & name){name.push_back(std::string("PFEAdj"));T::Name(name);} 00304 00305 //private: 00306 typename T::EdgePointer *_fepP ; 00307 }; 00308 00309 00310 /*----------------------------- PFHADJ ------------------------------*/ 00311 00312 template <class T> class PFHAdj: public T { 00313 public: 00314 typedef typename T::HEdgeType HEdgeType; 00315 typedef typename T::HEdgePointer HEdgePointer; 00316 00317 PFHAdj(){_fhP = NULL; } 00318 typename T::HEdgePointer &FHp() { return _fhP; } 00319 typename T::HEdgePointer const cFHp() const { return _fhP; } 00320 00321 template <class LeftF> 00322 void ImportLocal(const LeftF & leftF){T::ImportLocal(leftF);} 00323 inline void Alloc(const int & ns) {T::Alloc(ns);} 00324 inline void Dealloc() { T::Dealloc();} 00325 00326 static bool HasFHAdjacency() { return true; } 00327 static bool HasFHAdjacencyOcc() { return false; } 00328 static void Name(std::vector<std::string> & name){name.push_back(std::string("PFHAdj"));T::Name(name);} 00329 00330 //private: 00331 typename T::HEdgePointer _fhP ; 00332 }; 00333 00334 00335 00336 } // end namespace face 00337 }// end namespace vcg 00338 #endif