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.

80 lines
2.5 KiB

3 years ago
/**
* ------------------------------------
* @author: Weipeng Kong
* @date: 2021/11/17
* @email: yjxkwp@foxmail.com
* @site: https://donot.fit
* @description:
* ------------------------------------
**/
#include <iostream>
#include "Octree/OctreeBase.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() {
std::string mesh_path = "/Users/kwp/Projects/Porous/models/v8/V8.obj";
std::string out_octree_path = "/Users/kwp/Projects/Porous/models/v8/octree_V8.vtk";
std::string out_mc_path = "/Users/kwp/Projects/Porous/models/v8/mc_v8.obj";
pMesh::Triangle3dMesh<> mesh;
pMesh::io::OBJReader(mesh_path)
>> pMesh::io::DefaultSurfaceReadAdapter<>(mesh, false)();
// pMesh::io::VTKReader("/Users/kwp/Projects/Porous/models/v8/tris.vtk") >> pMesh::io::DefaultSurfaceReadAdapter<>(mesh)();
const int level = 5;
const double sample_step = 1;
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, SV, SF);
// igl::marching_cubes(B,GV,res(0),res(1),res(2),0,BV,BF);
}
return 0;
}