/** * ------------------------------------ * @author: Weipeng Kong * @date: 2021/11/17 * @email: yjxkwp@foxmail.com * @site: https://donot.fit * @description: * ------------------------------------ **/ #include #include "Octree/BaseOctree.h" #include "Octree/OctreeBuilder.h" #include "Octree/OctreeTraverser.h" #include "Octree/sdf/SDFTraversalSampler.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test-path.h" int main() { pMesh::io::fs_path data_base_path = TEST_DATA_BASE_PATH; BOOST_LOG_TRIVIAL(debug) << "base data path is " << boost::filesystem::absolute(data_base_path); auto mesh_path = data_base_path / "stanford-bunny.obj"; auto out_octree_path = data_base_path / "stanford-bunny-octree.vtk"; auto out_mc_path = data_base_path / "stanford-bunny-mc.obj"; pMesh::Triangle3dMesh<> mesh; pMesh::io::OBJReader(mesh_path) >> pMesh::io::DefaultSurfaceReadAdapter<>(mesh, false)(); const int level = 5; const double sample_step = 0.0001; if (1) { Eigen::MatrixXd V = Eigen::MatrixXd(mesh.v_size(), 3); Eigen::MatrixXi F = Eigen::MatrixXi(mesh.f_size(), 3); for (int i = 0; i < mesh.v_size(); ++i) { V.row(i) = mesh.vertices[i].attr.coordinate; } for (int i = 0; i < mesh.f_size(); ++i) { const auto &face = mesh.faces[i].attr.vertices; F.row(i) << face[0].id(), face[1].id(), face[2].id(); } Eigen::MatrixXd GV; Eigen::RowVector3i res; const int s = 100; igl::voxel_grid(V, 0, s, 1, GV, res); BOOST_LOG_TRIVIAL(debug) << res(0) << ", " << res(1) << ", " << res(2); // compute values std::cout << "Computing distances..." << std::endl; Eigen::VectorXd S = Eigen::VectorXd(GV.rows()); std::cout << "Marching cubes..." << std::endl; Eigen::MatrixXd SV, BV; Eigen::MatrixXi SF, BF; igl::marching_cubes(S, GV, res(0), res(1), res(2), 0, SV, SF); igl::writeOBJ(out_mc_path.string(), SV, SF); } return 0; }