main.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <igl/avg_edge_length.h>
  2. #include <igl/barycenter.h>
  3. #include <igl/jet.h>
  4. #include <igl/shapeup.h>
  5. #include <igl/shapeup_local_projections.h>
  6. #include <igl/quad_planarity.h>
  7. #include <igl/readDMAT.h>
  8. #include <igl/readOFF.h>
  9. #include <igl/slice.h>
  10. #include <igl/viewer/Viewer.h>
  11. #include <vector>
  12. #include <cstdlib>
  13. #include "tutorial_shared_path.h"
  14. // Quad mesh loaded
  15. Eigen::MatrixXd VQC;
  16. Eigen::MatrixXi FQC;
  17. Eigen::MatrixXi E;
  18. Eigen::MatrixXi FQCtri;
  19. Eigen::MatrixXd PQC0, PQC1, PQC2, PQC3;
  20. // Euclidean-regular quad mesh
  21. Eigen::MatrixXd VQCregular;
  22. Eigen::MatrixXi FQCtriregular;
  23. Eigen::MatrixXd PQC0regular, PQC1regular, PQC2regular, PQC3regular;
  24. igl::ShapeupData su_data;
  25. // Scale for visualizing the fields
  26. double global_scale; //TODO: not used
  27. bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
  28. {
  29. using namespace std;
  30. using namespace Eigen;
  31. // Plot the original quad mesh
  32. if (key == '1')
  33. {
  34. cout<<"before setting mesh 1"<<endl;
  35. // Draw the triangulated quad mesh
  36. viewer.data.set_mesh(VQC, FQCtri);
  37. // Assign a color to each quad that corresponds to its planarity
  38. VectorXd planarity;
  39. igl::quad_planarity( VQC, FQC, planarity);
  40. MatrixXd Ct;
  41. igl::jet(planarity, 0, 0.01, Ct);
  42. MatrixXd C(FQCtri.rows(),3);
  43. C << Ct, Ct;
  44. viewer.data.set_colors(C);
  45. // Plot a line for each edge of the quad mesh
  46. viewer.data.add_edges(PQC0, PQC1, Eigen::RowVector3d(0,0,0));
  47. viewer.data.add_edges(PQC1, PQC2, Eigen::RowVector3d(0,0,0));
  48. viewer.data.add_edges(PQC2, PQC3, Eigen::RowVector3d(0,0,0));
  49. viewer.data.add_edges(PQC3, PQC0, Eigen::RowVector3d(0,0,0));
  50. }
  51. // Plot the planarized quad mesh
  52. if (key == '2')
  53. {
  54. // Draw the triangulated quad mesh
  55. cout<<"before setting mesh 2"<<endl;
  56. viewer.data.set_mesh(VQCregular, FQCtri);
  57. // Assign a color to each quad that corresponds to its planarity
  58. VectorXd planarity;
  59. igl::quad_planarity( VQCregular, FQC, planarity);
  60. MatrixXd Ct;
  61. igl::jet(planarity, 0, 0.01, Ct);
  62. MatrixXd C(FQCtri.rows(),3);
  63. C << Ct, Ct;
  64. viewer.data.set_colors(C);
  65. // Plot a line for each edge of the quad mesh
  66. viewer.data.add_edges(PQC0regular, PQC1regular, Eigen::RowVector3d(0,0,0));
  67. viewer.data.add_edges(PQC1regular, PQC2regular, Eigen::RowVector3d(0,0,0));
  68. viewer.data.add_edges(PQC2regular, PQC3regular, Eigen::RowVector3d(0,0,0));
  69. viewer.data.add_edges(PQC3regular, PQC0regular, Eigen::RowVector3d(0,0,0));
  70. }
  71. return false;
  72. }
  73. int main(int argc, char *argv[])
  74. {
  75. using namespace Eigen;
  76. using namespace std;
  77. // Load a quad mesh
  78. igl::readOFF(TUTORIAL_SHARED_PATH "/halftunnel.off", VQC, FQC);
  79. // Convert it in a triangle mesh
  80. FQCtri.resize(2*FQC.rows(), 3);
  81. FQCtri << FQC.col(0),FQC.col(1),FQC.col(2),
  82. FQC.col(2),FQC.col(3),FQC.col(0);
  83. igl::slice( VQC, FQC.col(0).eval(), 1, PQC0);
  84. igl::slice( VQC, FQC.col(1).eval(), 1, PQC1);
  85. igl::slice( VQC, FQC.col(2).eval(), 1, PQC2);
  86. igl::slice( VQC, FQC.col(3).eval(), 1, PQC3);
  87. // Create a planar version with ShapeUp
  88. //igl::planarize_quad_mesh(VQC, FQC, 100, 0.005, VQCregular);
  89. E.resize(FQC.size(),2);
  90. E.col(0)<<FQC.col(0),FQC.col(1),FQC.col(2),FQC.col(3);
  91. E.col(1)<<FQC.col(1),FQC.col(2),FQC.col(3),FQC.col(0);
  92. VectorXi b;
  93. VectorXd w(FQC.rows());
  94. MatrixXd bc;
  95. VectorXi array_of_fours=VectorXi::Constant(FQC.rows(),4);
  96. cout<<"before pre-computation"<<endl;
  97. std::function<bool(const Eigen::PlainObjectBase<MatrixXd>&, const Eigen::PlainObjectBase<VectorXi>&, const Eigen::PlainObjectBase<MatrixXi>&, Eigen::PlainObjectBase<MatrixXd>&)> localFunction(igl::shapeup_identity_projection);
  98. shapeup_precomputation(VQC, array_of_fours,FQC,E,b,w, localFunction,su_data);
  99. cout<<"after pre-computation"<<endl;
  100. shapeup_solve(bc,VQC,su_data,VQCregular);
  101. cout<<"after computation"<<endl;
  102. // Convert the planarized mesh to triangles
  103. igl::slice( VQCregular, FQC.col(0).eval(), 1, PQC0regular);
  104. igl::slice( VQCregular, FQC.col(1).eval(), 1, PQC1regular);
  105. igl::slice( VQCregular, FQC.col(2).eval(), 1, PQC2regular);
  106. igl::slice( VQCregular, FQC.col(3).eval(), 1, PQC3regular);
  107. // Launch the viewer
  108. igl::viewer::Viewer viewer;
  109. key_down(viewer,'1',0);
  110. viewer.core.invert_normals = true;
  111. viewer.core.show_lines = false;
  112. viewer.callback_key_down = &key_down;
  113. viewer.launch();
  114. }