#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char * argv[]) { typedef Eigen::SparseMatrix SparseMat; //Constants used for smoothing const double howMuchToSmoothBy = 1e-1; const int howManySmoothingInterations = 50; //Read our mesh Eigen::MatrixXd V; Eigen::MatrixXi F; if(!igl::read_triangle_mesh (argc>1?argv[1]: TUTORIAL_SHARED_PATH "/elephant.obj",V,F)) { std::cout << "Failed to load mesh." << std::endl; } //Orient edges for plotting Eigen::MatrixXi E, oE; igl::orient_halfedges(F, E, oE); //Compute edge midpoints & edge vectors Eigen::MatrixXd edgeMps, parVec, perpVec; igl::edge_midpoints(V, F, E, oE, edgeMps); igl::edge_vectors(V, F, E, oE, parVec, perpVec); //Constructing a function to add noise to const auto zraw_function = [] (const Eigen::Vector3d& x) { return Eigen::Vector3d(0.2*x(1) + cos(2*x(1)+0.2), 0.5*x(0) + 0.15, 0.3*cos(0.2+igl::PI*x(2))); }; Eigen::VectorXd zraw(2*edgeMps.rows()); for(int i=0; i rhsSolver(M + howMuchToSmoothBy*L); zsmoothed = rhsSolver.solve(M*zsmoothed); } //Convert vector fields for plotting const auto cr_result_to_vecs_and_colors = [&] (const Eigen::VectorXd& z, Eigen::MatrixXd& vecs, Eigen::MatrixXd& colors) { vecs.resize(edgeMps.rows(), 3); for(int i=0; ibool { const Eigen::MatrixXd *vecs, *colors; switch(key) { case '1': vecs = &rawvecs; colors = &rawcolors; break; case '2': vecs = &noisyvecs; colors = &noisycolors; break; case '3': vecs = &smoothedvecs; colors = &smoothedcolors; break; default: return false; } viewer.data().set_data(*colors); viewer.data().clear_edges(); const double s = 0.08; //How much to scale vectors during plotting viewer.data().add_edges(edgeMps, edgeMps + s*(*vecs), Eigen::RowVector3d(0.1, 0.1, 0.1)); return true; }; std::cout << R"(Usage: 1 Show raw function 2 Show noisy function 3 Show smoothed function )"; Eigen::MatrixXd CM; igl::parula(Eigen::VectorXd::LinSpaced (500,znoisy.minCoeff(), znoisy.maxCoeff()).eval(), true, CM); viewer.data().set_colormap(CM); viewer.callback_key_down(viewer, '1', 0); viewer.launch(); return 0; }