From f898229f001f8f198a5f43c3b753ef7868bfbb68 Mon Sep 17 00:00:00 2001 From: Yihuan Mao Date: Tue, 25 Sep 2018 14:09:12 -0400 Subject: [PATCH] submit --- src/fd_grad.cpp | 11 +++++--- src/fd_interpolate.cpp | 35 +++++++++++++++++++++--- src/fd_partial_derivative.cpp | 37 +++++++++++++++++++++++--- src/poisson_surface_reconstruction.cpp | 27 +++++++++++++++++++ 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/fd_grad.cpp b/src/fd_grad.cpp index 9206181..101ecfa 100644 --- a/src/fd_grad.cpp +++ b/src/fd_grad.cpp @@ -1,4 +1,6 @@ #include "fd_grad.h" +#include "fd_partial_derivative.h" +#include void fd_grad( const int nx, @@ -7,7 +9,10 @@ void fd_grad( const double h, Eigen::SparseMatrix & G) { - //////////////////////////////////////////////////////////////////////////// - // Add your code here - //////////////////////////////////////////////////////////////////////////// + Eigen::SparseMatrix G1,G2,G3; + fd_partial_derivative(nx,ny,nz,h,0,G1); + fd_partial_derivative(nx,ny,nz,h,1,G2); + fd_partial_derivative(nx,ny,nz,h,2,G3); + G=igl::cat(1,G1,G2); + G=igl::cat(1,G,G3); } diff --git a/src/fd_interpolate.cpp b/src/fd_interpolate.cpp index 2a32675..2850382 100644 --- a/src/fd_interpolate.cpp +++ b/src/fd_interpolate.cpp @@ -1,5 +1,8 @@ #include "fd_interpolate.h" - +#include +#include +#include +typedef Eigen::Triplet T; void fd_interpolate( const int nx, const int ny, @@ -9,7 +12,31 @@ void fd_interpolate( const Eigen::MatrixXd & P, Eigen::SparseMatrix & W) { - //////////////////////////////////////////////////////////////////////////// - // Add your code here - //////////////////////////////////////////////////////////////////////////// + int n=P.rows(); + double x,y,z,dx,dy,dz; + std::vector tripletList; + tripletList.reserve(n*8); + W.resize(n,nx*ny*nz); + for (int i = 0; i< n; i++){ + x=floor((P(i,0)-corner(0))/h); + y=floor((P(i,1)-corner(1))/h); + z=floor((P(i, 2)-corner(2))/h); + dx=(P(i,0)-corner(0))/h-x; + dy=(P(i,1)-corner(1))/h-y; + dz=(P(i,2)-corner(2))/h-z; + + tripletList.push_back(T(i, x + y *nx + z * nx*ny, (1-dx) * (1-dy) * (1-dz))); + tripletList.push_back(T(i, (x+1) + y *nx + z * nx*ny, dx * (1-dy) * (1-dz))); + + tripletList.push_back(T(i, x + (y+1) *nx + z * nx*ny, (1-dx) * dy * (1-dz))); + tripletList.push_back(T(i, x + y * nx + (z+1) * nx*ny, (1-dx) * (1-dy) * dz)); + + tripletList.push_back(T(i, (x+1) + (y+1) *nx + z * nx*ny, dx * dy * (1-dz))); + tripletList.push_back(T(i, (x+1) + y *nx + (z+1) * nx*ny, dx * (1-dy) * dz)); + + tripletList.push_back(T(i, x + (y+1) *nx + (z+1) * nx*ny, (1-dx) * dy * dz)); + tripletList.push_back(T(i, (x+1) + (y+1) * nx + (z+1) * nx*ny, dx * dy * dz)); + + } + W.setFromTriplets(tripletList.begin(),tripletList.end()); } diff --git a/src/fd_partial_derivative.cpp b/src/fd_partial_derivative.cpp index c3c4deb..a451e3f 100644 --- a/src/fd_partial_derivative.cpp +++ b/src/fd_partial_derivative.cpp @@ -8,7 +8,38 @@ void fd_partial_derivative( const int dir, Eigen::SparseMatrix & D) { - //////////////////////////////////////////////////////////////////////////// - // Add your code here - //////////////////////////////////////////////////////////////////////////// + double h1=1/h; + if (dir==0){ + D.resize((nx-1)*ny*nz,nx*ny*nz); + for (int i=0; i #include +#include +#include "fd_interpolate.h" +#include "fd_grad.h" +#include void poisson_surface_reconstruction( const Eigen::MatrixXd & P, @@ -43,7 +47,30 @@ void poisson_surface_reconstruction( } } Eigen::VectorXd g = Eigen::VectorXd::Zero(nx*ny*nz); + //printf("%d %d %d %d ",n,nx,ny,nz); + Eigen::RowVector3d c1(h/2,0,0),c2(0,h/2,0),c3(0,0,h/2); + Eigen::SparseMatrix W1,W2,W3,W; + fd_interpolate(nx-1,ny,nz,h,corner+c1,P,W1); + fd_interpolate(nx,ny-1,nz,h,corner+c2,P,W2); + fd_interpolate(nx,ny,nz-1,h,corner+c3,P,W3); + Eigen::VectorXd V1((nx-1)*ny*nz),V2(nx*(ny-1)*nz),V3(nx*ny*(nz-1)),vv((nx-1)*ny*nz+nx*(ny-1)*nz+nx*ny*(nz-1)); + V1=W1.transpose()*N.col(0); + V2=W2.transpose()*N.col(1); + V3=W3.transpose()*N.col(2); + vv << V1,V2,V3; + Eigen::SparseMatrix gg; + fd_grad(nx,ny,nz,h,gg); + + Eigen::BiCGSTAB> solver; + solver.compute(gg.transpose()*gg); + printf("%d %d ",gg.rows(),gg.cols()); + Eigen::MatrixXd b=gg.transpose()*vv; + g=solver.solve(b); + + fd_interpolate(nx,ny,nz,h,corner,P,W); + double sigma=(Eigen::MatrixXd::Ones(1,n)*W*g).value()/n; + g=g-Eigen::VectorXd::Ones(nx*ny*nz)*sigma; //////////////////////////////////////////////////////////////////////////// // Add your code here ////////////////////////////////////////////////////////////////////////////