Updated to the new exception based strategy (no more assert for missing components)
This commit is contained in:
parent
e7f1949d8e
commit
18e2f6dd7c
|
@ -24,10 +24,6 @@
|
||||||
#ifndef __VCG_TRI_UPDATE_NORMALS
|
#ifndef __VCG_TRI_UPDATE_NORMALS
|
||||||
#define __VCG_TRI_UPDATE_NORMALS
|
#define __VCG_TRI_UPDATE_NORMALS
|
||||||
|
|
||||||
#include <vcg/space/triangle3.h>
|
|
||||||
#include <vcg/math/matrix33.h>
|
|
||||||
#include <vcg/simplex/face/component.h>
|
|
||||||
#include <vcg/complex/algorithms/update/normal.h>
|
|
||||||
#include <vcg/complex/algorithms/update/flag.h>
|
#include <vcg/complex/algorithms/update/flag.h>
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
@ -58,12 +54,12 @@ typedef typename MeshType::FacePointer FacePointer;
|
||||||
typedef typename MeshType::FaceIterator FaceIterator;
|
typedef typename MeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set to zero all the normals. Usued by all the face averaging algorithms.
|
Set to zero all the PerVertex normals. Used by all the face averaging algorithms.
|
||||||
by default it does not clear the normals of unreferenced vertices because they could be still useful
|
by default it does not clear the normals of unreferenced vertices because they could be still useful
|
||||||
*/
|
*/
|
||||||
static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
|
static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
|
||||||
{
|
{
|
||||||
assert(HasPerVertexNormal(m));
|
if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException();
|
||||||
if(ClearAllVertNormal)
|
if(ClearAllVertNormal)
|
||||||
UpdateFlags<ComputeMeshType>::VertexClearV(m);
|
UpdateFlags<ComputeMeshType>::VertexClearV(m);
|
||||||
else
|
else
|
||||||
|
@ -83,9 +79,8 @@ static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
|
||||||
|
|
||||||
static void PerFace(ComputeMeshType &m)
|
static void PerFace(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerFaceNormal(m)) return;
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
FaceIterator f;
|
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
|
||||||
if( !(*f).IsD() ) face::ComputeNormal(*f);
|
if( !(*f).IsD() ) face::ComputeNormal(*f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +90,8 @@ static void PerFace(ComputeMeshType &m)
|
||||||
*/
|
*/
|
||||||
static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m)
|
static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerVertexNormal(m)) return;
|
if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException();
|
||||||
|
|
||||||
VertexIterator vi;
|
VertexIterator vi;
|
||||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
if( !(*vi).IsD() && (*vi).IsRW() )
|
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||||
|
@ -117,7 +112,8 @@ static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m)
|
||||||
*/
|
*/
|
||||||
static void PerFaceFromCurrentVertexNormal(ComputeMeshType &m)
|
static void PerFaceFromCurrentVertexNormal(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
for (FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
|
if(!HasPerVertexNormal(m) || !HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
|
for (FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
|
||||||
if( !(*fi).IsD())
|
if( !(*fi).IsD())
|
||||||
{
|
{
|
||||||
NormalType n;
|
NormalType n;
|
||||||
|
@ -142,10 +138,9 @@ Journal of Graphics Tools, 1998
|
||||||
|
|
||||||
static void PerVertexAngleWeighted(ComputeMeshType &m)
|
static void PerVertexAngleWeighted(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
assert(HasPerVertexNormal(m));
|
|
||||||
PerVertexClear(m);
|
PerVertexClear(m);
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
{
|
{
|
||||||
typename FaceType::NormalType t = vcg::NormalizedNormal(*f);
|
typename FaceType::NormalType t = vcg::NormalizedNormal(*f);
|
||||||
|
@ -169,10 +164,7 @@ static void PerVertexAngleWeighted(ComputeMeshType &m)
|
||||||
*/
|
*/
|
||||||
static void PerVertexNelsonMaxWeighted(ComputeMeshType &m)
|
static void PerVertexNelsonMaxWeighted(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
assert(HasPerVertexNormal(m));
|
|
||||||
|
|
||||||
PerVertexClear(m);
|
PerVertexClear(m);
|
||||||
|
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
|
@ -195,10 +187,7 @@ static void PerVertexNelsonMaxWeighted(ComputeMeshType &m)
|
||||||
|
|
||||||
static void PerVertex(ComputeMeshType &m)
|
static void PerVertex(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
assert(HasPerVertexNormal(m));
|
|
||||||
|
|
||||||
PerVertexClear(m);
|
PerVertexClear(m);
|
||||||
|
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
|
@ -220,14 +209,9 @@ static void PerVertex(ComputeMeshType &m)
|
||||||
|
|
||||||
static void PerVertexPerFace(ComputeMeshType &m)
|
static void PerVertexPerFace(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerVertexNormal(m) || !HasPerFaceNormal(m)) return;
|
|
||||||
|
|
||||||
PerFace(m);
|
PerFace(m);
|
||||||
PerVertexClear(m);
|
PerVertexClear(m);
|
||||||
|
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
|
||||||
FaceIterator f;
|
|
||||||
|
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
{
|
{
|
||||||
for(int j=0; j<3; ++j)
|
for(int j=0; j<3; ++j)
|
||||||
|
@ -250,8 +234,8 @@ static void PerVertexNormalizedPerFace(ComputeMeshType &m)
|
||||||
/// \brief Normalize the lenght of the face normals.
|
/// \brief Normalize the lenght of the face normals.
|
||||||
static void NormalizeVertex(ComputeMeshType &m)
|
static void NormalizeVertex(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
VertexIterator vi;
|
if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException();
|
||||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
if( !(*vi).IsD() && (*vi).IsRW() )
|
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||||
(*vi).N().Normalize();
|
(*vi).N().Normalize();
|
||||||
}
|
}
|
||||||
|
@ -259,16 +243,17 @@ static void NormalizeVertex(ComputeMeshType &m)
|
||||||
/// \brief Normalize the lenght of the face normals.
|
/// \brief Normalize the lenght of the face normals.
|
||||||
static void NormalizeFace(ComputeMeshType &m)
|
static void NormalizeFace(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
FaceIterator fi;
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
if( !(*fi).IsD() ) (*fi).N().Normalize();
|
if( !(*fi).IsD() ) (*fi).N().Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AreaNormalizeFace(ComputeMeshType &m)
|
static void AreaNormalizeFace(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
FaceIterator fi;
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
FaceIterator fi;
|
||||||
if( !(*fi).IsD() )
|
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
|
if( !(*fi).IsD() )
|
||||||
{
|
{
|
||||||
(*fi).N().Normalize();
|
(*fi).N().Normalize();
|
||||||
(*fi).N() = (*fi).N() * DoubleArea(*fi);
|
(*fi).N() = (*fi).N() * DoubleArea(*fi);
|
||||||
|
@ -283,8 +268,7 @@ static void PerVertexNormalizedPerFaceNormalized(ComputeMeshType &m)
|
||||||
|
|
||||||
static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
|
static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
|
||||||
{
|
{
|
||||||
if( !HasPerFaceNormal(m)) return;
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
|
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
bool cn = true;
|
bool cn = true;
|
||||||
|
|
||||||
|
@ -317,17 +301,15 @@ static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
|
||||||
|
|
||||||
static void PerFaceNormalized(ComputeMeshType &m)
|
static void PerFaceNormalized(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerFaceNormal(m)) return;
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() ) face::ComputeNormalizedNormal(*f);
|
if( !(*f).IsD() ) face::ComputeNormalizedNormal(*f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PerBitQuadFaceNormalized(ComputeMeshType &m)
|
static void PerBitQuadFaceNormalized(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerFaceNormal(m)) return;
|
|
||||||
PerFace(m);
|
PerFace(m);
|
||||||
|
|
||||||
FaceIterator f;
|
FaceIterator f;
|
||||||
for(f=m.face.begin();f!=m.face.end();++f) {
|
for(f=m.face.begin();f!=m.face.end();++f) {
|
||||||
if( !(*f).IsD() ) {
|
if( !(*f).IsD() ) {
|
||||||
|
@ -343,7 +325,6 @@ static void PerBitQuadFaceNormalized(ComputeMeshType &m)
|
||||||
/// \brief Calculates the vertex normal.
|
/// \brief Calculates the vertex normal.
|
||||||
static void PerVertexNormalized(ComputeMeshType &m)
|
static void PerVertexNormalized(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
if( !HasPerVertexNormal(m)) return;
|
|
||||||
PerVertex(m);
|
PerVertex(m);
|
||||||
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
if( !(*vi).IsD() && (*vi).IsRW() )
|
if( !(*vi).IsD() && (*vi).IsRW() )
|
||||||
|
@ -351,12 +332,13 @@ static void PerVertexNormalized(ComputeMeshType &m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Multiply the vertex normals by the matrix passed. By default, the scale component is removed.
|
/// \brief Multiply the vertex normals by the matrix passed. By default, the scale component is removed.
|
||||||
static void PerVertexMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true){
|
static void PerVertexMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true)
|
||||||
float scale;
|
{
|
||||||
|
if(!HasPerVertexNormal(m)) throw vcg::MissingComponentException();
|
||||||
|
float scale;
|
||||||
|
|
||||||
Matrix33<ScalarType> mat33(mat,3);
|
Matrix33<ScalarType> mat33(mat,3);
|
||||||
|
|
||||||
if( !HasPerVertexNormal(m)) return;
|
|
||||||
|
|
||||||
if(remove_scaling){
|
if(remove_scaling){
|
||||||
scale = pow(mat33.Determinant(),(ScalarType)(1.0/3.0));
|
scale = pow(mat33.Determinant(),(ScalarType)(1.0/3.0));
|
||||||
|
@ -371,8 +353,10 @@ static void PerVertexMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Multiply the face normals by the matrix passed. By default, the scale component is removed.
|
/// \brief Multiply the face normals by the matrix passed. By default, the scale component is removed.
|
||||||
static void PerFaceMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true){
|
static void PerFaceMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true)
|
||||||
float scale;
|
{
|
||||||
|
if(!HasPerFaceNormal(m)) throw vcg::MissingComponentException();
|
||||||
|
float scale;
|
||||||
|
|
||||||
Matrix33<ScalarType> mat33(mat,3);
|
Matrix33<ScalarType> mat33(mat,3);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue