From 30f6267da1b18699ec222950c30584a332280a0d Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 24 Sep 2010 11:21:15 +0000 Subject: [PATCH] Corrected the unneeded resetting of un referenced normals when computing per vertex normals starting from faces. --- vcg/complex/trimesh/update/normal.h | 49 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/vcg/complex/trimesh/update/normal.h b/vcg/complex/trimesh/update/normal.h index d2fcce4d..7be220e4 100644 --- a/vcg/complex/trimesh/update/normal.h +++ b/vcg/complex/trimesh/update/normal.h @@ -26,7 +26,8 @@ #include #include -#include +#include + namespace vcg { namespace tri { @@ -55,6 +56,28 @@ typedef typename MeshType::FaceType FaceType; typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FaceIterator FaceIterator; +/** + Set to zero all the normals. Usued by all the face averaging algorithms. + 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) +{ + assert(HasPerVertexNormal(m)); + if(ClearAllVertNormal) + UpdateFlags::VertexClearV(m); + else + { + UpdateFlags::VertexSetV(m); + for(FaceIterator f=m.face.begin();f!=m.face.end();++f) + if( !(*f).IsD() ) + for(int i=0;i<3;++i) (*f).V(i)->ClearV(); + } + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) + if( !(*vi).IsD() && (*vi).IsRW() && (!(*vi).IsV()) ) + (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0); +} + /// \brief Calculates the face normal (if stored in the current face type) static void PerFace(ComputeMeshType &m) @@ -119,11 +142,7 @@ Journal of Graphics Tools, 1998 static void PerVertexAngleWeighted(ComputeMeshType &m) { assert(HasPerVertexNormal(m)); - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - if( !(*vi).IsD() && (*vi).IsRW() ) - (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0); - + PerVertexClear(m); FaceIterator f; for(f=m.face.begin();f!=m.face.end();++f) if( !(*f).IsD() && (*f).IsR() ) @@ -150,13 +169,10 @@ static void PerVertexAngleWeighted(ComputeMeshType &m) static void PerVertexWeighted(ComputeMeshType &m) { assert(HasPerVertexNormal(m)); - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - if( !(*vi).IsD() && (*vi).IsRW() ) - (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0); + + PerVertexClear(m); FaceIterator f; - for(f=m.face.begin();f!=m.face.end();++f) if( !(*f).IsD() && (*f).IsR() ) { @@ -180,13 +196,9 @@ static void PerVertex(ComputeMeshType &m) { assert(HasPerVertexNormal(m)); - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - if( !(*vi).IsD() && (*vi).IsRW() ) - (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0); + PerVertexClear(m); FaceIterator f; - for(f=m.face.begin();f!=m.face.end();++f) if( !(*f).IsD() && (*f).IsR() ) { @@ -210,10 +222,7 @@ static void PerVertexPerFace(ComputeMeshType &m) if( !m.HasPerVertexNormal() || !m.HasPerFaceNormal()) return; PerFace(m); - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - if( !(*vi).IsD() && (*vi).IsRW() ) - (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0); + PerVertexClear(m); FaceIterator f;