intrinsic_delaunay_cotmatrix.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <test_common.h>
  2. #include <igl/intrinsic_delaunay_cotmatrix.h>
  3. #include <igl/EPS.h>
  4. #include <igl/triangulated_grid.h>
  5. #include <igl/is_border_vertex.h>
  6. class intrinsic_delaunay_cotmatrix : public ::testing::TestWithParam<std::string> {};
  7. TEST(intrinsic_delaunay_cotmatrix,skewed_grid)
  8. {
  9. Eigen::MatrixXd V;
  10. Eigen::MatrixXi F;
  11. const int s = 7;
  12. igl::triangulated_grid(s,s,V,F);
  13. // Skew against diagonal direction
  14. V.col(0) -= 1.1*V.col(1);
  15. Eigen::SparseMatrix<double> L;
  16. Eigen::MatrixXi F_intrinsic;
  17. Eigen::MatrixXd l_intrinsic;
  18. igl::intrinsic_delaunay_cotmatrix(V,F,L,l_intrinsic,F_intrinsic);
  19. Eigen::VectorXi LI,LJ;
  20. Eigen::VectorXd LV;
  21. igl::find(L,LI,LJ,LV);
  22. const auto is_boundary_edge = [](const int i, const int j, const int s)->bool
  23. {
  24. const auto is_boundary_vertex = [](const int i, const int s)->bool
  25. {
  26. return (i<s) || (i>=s*s-s) || (i%s == 0) || (i%s == s-1);
  27. };
  28. return is_boundary_vertex(i,s) && is_boundary_vertex(j,s);
  29. };
  30. // Off diagonals should be all non-positive
  31. for(int k = 0;k<LI.size();k++)
  32. {
  33. if(LI(k) != LJ(k) && !is_boundary_edge(LI(k),LJ(k),s))
  34. {
  35. ASSERT_GT(LV(k),-igl::EPS<double>());
  36. }
  37. }
  38. }
  39. TEST_P(intrinsic_delaunay_cotmatrix,manifold_meshes)
  40. {
  41. Eigen::MatrixXd V;
  42. Eigen::MatrixXi F;
  43. test_common::load_mesh(GetParam(), V, F);
  44. Eigen::SparseMatrix<double> L;
  45. Eigen::MatrixXi F_intrinsic;
  46. Eigen::MatrixXd l_intrinsic;
  47. igl::intrinsic_delaunay_cotmatrix(V,F,L,l_intrinsic,F_intrinsic);
  48. Eigen::VectorXi LI,LJ;
  49. Eigen::VectorXd LV;
  50. igl::find(L,LI,LJ,LV);
  51. const std::vector<bool> is_boundary_vertex = igl::is_border_vertex(F);
  52. // Off diagonals should be all non-positive
  53. for(int k = 0;k<LI.size();k++)
  54. {
  55. if(LI(k) != LJ(k) &&
  56. !(is_boundary_vertex[LI(k)] && is_boundary_vertex[LJ(k)]))
  57. {
  58. ASSERT_GT(LV(k),-igl::EPS<double>());
  59. }
  60. }
  61. }
  62. INSTANTIATE_TEST_CASE_P
  63. (
  64. manifold_meshes,
  65. intrinsic_delaunay_cotmatrix,
  66. ::testing::ValuesIn(test_common::manifold_meshes()),
  67. test_common::string_test_name
  68. );