File size: 2,634 Bytes
5b89cb9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <test_common.h>
#include <igl/edge_lengths.h>
#include <iostream>
TEST_CASE("edge_lengths: 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);
//Create scaled versions of the cube
double scale = 1.0;
double huge_scale = 1.0e8;
double tiny_scale = 1.0e-8;
Eigen::MatrixXd V_huge = V * huge_scale;
Eigen::MatrixXd V_tiny = V * tiny_scale;
//Prepare another mesh with triangles along side diagonals of the cube
//These triangles are form a regular tetrahedron of side sqrt(2)
Eigen::MatrixXi F_tet(4,3);
F_tet << 4,6,1,
6,4,3,
4,1,3,
1,6,3;
//2. Check edge_lengths
double side = 1.0; //lenght of a side
double diag = sqrt(2.0); //lenght of a diagonal
Eigen::MatrixXd L;
igl::edge_lengths(V,F,L);
REQUIRE (L.rows() == F.rows());
REQUIRE (L.cols() == 3);
//All edges in unit cube measure 1.0 or sqrt(2) in diagonals
for(int f = 0;f<L.rows();f++)
{
//All edge_lengths_squared must be exactly "side" or "diag"
for(int e = 0;e<3;e++)
if (L(f,e) > 1.1*side)
REQUIRE (L(f,e) == diag);
else
REQUIRE (L(f,e) == side);
//All sides sum exactly side + side + diag
REQUIRE (side + side + diag == L.row(f).sum());
}
//Check the cube of huge sides
scale = 1.0e8;
side = scale; //lenght of a side
diag = scale*sqrt(2.0); //lenght of a diagonal
igl::edge_lengths(V_huge,F,L);
REQUIRE (L.rows() == F.rows());
REQUIRE (L.cols() == 3);
for(int f = 0;f<L.rows();f++)
{
//All edge_lengths_squared must be exactly "side" or "diag"
for(int e = 0;e<3;e++)
if (L(f,e) > 1.1*side)
REQUIRE (L(f,e) == diag);
else
REQUIRE (L(f,e) == side);
//All sides sum exactly side + side + diag
REQUIRE (side + side + diag == Approx (L.row(f).sum()).margin( epsilon));
}
//Check the cube of tiny sides
scale = 1.0e-8;
side = scale; //lenght of a side
diag = scale*sqrt(2.0); //lenght of a diagonal
igl::edge_lengths(V_tiny,F,L);
REQUIRE (L.rows() == F.rows());
REQUIRE (L.cols() == 3);
for(int f = 0;f<L.rows();f++)
{
//All edge_lengths_squared must be exactly "side" or "diag"
for(int e = 0;e<3;e++)
if (L(f,e) > 1.1*side)
REQUIRE (L(f,e) == diag);
else
REQUIRE (L(f,e) == side);
//All sides sum exactly side + side + diag
REQUIRE (side + side + diag == L.row(f).sum());
}
}
|