GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestMultiResGrid.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 88 88 100.0%
Functions: 5 5 100.0%
Branches: 128 682 18.8%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Exceptions.h>
5 #include <openvdb/openvdb.h>
6 #include <openvdb/tools/MultiResGrid.h>
7 #include <openvdb/tools/LevelSetSphere.h>
8 #include <openvdb/tools/Diagnostics.h>
9
10 #include <gtest/gtest.h>
11
12 #include <cstdio> // for remove()
13
14
15 5 class TestMultiResGrid : public ::testing::Test
16 {
17 public:
18 // Use to test logic in openvdb::tools::MultiResGrid
19 struct CoordMask {
20 static int Mask(int i, int j, int k) { return (i & 1) | ((j & 1) << 1) | ((k & 1) << 2); }
21 CoordMask() : mask(0) {}
22 CoordMask(const openvdb::Coord &c ) : mask( Mask(c[0],c[1],c[2]) ) {}
23 inline void setCoord(int i, int j, int k) { mask = Mask(i,j,k); }
24 inline void setCoord(const openvdb::Coord &c) { mask = Mask(c[0],c[1],c[2]); }
25 inline bool allEven() const { return mask == 0; }
26 inline bool xOdd() const { return mask == 1; }
27 inline bool yOdd() const { return mask == 2; }
28 inline bool zOdd() const { return mask == 4; }
29 inline bool xyOdd() const { return mask == 3; }
30 inline bool xzOdd() const { return mask == 5; }
31 inline bool yzOdd() const { return mask == 6; }
32 inline bool allOdd() const { return mask == 7; }
33 int mask;
34 };// CoordMask
35 };
36
37
38 // Uncomment to test on models from our web-site
39 //#define TestMultiResGrid_DATA_PATH "/home/kmu/src/openvdb/data/"
40 //#define TestMultiResGrid_DATA_PATH "/usr/pic1/Data/OpenVDB/LevelSetModels/"
41
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestMultiResGrid, testTwosComplement)
43 {
44 // test bit-operations that assume 2's complement representation of negative integers
45
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ( 1, 13 & 1 );// odd
46
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ( 1,-13 & 1 );// odd
47
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ( 0, 12 & 1 );// even
48
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ( 0,-12 & 1 );// even
49
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
1 EXPECT_EQ( 0, 0 & 1 );// even
50
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1 times.
102 for (int i=-50; i<=50; ++i) {
51
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 50 times.
101 if ( (i % 2) == 0 ) {//i.e. even number
52
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
51 EXPECT_EQ( 0, i & 1);
53
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
51 EXPECT_EQ( i, (i >> 1) << 1 );
54 } else {//i.e. odd number
55
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
50 EXPECT_EQ( 1, i & 1);
56
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 50 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.
50 EXPECT_TRUE( i != (i >> 1) << 1 );
57 }
58 }
59 1 }
60
61
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestMultiResGrid, testCoordMask)
63 {
64 using namespace openvdb;
65 CoordMask mask;
66
67 mask.setCoord(-4, 2, 18);
68 EXPECT_TRUE(mask.allEven());
69
70 mask.setCoord(1, 2, -6);
71 EXPECT_TRUE(mask.xOdd());
72
73 mask.setCoord(4, -3, -6);
74 EXPECT_TRUE(mask.yOdd());
75
76 mask.setCoord(-8, 2, -7);
77 EXPECT_TRUE(mask.zOdd());
78
79 mask.setCoord(1, -3, 2);
80 EXPECT_TRUE(mask.xyOdd());
81
82 mask.setCoord(1, 2, -7);
83 EXPECT_TRUE(mask.xzOdd());
84
85 mask.setCoord(-10, 3, -3);
86 EXPECT_TRUE(mask.yzOdd());
87
88 mask.setCoord(1, 3,-3);
89 EXPECT_TRUE(mask.allOdd());
90 1 }
91
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestMultiResGrid, testManualTopology)
93 {
94 // Perform tests when the sparsity (or topology) of the multiple grids is defined manually
95 using namespace openvdb;
96
97 typedef tools::MultiResGrid<DoubleTree> MultiResGridT;
98 const double background = -1.0;
99 1 const size_t levels = 4;
100
101
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 MultiResGridT::Ptr mrg(new MultiResGridT( levels, background));
102
103
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(mrg != nullptr);
104
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_EQ(levels , mrg->numLevels());
105
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_EQ(size_t(0), mrg->finestLevel());
106
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_EQ(levels-1, mrg->coarsestLevel());
107
108 // Define grid domain so they exactly overlap!
109 const int w = 16;//half-width of dense patch on the finest grid level
110 1 const CoordBBox bbox( Coord(-w), Coord(w) );// both inclusive
111
112 // First check all trees against the background value
113
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (size_t level = 0; level < mrg->numLevels(); ++level) {
114
2/2
✓ Branch 1 taken 41704 times.
✓ Branch 2 taken 4 times.
41708 for (CoordBBox::Iterator<true> iter(bbox>>level); iter; ++iter) {
115
2/16
✓ Branch 2 taken 41704 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 41704 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
83408 EXPECT_NEAR(background,
116 mrg->tree(level).getValue(*iter), /*tolerance=*/0.0);
117 }
118 }
119
120 // Fill all trees according to a power of two refinement pattern
121
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (size_t level = 0; level < mrg->numLevels(); ++level) {
122 8 mrg->tree(level).fill( bbox>>level, double(level));
123 4 mrg->tree(level).voxelizeActiveTiles();// avoid active tiles
124 // Check values
125
2/2
✓ Branch 1 taken 41704 times.
✓ Branch 2 taken 4 times.
41708 for (CoordBBox::Iterator<true> iter(bbox>>level); iter; ++iter) {
126
2/16
✓ Branch 2 taken 41704 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 41704 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
83408 EXPECT_NEAR(double(level),
127 mrg->tree(level).getValue(*iter), /*tolerance=*/0.0);
128 }
129 //mrg->tree( level ).print(std::cerr, 2);
130 // Check bounding box of active voxels
131 4 CoordBBox bbox_actual;// Expected Tree dimensions: 33^3 -> 17^3 -> 9^3 ->5^3
132
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 mrg->tree( level ).evalActiveVoxelBoundingBox( bbox_actual );
133
1/14
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
8 EXPECT_EQ( bbox >> level, bbox_actual );
134 }
135
136 //pick a grid point that is shared between all the grids
137 const Coord ijk(0);
138
139 // Value at ijk equals the level
140
3/18
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
1 EXPECT_NEAR(2.0, mrg->tree(2).getValue(ijk>>2), /*tolerance=*/ 0.001);
141
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_NEAR(2.0, mrg->sampleValue<0>(ijk, size_t(2)), /*tolerance=*/ 0.001);
142
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_NEAR(2.0, mrg->sampleValue<1>(ijk, size_t(2)), /*tolerance=*/ 0.001);
143
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_NEAR(2.0, mrg->sampleValue<2>(ijk, size_t(2)), /*tolerance=*/ 0.001);
144
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_NEAR(2.0, mrg->sampleValue<1>(ijk, 2.0f), /*tolerance=*/ 0.001);
145
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_NEAR(2.0, mrg->sampleValue<1>(ijk, float(2)), /*tolerance=*/ 0.001);
146
147 // Value at ijk at floating point level
148
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_NEAR(2.25, mrg->sampleValue<1>(ijk, 2.25f), /*tolerance=*/ 0.001);
149
150 // Value at a floating-point position close to ijk and a floating point level
151
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_NEAR(2.25,
152 mrg->sampleValue<1>(Vec3R(0.124), 2.25f), /*tolerance=*/ 0.001);
153
154 // prolongate at a given point at top level
155
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_NEAR(1.0, mrg->prolongateVoxel(ijk, 0), /*tolerance=*/ 0.0);
156
157 // First check the coarsest level (3)
158
2/2
✓ Branch 1 taken 125 times.
✓ Branch 2 taken 1 times.
126 for (CoordBBox::Iterator<true> iter(bbox>>size_t(3)); iter; ++iter) {
159
2/16
✓ Branch 2 taken 125 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 125 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
250 EXPECT_NEAR(3.0, mrg->tree(3).getValue(*iter), /*tolerance=*/0.0);
160 }
161
162 // Prolongate from level 3 -> level 2 and check values
163
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mrg->prolongateActiveVoxels(2);
164
2/2
✓ Branch 1 taken 729 times.
✓ Branch 2 taken 1 times.
730 for (CoordBBox::Iterator<true> iter(bbox>>size_t(2)); iter; ++iter) {
165
2/16
✓ Branch 2 taken 729 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 729 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1458 EXPECT_NEAR(3.0, mrg->tree(2).getValue(*iter), /*tolerance=*/0.0);
166 }
167
168 // Prolongate from level 2 -> level 1 and check values
169
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mrg->prolongateActiveVoxels(1);
170
2/2
✓ Branch 1 taken 4913 times.
✓ Branch 2 taken 1 times.
4914 for (CoordBBox::Iterator<true> iter(bbox>>size_t(1)); iter; ++iter) {
171
2/16
✓ Branch 2 taken 4913 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4913 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
9826 EXPECT_NEAR(3.0, mrg->tree(1).getValue(*iter), /*tolerance=*/0.0);
172 }
173
174 // Prolongate from level 1 -> level 0 and check values
175
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mrg->prolongateActiveVoxels(0);
176
2/2
✓ Branch 0 taken 35937 times.
✓ Branch 1 taken 1 times.
35938 for (CoordBBox::Iterator<true> iter(bbox); iter; ++iter) {
177
2/16
✓ Branch 2 taken 35937 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 35937 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
71874 EXPECT_NEAR(3.0, mrg->tree(0).getValue(*iter), /*tolerance=*/0.0);
178 }
179
180 // Redefine values at the finest level and check values
181
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.
2 mrg->finestTree().fill( bbox, 5.0 );
182 mrg->finestTree().voxelizeActiveTiles();// avoid active tiles
183
2/2
✓ Branch 0 taken 35937 times.
✓ Branch 1 taken 1 times.
35938 for (CoordBBox::Iterator<true> iter(bbox); iter; ++iter) {
184
2/16
✓ Branch 2 taken 35937 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 35937 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
71874 EXPECT_NEAR(5.0, mrg->tree(0).getValue(*iter), /*tolerance=*/0.0);
185 }
186
187 // USE RESTRICTION BY INJECTION since it doesn't have boundary issues
188 // // Restrict from level 0 -> level 1 and check values
189 // mrg->restrictActiveVoxels(1);
190 // for (CoordBBox::Iterator<true> iter((bbox>>1UL).expandBy(-1)); iter; ++iter) {
191 // EXPECT_NEAR(5.0, mrg->tree(1).getValue(*iter), /*tolerance=*/0.0);
192 // }
193
194 // // Restrict from level 1 -> level 2 and check values
195 // mrg->restrictActiveVoxels(2);
196 // for (CoordBBox::Iterator<true> iter(bbox>>2UL); iter; ++iter) {
197 // EXPECT_NEAR(5.0, mrg->tree(2).getValue(*iter), /*tolerance=*/0.0);
198 // }
199
200 // // Restrict from level 2 -> level 3 and check values
201 // mrg->restrictActiveVoxels(3);
202 // for (CoordBBox::Iterator<true> iter(bbox>>3UL); iter; ++iter) {
203 // EXPECT_NEAR(5.0, mrg->tree(3).getValue(*iter), /*tolerance=*/0.0);
204 // }
205 1 }
206
207
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestMultiResGrid, testIO)
208 {
209 using namespace openvdb;
210
211 const float radius = 1.0f;
212 const Vec3f center(0.0f, 0.0f, 0.0f);
213 const float voxelSize = 0.01f;
214
215 openvdb::FloatGrid::Ptr ls =
216 1 openvdb::tools::createLevelSetSphere<openvdb::FloatGrid>(radius, center, voxelSize);
217
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 ls->setName("LevelSetSphere");
218
219 typedef tools::MultiResGrid<FloatTree> MultiResGridT;
220
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t levels = 4;
221
222 // Generate LOD sequence
223
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 MultiResGridT mrg( levels, *ls, /* reduction by injection */ false );
224 //mrg.print( std::cout, 3 );
225
226
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_EQ(levels , mrg.numLevels());
227
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_EQ(size_t(0), mrg.finestLevel());
228
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_EQ(levels-1, mrg.coarsestLevel());
229
230 // Check inside and outside values
231
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for ( size_t level = 1; level < mrg.numLevels(); ++level) {
232
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 const float inside = mrg.sampleValue<1>( Coord(0,0,0), 0UL, level );
233
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 EXPECT_NEAR( -ls->background(), inside,/*tolerance=*/ 0.001 );
234
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 const float outside = mrg.sampleValue<1>( Coord( int(1.1*radius/voxelSize) ), 0UL, level );
235
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 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.
3 EXPECT_NEAR( ls->background(), outside,/*tolerance=*/ 0.001 );
236 }
237
238
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const std::string filename( "sphere.vdb" );
239
240 // Write grids
241
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 io::File outputFile( filename );
242
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 outputFile.write( *mrg.grids() );
243
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 outputFile.close();
244
245 // Read grids
246
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 openvdb::initialize();
247
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 openvdb::io::File file( filename );
248
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 file.open();
249
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GridPtrVecPtr grids = file.getGrids();
250
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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ( levels, grids->size() );
251 //std::cerr << "\nsize = " << grids->size() << std::endl;
252
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for ( size_t i=0; i<grids->size(); ++i ) {
253 FloatGrid::Ptr grid = gridPtrCast<FloatGrid>(grids->at(i));
254
4/20
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
4 EXPECT_EQ( grid->activeVoxelCount(), mrg.tree(i).activeVoxelCount() );
255 //grid->print(std::cerr, 3);
256 }
257
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 file.close();
258
259 1 ::remove(filename.c_str());
260 1 }
261
262
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestMultiResGrid, testModels)
263 {
264 using namespace openvdb;
265
266 #ifdef TestMultiResGrid_DATA_PATH
267 initialize();//required whenever I/O of OpenVDB files is performed!
268 const std::string path(TestMultiResGrid_DATA_PATH);
269 std::vector<std::string> filenames;
270 filenames.push_back("armadillo.vdb");
271 filenames.push_back("buddha.vdb");
272 filenames.push_back("bunny.vdb");
273 filenames.push_back("crawler.vdb");
274 filenames.push_back("dragon.vdb");
275 filenames.push_back("iss.vdb");
276 filenames.push_back("utahteapot.vdb");
277 util::CpuTimer timer;
278 for ( size_t i=0; i<filenames.size(); ++i) {
279 std::cerr << "\n=====================>\"" << filenames[i]
280 << "\" =====================" << std::endl;
281 std::cerr << "Reading \"" << filenames[i] << "\" ...";
282 io::File file( path + filenames[i] );
283 file.open(false);//disable delayed loading
284 FloatGrid::Ptr model = gridPtrCast<FloatGrid>(file.getGrids()->at(0));
285 std::cerr << " done\nProcessing \"" << filenames[i] << "\" ...";
286 timer.start("\nMultiResGrid processing");
287 tools::MultiResGrid<FloatTree> mrg( 6, model );
288 timer.stop();
289 std::cerr << "\n High-res level set " << tools::checkLevelSet(*mrg.grid(0)) << "\n";
290 std::cerr << " done\nWriting \"" << filenames[i] << "\" ...";
291
292 io::File file( "/tmp/" + filenames[i] );
293 file.write( *mrg.grids() );
294 file.close();
295
296 std::cerr << " done\n" << std::endl;
297 // {// in-betweening
298 // timer.start("\nIn-betweening");
299 // FloatGrid::Ptr model3 = mrg.createGrid( 1.9999f );
300 // timer.stop();
301 // //
302 // std::cerr << "\n" << tools::checkLevelSet(*model3) << "\n";
303 // //
304 // GridPtrVecPtr grids2( new GridPtrVec );
305 // grids2->push_back( model3 );
306 // io::File file2( "/tmp/inbetween_" + filenames[i] );
307 // file2.write( *grids2 );
308 // file2.close();
309 // }
310 // {// prolongate
311 // timer.start("\nProlongate");
312 // mrg.prolongateActiveVoxels(1);
313 // FloatGrid::Ptr model31= mrg.grid(1);
314 // timer.stop();
315 // GridPtrVecPtr grids2( new GridPtrVec );
316 // grids2->push_back( model31 );
317 // io::File file2( "/tmp/prolongate_" + filenames[i] );
318 // file2.write( *grids2 );
319 // file2.close();
320 // }
321 //::remove(filenames[i].c_str());
322 }
323 #endif
324 1 }
325