main.cpp 3.3 KB

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