main.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <igl/local_basis.h>
  4. #include <igl/barycenter.h>
  5. #include <igl/avg_edge_length.h>
  6. #include <igl/embree/ambient_occlusion.h>
  7. #include <algorithm>
  8. using namespace Eigen;
  9. using namespace std;
  10. // Mesh
  11. Eigen::MatrixXd V;
  12. Eigen::MatrixXi F;
  13. VectorXd AO;
  14. // It allows to change the degree of the field when a number is pressed
  15. bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
  16. {
  17. if (key == '1')
  18. {
  19. // Show the mesh without the ambient occlusion factor
  20. viewer.set_colors(Eigen::RowVector3d(1,1,1));
  21. }
  22. if (key == '2')
  23. {
  24. // Show the mesh with the ambient occlusion factor
  25. MatrixXd C = MatrixXd::Constant(V.rows(),3,1);
  26. for (unsigned i=0; i<C.rows();++i)
  27. C.row(i) *= std::min<double>(AO(i)+0.2,1);
  28. viewer.set_colors(C);
  29. }
  30. return false;
  31. }
  32. int main(int argc, char *argv[])
  33. {
  34. using namespace std;
  35. using namespace Eigen;
  36. // Load a mesh in OFF format
  37. igl::readOFF("../shared/fertility.off", V, F);
  38. MatrixXd N;
  39. igl::per_vertex_normals(V,F,N);
  40. // Compute ambient occlusion factor using embree
  41. igl::ambient_occlusion(V,F,V,N,500,AO);
  42. AO = 1.0 - AO.array();
  43. // Show mesh
  44. igl::Viewer viewer;
  45. viewer.set_mesh(V, F);
  46. viewer.callback_key_down = &key_down;
  47. key_down(viewer,'2',0);
  48. viewer.options.show_lines = false;
  49. viewer.launch();
  50. }