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.

101 lines
3.6 KiB

/**
* ------------------------------------
* @author: Weipeng Kong
* @date: 2021/11/17
* @email: yjxkwp@foxmail.com
* @site: https://donot.fit
* @description:
* ------------------------------------
**/
#include <iostream>
#include "Octree/sdf/SDFOctree.h"
#include "Octree/OctreeBuilder.h"
#include "Octree/OctreeTraverser.h"
#include "Octree/sdf/SDFTraversalSampler.h"
#include <igl/marching_cubes.h>
#include <igl/voxel_grid.h>
#include <igl/writeOBJ.h>
#include <igl/signed_distance.h>
#include <pMesh/mesh/TriangleMesh.h>
#include <pMesh/mesh/HexahedronMesh.h>
#include <pMesh/io/reader/OBJReader.h>
#include <pMesh/io/reader/VTKReader.h>
#include <pMesh/io/writer/VTKWriter.h>
#include <pMesh/io/adapter/DefaultReadAdapter.h>
#include <pMesh/io/adapter/DefaultWriteAdapter.h>
#include <boost/timer.hpp>
#include <boost/log/trivial.hpp>
#include <pMesh/io/reader/BaseReader.h>
#include <pMesh/io/adapter/DefaultReadAdapter.h>
#include "test-path.h"
int main(){
auto out_sphere_path = boost::filesystem::path(LOCAL_TEST_DATA_BASE_PATH) / "broken.vtk";
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";
double radius = 2;
Eigen::MatrixXd V;
Eigen::MatrixXi F;
std::vector<Eigen::Vector2i> mesh;
pMesh::SurfaceMesh half_sphere;
pMesh::SurfaceMesh debug_point_cloud;
for (int i = 0; i <= 180; ++i) {
double rad = i * M_PI / 180;
double x = radius * std::sin(rad);
double y = radius * std::cos(rad);
half_sphere.push_vertex(Eigen::Vector3d{x, y, 0});
if(i != 0)
half_sphere.push_face({i - 1, i});
}
pMesh::io::VTKWriter(3, out_sphere_path) << pMesh::io::DefaultSurfaceWriteAdapter(half_sphere)();
V.resize(half_sphere.v_size(), 3);
F.resize(half_sphere.f_size(), 2);
for (int i = 0; i < half_sphere.v_size(); ++i) {
V.row(i) = half_sphere.vertices[i].attr.coordinate;
}
for (int i = 0; i < half_sphere.f_size(); ++i) {
F.row(i) << half_sphere.faces[i].attr.vertices[0].id(), half_sphere.faces[i].attr.vertices[1].id();
}
Eigen::MatrixXd GV;
Eigen::RowVector3i res;
const int s = 10;
igl::voxel_grid(V, 0, s, 0, 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)();
}