|
|
|
/**
|
|
|
|
* ------------------------------------
|
|
|
|
* @author: Weipeng Kong
|
|
|
|
* @date: 2021/11/17
|
|
|
|
* @email: yjxkwp@foxmail.com
|
|
|
|
* @site: https://donot.fit
|
|
|
|
* @description:
|
|
|
|
* ------------------------------------
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include "Octree/BaseOctree.h"
|
|
|
|
#include "Octree/OctreeBuilder.h"
|
|
|
|
#include "Octree/OctreeTraverser.h"
|
|
|
|
#include "Octree/SDFTraversalSampler.h"
|
|
|
|
#include <igl/marching_cubes.h>
|
|
|
|
#include <igl/voxel_grid.h>
|
|
|
|
#include <igl/writeOBJ.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>
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
BOOST_LOG_TRIVIAL(debug) << "cwd is " << boost::filesystem::current_path();
|
|
|
|
pMesh::io::fs_path data_base_path = "../../../data";
|
|
|
|
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;
|
|
|
|
}
|