From 3b466514b3c8bd1a2ab75aa69271cfd91dcdd513 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 6 Dec 2012 10:34:08 +0000 Subject: [PATCH] Added Standard exception throwing functions to claim requirements in the mesh algorithmic functions (Te Deum!) for example, now at the beginning of a function requiring FFAdjacency you should just write: RequireFFAdjacency(mesh); No more assert please. --- vcg/complex/complex.h | 34 +++++++++++++++++ vcg/simplex/face/component.h | 63 ++++++++++++++++--------------- vcg/simplex/face/component_ocf.h | 64 ++++++++++++++++---------------- vcg/simplex/vertex/component.h | 14 +++---- 4 files changed, 104 insertions(+), 71 deletions(-) diff --git a/vcg/complex/complex.h b/vcg/complex/complex.h index 88c74834..89f44a6d 100644 --- a/vcg/complex/complex.h +++ b/vcg/complex/complex.h @@ -593,6 +593,40 @@ bool HasPerMeshAttribute(const MESH_TYPE &m, std::string name){ return (ai!= m.mesh_attr.end() ) ; } + +template void RequireVFAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); } +template void RequireFFAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); } +template void RequireFEAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); } +template void RequireFHAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); } + +template void RequirePerVertexQuality (MeshType &m) { if(!tri::HasPerVertexQuality (m)) throw vcg::MissingComponentException("PerVertexQuality "); } +template void RequirePerVertexNormal (MeshType &m) { if(!tri::HasPerVertexNormal (m)) throw vcg::MissingComponentException("PerVertexNormal "); } +template void RequirePerVertexColor (MeshType &m) { if(!tri::HasPerVertexColor (m)) throw vcg::MissingComponentException("PerVertexColor "); } +template void RequirePerVertexMark (MeshType &m) { if(!tri::HasPerVertexMark (m)) throw vcg::MissingComponentException("PerVertexMark "); } +template void RequirePerVertexFlags (MeshType &m) { if(!tri::HasPerVertexFlags (m)) throw vcg::MissingComponentException("PerVertexFlags "); } +template void RequirePerVertexRadius (MeshType &m) { if(!tri::HasPerVertexRadius (m)) throw vcg::MissingComponentException("PerVertexRadius "); } +template void RequirePerVertexCurvature (MeshType &m) { if(!tri::HasPerVertexCurvature (m)) throw vcg::MissingComponentException("PerVertexCurvature "); } +template void RequirePerVertexCurvatureDir(MeshType &m) { if(!tri::HasPerVertexCurvatureDir(m)) throw vcg::MissingComponentException("PerVertexCurvatureDir"); } +template void RequirePerVertexTexCoord (MeshType &m) { if(!tri::HasPerVertexTexCoord (m)) throw vcg::MissingComponentException("PerVertexTexCoord "); } + +template void RequirePerEdgeQuality (MeshType &m) { if(!tri::HasPerEdgeQuality (m)) throw vcg::MissingComponentException("PerEdgeQuality "); } +template void RequirePerEdgeNormal (MeshType &m) { if(!tri::HasPerEdgeNormal (m)) throw vcg::MissingComponentException("PerEdgeNormal "); } +template void RequirePerEdgeColor (MeshType &m) { if(!tri::HasPerEdgeColor (m)) throw vcg::MissingComponentException("PerEdgeColor "); } +template void RequirePerEdgeMark (MeshType &m) { if(!tri::HasPerEdgeMark (m)) throw vcg::MissingComponentException("PerEdgeMark "); } +template void RequirePerEdgeFlags (MeshType &m) { if(!tri::HasPerEdgeFlags (m)) throw vcg::MissingComponentException("PerEdgeFlags "); } + +template void RequirePerFaceFlags (MeshType &m) { if(!tri::HasPerFaceFlags (m)) throw vcg::MissingComponentException("PerFaceFlags "); } +template void RequirePerFaceNormal (MeshType &m) { if(!tri::HasPerFaceNormal (m)) throw vcg::MissingComponentException("PerFaceNormal "); } +template void RequirePerFaceColor (MeshType &m) { if(!tri::HasPerFaceColor (m)) throw vcg::MissingComponentException("PerFaceColor "); } +template void RequirePerFaceMark (MeshType &m) { if(!tri::HasPerFaceMark (m)) throw vcg::MissingComponentException("PerFaceMark "); } +template void RequirePerFaceQuality (MeshType &m) { if(!tri::HasPerFaceQuality (m)) throw vcg::MissingComponentException("PerFaceQuality "); } +template void RequirePerFaceCurvatureDir(MeshType &m) { if(!tri::HasPerFaceCurvatureDir(m)) throw vcg::MissingComponentException("PerFaceCurvatureDir"); } + +template void RequirePerFaceWedgeColor (MeshType &m) { if(!tri::HasPerWedgeColor (m)) throw vcg::MissingComponentException("PerFaceWedgeColor "); } +template void RequirePerFaceWedgeNormal (MeshType &m) { if(!tri::HasPerWedgeNormal (m)) throw vcg::MissingComponentException("PerFaceWedgeNormal "); } +template void RequirePerFaceWedgeTexCoord(MeshType &m) { if(!tri::HasPerWedgeTexCoord(m)) throw vcg::MissingComponentException("PerFaceWedgeTexCoord"); } + + /*@}*/ /*@}*/ } // end namespace diff --git a/vcg/simplex/face/component.h b/vcg/simplex/face/component.h index f5ed7c29..bb171364 100644 --- a/vcg/simplex/face/component.h +++ b/vcg/simplex/face/component.h @@ -54,7 +54,6 @@ public: static bool HasNormal() { return false; } static bool HasWedgeNormal() { return false; } - static bool HasFaceNormal() { return false; } typedef int WedgeTexCoordType; typedef vcg::TexCoord2 TexCoordType; @@ -69,7 +68,7 @@ public: inline void InitIMark() { } inline int &IMark() { assert(0); static int tmp=-1; return tmp;} - inline int cIMark() const {return 0;} + inline int cIMark() const { return 0;} typedef int MarkType; typedef float QualityType; @@ -85,25 +84,25 @@ public: 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 HasFaceColor() { return false; } + static bool HasColor() { return false; } static bool HasWedgeColor() { return false; } - static bool HasFaceQuality() { return false; } - static bool HasFaceQuality3() { return false; } - static bool HasFaceMark() { 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; 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; 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; 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; return z;} - char cFFi(int) const { static char z=0; return z;} + 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; } @@ -112,10 +111,10 @@ public: typedef int CurvatureDirType; - Point3f &PD1() { static Point3f dummy(0,0,0); return dummy;} - Point3f &PD2() { static Point3f dummy(0,0,0); return dummy;} - Point3f cPD1() const { static Point3f dummy(0,0,0); return dummy;} - Point3f cPD2() const { static Point3f dummy(0,0,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;} @@ -204,13 +203,13 @@ public: template void ImportData(const RightValueType & rightF) { - if(RightValueType::HasFaceNormal()) N().Import(rightF.cN()); + 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 HasFaceNormal() { return true; } + static bool HasNormal() { return true; } static void Name(std::vector & name){name.push_back(std::string("NormalAbs"));T::Name(name);} private: @@ -334,13 +333,13 @@ public: ColorType cC() const { return _color; } template void ImportData(const RightValueType & rightF){ - if(RightValueType::HasFaceColor()) + 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 HasFaceColor() { return true; } + static bool HasColor() { return true; } static void Name(std::vector & name){name.push_back(std::string("Color"));T::Name(name);} private: @@ -387,13 +386,13 @@ public: QualityType cQ() const { return _quality; } template void ImportData(const RightValueType & rightF){ - if(RightValueType::HasFaceQuality()) + 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 HasFaceQuality() { return true; } + static bool HasQuality() { return true; } static void Name(std::vector & name){name.push_back(std::string("Quality"));T::Name(name);} private: QualityType _quality; @@ -417,12 +416,12 @@ public: Quality3Type cQ3() const { return _quality; } template void ImportData(const RightValueType & rightF){ - if(RightValueType::HasFaceQuality3()) Q3() = rightF.cQ3(); + 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 HasFaceQuality3() { return true; } + static bool HasQuality3() { return true; } static void Name(std::vector & name){name.push_back(std::string("Quality3"));T::Name(name);} private: Quality3Type _quality; @@ -449,10 +448,10 @@ public: inline int &IMark() { return _imark;} inline int cIMark() const { return _imark;} inline void InitIMark() { _imark = 0; } - static bool HasFaceMark() { return true; } + static bool HasMark() { return true; } template void ImportData(const RightValueType & rightF){ - if(RightValueType::HasFaceMark()) + if(RightValueType::HasMark()) IMark() = rightF.cIMark(); T::ImportData(rightF); } diff --git a/vcg/simplex/face/component_ocf.h b/vcg/simplex/face/component_ocf.h index 2585a9aa..b2b2a484 100644 --- a/vcg/simplex/face/component_ocf.h +++ b/vcg/simplex/face/component_ocf.h @@ -235,52 +235,52 @@ void ReorderFace(std::vector &newFaceIndex ) bool IsQualityEnabled() const {return QualityEnabled;} void EnableQuality() { - assert(VALUE_TYPE::HasFaceQualityOcf()); + assert(VALUE_TYPE::HasQualityOcf()); QualityEnabled=true; QV.resize((*this).size()); } void DisableQuality() { - assert(VALUE_TYPE::HasFaceQualityOcf()); + assert(VALUE_TYPE::HasQualityOcf()); QualityEnabled=false; QV.clear(); } bool IsColorEnabled() const {return ColorEnabled;} void EnableColor() { - assert(VALUE_TYPE::HasFaceColorOcf()); + assert(VALUE_TYPE::HasColorOcf()); ColorEnabled=true; CV.resize((*this).size()); } void DisableColor() { - assert(VALUE_TYPE::HasFaceColorOcf()); + assert(VALUE_TYPE::HasColorOcf()); ColorEnabled=false; CV.clear(); } bool IsMarkEnabled() const {return MarkEnabled;} void EnableMark() { - assert(VALUE_TYPE::HasFaceMarkOcf()); + assert(VALUE_TYPE::HasMarkOcf()); MarkEnabled=true; MV.resize((*this).size()); } void DisableMark() { - assert(VALUE_TYPE::HasFaceMarkOcf()); + assert(VALUE_TYPE::HasMarkOcf()); MarkEnabled=false; MV.clear(); } bool IsNormalEnabled() const {return NormalEnabled;} void EnableNormal() { - assert(VALUE_TYPE::HasFaceNormalOcf()); + assert(VALUE_TYPE::HasNormalOcf()); NormalEnabled=true; NV.resize((*this).size()); } void DisableNormal() { - assert(VALUE_TYPE::HasFaceNormalOcf()); + assert(VALUE_TYPE::HasNormalOcf()); NormalEnabled=false; NV.clear(); } @@ -461,8 +461,8 @@ public: template class NormalOcf: public T { public: typedef A NormalType; - static bool HasFaceNormal() { return true; } - static bool HasFaceNormalOcf() { return true; } + static bool HasNormal() { return true; } + static bool HasNormalOcf() { return true; } NormalType &N() { // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() @@ -580,12 +580,12 @@ public: template void ImportData(const LeftF & leftF){ - if((*this).Base().QualityEnabled && LeftF::HasFaceQuality()) + if((*this).Base().QualityEnabled && LeftF::HasQuality()) Q() = leftF.cQ(); T::ImportData(leftF); } - static bool HasFaceQuality() { return true; } - static bool HasFaceQualityOcf() { return true; } + static bool HasQuality() { return true; } + static bool HasQualityOcf() { return true; } }; template class QualityfOcf: public QualityOcf {}; @@ -605,12 +605,12 @@ public: template void ImportData(const LeftF & leftF){ - if((*this).Base().ColorEnabled && LeftF::HasFaceColor()) + if((*this).Base().ColorEnabled && LeftF::HasColor()) C() = leftF.cC(); T::ImportData(leftF); } - static bool HasFaceColor() { return true; } - static bool HasFaceColorOcf() { return true; } + static bool HasColor() { return true; } + static bool HasColorOcf() { return true; } }; template class Color4bOcf: public ColorOcf {}; @@ -629,12 +629,12 @@ public: template void ImportData(const LeftF & leftF){ - if((*this).Base().MarkEnabled && LeftF::HasFaceMark()) + if((*this).Base().MarkEnabled && LeftF::HasMark()) IMark() = leftF.cIMark(); T::ImportData(leftF); } - static bool HasFaceMark() { return true; } - static bool HasFaceMarkOcf() { return true; } + static bool HasMark() { return true; } + static bool HasMarkOcf() { return true; } inline void InitIMark() { IMark() = 0; } }; @@ -713,11 +713,11 @@ public: template void ImportData(const LeftF & leftF){T::ImportData(leftF);} - static bool HasFaceColorOcf() { return false; } - static bool HasFaceQualityOcf() { return false; } - static bool HasFaceNormalOcf() { return false; } - static bool HasFaceCurvatureDirOcf() { return false; } - static bool HasFaceMarkOcf() { return false; } + static bool HasColorOcf() { return false; } + static bool HasQualityOcf() { return false; } + static bool HasNormalOcf() { return false; } + static bool HasCurvatureDirOcf() { return false; } + static bool HasMarkOcf() { return false; } static bool HasWedgeTexCoordOcf() { return false; } static bool HasWedgeColorOcf() { return false; } static bool HasWedgeNormalOcf() { return false; } @@ -763,20 +763,20 @@ public: template < class FaceType > bool FaceVectorHasPerFaceColor(const face::vector_ocf &fv) { - if(FaceType::HasFaceColorOcf()) return fv.IsColorEnabled(); - else return FaceType::HasFaceColor(); + if(FaceType::HasColorOcf()) return fv.IsColorEnabled(); + else return FaceType::HasColor(); } template < class FaceType > bool FaceVectorHasPerFaceQuality(const face::vector_ocf &fv) { - if(FaceType::HasFaceQualityOcf()) return fv.IsQualityEnabled(); - else return FaceType::HasFaceQuality(); + if(FaceType::HasQualityOcf()) return fv.IsQualityEnabled(); + else return FaceType::HasQuality(); } template < class FaceType > bool FaceVectorHasPerFaceMark(const face::vector_ocf &fv) { - if(FaceType::HasFaceMarkOcf()) return fv.IsMarkEnabled(); - else return FaceType::HasFaceMark(); + if(FaceType::HasMarkOcf()) return fv.IsMarkEnabled(); + else return FaceType::HasMark(); } template < class FaceType > bool FaceVectorHasPerFaceCurvatureDir(const face::vector_ocf &fv) @@ -787,8 +787,8 @@ public: template < class FaceType > bool FaceVectorHasPerFaceNormal(const face::vector_ocf &fv) { - if(FaceType::HasFaceNormalOcf()) return fv.IsNormalEnabled(); - else return FaceType::HasFaceNormal(); + if(FaceType::HasNormalOcf()) return fv.IsNormalEnabled(); + else return FaceType::HasNormal(); } template < class FaceType > void ReorderFace( std::vector &newFaceIndex, face::vector_ocf< FaceType > &faceVec) diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index 93113ae1..a3dfe7e6 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -377,12 +377,12 @@ public: static void Name(std::vector & name){name.push_back(std::st public: typedef CurvatureDirBaseType CurvatureDirType; - const Point3f &PD1() const { static Point3f dummy(0,0,0); return dummy;} - const Point3f &PD2() const { static Point3f dummy(0,0,0); return dummy;} - Point3f &PD1() { static Point3f dummy(0,0,0); return dummy;} - Point3f &PD2() { static Point3f dummy(0,0,0); return dummy;} - Point3f cPD1() const { static Point3f dummy(0,0,0); return dummy;} - Point3f cPD2() const { static Point3f dummy(0,0,0); return dummy;} + 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;} @@ -413,7 +413,7 @@ public: ScalarType &K1(){ return _curv.k1;} ScalarType &K2(){ return _curv.k2;} const ScalarType &cK1() const {return _curv.k1;} - const ScalarType &cK2()const {return _curv.k2;} + const ScalarType &cK2() const {return _curv.k2;} template < class RightValueType> void ImportData(const RightValueType & rVert ) { if(RightValueType::HasCurvatureDir()) {