Files
igl/tutorial/705_MarchingCubes/main.cpp
T
b0fd49d598 CMake refactor (#1805)
* Start CMake refactoring.

* WIP on instlal().

* Handle install + hunter setup.

* Handle module options + igl_include helper.

* Build all tutorials again.

* Update CMake for unit tests.

* Update triangle lib.

* Update Hunter integration.

* Fix for header-only mode.

* Fix Windows compilation + add GMP/MPFR find_package + set VS folders.

* Fix CGAL build.

* Add copy dll for Windows + improve find gmp/mpfr.

* Update Github Actions.

* Update README.

* Fixes for CMake 3.18

* Fix include option.

* Rename libigl_imgui_front to avoid conflicts.

* Fix when disabling unit tests.

* Build imguizmo with C++11.

* Update CMake option comments.

* Rename nonfree -> restricted.

* Update triangle and tetgen versions.

* Fix compilation issue.

* Update continuous.yml

* remove cork

* finding matlab with default

* mosek module compiles; default detected; osx dylib hack

* Reduce build parallelism.

* Fix find GMP/MPFR on Windows + cleanup CGAL changes.

* Update readme.

Co-authored-by: Alec Jacobson <alecjacobson@adobe.com>
Co-authored-by: Alec Jacobson <alecjacobson@gmail.com>
2022-02-09 18:58:40 -08:00

77 lines
2.0 KiB
C++
Executable File

#include <igl/marching_cubes.h>
#include <igl/signed_distance.h>
#include <igl/read_triangle_mesh.h>
#include <igl/voxel_grid.h>
#include <igl/opengl/glfw/Viewer.h>
#include <Eigen/Core>
#include <iostream>
int main(int argc, char * argv[])
{
using namespace Eigen;
using namespace std;
using namespace igl;
MatrixXi F;
MatrixXd V;
// Read in inputs as double precision floating point meshes
read_triangle_mesh(
TUTORIAL_SHARED_PATH "/armadillo.obj",V,F);
cout<<"Creating grid..."<<endl;
// number of vertices on the largest side
const int s = 100;
// create grid
MatrixXd GV;
Eigen::RowVector3i res;
igl::voxel_grid(V,0,s,1,GV,res);
// compute values
cout<<"Computing distances..."<<endl;
VectorXd S,B;
{
VectorXi I;
MatrixXd C,N;
signed_distance(GV,V,F,SIGNED_DISTANCE_TYPE_PSEUDONORMAL,S,I,C,N);
// Convert distances to binary inside-outside data --> aliasing artifacts
B = S;
for_each(B.data(),B.data()+B.size(),[](double& b){b=(b>0?1:(b<0?-1:0));});
}
cout<<"Marching cubes..."<<endl;
MatrixXd SV,BV;
MatrixXi SF,BF;
igl::marching_cubes(S,GV,res(0),res(1),res(2),0,SV,SF);
igl::marching_cubes(B,GV,res(0),res(1),res(2),0,BV,BF);
cout<<R"(Usage:
'1' Show original mesh.
'2' Show marching cubes contour of signed distance.
'3' Show marching cubes contour of indicator function.
)";
igl::opengl::glfw::Viewer viewer;
viewer.data().set_mesh(SV,SF);
viewer.callback_key_down =
[&](igl::opengl::glfw::Viewer & viewer, unsigned char key, int mod)->bool
{
switch(key)
{
default:
return false;
case '1':
viewer.data().clear();
viewer.data().set_mesh(V,F);
break;
case '2':
viewer.data().clear();
viewer.data().set_mesh(SV,SF);
break;
case '3':
viewer.data().clear();
viewer.data().set_mesh(BV,BF);
break;
}
viewer.data().set_face_based(true);
return true;
};
viewer.launch();
}