1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004-2016 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __VCG_POLYGON_COMPONENT
#define __VCG_POLYGON_COMPONENT
namespace vcg {
namespace face {
/*-------------------------- PolInfo -------------------------------------------*/
template <class T> class PolyInfo: public T {
protected:
inline void __SetVN(const int & n) {
assert((_ns==-1) || (_ns==n) || (n==-1));
_ns = n;
}
public:
PolyInfo(){ _ns = -1; }
static bool HasPolyInfo() { return true; }
inline const int & VN() const { return _ns;}
inline int Prev(const int & i){ return (i+(VN()-1))%VN();}
inline int Next(const int & i){ return (i+1)%VN();}
inline void Alloc(const int & ns){
T::Alloc(ns);
__SetVN(ns);
}
inline void Dealloc(){
T::Dealloc();
__SetVN(-1);
}
private:
int _ns;
};
template <class T> class PFVAdj: public T {
public:
typedef typename T::VertexType::CoordType CoordType;
typedef typename T::VertexType::ScalarType ScalarType;
typedef typename T::VertexType VertexType;
PFVAdj(){ _vpoly = NULL; }
/* Note: the destructor will not be called in general because there are no virtual destructors.
* Instead, the job of deallocating the memory will be done by the face allocator.
* This destructor is only done for those who istance a face alone (outside a mesh)
*/
// ~PFVAdj(){ __Dealloc(); }
inline typename T::VertexType * & V( const int j ) { assert(j>=0 && j<this->VN()); return _vpoly[j]; }
inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]; }
inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]; }
/** Return the pointer to the ((j+1)%3)-th vertex of the face.
@param j Index of the face vertex.
*/
inline VertexType * & V0( const int j ) { return V(j);}
inline VertexType * & V1( const int j ) { return V((j+1)%this->VN());}
inline VertexType * & V2( const int j ) { return V((j+2)%this->VN());}
inline const VertexType * const & V0( const int j ) const { return V(j);}
inline const VertexType * const & V1( const int j ) const { return V((j+1)%this->VN());}
inline const VertexType * const & V2( const int j ) const { return V((j+2)%this->VN());}
inline const VertexType * const & cV0( const int j ) const { return cV(j);}
inline const VertexType * const & cV1( const int j ) const { return cV((j+1)%this->VN());}
inline const VertexType * const & cV2( const int j ) const { return cV((j+2)%this->VN());}
inline CoordType &P( const int j ) { assert(j>=0 && j<this->VN()); return _vpoly[j]->P(); }
inline CoordType cP( const int j ) const { assert(j>=0 && j<this->VN()); return _vpoly[j]->cP(); }
inline CoordType & P0( const int j ) { return V(j)->P();}
inline CoordType & P1( const int j ) { return V((j+1)%this->VN())->P();}
inline CoordType & P2( const int j ) { return V((j+2)%this->VN())->P();}
inline CoordType cP0( const int j ) const { return cV(j)->P();}
inline CoordType cP1( const int j ) const { return cV((j+1)%this->VN())->P();}
inline CoordType cP2( const int j ) const { return cV((j+2)%this->VN())->P();}
template <class LeftF>
void ImportData(const LeftF & leftF){ T::ImportData(leftF);}
inline void Alloc(const int & ns) {
__Dealloc();
_vpoly = new typename T::VertexType*[ns];
for(int i = 0; i < ns; ++i) _vpoly[i] = 0;
T::Alloc(ns);
}
inline void Dealloc() {
__Dealloc();
T::Dealloc();
}
static bool HasVertexRef() { return true; }
static bool HasFVAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PFVAdj"));T::Name(name);}
private:
inline void __Dealloc(){
delete [] _vpoly;
_vpoly = NULL;
}
typename T::VertexPointer *_vpoly;
};
template <class T> class PVFAdj: public T {
public:
PVFAdj(){ _vfiP = NULL; _vfiP = NULL; }
/* Note: the destructor will not be called in general because there are no virtual destructors.
* Instead, the job of deallocating the memory will be done by the face allocator.
* This destructor is only done for those who istance a face alone (outside a mesh)
*/
// ~PVFAdj(){ __Dealloc(); }
typedef typename T::VertexType VertexType;
typedef typename T::FaceType FaceType;
typename T::FacePointer &VFp(const int j) { assert(j>=0 && j<this->VN()); return _vfpP[j]; }
typename T::FacePointer const VFp(const int j) const { assert(j>=0 && j<this->VN()); return _vfpP[j]; }
typename T::FacePointer const cVFp(const int j) const { assert(j>=0 && j<this->VN()); return _vfpP[j]; }
char &VFi(const int j) {return _vfiP[j]; }
template <class LeftF>
void ImportData(const LeftF & leftF){T::ImportData(leftF);}
inline void Alloc(const int & ns) {
_vfpP = new FaceType*[ns];
_vfiP = new char[ns];
for(int i = 0; i < ns; ++i) {_vfpP[i] = 0;_vfiP[i] = -1;}
T::Alloc(ns);
}
unsigned int SizeNeigh(){ return this->VN();}
inline void Dealloc() {
__Dealloc();
T::Dealloc();
}
static bool HasVFAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PVFAdj"));T::Name(name);}
private:
inline void __Dealloc(){
delete [] _vfpP; _vfpP = NULL;
delete [] _vfiP; _vfiP = NULL;
}
typename T::FacePointer *_vfpP ;
char *_vfiP ;
};
/*----------------------------- FFADJ ------------------------------*/
template <class T> class PFFAdj: public T {
public:
typedef typename T::FaceType FaceType;
PFFAdj(){ _ffpP = NULL; _ffiP = NULL; }
/* Note: the destructor will not be called in general because there are no virtual destructors.
* Instead, the job of deallocating the memory will be done by the face allocator.
* This destructor is only done for those who istance a face alone (outside a mesh)
*/
// ~PFFAdj(){ __Dealloc(); }
typename T::FacePointer &FFp(const int j) { assert(j>=0 && j<this->VN()); return _ffpP[j]; }
typename T::FacePointer FFp(const int j) const { assert(j>=0 && j<this->VN()); return _ffpP[j]; }
typename T::FacePointer cFFp(const int j) const { assert(j>=0 && j<this->VN()); return _ffpP[j]; }
char &FFi(const int j) { return _ffiP[j]; }
char cFFi(const int j) const { return _ffiP[j]; }
template <class LeftF>
void ImportData(const LeftF & leftF){T::ImportData(leftF);}
inline void Alloc(const int & ns) {
_ffpP = new FaceType*[ns];
_ffiP = new char[ns];
for(int i = 0; i < ns; ++i) {_ffpP[i] = 0;_ffiP[i] = 0;}
T::Alloc(ns);
}
inline void Dealloc() {
__Dealloc();
T::Dealloc();
}
static bool HasFFAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PFFAdj"));T::Name(name);}
private:
inline void __Dealloc(){
delete [] _ffpP; _ffpP = NULL;
delete [] _ffiP; _ffiP = NULL;
}
typename T::FacePointer *_ffpP ;
char *_ffiP ;
};
/*----------------------------- PFEADJ ------------------------------*/
template <class T> class PFEAdj: public T {
public:
typedef typename T::EdgeType EdgeType;
PFEAdj(){ _fepP = NULL; }
/* Note: the destructor will not be called in general because there are no virtual destructors.
* Instead, the job of deallocating the memory will be done by the face allocator.
* This destructor is only done for those who istance a face alone (outside a mesh)
*/
// ~PFEAdj(){ __Dealloc(); }
typename T::EdgePointer &FEp(const int j) { assert(j>=0 && j<this->VN()); return _fepP[j]; }
typename T::EdgePointer const FEp(const int j) const { assert(j>=0 && j<this->VN()); return _fepP[j]; }
typename T::EdgePointer const cFEp(const int j) const { assert(j>=0 && j<this->VN()); return _fepP[j]; }
template <class LeftF>
void ImportData(const LeftF & leftF){T::ImportData(leftF);}
inline void Alloc(const int & ns) {
_fepP = new EdgeType *[ns];
for(int i = 0; i < ns; ++i) {_fepP[i] = 0;}
T::Alloc(ns);
}
inline void Dealloc() {
T::Dealloc();
}
static bool HasFEAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PFEAdj"));T::Name(name);}
private:
inline void __Dealloc(){
delete [] _fepP; _fepP = NULL;
}
typename T::EdgePointer *_fepP ;
};
/*----------------------------- PFHADJ ------------------------------*/
template <class T> class PFHAdj: public T {
public:
typedef typename T::HEdgeType HEdgeType;
typedef typename T::HEdgePointer HEdgePointer;
PFHAdj(){ _fhP = NULL; }
typename T::HEdgePointer &FHp() { return _fhP; }
typename T::HEdgePointer const cFHp() const { return _fhP; }
template <class LeftF>
void ImportData(const LeftF & leftF){T::ImportData(leftF);}
inline void Alloc(const int & ns) {T::Alloc(ns);}
inline void Dealloc() { T::Dealloc();}
static bool HasFHAdjacency() { return true; }
static void Name(std::vector<std::string> & name){name.push_back(std::string("PFHAdj"));T::Name(name);}
private:
typename T::HEdgePointer _fhP ;
};
} // end namespace face
} // end namespace vcg
#endif
|