2
0

main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <igl/opengl/glfw/Viewer.h>
  2. #include <igl/read_triangle_mesh.h>
  3. #include <igl/material_colors.h>
  4. #include <igl/isolines.h>
  5. int main(int argc, char *argv[])
  6. {
  7. Eigen::MatrixXd V;
  8. Eigen::MatrixXi F;
  9. igl::read_triangle_mesh(
  10. argc>1?argv[1]:TUTORIAL_SHARED_PATH "/fertility.off",V,F);
  11. // Use y-coordinate as scalar field
  12. Eigen::VectorXd f = V.col(1);
  13. Eigen::MatrixXd iV;
  14. Eigen::MatrixXi iE;
  15. {
  16. // How many isolines in the range (min,max)?
  17. const int n = argc>2?atoi(argv[2]):128;
  18. // This is actually unnecessary since isolines will not output degenerate
  19. // segments.
  20. //Eigen::VectorXd vals = Eigen::VectorXd::LinSpaced(n+2,f.minCoeff(),f.maxCoeff()).segment(1,n);
  21. // Instead just use all n+2 and if the min-,max-value isolines are
  22. // non-degneerate then we'll compute them, too.
  23. Eigen::VectorXd vals = Eigen::VectorXd::LinSpaced(n+2,f.minCoeff(),f.maxCoeff());
  24. {
  25. Eigen::VectorXi I;
  26. igl::isolines(V,F,f,vals,iV,iE,I);
  27. }
  28. }
  29. // Plot the mesh
  30. igl::opengl::glfw::Viewer viewer;
  31. viewer.data().set_mesh(V, F);
  32. viewer.data().label_size = 10;
  33. viewer.data().set_face_based(true);
  34. viewer.data().show_faces = true;
  35. viewer.data().show_lines = false;
  36. viewer.data().uniform_colors(
  37. Eigen::Vector3d(0.94*viewer.core().background_color.head<3>().cast<double>()),
  38. Eigen::Vector3d(0.05*viewer.core().background_color.head<3>().cast<double>()),
  39. Eigen::Vector3d(0.01*viewer.core().background_color.head<3>().cast<double>()));
  40. viewer.core().lighting_factor = 0.5;
  41. viewer.data().set_edges(iV, iE,
  42. Eigen::RowVector3d(igl::GOLD_DIFFUSE[0], igl::GOLD_DIFFUSE[1], igl::GOLD_DIFFUSE[2]));
  43. viewer.data().line_width = 1;
  44. viewer.launch();
  45. }