/** * ------------------------------------ * @author: Weipeng Kong * @date: 2021/11/17 * @email: yjxkwp@foxmail.com * @site: https://donot.fit * @description: * ------------------------------------ **/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test-path.h" int main() { auto mesh_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "hole_quarter_sphere.obj"; auto inside_out_point_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "inside_output_point.vtk"; auto outside_out_point_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "outside_output_point.vtk"; auto mc_out_point_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "hole_quarter_sphere_mc.obj"; Eigen::MatrixXd V; Eigen::MatrixXi F; igl::read_triangle_mesh(mesh_path.string(), V, F); // typedef Eigen::Matrix RowVector3S; // igl::WindingNumberAABB hier3; // hier3.set_mesh(V, F); // hier3.grow(); // igl::AABB aabb; // igl::signed_distance_pseudonormal(aabb,) Eigen::MatrixXd GV; Eigen::RowVector3i res; const int s = 10; igl::voxel_grid(V, 0, s, 1, GV, res); Eigen::MatrixXd S; Eigen::MatrixXi I; Eigen::MatrixXd C; Eigen::MatrixXd N; igl::signed_distance(GV, V, F, igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL, S, I, C, N); pMesh::SurfaceMesh inside_mesh; pMesh::SurfaceMesh outside_mesh; for (int i = 0; i < GV.rows(); ++i) { auto p = GV.row(i); if (S(i) < 0) { // std::cout << hier3.winding_number(p) << std::endl; auto v = pMesh::Surface::Vertex(inside_mesh.v_size(), GV.row(i)); auto f = pMesh::Surface::Face({.vertices={pMesh::Surface::VertexHandle(inside_mesh.v_size())}}); inside_mesh.vertices.emplace_back(v); inside_mesh.faces.emplace_back(f); } else { auto v = pMesh::Surface::Vertex(outside_mesh.v_size(), GV.row(i)); auto f = pMesh::Surface::Face({.vertices={pMesh::Surface::VertexHandle(outside_mesh.v_size())}}); outside_mesh.vertices.emplace_back(v); outside_mesh.faces.emplace_back(f); } } pMesh::io::VTKWriter(1, inside_out_point_path.string()) << pMesh::io::DefaultSurfaceWriteAdapter(inside_mesh)(); pMesh::io::VTKWriter(1, outside_out_point_path.string()) << pMesh::io::DefaultSurfaceWriteAdapter(outside_mesh)(); Eigen::MatrixXd SV, BV; Eigen::MatrixXi SF, BF; igl::marching_cubes(S, GV, res(0), res(1), res(2), 0, SV, SF); igl::writeOBJ(mc_out_point_path.string(), SV, SF); return 0; }