#include #include #include #include #include TEST_CASE("cotmatrix: poly", "[igl]" ) { const auto test_case = [](const std::string ¶m) { Eigen::MatrixXd V; Eigen::MatrixXi F; // Load example mesh: GetParam() will be name of mesh file igl::read_triangle_mesh(test_common::data_path(param), V, F); Eigen::SparseMatrix tL,pL,pM,pP; igl::cotmatrix(V,F,tL); std::vector > vF; igl::matrix_to_list(F,vF); // trivial polygon mesh Eigen::VectorXi I,C; igl::polygon_corners(vF,I,C); igl::cotmatrix(V,I,C,pL,pM,pP); REQUIRE (tL.cols() == pL.cols()); REQUIRE (tL.rows() == pL.rows()); REQUIRE ( tL.isApprox(pL,1e-7) ); }; test_common::run_test_cases(test_common::all_meshes(), test_case); } TEST_CASE("cotmatrix: constant_in_null_space", "[igl]" "[slow]") { const auto test_case = [](const std::string ¶m) { Eigen::MatrixXd V; Eigen::MatrixXi F; Eigen::SparseMatrix L; // Load example mesh: GetParam() will be name of mesh file igl::read_triangle_mesh(test_common::data_path(param), V, F); igl::cotmatrix(V,F,L); REQUIRE (L.rows() == V.rows()); REQUIRE (L.cols() == L.rows()); Eigen::VectorXd C = Eigen::VectorXd::Ones(L.rows()); Eigen::VectorXd Z = Eigen::VectorXd::Zero(L.rows()); // REQUIRE (b == a); // REQUIRE (a==b); // ASSERT_NEAR(a,b,1e-15) REQUIRE (1e-12 > ((L*C)-(Z)).norm()); }; test_common::run_test_cases(test_common::all_meshes(), test_case); } TEST_CASE("cotmatrix: cube", "[igl]") { //The allowed error for this test const double epsilon = 1e-15; Eigen::MatrixXd V; Eigen::MatrixXi F; //This is a cube of dimensions 1.0x1.0x1.0 igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F); //Scale the cube to have huge sides Eigen::MatrixXd V_huge = V * 1.0e8; //Scale the cube to have tiny sides Eigen::MatrixXd V_tiny = V * 1.0e-8; //Check cotmatrix (Laplacian) //The laplacian for the cube is quite singular. //Each edge in a diagonal has two opposite angles of 90, with cotangent 0.0 each //Each edge in a side has two opposite angle of 45, with (half)cotangen 0.5 each //So the cotangent matrix always are (0+0) or (0.5+0.5) Eigen::SparseMatrix L1; igl::cotmatrix(V,F,L1); REQUIRE (L1.rows() == V.rows()); REQUIRE (L1.cols() == V.rows()); //// This is hitting an Eigen bug. https://github.com/libigl/libigl/pull/1064 // for(int f = 0;f L1; //Check the regular tetrahedron of side sqrt(2) igl::cotmatrix(V,F_equi,L1); REQUIRE (L1.rows() == V.rows()); REQUIRE (L1.cols() == V.rows()); for(int f = 0;f