From 2472215e8d5cecf5654e7cdeff41022e98b91141 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 15 Jul 2008 07:10:31 +0000 Subject: [PATCH] added VertexCoordPlanarLaplacian that moves only the vertices that does not change the orientation of the incident faces. Very useful for creating good meshing of CAD models. --- vcg/complex/trimesh/smooth.h | 55 +++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/vcg/complex/trimesh/smooth.h b/vcg/complex/trimesh/smooth.h index a51ff877..e4b5d9dc 100644 --- a/vcg/complex/trimesh/smooth.h +++ b/vcg/complex/trimesh/smooth.h @@ -340,6 +340,58 @@ static void VertexCoordLaplacian(MeshType &m, int step, bool SmoothSelected=fals } } +// Same of above but moves only the vertices that do not change FaceOrientation more that the given threshold +static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad = math::ToRad(1.0), bool SmoothSelected=false, vcg::CallBackPos * cb=0) +{ + VertexIterator vi; + FaceIterator fi; + LaplacianInfo lpz(CoordType(0,0,0),0); + SimpleTempData TD(m.vert,lpz); + for(int i=0;i0 ) + { + if(!SmoothSelected || (*vi).IsS()) + TD[*vi].sum = ( (*vi).P() + TD[*vi].sum)/(TD[*vi].cnt+1); + } + + for(fi=m.face.begin();fi!=m.face.end();++fi){ + if(!(*fi).IsD()){ + for (int j = 0; j < 3; ++j) { + if(Angle( NormalizedNormal(TD[(*fi).V0(j)].sum, (*fi).P1(j), (*fi).P2(j) ), + NormalizedNormal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad ) + TD[(*fi).V0(j)].sum = (*fi).P0(j); + } + } + } + for(fi=m.face.begin();fi!=m.face.end();++fi){ + if(!(*fi).IsD()){ + for (int j = 0; j < 3; ++j) { + if(Angle( NormalizedNormal(TD[(*fi).V0(j)].sum, TD[(*fi).V1(j)].sum, (*fi).P2(j) ), + NormalizedNormal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad ) + { + TD[(*fi).V0(j)].sum = (*fi).P0(j); + TD[(*fi).V1(j)].sum = (*fi).P1(j); + } + } + } + } + + for(vi=m.vert.begin();vi!=m.vert.end();++vi) + if(!(*vi).IsD() && TD[*vi].cnt>0 ) + (*vi).P()= TD[*vi].sum; + + + + }// end step + + +} + static void VertexCoordLaplacianBlend(MeshType &m, int step, float alpha, bool SmoothSelected=false) { VertexIterator vi; @@ -516,7 +568,7 @@ public: int cnt; }; -static void VertexColorLaplacian(MeshType &m, int step, bool SmoothSelected=false) +static void VertexColorLaplacian(MeshType &m, int step, bool SmoothSelected=false, vcg::CallBackPos * cb=0) { ColorSmoothInfo csi; csi.r=0; csi.g=0; csi.b=0; csi.cnt=0; @@ -524,6 +576,7 @@ static void VertexColorLaplacian(MeshType &m, int step, bool SmoothSelected=fals for(int i=0;i