GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestMeshToVolume.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 60 61 98.4%
Functions: 3 3 100.0%
Branches: 80 406 19.7%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/openvdb.h>
5 #include <openvdb/Exceptions.h>
6 #include <openvdb/tools/MeshToVolume.h>
7 #include <openvdb/util/Util.h>
8
9 #include <gtest/gtest.h>
10 #include <vector>
11
12 3 class TestMeshToVolume: public ::testing::Test
13 {
14 };
15
16
17 ////////////////////////////////////////
18
19
20
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestMeshToVolume, testUtils)
21 {
22 /// Test nearestCoord
23 openvdb::Vec3d xyz(0.7, 2.2, -2.7);
24 1 openvdb::Coord ijk = openvdb::util::nearestCoord(xyz);
25
4/22
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
1 EXPECT_TRUE(ijk[0] == 0 && ijk[1] == 2 && ijk[2] == -3);
26
27 1 xyz = openvdb::Vec3d(-22.1, 4.6, 202.34);
28 1 ijk = openvdb::util::nearestCoord(xyz);
29
4/22
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
1 EXPECT_TRUE(ijk[0] == -23 && ijk[1] == 4 && ijk[2] == 202);
30
31 /// Test the coordinate offset table for neghbouring voxels
32 openvdb::Coord sum(0, 0, 0);
33
34 unsigned int pX = 0, pY = 0, pZ = 0, mX = 0, mY = 0, mZ = 0;
35
36
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
27 for (unsigned int i = 0; i < 26; ++i) {
37
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 17 times.
26 ijk = openvdb::util::COORD_OFFSETS[i];
38 sum += ijk;
39
40
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 17 times.
26 if (ijk[0] == 1) ++pX;
41
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8 times.
17 else if (ijk[0] == -1) ++mX;
42
43
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 17 times.
26 if (ijk[1] == 1) ++pY;
44
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8 times.
17 else if (ijk[1] == -1) ++mY;
45
46
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 17 times.
26 if (ijk[2] == 1) ++pZ;
47
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 8 times.
17 else if (ijk[2] == -1) ++mZ;
48 }
49
50
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(sum == openvdb::Coord(0, 0, 0));
51
52
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( pX == 9);
53
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( pY == 9);
54
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( pZ == 9);
55
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( mX == 9);
56
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( mY == 9);
57
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE( mZ == 9);
58 1 }
59
60
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 TEST_F(TestMeshToVolume, testConversion)
61 {
62 using namespace openvdb;
63
64 std::vector<Vec3s> points;
65 std::vector<Vec4I> quads;
66
67 // cube vertices
68
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(2, 2, 2)); // 0 6--------7
69
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(5, 2, 2)); // 1 /| /|
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(2, 5, 2)); // 2 2--------3 |
71
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(5, 5, 2)); // 3 | | | |
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(2, 2, 5)); // 4 | 4------|-5
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(5, 2, 5)); // 5 |/ |/
74
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(2, 5, 5)); // 6 0--------1
75
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 points.push_back(Vec3s(5, 5, 5)); // 7
76
77 // cube faces
78
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 quads.push_back(Vec4I(0, 1, 3, 2)); // front
79
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 quads.push_back(Vec4I(5, 4, 6, 7)); // back
80
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 quads.push_back(Vec4I(0, 2, 6, 4)); // left
81
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 quads.push_back(Vec4I(1, 5, 7, 3)); // right
82
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 quads.push_back(Vec4I(2, 3, 7, 6)); // top
83 quads.push_back(Vec4I(0, 4, 5, 1)); // bottom
84
85
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 math::Transform::Ptr xform = math::Transform::createLinearTransform();
86
87 tools::QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, quads);
88
89
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr grid = tools::meshToVolume<FloatGrid>(mesh, *xform);
90
91
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(grid.get() != NULL);
92
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(int(GRID_LEVEL_SET), int(grid->getGridClass()));
93
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(1, int(grid->baseTree().leafCount()));
94
95
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
2 grid = tools::meshToLevelSet<FloatGrid>(*xform, points, quads);
96
97
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(grid.get() != NULL);
98
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(int(GRID_LEVEL_SET), int(grid->getGridClass()));
99
4/22
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
1 EXPECT_EQ(1, int(grid->baseTree().leafCount()));
100 1 }
101
102
103
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestMeshToVolume, testCreateLevelSetBox)
104 {
105 typedef openvdb::FloatGrid FloatGrid;
106 typedef openvdb::Vec3s Vec3s;
107 typedef openvdb::math::BBox<Vec3s> BBoxs;
108 typedef openvdb::math::Transform Transform;
109
110 1 BBoxs bbox(Vec3s(0.0, 0.0, 0.0), Vec3s(1.0, 1.0, 1.0));
111
112 1 Transform::Ptr transform = Transform::createLinearTransform(0.1);
113
114
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr grid = openvdb::tools::createLevelSetBox<FloatGrid>(bbox, *transform);
115
116
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 double gridBackground = grid->background();
117 1 double expectedBackground = transform->voxelSize().x() * double(openvdb::LEVEL_SET_HALF_WIDTH);
118
119
2/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1 EXPECT_NEAR(expectedBackground, gridBackground, 1e-6);
120
121
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(grid->tree().leafCount() > 0);
122
123 // test inside coord value
124
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 openvdb::Coord ijk = transform->worldToIndexNodeCentered(openvdb::Vec3d(0.5, 0.5, 0.5));
125
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(grid->tree().getValue(ijk) < 0.0f);
126
127 // test outside coord value
128
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 ijk = transform->worldToIndexNodeCentered(openvdb::Vec3d(1.5, 1.5, 1.5));
129
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(grid->tree().getValue(ijk) > 0.0f);
130 1 }
131
132