main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <igl/comiso/miq.h>
  4. #include <igl/barycenter.h>
  5. #include <igl/avg_edge_length.h>
  6. #include <igl/comiso/nrosy.h>
  7. #include <sstream>
  8. #include <igl/rotate_vectors.h>
  9. Eigen::VectorXi Seams;
  10. // Cuts
  11. Eigen::VectorXi C;
  12. // Singularities
  13. Eigen::VectorXd S;
  14. // Cross field
  15. Eigen::MatrixXd X;
  16. Eigen::MatrixXd X2;
  17. // Create a texture that hides the integer translation in the parametrization
  18. void line_texture(Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> &texture_R,
  19. Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> &texture_G,
  20. Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> &texture_B)
  21. {
  22. unsigned size = 128;
  23. unsigned size2 = size/2;
  24. unsigned lineWidth = 3;
  25. texture_R.setConstant(size, size, 255);
  26. for (unsigned i=0; i<size; ++i)
  27. for (unsigned j=size2-lineWidth; j<=size2+lineWidth; ++j)
  28. texture_R(i,j) = 0;
  29. for (unsigned i=size2-lineWidth; i<=size2+lineWidth; ++i)
  30. for (unsigned j=0; j<size; ++j)
  31. texture_R(i,j) = 0;
  32. texture_G = texture_R;
  33. texture_B = texture_R;
  34. }
  35. int main(int argc, char *argv[])
  36. {
  37. using namespace Eigen;
  38. Eigen::MatrixXd V;
  39. Eigen::MatrixXi F;
  40. // Load a mesh in OFF format
  41. igl::readOFF("../shared/3holes.off", V, F);
  42. // Contrain one face
  43. VectorXi b(1);
  44. b << 0;
  45. MatrixXd bc(1,3);
  46. bc << 1, 0, 0;
  47. // Create a smooth 4-RoSy field
  48. igl::nrosy(V,F,b,bc,VectorXi(),VectorXd(),MatrixXd(),4,0.5,X,S);
  49. // Find the the orthogonal vector
  50. MatrixXd B1,B2,B3;
  51. igl::local_basis(V,F,B1,B2,B3);
  52. X2 = igl::rotate_vectors(X, VectorXd::Constant(1,M_PI/2), B1, B2);
  53. Eigen::MatrixXd UV;
  54. Eigen::MatrixXi FUV;
  55. double gradient_size = 50;
  56. double iter = 0;
  57. double stiffness = 5.0;
  58. bool direct_round = 0;
  59. igl::miq(V,
  60. F,
  61. X,
  62. X2,
  63. UV,
  64. FUV,
  65. gradient_size,
  66. stiffness,
  67. direct_round,
  68. iter);
  69. // Face barycenters
  70. Eigen::MatrixXd MF;
  71. igl::barycenter(V, F, MF);
  72. double scale = .5*igl::avg_edge_length(V, F);
  73. // Plot the mesh
  74. igl::Viewer viewer;
  75. viewer.set_mesh(V, F);
  76. // Plot the field
  77. viewer.add_edges (MF, MF+scale*X ,Eigen::RowVector3d(1,0,1));
  78. viewer.add_edges (MF, MF+scale*X2,Eigen::RowVector3d(1,0,1));
  79. viewer.set_uv(UV,FUV);
  80. viewer.options.show_texture = true;
  81. Eigen::Matrix<char,Eigen::Dynamic,Eigen::Dynamic> texture_R, texture_G, texture_B;
  82. line_texture(texture_R, texture_G, texture_B);
  83. viewer.set_texture(texture_R, texture_B, texture_G);
  84. // Increase the thickness of the lines
  85. viewer.options.line_width = 2.0f;
  86. // Launch the viewer
  87. viewer.launch();
  88. }