From e646c1df7667cd45e2661997668f5d6dcbcd5f7c Mon Sep 17 00:00:00 2001 From: lab pc Date: Thu, 9 Dec 2021 19:58:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8ESIGNED=5FDISTANCE=5FTYPE=5FPS?= =?UTF-8?q?EUDONORMAL=20=E5=81=9A=E7=9A=84sdf=E5=8F=AF=E4=BB=A5=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E4=B9=8B=E5=89=8D=E7=9A=84=E7=A9=BA=E9=97=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/aabb_tree_test/main.cpp | 61 ++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/aabb_tree_test/main.cpp b/tests/aabb_tree_test/main.cpp index 267dce6..977e690 100644 --- a/tests/aabb_tree_test/main.cpp +++ b/tests/aabb_tree_test/main.cpp @@ -8,6 +8,8 @@ * ------------------------------------ **/ +#include +#include #include #include #include @@ -15,16 +17,73 @@ #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) / "quarter_sphere.obj"; + 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; } +