#include #include #include #include #include TEST_CASE("massmatrix: full", "[igl]" ) { const auto test_case = [](const std::string ¶m) { const double epsilon = 1e-15; 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 M; igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_FULL,M); REQUIRE(M.rows() == V.rows()); REQUIRE(M.cols() == V.rows()); Eigen::MatrixXd dblA; igl::doublearea(V,F,dblA); REQUIRE(M.sum() == Approx(dblA.sum()/2.).margin(epsilon)); }; test_common::run_test_cases(test_common::all_meshes(), test_case); } TEST_CASE("massmatrix: barycentric", "[igl]" ) { const auto test_case = [](const std::string ¶m) { const double epsilon = 1e-15; 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 M; igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_BARYCENTRIC,M); REQUIRE(M.rows() == V.rows()); REQUIRE(M.cols() == V.rows()); Eigen::MatrixXd dblA; igl::doublearea(V,F,dblA); REQUIRE(M.sum() == Approx(dblA.sum()/2.).margin(epsilon)); }; test_common::run_test_cases(test_common::all_meshes(), test_case); } TEST_CASE("massmatrix: cube_barycentric", "[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); Eigen::SparseMatrix M; //Check the mass matrix of the cube igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_BARYCENTRIC,M); REQUIRE(M.rows() == V.rows()); REQUIRE(M.cols() == V.rows()); //All triangles' areas are 0.5 //barycentric area for a vertex is {number of adj triangles} * 0.5 / 3 Eigen::VectorXi adj(8); adj << 6,4,4,4,4,4,6,4; for(int f = 0;f M; //Check the regular tetrahedron of side sqrt(2) igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_FULL,M); REQUIRE(M.rows() == V.rows()); REQUIRE(M.cols() == V.rows()); Eigen::VectorXi adj(8); adj << 6,4,4,4,4,4,6,4; //All triangles' areas are 0.5 //full mass matrix on diagnol is {number of adj triangles} * 0.5 / 6 for(int f=0;f