Files
igl/tutorial/605_Tetgen/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

80 lines
1.9 KiB
C++
Executable File

#include <igl/opengl/glfw/Viewer.h>
#include <igl/copyleft/tetgen/tetrahedralize.h>
#include <igl/readOFF.h>
#include <igl/barycenter.h>
// Input polygon
Eigen::MatrixXd V;
Eigen::MatrixXi F;
Eigen::MatrixXd B;
// Tetrahedralized interior
Eigen::MatrixXd TV;
Eigen::MatrixXi TT;
Eigen::MatrixXi TF;
// This function is called every time a keyboard button is pressed
bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
{
using namespace std;
using namespace Eigen;
if (key >= '1' && key <= '9')
{
double t = double((key - '1')+1) / 9.0;
VectorXd v = B.col(2).array() - B.col(2).minCoeff();
v /= v.col(0).maxCoeff();
vector<int> s;
for (unsigned i=0; i<v.size();++i)
if (v(i) < t)
s.push_back(i);
MatrixXd V_temp(s.size()*4,3);
MatrixXi F_temp(s.size()*4,3);
for (unsigned i=0; i<s.size();++i)
{
V_temp.row(i*4+0) = TV.row(TT(s[i],0));
V_temp.row(i*4+1) = TV.row(TT(s[i],1));
V_temp.row(i*4+2) = TV.row(TT(s[i],2));
V_temp.row(i*4+3) = TV.row(TT(s[i],3));
F_temp.row(i*4+0) << (i*4)+0, (i*4)+1, (i*4)+3;
F_temp.row(i*4+1) << (i*4)+0, (i*4)+2, (i*4)+1;
F_temp.row(i*4+2) << (i*4)+3, (i*4)+2, (i*4)+0;
F_temp.row(i*4+3) << (i*4)+1, (i*4)+2, (i*4)+3;
}
viewer.data().clear();
viewer.data().set_mesh(V_temp,F_temp);
viewer.data().set_face_based(true);
}
return false;
}
int main(int argc, char *argv[])
{
using namespace Eigen;
using namespace std;
// Load a surface mesh
igl::readOFF(TUTORIAL_SHARED_PATH "/fertility.off",V,F);
// Tetrahedralize the interior
igl::copyleft::tetgen::tetrahedralize(V,F,"pq1.414Y", TV,TT,TF);
// Compute barycenters
igl::barycenter(TV,TT,B);
// Plot the generated mesh
igl::opengl::glfw::Viewer viewer;
viewer.callback_key_down = &key_down;
key_down(viewer,'5',0);
viewer.launch();
}