From e29b6f4a46d0b52e1e555729088c98b767c3e348 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 5 Nov 2014 17:23:13 +0000 Subject: [PATCH] More refactoring of implicit smooting class --- vcg/complex/algorithms/implicit_smooth.h | 50 +++++++++++------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/vcg/complex/algorithms/implicit_smooth.h b/vcg/complex/algorithms/implicit_smooth.h index a07ffdbf..4eb6bc38 100644 --- a/vcg/complex/algorithms/implicit_smooth.h +++ b/vcg/complex/algorithms/implicit_smooth.h @@ -42,7 +42,6 @@ class ImplicitSmoother typedef typename MeshType::ScalarType ScalarType; typedef typename Eigen::Matrix MatrixXm; - MeshType &to_smooth_mesh; public: @@ -69,7 +68,7 @@ public: } }; - struct SmoothParam + struct Parameter { //the amount of smoothness, useful only if we set the mass matrix ScalarType lambda; @@ -85,7 +84,7 @@ public: //the set of faces for barycentric constraints std::vector ConstrainedF; - SmoothParam() + Parameter() { lambda=0.2; useMassMatrix=true; @@ -124,13 +123,12 @@ private: // } // } - void InitSparse(const std::vector > &Index, + static void InitSparse(const std::vector > &Index, const std::vector &Values, const size_t m, const size_t n, Eigen::SparseMatrix& X) { - assert(Index.size()==Values.size()); std::vector > IJV; @@ -151,14 +149,14 @@ private: X.setFromTriplets(IJV.begin(),IJV.end()); } - int SystemSize(SmoothParam & SParam) + int SystemSize(MeshType &mesh, Parameter & SParam) { - int basic_size=to_smooth_mesh.vert.size(); + int basic_size=mesh.vert.size(); int constr_size=SParam.ConstrainedF.size(); return (basic_size+constr_size); } - void CollectHardConstraints(const SmoothParam &SParam, + void CollectHardConstraints(MeshType &mesh,const Parameter &SParam, std::vector > &IndexC, std::vector &WeightC) { @@ -168,9 +166,9 @@ private: if (SParam.fixBorder) { //add penalization constra - for (int i=0;i ValuesM; //add the entries for mass matrix - if (SParam.useMassMatrix) MeshToMatrix::MassMatrixEntry(to_smooth_mesh,IndexM,ValuesM); + if (SParam.useMassMatrix) MeshToMatrix::MassMatrixEntry(mesh,IndexM,ValuesM); //then also collect hard constraints - //CollectHardConstraints(SParam,IndexM,ValuesM); + //CollectHardConstraints(mesh,SParam,IndexM,ValuesM); //initialize sparse mass matrix - InitSparse(IndexM,ValuesM,to_smooth_mesh.vert.size()*3,to_smooth_mesh.vert.size()*3,M); + InitSparse(IndexM,ValuesM,mesh.vert.size()*3,mesh.vert.size()*3,M); //get the entries for laplacian matrix std::vector > IndexL; std::vector ValuesL; - MeshToMatrix::GetLaplacianMatrix(to_smooth_mesh,IndexL,ValuesL,false);//SParam.useCotWeight); + MeshToMatrix::GetLaplacianMatrix(mesh,IndexL,ValuesL,false);//SParam.useCotWeight); //initialize sparse laplacian matrix - InitSparse(IndexL,ValuesL,to_smooth_mesh.vert.size()*3,to_smooth_mesh.vert.size()*3,L); + InitSparse(IndexL,ValuesL,mesh.vert.size()*3,mesh.vert.size()*3,L); //then solve the system Eigen::SparseMatrix S = (M + SParam.lambda*L); @@ -273,30 +271,28 @@ public: fflush(stdout); assert(solver.info() == Eigen::Success); - int size=to_smooth_mesh.vert.size()*3; + int size=mesh.vert.size()*3; MatrixXm V(size,1); - for (size_t i=0;i