mirror of https://github.com/wpkong/Octree.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.1 KiB
89 lines
3.1 KiB
/**
|
|
* ------------------------------------
|
|
* @author: Weipeng Kong
|
|
* @date: 2021/11/17
|
|
* @email: yjxkwp@foxmail.com
|
|
* @site: https://donot.fit
|
|
* @description:
|
|
* ------------------------------------
|
|
**/
|
|
|
|
#include <igl/WindingNumberTree.h>
|
|
#include <igl/WindingNumberAABB.h>
|
|
#include <iostream>
|
|
#include <igl/marching_cubes.h>
|
|
#include <igl/voxel_grid.h>
|
|
#include <igl/writeOBJ.h>
|
|
#include <igl/readOBJ.h>
|
|
#include <igl/read_triangle_mesh.h>
|
|
#include <igl/in_element.h>
|
|
#include <igl/signed_distance.h>
|
|
#include <boost/log/trivial.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include <Eigen/Core>
|
|
#include <pMesh/io/writer/VTKWriter.h>
|
|
#include <pMesh/mesh/TriangleMesh.h>
|
|
#include <pMesh/io/adapter/DefaultWriteAdapter.h>
|
|
#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<double, 1, 3> RowVector3S;
|
|
// igl::WindingNumberAABB<RowVector3S, Eigen::MatrixXd, Eigen::MatrixXi> hier3;
|
|
// hier3.set_mesh(V, F);
|
|
// hier3.grow();
|
|
// igl::AABB<Eigen::MatrixXd, 3> 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;
|
|
}
|
|
|
|
|