| #include <test_common.h> |
| #include <igl/PI.h> |
| #include <igl/cotmatrix.h> |
| #include <igl/matrix_to_list.h> |
| #include <igl/polygon_corners.h> |
|
|
| TEST_CASE("cotmatrix: poly", "[igl]" ) |
| { |
| const auto test_case = [](const std::string ¶m) |
| { |
| Eigen::MatrixXd V; |
| Eigen::MatrixXi F; |
| |
| igl::read_triangle_mesh(test_common::data_path(param), V, F); |
| Eigen::SparseMatrix<double> tL,pL,pM,pP; |
| igl::cotmatrix(V,F,tL); |
| std::vector<std::vector<int> > vF; |
| igl::matrix_to_list(F,vF); |
| |
| 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<double> L; |
| |
| 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 (1e-12 > ((L*C)-(Z)).norm()); |
| }; |
|
|
| test_common::run_test_cases(test_common::all_meshes(), test_case); |
| } |
|
|
| TEST_CASE("cotmatrix: cube", "[igl]") |
| { |
| |
| const double epsilon = 1e-15; |
|
|
| Eigen::MatrixXd V; |
| Eigen::MatrixXi F; |
| |
| igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F); |
|
|
| |
| Eigen::MatrixXd V_huge = V * 1.0e8; |
|
|
| |
| Eigen::MatrixXd V_tiny = V * 1.0e-8; |
|
|
| |
| |
| |
| |
| |
| Eigen::SparseMatrix<double> L1; |
| igl::cotmatrix(V,F,L1); |
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| Eigen::VectorXd row_sum = L1 * Eigen::VectorXd::Constant(L1.rows(),1,1); |
| Eigen::RowVectorXd col_sum = Eigen::RowVectorXd::Constant(1,L1.rows(),1) * L1; |
| Eigen::VectorXd diag = L1.diagonal(); |
| #ifdef IGL_EDGE_LENGTHS_SQUARED_H |
| test_common::assert_eq( row_sum, Eigen::VectorXd::Zero(L1.rows()) ); |
| test_common::assert_eq( col_sum, Eigen::RowVectorXd::Zero(L1.rows()) ); |
| test_common::assert_eq( diag, Eigen::VectorXd::Constant(L1.rows(),1,-3) ); |
| #else |
| test_common::assert_near( row_sum, Eigen::VectorXd::Zero(L1.rows()) , epsilon); |
| test_common::assert_near( col_sum, Eigen::RowVectorXd::Zero(L1.rows()) , epsilon); |
| test_common::assert_near( diag, Eigen::VectorXd::Constant(L1.rows(),1,-3) , epsilon); |
| #endif |
|
|
| |
| igl::cotmatrix(V_huge,F,L1); |
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| for(int f = 0;f<L1.rows();f++) |
| { |
| REQUIRE (L1.coeff(f,f) == Approx (-3.0).margin( epsilon)); |
| REQUIRE (L1.row(f).sum() == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.col(f).sum() == Approx (0.0).margin( epsilon)); |
| } |
|
|
| |
| igl::cotmatrix(V_tiny,F,L1); |
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| for(int f = 0;f<L1.rows();f++) |
| { |
| REQUIRE (L1.coeff(f,f) == Approx (-3.0).margin( epsilon)); |
| REQUIRE (L1.row(f).sum() == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.col(f).sum() == Approx (0.0).margin( epsilon)); |
| } |
| } |
|
|
| TEST_CASE("cotmatrix: tetrahedron", "[igl]") |
| { |
| |
| const double epsilon = 1e-15; |
|
|
| Eigen::MatrixXd V; |
| Eigen::MatrixXi F; |
| |
| igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F); |
|
|
| |
| |
| Eigen::MatrixXi F_equi(4,3); |
| F_equi << 4,6,1, |
| 6,4,3, |
| 4,1,3, |
| 1,6,3; |
|
|
| |
| Eigen::MatrixXd V_huge = V * 1.0e8; |
|
|
| |
| Eigen::MatrixXd V_tiny = V * 1.0e-8; |
|
|
| |
| |
| |
| |
| |
| Eigen::SparseMatrix<double> L1; |
|
|
| |
| igl::cotmatrix(V,F_equi,L1); |
|
|
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| for(int f = 0;f<L1.rows();f++) |
| { |
| |
| if (L1.coeff(f,f) < -0.1) |
| REQUIRE (L1.coeff(f,f) == Approx (-3 / tan(igl::PI / 3.0)).margin( epsilon)); |
| else |
| REQUIRE (L1.coeff(f,f) == Approx (0.0).margin( epsilon)); |
| #ifdef IGL_EDGE_LENGTHS_SQUARED_H |
| |
| REQUIRE (L1.row(f).sum() == 0.0); |
| REQUIRE (L1.col(f).sum() == 0.0); |
| #else |
| |
| REQUIRE (L1.row(f).sum() == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.col(f).sum() == Approx (0.0).margin( epsilon)); |
| #endif |
| } |
|
|
| |
| igl::cotmatrix(V_huge,F_equi,L1); |
|
|
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| for(int f = 0;f<L1.rows();f++) |
| { |
| |
| if (L1.coeff(f,f) < -0.1) |
| REQUIRE (L1.coeff(f,f) == Approx (-3 / tan(igl::PI / 3.0)).margin( epsilon)); |
| else |
| REQUIRE (L1.coeff(f,f) == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.row(f).sum() == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.col(f).sum() == Approx (0.0).margin( epsilon)); |
| } |
|
|
| |
| igl::cotmatrix(V_tiny,F_equi,L1); |
|
|
| REQUIRE (L1.rows() == V.rows()); |
| REQUIRE (L1.cols() == V.rows()); |
| for(int f = 0;f<L1.rows();f++) |
| { |
| |
| if (L1.coeff(f,f) < -0.1) |
| REQUIRE (L1.coeff(f,f) == Approx (-3 / tan(igl::PI / 3.0)).margin( epsilon)); |
| else |
| REQUIRE (L1.coeff(f,f) == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.row(f).sum() == Approx (0.0).margin( epsilon)); |
| REQUIRE (L1.col(f).sum() == Approx (0.0).margin( epsilon)); |
| } |
| } |
|
|