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.
This commit is contained in:
Paolo Cignoni 2012-12-06 10:34:08 +00:00
parent b9406fad93
commit 3b466514b3
4 changed files with 104 additions and 71 deletions

View File

@ -593,6 +593,40 @@ bool HasPerMeshAttribute(const MESH_TYPE &m, std::string name){
return (ai!= m.mesh_attr.end() ) ;
}
template <class MeshType> void RequireVFAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); }
template <class MeshType> void RequireFFAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); }
template <class MeshType> void RequireFEAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); }
template <class MeshType> void RequireFHAdjacency (MeshType &m) { if(!tri::HasVFAdjacency (m)) throw vcg::MissingComponentException("VFAdjacency"); }
template <class MeshType> void RequirePerVertexQuality (MeshType &m) { if(!tri::HasPerVertexQuality (m)) throw vcg::MissingComponentException("PerVertexQuality "); }
template <class MeshType> void RequirePerVertexNormal (MeshType &m) { if(!tri::HasPerVertexNormal (m)) throw vcg::MissingComponentException("PerVertexNormal "); }
template <class MeshType> void RequirePerVertexColor (MeshType &m) { if(!tri::HasPerVertexColor (m)) throw vcg::MissingComponentException("PerVertexColor "); }
template <class MeshType> void RequirePerVertexMark (MeshType &m) { if(!tri::HasPerVertexMark (m)) throw vcg::MissingComponentException("PerVertexMark "); }
template <class MeshType> void RequirePerVertexFlags (MeshType &m) { if(!tri::HasPerVertexFlags (m)) throw vcg::MissingComponentException("PerVertexFlags "); }
template <class MeshType> void RequirePerVertexRadius (MeshType &m) { if(!tri::HasPerVertexRadius (m)) throw vcg::MissingComponentException("PerVertexRadius "); }
template <class MeshType> void RequirePerVertexCurvature (MeshType &m) { if(!tri::HasPerVertexCurvature (m)) throw vcg::MissingComponentException("PerVertexCurvature "); }
template <class MeshType> void RequirePerVertexCurvatureDir(MeshType &m) { if(!tri::HasPerVertexCurvatureDir(m)) throw vcg::MissingComponentException("PerVertexCurvatureDir"); }
template <class MeshType> void RequirePerVertexTexCoord (MeshType &m) { if(!tri::HasPerVertexTexCoord (m)) throw vcg::MissingComponentException("PerVertexTexCoord "); }
template <class MeshType> void RequirePerEdgeQuality (MeshType &m) { if(!tri::HasPerEdgeQuality (m)) throw vcg::MissingComponentException("PerEdgeQuality "); }
template <class MeshType> void RequirePerEdgeNormal (MeshType &m) { if(!tri::HasPerEdgeNormal (m)) throw vcg::MissingComponentException("PerEdgeNormal "); }
template <class MeshType> void RequirePerEdgeColor (MeshType &m) { if(!tri::HasPerEdgeColor (m)) throw vcg::MissingComponentException("PerEdgeColor "); }
template <class MeshType> void RequirePerEdgeMark (MeshType &m) { if(!tri::HasPerEdgeMark (m)) throw vcg::MissingComponentException("PerEdgeMark "); }
template <class MeshType> void RequirePerEdgeFlags (MeshType &m) { if(!tri::HasPerEdgeFlags (m)) throw vcg::MissingComponentException("PerEdgeFlags "); }
template <class MeshType> void RequirePerFaceFlags (MeshType &m) { if(!tri::HasPerFaceFlags (m)) throw vcg::MissingComponentException("PerFaceFlags "); }
template <class MeshType> void RequirePerFaceNormal (MeshType &m) { if(!tri::HasPerFaceNormal (m)) throw vcg::MissingComponentException("PerFaceNormal "); }
template <class MeshType> void RequirePerFaceColor (MeshType &m) { if(!tri::HasPerFaceColor (m)) throw vcg::MissingComponentException("PerFaceColor "); }
template <class MeshType> void RequirePerFaceMark (MeshType &m) { if(!tri::HasPerFaceMark (m)) throw vcg::MissingComponentException("PerFaceMark "); }
template <class MeshType> void RequirePerFaceQuality (MeshType &m) { if(!tri::HasPerFaceQuality (m)) throw vcg::MissingComponentException("PerFaceQuality "); }
template <class MeshType> void RequirePerFaceCurvatureDir(MeshType &m) { if(!tri::HasPerFaceCurvatureDir(m)) throw vcg::MissingComponentException("PerFaceCurvatureDir"); }
template <class MeshType> void RequirePerFaceWedgeColor (MeshType &m) { if(!tri::HasPerWedgeColor (m)) throw vcg::MissingComponentException("PerFaceWedgeColor "); }
template <class MeshType> void RequirePerFaceWedgeNormal (MeshType &m) { if(!tri::HasPerWedgeNormal (m)) throw vcg::MissingComponentException("PerFaceWedgeNormal "); }
template <class MeshType> void RequirePerFaceWedgeTexCoord(MeshType &m) { if(!tri::HasPerWedgeTexCoord(m)) throw vcg::MissingComponentException("PerFaceWedgeTexCoord"); }
/*@}*/
/*@}*/
} // end namespace

View File

@ -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<float,1> 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 <class RightValueType>
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<std::string> & name){name.push_back(std::string("NormalAbs"));T::Name(name);}
private:
@ -334,13 +333,13 @@ public:
ColorType cC() const { return _color; }
template <class RightValueType>
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<std::string> & name){name.push_back(std::string("Color"));T::Name(name);}
private:
@ -387,13 +386,13 @@ public:
QualityType cQ() const { return _quality; }
template <class RightValueType>
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<std::string> & name){name.push_back(std::string("Quality"));T::Name(name);}
private:
QualityType _quality;
@ -417,12 +416,12 @@ public:
Quality3Type cQ3() const { return _quality; }
template <class RightValueType>
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<std::string> & 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 <class RightValueType>
void ImportData(const RightValueType & rightF){
if(RightValueType::HasFaceMark())
if(RightValueType::HasMark())
IMark() = rightF.cIMark();
T::ImportData(rightF);
}

View File

@ -235,52 +235,52 @@ void ReorderFace(std::vector<size_t> &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 A, class T> 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 <class LeftF>
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 T> class QualityfOcf: public QualityOcf<float, T> {};
@ -605,12 +605,12 @@ public:
template <class LeftF>
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 T> class Color4bOcf: public ColorOcf<vcg::Color4b, T> {};
@ -629,12 +629,12 @@ public:
template <class LeftF>
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 <class LeftF>
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<FaceType> &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<FaceType> &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<FaceType> &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<FaceType> &fv)
@ -787,8 +787,8 @@ public:
template < class FaceType >
bool FaceVectorHasPerFaceNormal(const face::vector_ocf<FaceType> &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<size_t> &newFaceIndex, face::vector_ocf< FaceType > &faceVec)

View File

@ -377,12 +377,12 @@ public: static void Name(std::vector<std::string> & name){name.push_back(std::st
public:
typedef CurvatureDirBaseType<float> 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()) {