From bf13a8ee8f58897d7c57bf026e6110721cf1eb0a Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 11 Oct 2012 11:04:37 +0000 Subject: [PATCH] Changed a bit the interface of the exception throwing. Updated normals and other to follow this changes --- vcg/complex/algorithms/update/component_ep.h | 2 +- vcg/complex/algorithms/update/normal.h | 31 ++++++++++---------- vcg/complex/exception.h | 12 ++++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/vcg/complex/algorithms/update/component_ep.h b/vcg/complex/algorithms/update/component_ep.h index 06aaf73e..7d89a455 100644 --- a/vcg/complex/algorithms/update/component_ep.h +++ b/vcg/complex/algorithms/update/component_ep.h @@ -76,7 +76,7 @@ namespace tri { static void Set(ComputeMeshType &m) { - if(!FaceType::HasEdgePlane()) throw vcg::MissingComponentException(); + if(!FaceType::HasEdgePlane()) throw vcg::MissingComponentException("PerFaceEdgePlane"); for(FaceIterator f = m.face.begin(); f!=m.face.end(); ++f) if(!(*f).IsD()) ComputeEdgePlane(*f); diff --git a/vcg/complex/algorithms/update/normal.h b/vcg/complex/algorithms/update/normal.h index 64cb341a..7bd2b989 100644 --- a/vcg/complex/algorithms/update/normal.h +++ b/vcg/complex/algorithms/update/normal.h @@ -42,7 +42,7 @@ It must be included \b after complex.h */ template -class UpdateNormal +class UpdateNormal { public: typedef ComputeMeshType MeshType; @@ -63,7 +63,7 @@ typedef typename MeshType::FaceIterator FaceIterator; */ static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false) { - if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException("PerVertexNormal"); if(ClearAllVertNormal) UpdateFlags::VertexClearV(m); else @@ -157,7 +157,7 @@ static void PerVertexNelsonMaxWeighted(ComputeMeshType &m) /// Not normalized. Use PerFaceNormalized() or call NormalizePerVertex() if you need unit length per face normals. static void PerFace(ComputeMeshType &m) { - if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); for(FaceIterator f=m.face.begin();f!=m.face.end();++f) if( !(*f).IsD() ) face::ComputeNormal(*f); } @@ -168,7 +168,7 @@ static void PerFace(ComputeMeshType &m) */ static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m) { - if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException("PerVertexNormal"); VertexIterator vi; for(vi=m.vert.begin();vi!=m.vert.end();++vi) @@ -191,7 +191,8 @@ static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m) */ static void PerFaceFromCurrentVertexNormal(ComputeMeshType &m) { - if(!HasPerVertexNormal(m) || !HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerVertexNormal(m) ) throw vcg::MissingComponentException("PerVertexNormal"); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); for (FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD()) { @@ -207,7 +208,7 @@ static void PerFaceFromCurrentVertexNormal(ComputeMeshType &m) /// \brief Normalize the length of the vertex normals. static void NormalizePerVertex(ComputeMeshType &m) { - if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException("PerVertexNormal"); for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) if( !(*vi).IsD() && (*vi).IsRW() ) (*vi).N().Normalize(); @@ -216,7 +217,7 @@ static void NormalizePerVertex(ComputeMeshType &m) /// \brief Normalize the length of the face normals. static void NormalizePerFace(ComputeMeshType &m) { - if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if( !(*fi).IsD() ) (*fi).N().Normalize(); } @@ -224,7 +225,7 @@ static void NormalizePerFace(ComputeMeshType &m) /// \brief Set the length of the face normals to their area (without recomputing their directions). static void NormalizePerFaceByArea(ComputeMeshType &m) { - if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); FaceIterator fi; for(fi=m.face.begin();fi!=m.face.end();++fi) if( !(*fi).IsD() ) @@ -269,7 +270,7 @@ static void PerVertexNormalizedPerFaceNormalized(ComputeMeshType &m) NormalizePerFace(m); } -/// \brief +/// \brief Exploit bitquads to compute a per-polygon face normal static void PerBitQuadFaceNormalized(ComputeMeshType &m) { PerFace(m); @@ -287,7 +288,7 @@ static void PerBitQuadFaceNormalized(ComputeMeshType &m) /// \brief Multiply the vertex normals by the matrix passed. By default, the scale component is removed. static void PerVertexMatrix(ComputeMeshType &m, const Matrix44 &mat, bool remove_scaling= true) { - if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException("PerVertexNormal"); float scale; Matrix33 mat33(mat,3); @@ -308,7 +309,7 @@ static void PerVertexMatrix(ComputeMeshType &m, const Matrix44 &mat, /// \brief Multiply the face normals by the matrix passed. By default, the scale component is removed. static void PerFaceMatrix(ComputeMeshType &m, const Matrix44 &mat, bool remove_scaling= true) { - if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); float scale; Matrix33 mat33(mat,3); @@ -333,10 +334,10 @@ static void PerFaceMatrix(ComputeMeshType &m, const Matrix44 &mat, b /// It requires FFAdjacency. static void PerWedgeCrease(ComputeMeshType &m, ScalarType angleRad) { - if(!HasPerWedgeNormal(m) ) throw vcg::MissingComponentException(); - if(!HasFFAdjacency(m)) throw vcg::MissingComponentException(); + if(!HasPerWedgeNormal(m) ) throw vcg::MissingComponentException("PerWedgeNormal"); + if(!HasFFAdjacency(m)) throw vcg::MissingComponentException("Face-Face Adjacency"); - ScalarType cosangle=Cos(angleRad); + ScalarType cosangle=math::Cos(angleRad); // Clear the per wedge normals for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) @@ -364,7 +365,7 @@ static void PerWedgeCrease(ComputeMeshType &m, ScalarType angleRad) static void PerFaceRW(ComputeMeshType &m, bool normalize=false) { - if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException(); + if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException("PerFaceNormal"); FaceIterator f; bool cn = true; diff --git a/vcg/complex/exception.h b/vcg/complex/exception.h index e3125f7d..b77d9e02 100644 --- a/vcg/complex/exception.h +++ b/vcg/complex/exception.h @@ -22,13 +22,19 @@ ****************************************************************************/ #ifndef __VCG_EXCEPTION_H #define __VCG_EXCEPTION_H - +#include +#include namespace vcg { -class MissingComponentException : public std::exception +class MissingComponentException : public std::runtime_error { public: - MissingComponentException() {} + MissingComponentException(const std::string &err):std::runtime_error(err) { std::cout << "Missing Component Exception -" << err << "- \n";} + virtual const char *what() const throw () + { + static char buf[128]="Missing Component"; + return buf; + } }; }