cotmatrix_intrinsic.cpp 2.9 KB

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