Files
igl/tutorial/206_GeodesicDistance/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

74 lines
2.0 KiB
C++
Executable File

#include <igl/readOBJ.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/exact_geodesic.h>
#include <igl/unproject_onto_mesh.h>
#include <igl/parula.h>
#include <igl/isolines_map.h>
#include <igl/PI.h>
#include <iostream>
int main(int argc, char *argv[])
{
using namespace Eigen;
using namespace std;
Eigen::MatrixXd V;
Eigen::MatrixXi F;
igl::opengl::glfw::Viewer viewer;
// Load a mesh in OFF format
igl::readOBJ(TUTORIAL_SHARED_PATH "/armadillo.obj", V, F);
const auto update_distance = [&](const int vid)
{
Eigen::VectorXi VS,FS,VT,FT;
// The selected vertex is the source
VS.resize(1);
VS << vid;
// All vertices are the targets
VT.setLinSpaced(V.rows(),0,V.rows()-1);
Eigen::VectorXd d;
std::cout<<"Computing geodesic distance to vertex "<<vid<<"..."<<std::endl;
igl::exact_geodesic(V,F,VS,FS,VT,FT,d);
// Plot the mesh
Eigen::MatrixXd CM;
igl::parula(Eigen::VectorXd::LinSpaced(21,0,1).eval(),false,CM);
igl::isolines_map(Eigen::MatrixXd(CM),CM);
viewer.data().set_colormap(CM);
viewer.data().set_data(d);
};
// Plot a distance when a vertex is picked
viewer.callback_mouse_down =
[&](igl::opengl::glfw::Viewer& viewer, int, int)->bool
{
int fid;
Eigen::Vector3f bc;
// Cast a ray in the view direction starting from the mouse position
double x = viewer.current_mouse_x;
double y = viewer.core().viewport(3) - viewer.current_mouse_y;
if(igl::unproject_onto_mesh(
Eigen::Vector2f(x,y),
viewer.core().view,
viewer.core().proj,
viewer.core().viewport,
V,
F,
fid,
bc))
{
int max;
bc.maxCoeff(&max);
int vid = F(fid,max);
update_distance(vid);
return true;
}
return false;
};
viewer.data().set_mesh(V,F);
viewer.data().show_lines = false;
cout << "Click on mesh to define new source.\n" << std::endl;
update_distance(0);
return viewer.launch();
}