miq.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <gtest/gtest.h>
  2. #include <test_common.h>
  3. #include <igl/avg_edge_length.h>
  4. #include <igl/barycenter.h>
  5. #include <igl/comb_cross_field.h>
  6. #include <igl/comb_frame_field.h>
  7. #include <igl/compute_frame_field_bisectors.h>
  8. #include <igl/cross_field_mismatch.h>
  9. #include <igl/cut_mesh_from_singularities.h>
  10. #include <igl/find_cross_field_singularities.h>
  11. #include <igl/local_basis.h>
  12. #include <igl/readOFF.h>
  13. #include <igl/rotate_vectors.h>
  14. #include <igl/copyleft/comiso/miq.h>
  15. #include <igl/copyleft/comiso/nrosy.h>
  16. #include <igl/PI.h>
  17. #include <igl/serialize.h>
  18. #include <sstream>
  19. #include <igl/writeDMAT.h>
  20. TEST(miq, 3_holes)
  21. {
  22. using namespace Eigen;
  23. // Input mesh
  24. Eigen::MatrixXd V;
  25. Eigen::MatrixXi F;
  26. // Face barycenters
  27. Eigen::MatrixXd B;
  28. // Cross field
  29. Eigen::MatrixXd X1,X2;
  30. // Bisector field
  31. Eigen::MatrixXd BIS1, BIS2;
  32. // Combed bisector
  33. Eigen::MatrixXd BIS1_combed, BIS2_combed;
  34. // Per-corner, integer mismatches
  35. Eigen::Matrix<int, Eigen::Dynamic, 3> MMatch;
  36. // Field singularities
  37. Eigen::Matrix<int, Eigen::Dynamic, 1> isSingularity, singularityIndex;
  38. // Per corner seams
  39. Eigen::Matrix<int, Eigen::Dynamic, 3> Seams;
  40. // Combed field
  41. Eigen::MatrixXd X1_combed, X2_combed;
  42. // Global parametrization
  43. Eigen::MatrixXd UV;
  44. Eigen::MatrixXi FUV;
  45. // Global parametrization (reference)
  46. Eigen::MatrixXd UV_ref;
  47. Eigen::MatrixXi FUV_ref;
  48. // Load a mesh in OFF format
  49. igl::readOFF(test_common::data_path("3holes.off"), V, F);
  50. double gradient_size = 50;
  51. double iter = 0;
  52. double stiffness = 5.0;
  53. bool direct_round = 0;
  54. // Compute face barycenters
  55. igl::barycenter(V, F, B);
  56. // Contrain one face
  57. VectorXi b(1);
  58. b << 0;
  59. MatrixXd bc(1, 3);
  60. bc << 1, 0, 0;
  61. // Create a smooth 4-RoSy field
  62. VectorXd S;
  63. igl::copyleft::comiso::nrosy(V, F, b, bc, VectorXi(), VectorXd(), MatrixXd(), 4, 0.5, X1, S);
  64. // Find the orthogonal vector
  65. MatrixXd B1, B2, B3;
  66. igl::local_basis(V, F, B1, B2, B3);
  67. X2 = igl::rotate_vectors(X1, VectorXd::Constant(1, igl::PI / 2), B1, B2);
  68. // Always work on the bisectors, it is more general
  69. igl::compute_frame_field_bisectors(V, F, X1, X2, BIS1, BIS2);
  70. // Comb the field, implicitly defining the seams
  71. igl::comb_cross_field(V, F, BIS1, BIS2, BIS1_combed, BIS2_combed);
  72. // Find the integer mismatches
  73. igl::cross_field_mismatch(V, F, BIS1_combed, BIS2_combed, true, MMatch);
  74. // Find the singularities
  75. igl::find_cross_field_singularities(V, F, MMatch, isSingularity, singularityIndex);
  76. // Cut the mesh, duplicating all vertices on the seams
  77. igl::cut_mesh_from_singularities(V, F, MMatch, Seams);
  78. // Comb the frame-field accordingly
  79. igl::comb_frame_field(V, F, X1, X2, BIS1_combed, BIS2_combed, X1_combed, X2_combed);
  80. // Global parametrization
  81. igl::copyleft::comiso::miq(V,
  82. F,
  83. X1_combed,
  84. X2_combed,
  85. MMatch,
  86. isSingularity,
  87. Seams,
  88. UV,
  89. FUV,
  90. gradient_size,
  91. stiffness,
  92. direct_round,
  93. iter,
  94. 5,
  95. true);
  96. // Refresh the test data
  97. // igl::writeDMAT(test_common::data_path("3holes-miq-UV.dmat"),UV);
  98. // igl::writeDMAT(test_common::data_path("3holes-miq-FUV.dmat"),FUV);
  99. igl::readDMAT(test_common::data_path("3holes-miq-UV.dmat"),UV_ref);
  100. igl::readDMAT(test_common::data_path("3holes-miq-FUV.dmat"),FUV_ref);
  101. ASSERT_LT((UV-UV_ref).array().abs().maxCoeff() ,1e-6);
  102. ASSERT_LT((FUV-FUV_ref).array().abs().maxCoeff() ,1e-6);
  103. }