From 5e1f0ce521f4427545507e931384f1a4673aefc4 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 3 Mar 2010 16:01:39 +0000 Subject: [PATCH] Heavily restructured component of vertex simplex. Compacted all the emptyXXXX into a single EmptyCore class. Cleaned up the interface for the optional stuff now there is a standard static function that can say if a given component is enabled or not. --- vcg/simplex/vertex/component.h | 357 ++++++++--------------------- vcg/simplex/vertex/component_ocf.h | 34 ++- 2 files changed, 121 insertions(+), 270 deletions(-) diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index 4b11bf81..f26ea169 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -19,99 +19,6 @@ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * -****************************************************************************/ -/**************************************************************************** - History - -$Log: not supported by cvs2svn $ -Revision 1.27 2008/04/03 23:12:28 cignoni -compacted two pair of empty components to shorten derivation chains - -Revision 1.26 2008/03/17 11:39:14 ganovelli -added curvature and curvatruredir (compiled .net 2005 and gcc) - -Revision 1.25 2008/02/05 10:11:34 cignoni -A small typo (a T:: instead of TT::) - -Revision 1.24 2008/02/04 21:26:49 ganovelli -added ImportLocal which imports all local attributes into vertexplus and faceplus. -A local attribute is everything (N(), C(), Q()....) except pointers to other simplices -(i.e. FFAdj, VFAdj, VertexRef) which are set to NULL. -Added some function for const attributes - -Revision 1.23 2007/06/04 15:40:22 turini -Add vertex-tetrahedron adjacency component VTAdj. - -Revision 1.22 2007/03/12 15:37:21 tarini -Texture coord name change! "TCoord" and "Texture" are BAD. "TexCoord" is GOOD. - -Revision 1.21 2007/02/18 07:41:32 cignoni -Corrected small syntax errors detected by gcc - -Revision 1.20 2007/02/12 19:00:56 ganovelli -added Name(std:vector& n) that fills n with the names of the attribute of the vertex type - -Revision 1.19 2006/12/11 23:40:57 ganovelli -Has*Opt migrated to Has*Occ - -Revision 1.18 2006/11/28 22:34:28 cignoni -Added default constructor with null initialization to adjacency members. -AddFaces and AddVertices NEED to know if the topology is correctly computed to update it. - -Revision 1.17 2006/01/09 13:58:56 cignoni -Added Initialization of Color in Vertex and Face Components - -Revision 1.16 2005/11/22 23:58:03 cignoni -Added intiailization of flags to zero in the constructor, - -Revision 1.15 2005/11/18 15:44:51 cignoni -Access to constant normal changed from by val to by reference - -Revision 1.14 2005/11/16 23:02:37 cignoni -Added some missing members to EmptyMark -Standardized name of flags. It is plural becouse each simplex has many flag. - -Revision 1.13 2005/11/14 23:50:57 cignoni -Added Incremental Mark - -Revision 1.12 2005/11/12 18:35:49 cignoni -Changed HasFlag -> HasFlags - -Revision 1.11 2005/11/01 18:17:52 cignoni -Added an assert(0) in all the accesses to empty components - -Revision 1.10 2005/10/15 16:24:10 ganovelli -Working release (compilata solo su MSVC), component_occ � migrato da component_opt - -Revision 1.9 2005/10/14 13:30:07 cignoni -Added constant access functions and reflective functions (HasSomething stuff) -to all the components This is the first really working version... - -Revision 1.8 2005/10/07 15:19:54 cignoni -minor updates to keep it in line with the rest of the library - -Revision 1.7 2004/05/10 13:50:32 cignoni -Updated names of adj functions to the new standards - -Revision 1.6 2004/04/05 11:53:06 cignoni -addend constant access funcs - -Revision 1.5 2004/04/03 13:35:51 cignoni -minor changes - -Revision 1.4 2004/03/31 13:15:28 cignoni -Added optional cpmponent - -Revision 1.3 2004/03/31 12:28:37 ganovelli -*** empty log message *** - -Revision 1.2 2004/03/29 14:26:38 cignoni -Error in color - -Revision 1.1 2004/03/29 08:36:26 cignoni -First working version! - - ****************************************************************************/ #ifndef __VCG_VERTEX_PLUS_COMPONENT #define __VCG_VERTEX_PLUS_COMPONENT @@ -129,26 +36,106 @@ All the Components that can be added to a vertex should be defined in the namesp */ -/*------------------------- EMPTY COORD & NORMAL -----------------------------------------*/ -template class EmptyCoordNormal: public T { +/*------------------------- EMPTY CORE COMPONENTS -----------------------------------------*/ + +template class EmptyCore: public TT { public: + typedef int FlagType; + int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } + int Flags() const { return 0; } + static bool HasFlags() { return false; } + typedef vcg::Point3f CoordType; typedef CoordType::ScalarType ScalarType; - CoordType &P() { static CoordType coord(0, 0, 0); return coord; } const CoordType &P() const { static CoordType coord(0, 0, 0); assert(0); return coord; } const CoordType &cP() const { static CoordType coord(0, 0, 0); assert(0); return coord; } - CoordType &UberP() { static CoordType coord(0, 0, 0); return coord; } - static bool HasCoord() { return false; } + static bool HasCoord() { return false; } typedef vcg::Point3s NormalType; NormalType &N() { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } const NormalType cN()const { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } - static bool HasNormal() { return false; } - static bool HasNormalOcc() { return false; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static void Name(std::vector & name){T::Name(name);} + static bool HasNormal() { return false; } + static bool HasNormalOcf() { return false; } + + typedef float QualityType; + QualityType &Q() { static QualityType dummyQuality(0); assert(0); return dummyQuality; } + const QualityType &cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } + static bool HasQuality() { return false; } + static bool HasQualityOcf() { return false; } + static bool IsQualityEnabled(const typename TT::VertType *) { return false; } + + typedef vcg::Color4b ColorType; + ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + const ColorType &cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + static bool HasColor() { return false; } + static bool HasColorOcf() { return false; } + static bool IsColorEnabled(const typename TT::VertType *) { return false; } + + inline void InitIMark() { } + inline const int & cIMark() const { assert(0); static int tmp=-1; return tmp;} + inline int & IMark() { assert(0); static int tmp=-1; return tmp;} + inline int IMark() const {return 0;} + static bool HasMark() { return false; } + static bool HasMarkOcf() { return false; } + static bool IsMarkEnabled(const typename TT::VertType *) { return false; } + + typedef ScalarType RadiusType; + RadiusType &R(){ static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } + const RadiusType &cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } + static bool HasRadius() { return false; } + static bool HasRadiusOcf() { return false; } + static bool IsRadiusEnabled(const typename TT::VertType *) { return false; } + + typedef vcg::TexCoord2 TexCoordType; + TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } + const TexCoordType &cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } + static bool HasTexCoord() { return false; } + static bool IsTexCoordEnabled(const typename TT::VertType *) { return false; } + + typename TT::TetraPointer &VTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; } + typename TT::TetraPointer cVTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; } + int &VTi() { static int z = 0; return z; }; + static bool HasVTAdjacency() { return false; } + + typename TT::FacePointer &VFp() { static typename TT::FacePointer fp=0; assert(0); return fp; } + typename TT::FacePointer cVFp() const { static typename TT::FacePointer fp=0; assert(0); return fp; } + int &VFi(){static int z=0; return z;}; + int cVFi() const {static int z=0; return z;}; + static bool HasVFAdjacency() { return false; } + + typename TT::EdgePointer &VEp() { static typename TT::EdgePointer ep=0; assert(0); return ep; } + typename TT::EdgePointer cVEp() { static typename TT::EdgePointer ep=0; assert(0); return ep; } + int &VEi(){static int z=0; return z;}; + static bool HasVEAdjacency() { return false; } + + typedef Point3f VecType; + float &Kh() { static float dummy = 0.f; assert(0);return dummy;} + float &Kg() { static float dummy = 0.f; assert(0);return dummy;} + const float &cKh() const { static float dummy = 0.f; assert(0); return dummy;} + const float &cKg() const { static float dummy = 0.f; assert(0); return dummy;} + + VecType &PD1(){static VecType v(0,0,0); assert(0);return v;} + VecType &PD2(){static VecType v(0,0,0); assert(0);return v;} + const VecType &cPD1() const {static VecType v(0,0,0); assert(0);return v;} + const VecType &cPD2() const {static VecType v(0,0,0); assert(0);return v;} + + ScalarType &K1(){ static ScalarType v = 0.0;assert(0);return v;} + ScalarType &K2(){ static ScalarType v = 0.0;assert(0);return v;} + const ScalarType &cK1() const {static ScalarType v = 0.0;assert(0);return v;} + const ScalarType &cK2()const {static ScalarType v = 0.0;assert(0);return v;} + + static bool HasCurvature() { return false; } + static bool IsCurvatureEnabled(const typename TT::VertType *) { return false; } + static bool HasCurvatureDir() { return false; } + static bool IsCurvatureDirEnabled(const typename TT::VertType *) { return false; } + + + template < class LeftV> + void ImportLocal(const LeftV & left ) { + TT::ImportLocal( left); + } + static void Name(std::vector & name){TT::Name(name);} }; /*-------------------------- COORD ----------------------------------------*/ @@ -160,7 +147,6 @@ public: CoordType &P() { return _coord; } const CoordType &P() const { return _coord; } const CoordType &cP() const { return _coord; } - CoordType &UberP() { return _coord; } template < class LeftV> void ImportLocal(const LeftV & left ) { if(LeftV::HasCoord()) P().Import(left.cP()); T::ImportLocal( left); } @@ -191,7 +177,7 @@ public: T::ImportLocal( left); } static bool HasNormal() { return true; } - static bool HasNormalOcf() { return false; } +// static bool HasNormalOcf() { return false; } static void Name(std::vector & name){name.push_back(std::string("Normal"));T::Name(name);} private: @@ -229,17 +215,6 @@ public: /*-------------------------- TEXCOORD ----------------------------------------*/ -template class EmptyTexCoord: public TT { -public: - typedef vcg::TexCoord2 TexCoordType; - TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } - const TexCoordType &cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { TT::ImportLocal( left); } - static bool HasTexCoord() { return false; } - static void Name(std::vector & name){TT::Name(name);} - - }; template class TexCoord: public TT { public: typedef A TexCoordType; @@ -265,18 +240,6 @@ public: static void Name(std::vector & name){name.push_back(std::st }; /*------------------------- FLAGS -----------------------------------------*/ -template class EmptyBitFlags: public T { -public: - typedef int FlagType; - /// Return the vector of Flags(), senza effettuare controlli sui bit - int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } - int Flags() const { return 0; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static bool HasFlags() { return false; } - static void Name(std::vector & name){T::Name(name);} - -}; template class BitFlags: public T { public: @@ -293,32 +256,6 @@ private: int _flags; }; -/*-------------------------- EMPTY COLOR & QUALITY ----------------------------------*/ - -template class EmptyColorMarkQuality: public T { -public: - typedef float QualityType; - QualityType &Q() { static QualityType dummyQuality(0); assert(0); return dummyQuality; } - const QualityType &cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } - static bool HasQuality() { return false; } - - typedef vcg::Color4b ColorType; - ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } - const ColorType &cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } - - static bool HasMark() { return false; } - static bool HasMarkOcc() { return false; } - inline void InitIMark() { } - inline const int & cIMark() const { assert(0); static int tmp=-1; return tmp;} - inline int & IMark() { assert(0); static int tmp=-1; return tmp;} - inline const int & IMark() const {return 0;} - -template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static bool HasColor() { return false; } - static bool HasColorOcf() { return false; } - static void Name(std::vector & name){T::Name(name);} -}; /*-------------------------- Color ----------------------------------*/ @@ -332,8 +269,8 @@ public: template < class LeftV> void ImportLocal(const LeftV & left ) { if(LeftV::HasColor()) C() = left.cC(); T::ImportLocal( left); } static bool HasColor() { return true; } - static bool HasColorOcf() { return true; } - static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} + static bool IsColorEnabled(typename T::VertType *) { return true; } + static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: ColorType _color; @@ -380,56 +317,6 @@ struct CurvatureDirBaseType{ S k1,k2;// max and min curvature values }; -template class EmptyCurvatureData:public TT { -public: - typedef vcg::Point2 CurvatureType; - typedef CurvatureDirBaseType CurvatureDirType; - - typedef float ScalarType; - typedef Point3f VecType; - float &Kh() {static float dummy = 0.f; assert(0);return dummy;;} - float &Kg() { static float dummy = 0.f; assert(0);return dummy;} - const float &cKh() const {static float dummy = 0.f; assert(0);return dummy;;} - const float &cKg()const { static float dummy = 0.f;assert(0); return dummy;} - - VecType &PD1(){static VecType v(0,0,0); assert(0);return v;} - VecType &PD2(){static VecType v(0,0,0); assert(0);return v;} - const VecType &cPD1() const {static VecType v(0,0,0); assert(0);return v;} - const VecType &cPD2() const {static VecType v(0,0,0); assert(0);return v;} - - ScalarType &K1(){ static ScalarType v = 0.0;assert(0);return v;} - ScalarType &K2(){ static ScalarType v = 0.0;assert(0);return v;} - const ScalarType &cK1() const {static ScalarType v = 0.0;assert(0);return v;} - const ScalarType &cK2()const {static ScalarType v = 0.0;assert(0);return v;} - - static bool HasCurvatureOcc() { return false; } - static bool HasCurvatureOcf() { return false; } - static bool HasCurvature() { return false; } - static bool HasCurvatureDir() { return false; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { TT::ImportLocal( left); } - static void Name(std::vector & name){TT::Name(name);} -}; - -/*-------------------------- Curvature ----------------------------------*/ - -template class EmptyCurvature: public TT { -public: - typedef vcg::Point2 CurvatureType; - - float &Kh() {static float dummy = 0.f; return dummy;;} - float &Kg() { static float dummy = 0.f; return dummy;} - const float &cKh() const {static float dummy = 0.f; return dummy;;} - const float &cKg()const { static float dummy = 0.f; return dummy;} - - static bool HasCurvatureOcc() { return false; } - static bool HasCurvatureOcf() { return false; } - static bool HasCurvature() { return false; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { TT::ImportLocal( left); } - static void Name(std::vector & name){TT::Name(name);} -}; - template class Curvature: public TT { public: typedef Point2 CurvatureType; @@ -440,7 +327,8 @@ public: const ScalarType &cKg() const { return _hk[1];} static bool HasCurvature() { return true; } - static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} + static bool IsCurvatureEnabled(typename TT::VertType *) { return true; } + static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} private: Point2 _hk; @@ -508,23 +396,6 @@ template class CurvatureDird: public CurvatureDir & name){name.push_back(std::string("CurvatureDird"));T::Name(name);} }; -/*-------------------------- Empty Radius ----------------------------------*/ - -template class EmptyRadius: public T { -public: - - typedef float RadiusType; - typedef RadiusType ScalarType; - - RadiusType &R(){ static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } - const RadiusType &cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } - - static bool HasRadius() { return false; } - static bool HasRadiusOcf() { return false; } - template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static void Name(std::vector & name){ T::Name(name);} -}; /*-------------------------- Radius ----------------------------------*/ template class Radius: public TT { @@ -548,19 +419,6 @@ public: static void Name(std::vector & name){name.push_back(std::st /*----------------------------- VEADJ ------------------------------*/ - -template class EmptyVEAdj: public T { -public: - typename T::EdgePointer &VEp() { static typename T::EdgePointer ep=0; assert(0); return ep; } - typename T::EdgePointer cVEp() { static typename T::EdgePointer ep=0; assert(0); return ep; } - int &VEi(){static int z=0; return z;}; - template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static bool HasVEAdjacency() { return false; } - static bool HasVEAdjacencyOcc() { return false; } - static void Name(std::vector & name){ T::Name(name);} -}; - template class VEAdj: public T { public: VEAdj(){_ep=0;} @@ -580,20 +438,6 @@ private: /*----------------------------- VFADJ ------------------------------*/ - -template class EmptyVFAdj: public T { -public: - typename T::FacePointer &VFp() { static typename T::FacePointer fp=0; assert(0); return fp; } - typename T::FacePointer cVFp() const { static typename T::FacePointer fp=0; assert(0); return fp; } - int &VFi(){static int z=0; return z;}; - int cVFi() const {static int z=0; return z;}; - template < class LeftV> - void ImportLocal(const LeftV & left ) { T::ImportLocal( left); } - static bool HasVFAdjacency() { return false; } - static bool HasVFAdjacencyOcc() { return false; } - static void Name(std::vector & name){ T::Name(name);} -}; - template class VFAdj: public T { public: VFAdj(){_fp=0;} @@ -613,17 +457,6 @@ private: /*----------------------------- VTADJ ------------------------------*/ - -template class EmptyVTAdj: public T { -public: - typename T::TetraPointer &VTp() { static typename T::TetraPointer tp = 0; assert(0); return tp; } - typename T::TetraPointer cVTp() { static typename T::TetraPointer tp = 0; assert(0); return tp; } - int &VTi() { static int z = 0; return z; }; - static bool HasVTAdjacency() { return false; } - static bool HasVTAdjacencyOcc() { return false; } - static void Name( std::vector< std::string > & name ) { T::Name(name); } -}; - template class VTAdj: public T { public: VTAdj() { _tp = 0; } diff --git a/vcg/simplex/vertex/component_ocf.h b/vcg/simplex/vertex/component_ocf.h index 7fee193f..222ba2cc 100644 --- a/vcg/simplex/vertex/component_ocf.h +++ b/vcg/simplex/vertex/component_ocf.h @@ -402,8 +402,9 @@ public: T::ImportLocal(leftV); } - static bool HasVFAdjacency() { return true; } - static bool HasVFAdjacencyOcf() {assert(!T::HasVFAdjacencyOcf()); return true; } + static bool HasVFAdjacency() { return true; } + static bool HasVFAdjacencyOcf() { return true; } + static bool IsVFAdjacencyEnabled(const typename T::VertType *vp) {return vp->Base().VFAdjacencyEnabled;} private: }; @@ -471,7 +472,8 @@ public: template void ImportLocal(const LeftV & leftV) { - if((*this).Base().QualityEnabled && leftV.Base().QualityEnabled ) // copy the data only if they are enabled in both vertices +// if((*this).Base().QualityEnabled && leftV.Base().QualityEnabled ) // copy the data only if they are enabled in both vertices + if((*this).Base().QualityEnabled && leftV.HasQuality() ) // copy the data only if they are enabled in both vertices Q() = leftV.cQ(); T::ImportLocal(leftV); } @@ -547,7 +549,7 @@ public: template void ImportLocal(const LeftV & leftV){ // if((*this).Base().CurvatureEnabled && leftV.Base().CurvatureEnabled ) // WRONG I do not know anything about leftV! - if((*this).Base().CurvatureEnabled) + if((*this).Base().CurvatureEnabled && LeftV::IsCurvatureEnabled(&leftV)) { (*this).Base().CuV[(*this).Index()][0] = leftV.cKh(); (*this).Base().CuV[(*this).Index()][1] = leftV.cKg(); @@ -555,6 +557,9 @@ public: TT::ImportLocal(leftV); } + static bool HasCurvature() { return true; } + static bool IsCurvatureEnabled(const typename TT::VertType *v) { return v->Base().CurvatureEnabled; } + static bool HasCurvatureOcf() { return true; } static void Name(std::vector & name){name.push_back(std::string("CurvatureOcf"));TT::Name(name);} @@ -585,16 +590,29 @@ public: VecType &PD1(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].max_dir;} VecType &PD2(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].min_dir;} - const VecType &cPD1() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuV[(*this).Index()].max_dir;} - const VecType &cPD2() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuV[(*this).Index()].min_dir;} + const VecType &cPD1() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].max_dir;} + const VecType &cPD2() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].min_dir;} ScalarType &K1(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k1;} ScalarType &K2(){ assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k2;} const ScalarType &cK1() const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k1;} const ScalarType &cK2()const {assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k2;} - static bool HasCurvatureDirOcf() { return true; } - static void Name(std::vector & name){name.push_back(std::string("CurvatureDirOcf"));TT::Name(name);} + template + void ImportLocal(const LeftV & leftV){ +// if((*this).Base().CurvatureEnabled && leftV.Base().CurvatureEnabled ) // WRONG I do not know anything about leftV! + if((*this).Base().CurvatureDirEnabled && LeftV::IsCurvatureDirEnabled(&leftV)) + { + (*this).PD1() = leftV.cPD1(); + (*this).PD2() = leftV.cPD2(); + (*this).K1() = leftV.cK1(); + (*this).K2() = leftV.cK2(); + } + TT::ImportLocal(leftV); + } + static bool HasCurvatureDir() { return true; } + static bool HasCurvatureDirOcf() { return true; } + static void Name(std::vector & name){name.push_back(std::string("CurvatureDirOcf"));TT::Name(name);} private: };