From 8476a1ff209274fffb8b3a6545e3804b06a26e82 Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 17 Dec 2012 22:54:48 +0000 Subject: [PATCH] Reorganized ocf vertex component and added a standard interface for query the availability of data: now we have static bool vertextype::HasXXX() // statically says if a certain type is present bool vertextype::IsXXXAvaialble() // NON STATIC (always true for non ocf objects) So now ImportData correctly works for both sides of vertex ocf component. --- vcg/simplex/vertex/component.h | 59 +++++++-------- vcg/simplex/vertex/component_ocf.h | 111 ++++++++++++++++------------- 2 files changed, 87 insertions(+), 83 deletions(-) diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index a3dfe7e6..e8baf45d 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -55,37 +55,44 @@ public: CoordType &P() { assert(0); static CoordType coord(0, 0, 0); return coord; } CoordType cP() const { assert(0); static CoordType coord(0, 0, 0); assert(0); return coord; } static bool HasCoord() { return false; } + inline bool IsCoordEnabled() const { return TT::VertexType::HasCoord();} typedef vcg::Point3s NormalType; NormalType &N() { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; } NormalType cN() const { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; } static bool HasNormal() { return false; } + inline bool IsNormalEnabled() const { return TT::VertexType::HasNormal();} typedef float QualityType; QualityType &Q() { assert(0); static QualityType dummyQuality(0); return dummyQuality; } QualityType cQ() const { assert(0); static QualityType dummyQuality(0); return dummyQuality; } static bool HasQuality() { return false; } + inline bool IsQualityEnabled() const { return TT::VertexType::HasQuality();} 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; } static bool HasColor() { return false; } + inline bool IsColorEnabled() const { return TT::VertexType::HasColor();} typedef int MarkType; void InitIMark() { } int cIMark() const { assert(0); static int tmp=-1; return tmp;} int &IMark() { assert(0); static int tmp=-1; return tmp;} static bool HasMark() { return false; } + inline bool IsMarkEnabled() const { return TT::VertexType::HasMark();} typedef ScalarType RadiusType; RadiusType &R() { static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } RadiusType cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } static bool HasRadius() { return false; } + inline bool IsRadiusEnabled() const { return TT::VertexType::HasRadius();} typedef vcg::TexCoord2 TexCoordType; TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } TexCoordType cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } static bool HasTexCoord() { return false; } + inline bool IsTexCoordEnabled() const { return TT::VertexType::HasTexCoord();} typename TT::TetraPointer &VTp() { static typename TT::TetraPointer tp = 0; assert(0); return tp; } typename TT::TetraPointer cVTp() const { static typename TT::TetraPointer tp = 0; assert(0); return tp; } @@ -130,6 +137,8 @@ public: static bool HasCurvature() { return false; } static bool HasCurvatureDir() { return false; } + inline bool IsCurvatureEnabled() const { return TT::VertexType::HasCurvature();} + inline bool IsCurvatureDirEnabled() const { return TT::VertexType::HasCurvatureDir();} template < class RightValueType> void ImportData(const RightValueType & /*rVert*/ ) { @@ -152,7 +161,7 @@ public: inline CoordType cP() const { return _coord; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasCoord()) P().Import(rVert.cP()); T::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsCoordEnabled()) P().Import(rVert.cP()); T::ImportData( rVert); } static bool HasCoord() { return true; } static void Name(std::vector & name){name.push_back(std::string("Coord"));T::Name(name);} @@ -180,7 +189,7 @@ public: inline NormalType cN() const { return _norm; } template < class RightValueType> void ImportData(const RightValueType & rVert ){ - if(RightValueType::HasNormal()) N().Import(rVert.cN()); + if(rVert.IsNormalEnabled()) N().Import(rVert.cN()); T::ImportData( rVert); } static bool HasNormal() { return true; } @@ -215,7 +224,7 @@ public: static bool HasMark() { return true; } inline void InitIMark() { _imark = 0; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasMark()) IMark() = rVert.cIMark(); T::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsMarkEnabled()) IMark() = rVert.cIMark(); T::ImportData( rVert); } static void Name(std::vector & name){name.push_back(std::string("Mark"));T::Name(name);} private: @@ -237,7 +246,7 @@ public: TexCoordType &T() { return _t; } TexCoordType cT() const { return _t; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasTexCoord()) T() = rVert.cT(); TT::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsTexCoordEnabled()) T() = rVert.cT(); TT::ImportData( rVert); } static bool HasTexCoord() { return true; } static void Name(std::vector & name){name.push_back(std::string("TexCoord"));TT::Name(name);} @@ -292,9 +301,8 @@ public: inline ColorType &C() { return _color; } inline ColorType cC() const { return _color; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasColor()) C() = rVert.cC(); T::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsColorEnabled()) C() = rVert.cC(); T::ImportData( rVert); } static bool HasColor() { return true; } - static bool IsColorEnabled(typename T::VertexType *) { return true; } static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: @@ -320,7 +328,7 @@ public: inline QualityType &Q() { return _quality; } inline QualityType cQ() const {return _quality; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasQuality()) Q() = rVert.cQ(); TT::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsQualityEnabled()) Q() = rVert.cQ(); TT::ImportData( rVert); } static bool HasQuality() { return true; } static void Name(std::vector & name){name.push_back(std::string("Quality"));TT::Name(name);} @@ -354,8 +362,16 @@ public: static void Name(std::vector & name){name.push_back(std::st ScalarType cKh() const { return _hk[0];} ScalarType cKg() const { return _hk[1];} + template < class RightValueType> + void ImportData(const RightValueType & rVert ) { + if(rVert.IsCurvatureEnabled()) { + Kh() = rVert.cKh(); + Kg() = rVert.cKg(); + } + TT::ImportData( rVert); + } + static bool HasCurvature() { return true; } - static bool IsCurvatureEnabled(typename TT::VertexType *) { return true; } static void Name(std::vector & name){name.push_back(std::string("Curvature"));TT::Name(name);} private: @@ -372,29 +388,6 @@ public: static void Name(std::vector & name){name.push_back(std::st /*-------------------------- Curvature Direction ----------------------------------*/ - - template class EmptyCurvatureDir: public TT { - public: - typedef CurvatureDirBaseType CurvatureDirType; - - const Point3f &PD1() const { static Point3f dummy(0,0,0);assert(0); return dummy;} - const Point3f &PD2() const { static Point3f dummy(0,0,0);assert(0); return dummy;} - 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; } - template < class RightValueType> - void ImportData(const RightValueType & rVert ) { TT::ImportData( rVert); } - static void Name(std::vector & name){TT::Name(name);} - }; - /*! \brief \em Component: Per vertex \b curvature \b directions This component keep the principal curvature directions. Used by some of the algorithms of vcg::tri::UpdateCurvature to store the computed curvatures. */ @@ -416,7 +409,7 @@ public: const ScalarType &cK2() const {return _curv.k2;} template < class RightValueType> void ImportData(const RightValueType & rVert ) { - if(RightValueType::HasCurvatureDir()) { + if(rVert.IsCurvatureDirEnabled()) { PD1() = rVert.cPD1(); PD2() = rVert.cPD2(); K1() = rVert.cK1(); K2() = rVert.cK2(); } @@ -450,7 +443,7 @@ public: static void Name(std::vector & name){name.push_back(std::st RadiusType &R() { return _radius; } RadiusType cR() const {return _radius; } template < class RightValueType> - void ImportData(const RightValueType & rVert ) { if(RightValueType::HasRadius()) R() = rVert.cR(); TT::ImportData( rVert); } + void ImportData(const RightValueType & rVert ) { if(rVert.IsRadiusEnabled()) R() = rVert.cR(); TT::ImportData( rVert); } static bool HasRadius() { return true; } static void Name(std::vector & name){name.push_back(std::string("Radius"));TT::Name(name);} diff --git a/vcg/simplex/vertex/component_ocf.h b/vcg/simplex/vertex/component_ocf.h index ef2f7b8b..fb1d1d5c 100644 --- a/vcg/simplex/vertex/component_ocf.h +++ b/vcg/simplex/vertex/component_ocf.h @@ -283,10 +283,10 @@ public: if(! (*this).Base().VFAdjacencyEnabled ) return -1; return (*this).Base().AV[(*this).Index()]._zp; } - template - void ImportData(const LeftV & leftV) + template + void ImportData(const RightVertexType & rightV) { - T::ImportData(leftV); + T::ImportData(rightV); } static bool HasVFAdjacency() { return true; } @@ -309,11 +309,11 @@ public: NormalType &N() { assert((*this).Base().NormalEnabled); return (*this).Base().NV[(*this).Index()]; } NormalType cN() const { assert((*this).Base().NormalEnabled); return (*this).Base().NV[(*this).Index()]; } - template - void ImportData(const LeftV & leftV){ - if((*this).Base().NormalEnabled && LeftV::HasNormal() ) - N().Import(leftV.cN()); - T::ImportData(leftV);} + template + void ImportData(const RightVertexType & rightV){ + if((*this).IsNormalEnabled() && rightV.IsNormalEnabled() ) + N().Import(rightV.cN()); + T::ImportData(rightV);} }; template class Normal3sOcf: public NormalOcf {public: static void Name(std::vector & name){name.push_back(std::string("Normal3sOcf"));T::Name(name);}}; @@ -328,12 +328,12 @@ public: const ColorType &C() const { assert((*this).Base().ColorEnabled); return (*this).Base().CV[(*this).Index()]; } ColorType &C() { assert((*this).Base().ColorEnabled); return (*this).Base().CV[(*this).Index()]; } ColorType cC() const { assert((*this).Base().ColorEnabled); return (*this).Base().CV[(*this).Index()]; } - template - void ImportData(const LeftV & leftV) + template + void ImportData(const RightVertexType & rightV) { - if((*this).Base().ColorEnabled && LeftV::HasColor() ) - C() = leftV.cC(); - T::ImportData(leftV); + if((*this).IsColorEnabled() && rightV.IsColorEnabled() ) + C() = rightV.cC(); + T::ImportData(rightV); } static bool HasColor() { return true; } @@ -352,12 +352,12 @@ public: const QualityType &Q() const { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } QualityType &Q() { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } QualityType cQ() const { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } - template - void ImportData(const LeftV & leftV) + template + void ImportData(const RightVertexType & rightV) { - if((*this).Base().QualityEnabled && LeftV::HasQuality() ) // copy the data only if they are enabled in both vertices - Q() = leftV.cQ(); - T::ImportData(leftV); + if((*this).IsQualityEnabled && rightV.IsQualityEnabled() ) // copy the data only if they are enabled in both vertices + Q() = rightV.cQ(); + T::ImportData(rightV); } static bool HasQuality() { return true; } static bool HasQualityOcf() { assert(!T::HasQualityOcf()); return true; } @@ -376,12 +376,12 @@ public: const TexCoordType &T() const { assert((*this).Base().TexCoordEnabled); return (*this).Base().TV[(*this).Index()]; } TexCoordType &T() { assert((*this).Base().TexCoordEnabled); return (*this).Base().TV[(*this).Index()]; } TexCoordType cT() const { assert((*this).Base().TexCoordEnabled); return (*this).Base().TV[(*this).Index()]; } - template < class LeftV> - void ImportData(const LeftV & leftV) + template < class RightVertexType> + void ImportData(const RightVertexType & rightV) { - if((*this).Base().TexCoordEnabled && LeftV::HasTexCoord()) // copy the data only if they are enabled in both vertices - T() = leftV.cT(); - TT::ImportData(leftV); + if((*this).IsTexCoordEnabled() && rightV.IsTexCoordEnabled()) // copy the data only if they are enabled in both vertices + T() = rightV.cT(); + TT::ImportData(rightV); } static bool HasTexCoord() { return true; } static bool HasTexCoordOcf() { assert(!TT::HasTexCoordOcf()); return true; } @@ -400,12 +400,12 @@ public: inline int &IMark() { assert((*this).Base().MarkEnabled); return (*this).Base().MV[(*this).Index()]; } inline int cIMark() const { assert((*this).Base().MarkEnabled); return (*this).Base().MV[(*this).Index()]; } - template - void ImportData(const LeftV & leftV) + template + void ImportData(const RightVertexType & rightV) { - if((*this).Base().MarkEnabled && LeftV::HasMark()) // copy the data only if they are enabled in both vertices - IMark() = leftV.cIMark(); - T::ImportData(leftV); + if((*this).IsMarkEnabled() && rightV.IsMarkEnabled()) // copy the data only if they are enabled in both vertices + IMark() = rightV.cIMark(); + T::ImportData(rightV); } static bool HasMark() { return true; } static bool HasMarkOcf() { return true; } @@ -427,14 +427,14 @@ public: ScalarType cKh() const { assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][0];} ScalarType cKg() const { assert((*this).Base().CurvatureEnabled); return (*this).Base().CuV[(*this).Index()][1];} - template - void ImportData(const LeftV & leftV){ - if((*this).Base().CurvatureEnabled && LeftV::HasCurvature()) + template + void ImportData(const RightVertexType & rightV){ + if((*this).IsCurvatureEnabled() && rightV.IsCurvatureEnabled()) { - (*this).Base().CuV[(*this).Index()][0] = leftV.cKh(); - (*this).Base().CuV[(*this).Index()][1] = leftV.cKg(); + (*this).Base().CuV[(*this).Index()][0] = rightV.cKh(); + (*this).Base().CuV[(*this).Index()][1] = rightV.cKg(); } - TT::ImportData(leftV); + TT::ImportData(rightV); } static bool HasCurvature() { return true; } @@ -473,16 +473,16 @@ public: ScalarType cK1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k1;} ScalarType cK2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CuDV[(*this).Index()].k2;} - template - void ImportData(const LeftV & leftV){ - if((*this).Base().IsCurvatureDirEnabled() && LeftV::HasCurvatureDir()) + template + void ImportData(const RightVertexType & rightV){ + if((*this).IsCurvatureDirEnabled() && rightV.IsCurvatureDirEnabled()) { - (*this).PD1() = leftV.cPD1(); - (*this).PD2() = leftV.cPD2(); - (*this).K1() = leftV.cK1(); - (*this).K2() = leftV.cK2(); + (*this).PD1() = rightV.cPD1(); + (*this).PD2() = rightV.cPD2(); + (*this).K1() = rightV.cK1(); + (*this).K2() = rightV.cK2(); } - TT::ImportData(leftV); + TT::ImportData(rightV); } static bool HasCurvatureDir() { return true; } static bool HasCurvatureDirOcf() { return true; } @@ -508,12 +508,12 @@ public: RadiusType &R() { assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];} RadiusType cR() const { assert((*this).Base().RadiusEnabled); return (*this).Base().RadiusV[(*this).Index()];} - template - void ImportData(const LeftV & leftV) + template + void ImportData(const RightVertexType & rightV) { - if ((*this).Base().RadiusEnabled && LeftV::HasRadius()) - (*this).Base().RadiusV[(*this).Index()] = leftV.cR(); - TT::ImportData(leftV); + if ((*this).IsRadiusEnabled() && rightV.IsRadiusEnabled()) + (*this).Base().RadiusV[(*this).Index()] = rightV.cR(); + TT::ImportData(rightV); } static bool HasRadius() { return true; } @@ -545,14 +545,25 @@ public: public: vector_ocf *_ovp; - static bool HasQualityOcf() { return false; } - static bool HasRadiusOcf() { return false; } static bool HasColorOcf() { return false; } - static bool HasNormalOcf() { return false; } static bool HasCurvatureOcf() { return false; } static bool HasCurvatureDirOcf() { return false; } + static bool HasNormalOcf() { return false; } + static bool HasMarkOcf() { return false; } + static bool HasQualityOcf() { return false; } + static bool HasRadiusOcf() { return false; } static bool HasTexCoordOcf() { return false; } static bool HasVFAdjacencyOcf() { return false; } + + inline bool IsColorEnabled() const { return _ovp->IsColorEnabled();} + inline bool IsCurvatureEnabled( ) const { return _ovp->IsCurvatureDirEnabled(); } + inline bool IsCurvatureDirEnabled( ) const { return _ovp->IsCurvatureDirEnabled(); } + inline bool IsMarkEnabled( ) const { return _ovp->IsMarkEnabled(); } + inline bool IsNormalEnabled( ) const { return _ovp->IsNormalEnabled(); } + inline bool IsQualityEnabled( ) const { return _ovp->IsQualityEnabled(); } + inline bool IsRadiusEnabled( ) const { return _ovp->IsRadiusEnabled(); } + inline bool IsTexCoordEnabled( ) const { return _ovp->IsTexCoordEnabled(); } + };