123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #include <test_common.h>
- #include <igl/cotmatrix_entries.h>
- #include <igl/edge_lengths.h>
- #include <igl/EPS.h>
- TEST_CASE("cotmatrix_entries: simple", "[igl]")
- {
-
- const double epsilon = 1e-15;
- Eigen::MatrixXd V;
- Eigen::MatrixXi F;
-
- test_common::load_mesh("cube.obj", V, F);
-
-
- Eigen::MatrixXi F_tet(4,3);
- F_tet << 4,6,1,
- 6,4,3,
- 4,1,3,
- 1,6,3;
-
- Eigen::MatrixXd C1;
- igl::cotmatrix_entries(V,F,C1);
- REQUIRE (C1.rows() == F.rows());
- REQUIRE (C1.cols() == 3);
-
-
- for(int f = 0;f<C1.rows();f++)
- {
- #ifdef IGL_EDGE_LENGTHS_SQUARED_H
-
- for(int v = 0;v<3;v++)
- if (C1(f,v) > 0.1)
- REQUIRE (C1(f,v) == 0.5);
- else
- REQUIRE (C1(f,v) == 0.0);
-
- REQUIRE (C1.row(f).sum() == 1.0);
- #else
-
- for(int v = 0;v<3;v++)
- if (C1(f,v) > 0.1)
- REQUIRE (C1(f,v) == Approx (0.5).margin( epsilon));
- else
- REQUIRE (C1(f,v) == Approx (0.0).margin( epsilon));
-
- REQUIRE (C1.row(f).sum() == Approx (1.0).margin( epsilon));
- #endif
- }
-
- Eigen::MatrixXd C2;
- igl::cotmatrix_entries(V,F_tet,C2);
- REQUIRE (C2.rows() == F_tet.rows());
- REQUIRE (C2.cols() == 3);
- for(int f = 0;f<C2.rows();f++)
- {
-
- for(int v = 0;v<3;v++)
- REQUIRE (C2(f,v) == Approx (0.5 / tan(M_PI / 3.0)).margin( epsilon));
- }
-
- Eigen::MatrixXd V_huge = V * 1.0e8;
- igl::cotmatrix_entries(V_huge,F,C1);
- REQUIRE (C1.rows() == F.rows());
- REQUIRE (C1.cols() == 3);
-
-
- for(int f = 0;f<C1.rows();f++)
- {
- #ifdef IGL_EDGE_LENGTHS_SQUARED_H
-
- for(int v = 0;v<3;v++)
- if (C1(f,v) > 0.1)
- REQUIRE (C1(f,v) == 0.5);
- else
- REQUIRE (C1(f,v) == 0.0);
-
- REQUIRE (C1.row(f).sum() == 1.0);
- #else
-
- for(int v = 0;v<3;v++)
- if (C1(f,v) > 0.1)
- REQUIRE (C1(f,v) == Approx (0.5).margin( epsilon));
- else
- REQUIRE (C1(f,v) == Approx (0.0).margin( epsilon));
-
- REQUIRE (C1.row(f).sum() == Approx (1.0).margin( epsilon));
- #endif
- }
-
- igl::cotmatrix_entries(V_huge,F_tet,C2);
- REQUIRE (C2.rows() == F_tet.rows());
- REQUIRE (C2.cols() == 3);
- for(int f = 0;f<C2.rows();f++)
- {
-
- for(int v = 0;v<3;v++)
- REQUIRE (C2(f,v) == Approx (0.5 / tan(M_PI / 3.0)).margin( epsilon));
- }
-
- Eigen::MatrixXd V_tiny = V * 1.0e-8;
- igl::cotmatrix_entries(V_tiny,F,C1);
- REQUIRE (C1.rows() == F.rows());
- REQUIRE (C1.cols() == 3);
-
-
- for(int f = 0;f<C1.rows();f++)
- {
- for(int v = 0;v<3;v++)
- if (C1(f,v) > 0.1)
- REQUIRE (C1(f,v) == Approx (0.5).margin( epsilon));
- else
- REQUIRE (C1(f,v) == Approx (0.0).margin( epsilon));
-
- REQUIRE (C1.row(f).sum() == Approx (1.0).margin( epsilon));
- }
-
- igl::cotmatrix_entries(V_tiny,F_tet,C2);
- REQUIRE (C2.rows() == F_tet.rows());
- REQUIRE (C2.cols() == 3);
- for(int f = 0;f<C2.rows();f++)
- {
-
- for(int v = 0;v<3;v++)
- REQUIRE (C2(f,v) == Approx (0.5 / tan(M_PI / 3.0)).margin( epsilon));
- }
- }
- TEST_CASE("cotmatrix_entries: intrinsic", "[igl]")
- {
- Eigen::MatrixXd V;
- Eigen::MatrixXi F;
-
- test_common::load_mesh("cube.obj", V, F);
- Eigen::MatrixXd Cext,Cint;
-
- igl::cotmatrix_entries(V,F,Cext);
-
- Eigen::MatrixXd l;
- igl::edge_lengths(V,F,l);
- igl::cotmatrix_entries(l,Cint);
- test_common::assert_near(Cext,Cint,igl::EPS<double>());
- }
|