main.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <igl/avg_edge_length.h>
  2. #include <igl/barycenter.h>
  3. #include <igl/jet.h>
  4. #include <igl/planarize_quad_mesh.h>
  5. #include <igl/quad_planarity.h>
  6. #include <igl/readDMAT.h>
  7. #include <igl/readOFF.h>
  8. #include <igl/opengl/glfw/Viewer.h>
  9. #include <vector>
  10. #include <cstdlib>
  11. // Quad mesh generated from conjugate field
  12. Eigen::MatrixXd VQC;
  13. Eigen::MatrixXi FQC;
  14. Eigen::MatrixXi FQCtri;
  15. Eigen::MatrixXd PQC0, PQC1, PQC2, PQC3;
  16. // Planarized quad mesh
  17. Eigen::MatrixXd VQCplan;
  18. Eigen::MatrixXi FQCtriplan;
  19. Eigen::MatrixXd PQC0plan, PQC1plan, PQC2plan, PQC3plan;
  20. // Scale for visualizing the fields
  21. double global_scale; //TODO: not used
  22. bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)
  23. {
  24. using namespace std;
  25. using namespace Eigen;
  26. // Plot the original quad mesh
  27. if (key == '1')
  28. {
  29. // Draw the triangulated quad mesh
  30. viewer.data().set_mesh(VQC, FQCtri);
  31. // Assign a color to each quad that corresponds to its planarity
  32. VectorXd planarity;
  33. igl::quad_planarity( VQC, FQC, planarity);
  34. MatrixXd Ct;
  35. igl::jet(planarity, 0, 0.01, Ct);
  36. MatrixXd C(FQCtri.rows(),3);
  37. C << Ct, Ct;
  38. viewer.data().set_colors(C);
  39. // Plot a line for each edge of the quad mesh
  40. viewer.data().add_edges(PQC0, PQC1, Eigen::RowVector3d(0,0,0));
  41. viewer.data().add_edges(PQC1, PQC2, Eigen::RowVector3d(0,0,0));
  42. viewer.data().add_edges(PQC2, PQC3, Eigen::RowVector3d(0,0,0));
  43. viewer.data().add_edges(PQC3, PQC0, Eigen::RowVector3d(0,0,0));
  44. }
  45. // Plot the planarized quad mesh
  46. if (key == '2')
  47. {
  48. // Draw the triangulated quad mesh
  49. viewer.data().set_mesh(VQCplan, FQCtri);
  50. // Assign a color to each quad that corresponds to its planarity
  51. VectorXd planarity;
  52. igl::quad_planarity( VQCplan, FQC, planarity);
  53. MatrixXd Ct;
  54. igl::jet(planarity, 0, 0.01, Ct);
  55. MatrixXd C(FQCtri.rows(),3);
  56. C << Ct, Ct;
  57. viewer.data().set_colors(C);
  58. // Plot a line for each edge of the quad mesh
  59. viewer.data().add_edges(PQC0plan, PQC1plan, Eigen::RowVector3d(0,0,0));
  60. viewer.data().add_edges(PQC1plan, PQC2plan, Eigen::RowVector3d(0,0,0));
  61. viewer.data().add_edges(PQC2plan, PQC3plan, Eigen::RowVector3d(0,0,0));
  62. viewer.data().add_edges(PQC3plan, PQC0plan, Eigen::RowVector3d(0,0,0));
  63. }
  64. return false;
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. using namespace Eigen;
  69. using namespace std;
  70. // Load a quad mesh generated by a conjugate field
  71. igl::readOFF(TUTORIAL_SHARED_PATH "/inspired_mesh_quads_Conjugate.off", VQC, FQC);
  72. // Convert it in a triangle mesh
  73. FQCtri.resize(2*FQC.rows(), 3);
  74. FQCtri << FQC.col(0),FQC.col(1),FQC.col(2),
  75. FQC.col(2),FQC.col(3),FQC.col(0);
  76. PQC0 = VQC(FQC.col(0).eval(), Eigen::all);
  77. PQC1 = VQC(FQC.col(1).eval(), Eigen::all);
  78. PQC2 = VQC(FQC.col(2).eval(), Eigen::all);
  79. PQC3 = VQC(FQC.col(3).eval(), Eigen::all);
  80. // Planarize it
  81. igl::planarize_quad_mesh(VQC, FQC, 100, 0.005, VQCplan);
  82. // Convert the planarized mesh to triangles
  83. PQC0plan = VQCplan(FQC.col(0).eval(), Eigen::all);
  84. PQC1plan = VQCplan(FQC.col(1).eval(), Eigen::all);
  85. PQC2plan = VQCplan(FQC.col(2).eval(), Eigen::all);
  86. PQC3plan = VQCplan(FQC.col(3).eval(), Eigen::all);
  87. // Launch the viewer
  88. igl::opengl::glfw::Viewer viewer;
  89. key_down(viewer,'2',0);
  90. viewer.data().invert_normals = true;
  91. viewer.data().show_lines = false;
  92. viewer.callback_key_down = &key_down;
  93. viewer.launch();
  94. }