diff --git a/vcg/complex/algorithms/smooth.h b/vcg/complex/algorithms/smooth.h index 24025e35..60074523 100644 --- a/vcg/complex/algorithms/smooth.h +++ b/vcg/complex/algorithms/smooth.h @@ -25,7 +25,6 @@ #ifndef __VCGLIB__SMOOTH #define __VCGLIB__SMOOTH -#include #include #include #include @@ -985,7 +984,7 @@ static void FaceNormalLaplacianFF(MeshType &m, int step=1, bool SmoothSelected=f // VF Topology // Normalized Face Normals // -// This is the Normal Smoothing approach bsased on a angle thresholded weighting +// This is the Normal Smoothing approach based on a angle thresholded weighting // sigma is in the 0 .. 1 range, it represent the cosine of a threshold angle. // sigma == 0 All the normals are averaged // sigma == 1 Nothing is averaged. @@ -993,57 +992,51 @@ static void FaceNormalLaplacianFF(MeshType &m, int step=1, bool SmoothSelected=f static void FaceNormalAngleThreshold(MeshType &m, - SimpleTempData &TD, - ScalarType sigma) + SimpleTempData &TD, + ScalarType sigma) { - int i; - - - FaceIterator fi; - - for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) - { - CoordType bc=Barycenter(*fi); + for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) + { // 1) Clear all the visited flag of faces that are vertex-adjacent to fi - for(i=0;i<3;++i) - { - VFLocalIterator ep(&*fi,i); - for (;!ep.End();++ep) - ep.f->ClearV(); - } + for(int i=0;i<3;++i) + { + VFLocalIterator ep(&*fi,i); + for (;!ep.End();++ep) + ep.f->ClearV(); + } // 1) Effectively average the normals weighting them with the squared difference of the angle similarity - // sigma is the cosine of a threshold angle. sigma \in 0..1 - // sigma == 0 All the normals are averaged - // sigma == 1 Nothing is averaged. - // The averaging is weighted with the difference between normals. more similar the normal more important they are. + // sigma is the cosine of a threshold angle. sigma \in 0..1 + // sigma == 0 All the normals are averaged + // sigma == 1 Nothing is averaged. + // The averaging is weighted with the difference between normals. more similar the normal more important they are. CoordType normalSum=CoordType(0,0,0); - for(i=0;i<3;++i) + for(int i=0;i<3;++i) + { + VFLocalIterator ep(&*fi,i); + for (;!ep.End();++ep) + { + if(! (*ep.f).IsV() ) { - VFLocalIterator ep(&*fi,i); - for (;!ep.End();++ep) - { - if(! (*ep.f).IsV() ) - { ScalarType cosang=ep.f->N().dot((*fi).N()); - // Note that if two faces form an angle larger than 90 deg, their contribution should be very very small. - // Without this clamping - cosang = math::Clamp(cosang,ScalarType(0.0001),ScalarType(1.f)); + // Note that if two faces form an angle larger than 90 deg, their contribution should be very very small. + // Without this clamping + cosang = math::Clamp(cosang,ScalarType(0.0001),ScalarType(1.f)); if(cosang >= sigma) { ScalarType w = cosang-sigma; - normalSum += ep.f->N()*(w*w); // similar normals have a cosang very close to 1 so cosang - sigma is maximized + normalSum += ep.f->N()*(w*w); // similar normals have a cosang very close to 1 so cosang - sigma is maximized } - (*ep.f).SetV(); - } - } + (*ep.f).SetV(); } - normalSum.Normalize(); - TD[*fi].m=normalSum; + } } + normalSum.Normalize(); + TD[*fi].m=normalSum; + } - for(fi=m.face.begin();fi!=m.face.end();++fi) + for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) (*fi).N()=TD[*fi].m; } @@ -1111,7 +1104,6 @@ static void FitMesh(MeshType &m, SimpleTempData &TDF, float lambda) { - //vcg::face::Pos ep; vcg::face::VFIterator ep; VertexIterator vi; for(vi=m.vert.begin();vi!=m.vert.end();++vi) @@ -1173,46 +1165,22 @@ static void FastFitMesh(MeshType &m, -static void VertexCoordPasoDoble(MeshType &m, int step, typename MeshType::ScalarType Sigma=0, int FitStep=10, typename MeshType::ScalarType FitLambda=0.05) -{ - SimpleTempData< typename MeshType::VertContainer, PDVertInfo> TDV(m.vert); - SimpleTempData< typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face); - PDVertInfo lpzv; - lpzv.np=CoordType(0,0,0); - PDFaceInfo lpzf(CoordType(0,0,0)); - - assert(m.HasVFTopology()); - m.HasVFTopology(); - TDV.Start(lpzv); - TDF.Start(lpzf); - for(int j=0;j::PerFace(m); - FaceNormalAngleThreshold(m,TDF,Sigma); - for(int k=0;k TDV(m.vert,lpzv); - SimpleTempData< typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face,lpzf); + assert(HasPerVertexVFAdjacency(m) && HasPerFaceVFAdjacency(m)); + SimpleTempData< typename MeshType::VertContainer, PDVertInfo> TDV(m.vert,lpzv); + SimpleTempData< typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face,lpzf); for(int j=0;j