cotmatrix_intrinsic.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <test_common.h>
  2. #include <igl/cotmatrix_intrinsic.h>
  3. #include <igl/cotmatrix.h>
  4. #include <igl/edge_lengths.h>
  5. #include <igl/matlab_format.h>
  6. #include <igl/EPS.h>
  7. class cotmatrix_intrinsic : public ::testing::TestWithParam<std::string> {};
  8. TEST(cotmatrix_intrinsic, periodic)
  9. {
  10. const Eigen::MatrixXi F = (Eigen::MatrixXi(18,3)<<
  11. 0,3,1,
  12. 3,4,1,
  13. 1,4,2,
  14. 4,5,2,
  15. 2,5,0,
  16. 5,3,0,
  17. 3,6,4,
  18. 6,7,4,
  19. 4,7,5,
  20. 7,8,5,
  21. 5,8,3,
  22. 8,6,3,
  23. 6,0,7,
  24. 0,1,7,
  25. 7,1,8,
  26. 1,2,8,
  27. 8,2,6,
  28. 2,0,6).finished();
  29. const Eigen::MatrixXd l = (Eigen::MatrixXd(18,3)<<
  30. 0.47140452079103168,0.33333333333333331,0.33333333333333331,
  31. 0.33333333333333331,0.47140452079103168,0.33333333333333331,
  32. 0.47140452079103168,0.33333333333333331,0.33333333333333331,
  33. 0.33333333333333331,0.47140452079103168,0.33333333333333331,
  34. 0.47140452079103168,0.33333333333333337,0.33333333333333331,
  35. 0.33333333333333331,0.47140452079103168,0.33333333333333337,
  36. 0.47140452079103168,0.33333333333333331,0.33333333333333331,
  37. 0.33333333333333331,0.47140452079103168,0.33333333333333331,
  38. 0.47140452079103168,0.33333333333333331,0.33333333333333331,
  39. 0.33333333333333331,0.47140452079103168,0.33333333333333331,
  40. 0.47140452079103168,0.33333333333333337,0.33333333333333331,
  41. 0.33333333333333331,0.47140452079103168,0.33333333333333337,
  42. 0.47140452079103168,0.33333333333333331,0.33333333333333337,
  43. 0.33333333333333337,0.47140452079103168,0.33333333333333331,
  44. 0.47140452079103168,0.33333333333333331,0.33333333333333337,
  45. 0.33333333333333337,0.47140452079103168,0.33333333333333331,
  46. 0.47140452079103173,0.33333333333333337,0.33333333333333337,
  47. 0.33333333333333337,0.47140452079103173,0.33333333333333337).finished();
  48. Eigen::SparseMatrix<double> L;
  49. igl::cotmatrix_intrinsic(l,F,L);
  50. const Eigen::MatrixXd L_d = L;
  51. const Eigen::MatrixXd L_gt = (Eigen::MatrixXd(9,9)<<
  52. -4,1,1,1,0,0,1,0,0,
  53. 1,-4,1,0,1,0,0,1,0,
  54. 1,1,-4,0,0,1,0,0,1,
  55. 1,0,0,-4,1,1,1,0,0,
  56. 0,1,0,1,-4,1,0,1,0,
  57. 0,0,1,1,1,-4,0,0,1,
  58. 1,0,0,1,0,0,-4,1,1,
  59. 0,1,0,0,1,0,1,-4,1,
  60. 0,0,1,0,0,1,1,1,-4).finished();
  61. test_common::assert_near(L_d,L_gt,igl::EPS<double>());
  62. }
  63. TEST_P(cotmatrix_intrinsic , manifold_meshes)
  64. {
  65. Eigen::MatrixXd V;
  66. Eigen::MatrixXi F;
  67. test_common::load_mesh(GetParam(), V, F);
  68. Eigen::MatrixXd l;
  69. igl::edge_lengths(V,F,l);
  70. Eigen::SparseMatrix<double> L,Li;
  71. igl::cotmatrix(V,F,L);
  72. igl::cotmatrix_intrinsic(l,F,Li);
  73. // Augh, we don't have assert_near for sparse matrices...
  74. // Instead test that bilinear form is near equal for 2 random vectors
  75. const Eigen::VectorXd u = Eigen::VectorXd::Random(V.rows(),1);
  76. const Eigen::VectorXd v = Eigen::VectorXd::Random(V.rows(),1);
  77. const double uv = u.norm()*v.norm();
  78. ASSERT_NEAR( u.dot(L*v)/uv, u.dot(Li*v)/uv, igl::EPS<double>());
  79. }
  80. INSTANTIATE_TEST_CASE_P
  81. (
  82. manifold_meshes,
  83. cotmatrix_intrinsic,
  84. ::testing::ValuesIn(test_common::manifold_meshes()),
  85. test_common::string_test_name
  86. );