/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004 \/)\/ * * 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_MESH #error "This file should not be included alone. It is automatically included by complex.h" #endif #ifndef __VCG_FACE_PLUS_COMPONENT #define __VCG_FACE_PLUS_COMPONENT namespace vcg { namespace face { /** \addtogroup FaceComponentGroup @{ */ /*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/ template class EmptyCore: public T { public: inline typename T::VertexType * &V( const int ) { assert(0); static typename T::VertexType *vp=0; return vp; } inline typename T::VertexType * cV( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; } inline typename T::VertexType * &FVp( const int i ) { return this->V(i); } inline typename T::VertexType * cFVp( const int i ) const { return this->cV(i); } inline typename T::CoordType &P( const int ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } inline typename T::CoordType cP( const int ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } static bool HasVertexRef() { return false; } static bool HasFVAdjacency() { return false; } typedef typename T::VertexType::NormalType NormalType; NormalType &N() { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } NormalType cN() const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } NormalType &WN(int) { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } NormalType cWN(int) const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } static bool HasNormal() { return false; } static bool HasWedgeNormal() { return false; } typedef int WedgeTexCoordType; typedef vcg::TexCoord2 TexCoordType; TexCoordType &WT(const int) { static TexCoordType dummy_texture; assert(0); return dummy_texture;} TexCoordType const &cWT(const int) const { static TexCoordType dummy_texture; return dummy_texture;} static bool HasWedgeTexCoord() { return false; } int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } int cFlags() const { return 0; } static bool HasFlags() { return false; } inline void InitIMark() { } inline int &IMark() { assert(0); static int tmp=-1; return tmp;} inline int cIMark() const { return 0;} typedef int MarkType; typedef float QualityType; typedef Point3f Quality3Type; typedef vcg::Color4b ColorType; ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } ColorType &WC(const int) { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } ColorType cWC(const int) const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } QualityType &Q() { static QualityType dummyQuality(0); assert(0); return dummyQuality; } QualityType cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } Quality3Type &Q3() { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } Quality3Type cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } static bool HasColor() { return false; } static bool HasWedgeColor() { return false; } static bool HasQuality() { return false; } static bool HasQuality3() { return false; } static bool HasMark() { return false; } typedef int VFAdjType; typename T::FacePointer &VFp(int) { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer cVFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer &FFp(int) { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer cFFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::EdgePointer &FEp(int) { static typename T::EdgePointer fp=0; assert(0); return fp; } typename T::EdgePointer cFEp(int) const { static typename T::EdgePointer fp=0; assert(0); return fp; } typename T::HEdgePointer &FHp() { static typename T::HEdgePointer fp=0; assert(0); return fp; } typename T::HEdgePointer cFHp() const { static typename T::HEdgePointer fp=0; assert(0); return fp; } char &VFi(int) { static char z=0; assert(0); return z;} char &FFi(int) { static char z=0; assert(0); return z;} char cVFi(int) const { static char z=0; assert(0); return z;} char cFFi(int) const { static char z=0; assert(0); return z;} static bool HasVFAdjacency() { return false; } static bool HasFFAdjacency() { return false; } static bool HasFEAdjacency() { return false; } static bool HasFHAdjacency() { return false; } typedef int CurvatureDirType; Point3f &PD1() { static Point3f dummy(0,0,0); assert(0); return dummy;} Point3f &PD2() { static Point3f dummy(0,0,0); assert(0); return dummy;} Point3f cPD1() const { static Point3f dummy(0,0,0); assert(0); return dummy;} Point3f cPD2() const { static Point3f dummy(0,0,0); assert(0); return dummy;} float &K1() { static float dummy(0); assert(0); return dummy;} float &K2() { static float dummy(0); assert(0); return dummy;} float cK1() const { static float dummy(0); assert(0); return dummy;} float cK2() const { static float dummy(0); assert(0); return dummy;} static bool HasCurvatureDir() { return false; } inline void SetVN(const int & /*n*/) {assert(0);} static bool HasPolyInfo() { return false; } template void ImportData(const RightValueType & rightF) {T::ImportData(rightF);} inline void Alloc(const int & ns) {T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static void Name(std::vector & name){T::Name(name);} }; /*-------------------------- VertexRef ----------------------------------------*/ /*! \brief The references to the vertexes of a triangular face * * Stored as three pointers to the VertexType */ template class VertexRef: public T { public: VertexRef(){ v[0]=0; v[1]=0; v[2]=0; } typedef typename T::VertexType::CoordType CoordType; typedef typename T::VertexType::ScalarType ScalarType; inline typename T::VertexType * &V( const int j ) { assert(j>=0 && j<3); return v[j]; } /// \brief The pointer to the i-th vertex inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<3); return v[j]; } inline CoordType &P( const int j ) { assert(j>=0 && j<3); return v[j]->P(); } /// \brief Shortcut: the position of the i-th vertex (equivalent to \c V(i)->P() ) inline CoordType cP( const int j ) const { assert(j>=0 && j<3); return v[j]->cP(); } inline typename T::VertexType * & V0( const int j ) { return V(j);} /** \brief Return the pointer to the j-th vertex of the face. */ inline typename T::VertexType * & V1( const int j ) { return V((j+1)%3);} /** \brief Return the pointer to the ((j+1)%3)-th vertex of the face. */ inline typename T::VertexType * & V2( const int j ) { return V((j+2)%3);} /** \brief Return the pointer to the ((j+2)%3)-th vertex of the face. */ inline typename T::VertexType * cV0( const int j ) const { return cV(j);} inline typename T::VertexType * cV1( const int j ) const { return cV((j+1)%3);} inline typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);} inline CoordType & P0( const int j ) { return V(j)->P();} inline CoordType & P1( const int j ) { return V((j+1)%3)->P();} inline CoordType & P2( const int j ) { return V((j+2)%3)->P();} inline const CoordType & cP0( const int j ) const { return cV(j)->P();} inline const CoordType & cP1( const int j ) const { return cV((j+1)%3)->P();} inline const CoordType & cP2( const int j ) const { return cV((j+2)%3)->P();} // Small comment about the fact that the pointers are zero filled. // The importLocal is meant for copyng stuff between very different meshes, so copying the pointers would be meaningless. // if you are using ImportData for copying internally simplex you have to set up all the pointers by hand. template void ImportData(const RightValueType & rightF){ T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasVertexRef() { return true; } static bool HasFVAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("VertexRef"));T::Name(name);} private: typename T::VertexType *v[3]; }; template void ComputeNormal(T &f) { f.N().Import(vcg::Normal(f)); } template void ComputeNormalizedNormal(T &f) { f.N().Import(vcg::NormalizedNormal(f)); } template class NormalAbs: public T { public: typedef A NormalType; inline NormalType &N() { return _norm; } inline NormalType cN() const { return _norm; } template void ImportData(const RightValueType & rightF) { if(RightValueType::HasNormal()) N().Import(rightF.cN()); T::ImportData( rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasNormal() { return true; } static void Name(std::vector & name){name.push_back(std::string("NormalAbs"));T::Name(name);} private: NormalType _norm; }; template class WedgeNormal: public T { public: typedef typename T::VertexType::NormalType NormalType; inline NormalType &WN(int j) { return _wnorm[j]; } inline NormalType cWN(int j) const { return _wnorm[j]; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasWedgeNormal()) for (int i=0; i<3; ++i) { WN(i) = rightF.cWN(i); } T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasWedgeNormal() { return true; } static void Name(std::vector & name){name.push_back(std::string("WedgeNormal"));T::Name(name);} private: NormalType _wnorm[3]; }; template class WedgeRealNormal: public T { public: typedef A NormalType; inline NormalType &WN(int i) { return _wn[i]; } inline NormalType cWN(int i) const { return _wn[i]; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasWedgeNormal()) for (int i=0; i<3; ++i) { WN(i) = rightF.cWN(i); } T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasWedgeNormal() { return true; } static void Name(std::vector & name){name.push_back(std::string("WedgeRealNormal"));T::Name(name);} private: NormalType _wn[3]; }; template class WedgeRealNormal3s: public WedgeRealNormal { public: static void Name(std::vector & name){name.push_back(std::string("WedgeRealNormal2s"));TT::Name(name);}}; template class WedgeRealNormal3f: public WedgeRealNormal { public: static void Name(std::vector & name){name.push_back(std::string("WedgeRealNormal2f"));TT::Name(name);}}; template class WedgeRealNormal3d: public WedgeRealNormal { public: static void Name(std::vector & name){name.push_back(std::string("WedgeRealNormal2d"));TT::Name(name);}}; template class Normal3s: public NormalAbs { public:static void Name(std::vector & name){name.push_back(std::string("Normal3s"));T::Name(name);} }; template class Normal3f: public NormalAbs { public: static void Name(std::vector & name){name.push_back(std::string("Normal3f"));T::Name(name);} }; template class Normal3d: public NormalAbs { public: static void Name(std::vector & name){name.push_back(std::string("Normal3d"));T::Name(name);} }; /*-------------------------- TexCoord ----------------------------------------*/ template class WedgeTexCoord: public T { public: typedef int WedgeTexCoordType; typedef A TexCoordType; TexCoordType &WT(const int i) { return _wt[i]; } TexCoordType cWT(const int i) const { return _wt[i]; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasWedgeTexCoord()) for (int i=0; i<3; ++i) { WT(i) = rightF.cWT(i); } T::ImportData(rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasWedgeTexCoord() { return true; } static void Name(std::vector & name){name.push_back(std::string("WedgeTexCoord"));T::Name(name);} private: TexCoordType _wt[3]; }; template class WedgeTexCoord2s: public WedgeTexCoord, TT> { public: static void Name(std::vector & name){name.push_back(std::string("WedgeTexCoord2s"));TT::Name(name);} }; template class WedgeTexCoord2f: public WedgeTexCoord, TT> { public: static void Name(std::vector & name){name.push_back(std::string("WedgeTexCoord2f"));TT::Name(name);} }; template class WedgeTexCoord2d: public WedgeTexCoord, TT> { public: static void Name(std::vector & name){name.push_back(std::string("WedgeTexCoord2d"));TT::Name(name);} }; /*------------------------- BitFlags -----------------------------------------*/ /*! \brief \em Component: Per face \b Flags This component stores a 32 bit array of bit flags. These bit flags are used for keeping track of selection, deletion, visiting etc. \sa \ref flags for more details on common uses of flags. */ template class BitFlags: public T { public: BitFlags():_flags(0) {} int &Flags() {return _flags; } int cFlags() const {return _flags; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasFlags()) Flags() = rightF.cFlags(); T::ImportData(rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasFlags() { return true; } static void Name(std::vector & name){name.push_back(std::string("BitFlags"));T::Name(name);} private: int _flags; }; /*-------------------------- Color ----------------------------------*/ template class Color: public T { public: typedef A ColorType; Color():_color(vcg::Color4b::White) {} ColorType &C() { return _color; } ColorType cC() const { return _color; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasColor()) C() = rightF.cC(); T::ImportData(rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasColor() { return true; } static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: ColorType _color; }; template class WedgeColor: public T { public: typedef A ColorType; ColorType &WC(int i) { return _color[i]; } ColorType cWC(int i) const { return _color[i]; } template void ImportData(const RightValueType & rightF){ if (RightValueType::HasWedgeColor()) { for (int i=0; i<3; ++i) { WC(i) = rightF.cWC(i); } } T::ImportData(rightF); } static bool HasWedgeColor() { return true; } static void Name(std::vector & name){name.push_back(std::string("WedgeColor"));T::Name(name);} private: ColorType _color[3]; }; template class WedgeColor4b: public WedgeColor { public: static void Name(std::vector & name){name.push_back(std::string("WedgeColor4b"));T::Name(name);} }; template class WedgeColor4f: public WedgeColor { public: static void Name(std::vector & name){name.push_back(std::string("WedgeColor4f"));T::Name(name);} }; template class Color4b: public Color { public: public: static void Name(std::vector & name){name.push_back(std::string("Color4b"));T::Name(name);} }; /*-------------------------- Quality ----------------------------------*/ template class Quality: public T { public: typedef A QualityType; QualityType &Q() { return _quality; } QualityType cQ() const { return _quality; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasQuality()) Q() = rightF.cQ(); T::ImportData(rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasQuality() { return true; } static void Name(std::vector & name){name.push_back(std::string("Quality"));T::Name(name);} private: QualityType _quality; }; template class Qualitys: public Quality { public: static void Name(std::vector & name){name.push_back(std::string("Qualitys"));T::Name(name);} }; template class Qualityf: public Quality { public: static void Name(std::vector & name){name.push_back(std::string("Qualityf"));T::Name(name);} }; template class Qualityd: public Quality { public: static void Name(std::vector & name){name.push_back(std::string("Qualityd"));T::Name(name);} }; /*-------------------------- Quality3 ----------------------------------*/ template class Quality3: public T { public: typedef vcg::Point3 Quality3Type; Quality3Type &Q3() { return _quality; } Quality3Type cQ3() const { return _quality; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasQuality3()) Q3() = rightF.cQ3(); T::ImportData(rightF); } inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasQuality3() { return true; } static void Name(std::vector & name){name.push_back(std::string("Quality3"));T::Name(name);} private: Quality3Type _quality; }; template class Quality3s: public Quality3 { public: static void Name(std::vector & name){name.push_back(std::string("Quality3s"));T::Name(name);} }; template class Quality3f: public Quality3 { public: static void Name(std::vector & name){name.push_back(std::string("Quality3f"));T::Name(name);} }; template class Quality3d: public Quality3 { public: static void Name(std::vector & name){name.push_back(std::string("Quality3d"));T::Name(name);} }; /*-------------------------- INCREMENTAL MARK ----------------------------------------*/ /*! \brief Per vertex \b Incremental \b Mark It is just an \c int that allows to efficently (in constant time) un-mark the whole mesh. \sa UnmarkAll */ template class Mark: public T { public: inline int &IMark() { return _imark;} inline int cIMark() const { return _imark;} inline void InitIMark() { _imark = 0; } static bool HasMark() { return true; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasMark()) IMark() = rightF.cIMark(); T::ImportData(rightF); } static void Name(std::vector & name){name.push_back(std::string("Mark"));T::Name(name);} private: int _imark; }; /*-------------------------- Curvature Direction ----------------------------------*/ template struct CurvatureDirBaseType{ typedef Point3 VecType; typedef S ScalarType; CurvatureDirBaseType () {} Point3max_dir,min_dir; // max and min curvature direction S k1,k2;// max and min curvature values }; template class CurvatureDir: public TT { public: typedef A CurvatureDirType; typedef typename CurvatureDirType::VecType VecType; typedef typename CurvatureDirType::ScalarType ScalarType; VecType &PD1() { return _curv.max_dir;} VecType &PD2() { return _curv.min_dir;} VecType cPD1() const { return _curv.max_dir;} VecType cPD2() const { return _curv.min_dir;} ScalarType &K1() { return _curv.k1;} ScalarType &K2() { return _curv.k2;} ScalarType cK1() const {return _curv.k1;} ScalarType cK2() const {return _curv.k2;} template < class RightValueType> void ImportData(const RightValueType & left ) { if(RightValueType::HasCurvatureDir()) { PD1() = left.cPD1(); PD2() = left.cPD2(); K1() = left.cK1(); K2() = left.cK2(); } TT::ImportData( left); } static bool HasCurvatureDir() { return true; } static void Name(std::vector & name){name.push_back(std::string("CurvatureDir"));TT::Name(name);} private: CurvatureDirType _curv; }; template class CurvatureDirf: public CurvatureDir, T> { public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirf"));T::Name(name);} }; template class CurvatureDird: public CurvatureDir, T> { public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDird"));T::Name(name);} }; /*----------------------------- VFADJ ------------------------------*/ template class VFAdj: public T { public: VFAdj(){ _vfp[0]=0; _vfp[1]=0; _vfp[2]=0; } typename T::FacePointer &VFp(const int j) { assert(j>=0 && j<3); return _vfp[j]; } typename T::FacePointer cVFp(const int j) const { assert(j>=0 && j<3); return _vfp[j]; } char &VFi(const int j) {return _vfi[j]; } template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasVFAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("VFAdj"));T::Name(name);} private: typename T::FacePointer _vfp[3] ; char _vfi[3] ; }; /*----------------------------- EFADJ ------------------------------*/ template class EFAdj: public T { public: EFAdj(){ _efp[0]=0; _efp[1]=0; _efp[2]=0; _efi[0]=-1; _efi[1]=-1; _efi[2]=-1; } typename T::FacePointer &EFp(const int j) { assert(j>=0 && j<3); return _efp[j]; } typename T::FacePointer cEFp(const int j) const { assert(j>=0 && j<3); return _efp[j]; } char &VFi(const int j) {return _efi[j]; } template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasEFAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("EFAdj"));T::Name(name);} private: typename T::FacePointer _efp[3] ; char _efi[3] ; }; /*----------------------------- FFADJ ------------------------------*/ template class FFAdj: public T { public: FFAdj(){ _ffp[0]=0; _ffp[1]=0; _ffp[2]=0; } typename T::FacePointer &FFp(const int j) { assert(j>=0 && j<3); return _ffp[j]; } typename T::FacePointer cFFp(const int j) const { assert(j>=0 && j<3); return _ffp[j]; } char &FFi(const int j) { return _ffi[j]; } char cFFi(const int j) const { return _ffi[j]; } typename T::FacePointer &FFp1( const int j ) { return FFp((j+1)%3);} typename T::FacePointer &FFp2( const int j ) { return FFp((j+2)%3);} typename T::FacePointer cFFp1( const int j ) const { return FFp((j+1)%3);} typename T::FacePointer cFFp2( const int j ) const { return FFp((j+2)%3);} template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasFFAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("FFAdj"));T::Name(name);} private: typename T::FacePointer _ffp[3] ; char _ffi[3] ; }; /*----------------------------- FEADJ ------------------------------*/ template class FEAdj: public T { public: FEAdj(){ _fep[0]=0; _fep[1]=0; _fep[2]=0; } typename T::EdgePointer &FEp( int j) { assert(j>=0 && j<3); return _fep[j]; } typename T::EdgePointer cFEp( int j) const { assert(j>=0 && j<3); return _fep[j]; } typename T::EdgePointer &FEp1( int j ) { return FEp((j+1)%3);} typename T::EdgePointer &FEp2( int j ) { return FEp((j+2)%3);} typename T::EdgePointer FEp1( int j ) const { return FEp((j+1)%3);} typename T::EdgePointer FEp2( int j ) const { return FEp((j+2)%3);} template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasFEAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("FEAdj"));T::Name(name);} private: typename T::EdgePointer _fep[3] ; char _fei[3] ; }; /*----------------------------- FHADJ ------------------------------*/ template class FHAdj: public T { public: FHAdj(){_fh=0;} typename T::HEdgePointer &FHp( ) { return _fh; } typename T::HEdgePointer cFHp( ) const { return _fh; } template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} inline void Dealloc(){T::Dealloc();} static bool HasFHAdjacency() { return true; } static void Name(std::vector & name){name.push_back(std::string("FHAdj"));T::Name(name);} private: typename T::HEdgePointer _fh ; }; /** @} */ // End Doxygen FaceComponentGroup } // end namespace face }// end namespace vcg #endif