main.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(
  25. Eigen::Vector2f(x,y),
  26. viewer.core.view * viewer.core.model,
  27. viewer.core.proj,
  28. viewer.core.viewport,
  29. V,
  30. F,
  31. fid,
  32. bc))
  33. {
  34. // paint hit red
  35. C.row(fid)<<1,0,0;
  36. viewer.data.set_colors(C);
  37. return true;
  38. }
  39. return false;
  40. };
  41. std::cout<<R"(Usage:
  42. [click] Pick face on shape
  43. )";
  44. // Show mesh
  45. viewer.data.set_mesh(V, F);
  46. viewer.data.set_colors(C);
  47. viewer.core.show_lines = false;
  48. viewer.launch();
  49. }