main.cpp 1.3 KB

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