main.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <igl/readOFF.h>
  2. #include <igl/unproject_onto_mesh.h>
  3. #include <igl/opengl/glfw/Viewer.h>
  4. #include <iostream>
  5. int main(int argc, char *argv[])
  6. {
  7. // Mesh with per-face color
  8. Eigen::MatrixXd V, C;
  9. Eigen::MatrixXi F;
  10. // Load a mesh in OFF format
  11. igl::readOFF(TUTORIAL_SHARED_PATH "/fertility.off", V, F);
  12. // Initialize white
  13. C = Eigen::MatrixXd::Constant(F.rows(),3,1);
  14. igl::opengl::glfw::Viewer viewer;
  15. viewer.callback_mouse_down =
  16. [&V,&F,&C](igl::opengl::glfw::Viewer& viewer, int, int)->bool
  17. {
  18. int fid;
  19. Eigen::Vector3f bc;
  20. // Cast a ray in the view direction starting from the mouse position
  21. double x = viewer.current_mouse_x;
  22. double y = viewer.core().viewport(3) - viewer.current_mouse_y;
  23. if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core().view,
  24. viewer.core().proj, viewer.core().viewport, V, F, fid, bc))
  25. {
  26. // paint hit red
  27. C.row(fid)<<1,0,0;
  28. viewer.data().set_colors(C);
  29. return true;
  30. }
  31. return false;
  32. };
  33. std::cout<<R"(Usage:
  34. [click] Pick face on shape
  35. )";
  36. // Show mesh
  37. viewer.data().set_mesh(V, F);
  38. viewer.data().set_colors(C);
  39. viewer.data().show_lines = false;
  40. viewer.launch();
  41. }