GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestTreeIterators.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 267 267 100.0%
Functions: 13 13 100.0%
Branches: 307 1834 16.7%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/tree/Tree.h>
5 #include <openvdb/openvdb.h>
6 #include <openvdb/Types.h>
7 #include <openvdb/tools/LevelSetSphere.h> // for tools::createLevelSetSphere()
8
9 #include <gtest/gtest.h>
10
11
12 #define ASSERT_DOUBLES_EXACTLY_EQUAL(expected, actual) \
13 EXPECT_NEAR((expected), (actual), /*tolerance=*/0.0)
14
15
16 8 class TestTreeIterators: public ::testing::Test
17 {
18 public:
19 8 void SetUp() override { openvdb::initialize(); }
20 8 void TearDown() override { openvdb::uninitialize(); }
21 };
22
23
24 typedef openvdb::FloatTree TreeType;
25
26
27
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testLeafIterator)
28 {
29 1 const float fillValue = 256.0f;
30
31 2 TreeType tree(fillValue);
32
33
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(0, 0, 0), 1.0);
34
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(1, 0, 0), 1.5);
35
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(0, 0, 8), 2.0);
36
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(1, 0, 8), 2.5);
37
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(openvdb::Coord(0, 0, 16), 3.0);
38
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(1, 0, 16), 3.5);
39
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(0, 0, 24), 4.0);
40
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(openvdb::Coord(1, 0, 24), 4.5);
41
42 float val = 1.f;
43
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (TreeType::LeafCIter iter = tree.cbeginLeaf(); iter; ++iter) {
44 const TreeType::LeafNodeType* leaf = iter.getLeaf();
45
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 4 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.
4 EXPECT_TRUE(leaf != NULL);
46
3/18
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 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.
4 ASSERT_DOUBLES_EXACTLY_EQUAL(val, leaf->getValue(openvdb::Coord(0, 0, 0)));
47
3/18
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 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.
4 ASSERT_DOUBLES_EXACTLY_EQUAL(val + 0.5, iter->getValue(openvdb::Coord(1, 0, 0)));
48
3/18
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 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.
4 ASSERT_DOUBLES_EXACTLY_EQUAL(fillValue, iter->getValue(openvdb::Coord(1, 1, 1)));
49
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 val = val + 1.f;
50 }
51 1 }
52
53
54 // Test the leaf iterator over a tree without any leaf nodes.
55
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testEmptyLeafIterator)
56 {
57 using namespace openvdb;
58
59
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 TreeType tree(/*fillValue=*/256.0);
60
61 std::vector<Index> dims;
62
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.getNodeLog2Dims(dims);
63
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(4, int(dims.size()));
64
65 // Start with an iterator over an empty tree.
66 TreeType::LeafCIter iter = tree.cbeginLeaf();
67
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(!iter);
68
69 // Using sparse fill, add internal nodes but no leaf nodes to the tree.
70
71 // Fill the region subsumed by a level-2 internal node (assuming a four-level tree).
72 1 Index log2Sum = dims[1] + dims[2] + dims[3];
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 CoordBBox bbox(Coord(0), Coord((1 << log2Sum) - 1));
74
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.fill(bbox, /*value=*/1.0);
75 1 iter = tree.cbeginLeaf();
76
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(!iter);
77
78 // Fill the region subsumed by a level-1 internal node.
79 1 log2Sum = dims[2] + dims[3];
80
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 bbox.reset(Coord(0), Coord((1 << log2Sum) - 1));
81
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 tree.fill(bbox, /*value=*/2.0);
82 1 iter = tree.cbeginLeaf();
83
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(!iter);
84 1 }
85
86
87
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testOnlyNegative)
88 {
89 using openvdb::Index64;
90
91 1 const float fillValue = 5.0f;
92
93 2 TreeType tree(fillValue);
94
95
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(tree.empty());
96
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 ASSERT_DOUBLES_EXACTLY_EQUAL(fillValue, tree.getValue(openvdb::Coord(5, -10, 20)));
97
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 ASSERT_DOUBLES_EXACTLY_EQUAL(fillValue, tree.getValue(openvdb::Coord(-500, 200, 300)));
98
99
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-5, 10, 20), 0.1f);
100
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord( 5, -10, 20), 0.2f);
101
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord( 5, 10, -20), 0.3f);
102
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-5, -10, 20), 0.4f);
103
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-5, 10, -20), 0.5f);
104
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord( 5, -10, -20), 0.6f);
105
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-5, -10, -20), 0.7f);
106
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-500, 200, -300), 4.5678f);
107
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord( 500, -200, -300), 4.5678f);
108
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.setValue(openvdb::Coord(-500, -200, 300), 4.5678f);
109
110
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.1f, tree.getValue(openvdb::Coord(-5, 10, 20)));
111
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.2f, tree.getValue(openvdb::Coord( 5, -10, 20)));
112
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.3f, tree.getValue(openvdb::Coord( 5, 10, -20)));
113
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.4f, tree.getValue(openvdb::Coord(-5, -10, 20)));
114
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.5f, tree.getValue(openvdb::Coord(-5, 10, -20)));
115
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.6f, tree.getValue(openvdb::Coord( 5, -10, -20)));
116
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 ASSERT_DOUBLES_EXACTLY_EQUAL(0.7f, tree.getValue(openvdb::Coord(-5, -10, -20)));
117
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 ASSERT_DOUBLES_EXACTLY_EQUAL(4.5678f, tree.getValue(openvdb::Coord(-500, 200, -300)));
118
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 ASSERT_DOUBLES_EXACTLY_EQUAL(4.5678f, tree.getValue(openvdb::Coord( 500, -200, -300)));
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 ASSERT_DOUBLES_EXACTLY_EQUAL(4.5678f, tree.getValue(openvdb::Coord(-500, -200, 300)));
120
121 1 int count = 0;
122
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 1 times.
51 for (int i = -25; i < 25; ++i) {
123
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 50 times.
2550 for (int j = -25; j < 25; ++j) {
124
2/2
✓ Branch 0 taken 125000 times.
✓ Branch 1 taken 2500 times.
127500 for (int k = -25; k < 25; ++k) {
125
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 124993 times.
125000 if (tree.getValue(openvdb::Coord(i, j, k)) < 1.0f) {
126 //fprintf(stderr, "(%i, %i, %i) = %f\n",
127 // i, j, k, tree.getValue(openvdb::Coord(i, j, k)));
128 7 ++count;
129 }
130 }
131 }
132 }
133
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(7, count);
134
135 openvdb::Coord xyz;
136
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 int count2 = 0;
137
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for (TreeType::ValueOnCIter iter = tree.cbeginValueOn();iter; ++iter) {
138
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ++count2;
139 xyz = iter.getCoord();
140 //std::cerr << xyz << " = " << *iter << "\n";
141 }
142
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(10, count2);
143
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(Index64(10), tree.activeVoxelCount());
144 1 }
145
146
147
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testValueAllIterator)
148 {
149 const openvdb::Index DIM0 = 3, DIM1 = 2, DIM2 = 3;
150
151 typedef openvdb::tree::Tree4<float, DIM2, DIM1, DIM0>::Type Tree323f;
152
153 typedef Tree323f::RootNodeType RootT;
154 typedef RootT::ChildNodeType Int1T;
155 typedef Int1T::ChildNodeType Int2T;
156 typedef Int2T::ChildNodeType LeafT;
157
158 2 Tree323f tree(/*fillValue=*/256.0f);
159
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(4), 0.0f);
160
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-4), -1.0f);
161
162
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t expectedNumOff =
163 2 * ((1 << (3 * DIM2)) - 1) // 2 8x8x8 InternalNodes - 1 child pointer each
164 + 2 * ((1 << (3 * DIM1)) - 1) // 2 4x4x4 InternalNodes - 1 child pointer each
165 + 2 * ((1 << (3 * DIM0)) - 1); // 2 8x8x8 LeafNodes - 1 active value each
166
167 {
168 Tree323f::ValueAllIter iter = tree.beginValueAll();
169
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(iter.test());
170
171 // Read all tile and voxel values through a non-const value iterator.
172 1 size_t numOn = 0, numOff = 0;
173
2/2
✓ Branch 0 taken 2172 times.
✓ Branch 1 taken 1 times.
2173 for ( ; iter; ++iter) {
174
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2172 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.
2172 EXPECT_TRUE(iter.getLevel() <= 3);
175 const openvdb::Index iterLevel = iter.getLevel();
176
2/2
✓ Branch 0 taken 8688 times.
✓ Branch 1 taken 2172 times.
10860 for (openvdb::Index lvl = 0; lvl <= 3; ++lvl) {
177 RootT* root; Int1T* int1; Int2T* int2; LeafT* leaf;
178
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 8688 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.
8688 iter.getNode(root); EXPECT_TRUE(root != NULL);
179
2/18
✓ Branch 0 taken 8688 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8688 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
8688 iter.getNode(int1); EXPECT_TRUE(iterLevel < 3 ? int1 != NULL: int1 == NULL);
180
3/18
✓ Branch 0 taken 4600 times.
✓ Branch 1 taken 4088 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8688 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
8688 iter.getNode(int2); EXPECT_TRUE(iterLevel < 2 ? int2 != NULL: int2 == NULL);
181
3/18
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 4592 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8688 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
8688 iter.getNode(leaf); EXPECT_TRUE(iterLevel < 1 ? leaf != NULL: leaf == NULL);
182 }
183
184
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2170 times.
2172 if (iter.isValueOn()) {
185
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 ++numOn;
186 2 const float f = iter.getValue();
187
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (openvdb::math::isZero(f)) {
188
2/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
2 EXPECT_TRUE(iter.getCoord() == openvdb::Coord(4));
189
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(iter.isVoxelValue());
190 } else {
191
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 ASSERT_DOUBLES_EXACTLY_EQUAL(-1.0f, f);
192
2/18
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
2 EXPECT_TRUE(iter.getCoord() == openvdb::Coord(-4));
193
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(iter.isVoxelValue());
194 }
195 } else {
196 2170 ++numOff;
197
198 // For every tenth inactive value, check that the size of
199 // the tile or voxel is as expected.
200
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 1953 times.
2170 if (numOff % 10 == 0) {
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 217 times.
217 const int dim[4] = {
202 1, 1 << DIM0, 1 << (DIM1 + DIM0), 1 << (DIM2 + DIM1 + DIM0)
203 };
204 217 const int lvl = iter.getLevel();
205
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 217 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.
217 EXPECT_TRUE(lvl < 4);
206 217 openvdb::CoordBBox bbox;
207
1/2
✓ Branch 1 taken 217 times.
✗ Branch 2 not taken.
217 iter.getBoundingBox(bbox);
208
2/16
✓ Branch 2 taken 217 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 217 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.
217 EXPECT_EQ(
209 bbox.extents(), openvdb::Coord(dim[lvl], dim[lvl], dim[lvl]));
210 }
211 }
212 }
213
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(2, int(numOn));
214
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
215 }
216 {
217 Tree323f::ValueAllCIter iter = tree.cbeginValueAll();
218
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(iter.test());
219
220 // Read all tile and voxel values through a const value iterator.
221 1 size_t numOn = 0, numOff = 0;
222
3/4
✓ Branch 0 taken 2172 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 2172 times.
✗ Branch 4 not taken.
4345 for ( ; iter.test(); iter.next()) {
223
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2170 times.
2172 if (iter.isValueOn()) ++numOn; else ++numOff;
224 }
225
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(2, int(numOn));
226
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
227 }
228 {
229 Tree323f::ValueAllIter iter = tree.beginValueAll();
230
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(iter.test());
231
232 // Read all tile and voxel values through a non-const value iterator
233 // and overwrite all active values.
234 1 size_t numOn = 0, numOff = 0;
235
2/2
✓ Branch 0 taken 2172 times.
✓ Branch 1 taken 1 times.
2173 for ( ; iter; ++iter) {
236
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2170 times.
2172 if (iter.isValueOn()) {
237
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 iter.setValue(iter.getValue() - 5);
238 2 ++numOn;
239 } else {
240 2170 ++numOff;
241 }
242 }
243
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(2, int(numOn));
244
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
245 }
246 1 }
247
248
249
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testValueOnIterator)
250 {
251 typedef openvdb::tree::Tree4<float, 3, 2, 3>::Type Tree323f;
252
253
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 Tree323f tree(/*fillValue=*/256.0f);
254
255 {
256 Tree323f::ValueOnIter iter = tree.beginValueOn();
257
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(!iter.test()); // empty tree
258 }
259
260 1 const int STEP = 8/*100*/, NUM_STEPS = 10;
261
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for (int i = 0; i < NUM_STEPS; ++i) {
262
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 tree.setValue(openvdb::Coord(STEP * i), 0.0f);
263 }
264
265 {
266 Tree323f::ValueOnIter iter = tree.beginValueOn();
267
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(iter.test());
268
269 // Read all active tile and voxel values through a non-const value iterator.
270 1 int numOn = 0;
271
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for ( ; iter; ++iter) {
272
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isVoxelValue());
273
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isValueOn());
274
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 ASSERT_DOUBLES_EXACTLY_EQUAL(0.0f, iter.getValue());
275
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 EXPECT_EQ(openvdb::Coord(STEP * numOn), iter.getCoord());
276
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ++numOn;
277 }
278
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(NUM_STEPS, numOn);
279 }
280 {
281 Tree323f::ValueOnCIter iter = tree.cbeginValueOn();
282
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(iter.test());
283
284 // Read all active tile and voxel values through a const value iterator.
285 1 int numOn = 0;
286
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for ( ; iter.test(); iter.next()) {
287
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isVoxelValue());
288
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isValueOn());
289
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 ASSERT_DOUBLES_EXACTLY_EQUAL(0.0f, iter.getValue());
290
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 EXPECT_EQ(openvdb::Coord(STEP * numOn), iter.getCoord());
291
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ++numOn;
292 }
293
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(NUM_STEPS, numOn);
294 }
295 {
296 Tree323f::ValueOnIter iter = tree.beginValueOn();
297
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(iter.test());
298
299 // Read all active tile and voxel values through a non-const value iterator
300 // and overwrite the values.
301 1 int numOn = 0;
302
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for ( ; iter; ++iter) {
303
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isVoxelValue());
304
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 10 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.
10 EXPECT_TRUE(iter.isValueOn());
305
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 ASSERT_DOUBLES_EXACTLY_EQUAL(0.0f, iter.getValue());
306
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 iter.setValue(5.0f);
307
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 ASSERT_DOUBLES_EXACTLY_EQUAL(5.0f, iter.getValue());
308
2/16
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 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.
10 EXPECT_EQ(openvdb::Coord(STEP * numOn), iter.getCoord());
309
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ++numOn;
310 }
311
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(NUM_STEPS, numOn);
312 }
313 1 }
314
315
316
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testValueOffIterator)
317 {
318 const openvdb::Index DIM0 = 3, DIM1 = 2, DIM2 = 3;
319
320 typedef openvdb::tree::Tree4<float, DIM2, DIM1, DIM0>::Type Tree323f;
321
322 2 Tree323f tree(/*fillValue=*/256.0f);
323
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(4), 0.0f);
324
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-4), -1.0f);
325
326
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const size_t expectedNumOff =
327 2 * ((1 << (3 * DIM2)) - 1) // 2 8x8x8 InternalNodes - 1 child pointer each
328 + 2 * ((1 << (3 * DIM1)) - 1) // 2 4x4x4 InternalNodes - 1 child pointer each
329 + 2 * ((1 << (3 * DIM0)) - 1); // 2 8x8x8 LeafNodes - 1 active value each
330
331 {
332 Tree323f::ValueOffIter iter = tree.beginValueOff();
333
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(iter.test());
334
335 // Read all inactive tile and voxel values through a non-const value iterator.
336 1 size_t numOff = 0;
337
2/2
✓ Branch 0 taken 2170 times.
✓ Branch 1 taken 1 times.
2171 for ( ; iter; ++iter) {
338
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2170 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.
2170 EXPECT_TRUE(!iter.isValueOn());
339 2170 ++numOff;
340 // For every tenth inactive value, check that the size of
341 // the tile or voxel is as expected.
342
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 1953 times.
2170 if (numOff % 10 == 0) {
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 217 times.
217 const int dim[4] = {
344 1, 1 << DIM0, 1 << (DIM1 + DIM0), 1 << (DIM2 + DIM1 + DIM0)
345 };
346 217 const int lvl = iter.getLevel();
347
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 217 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.
217 EXPECT_TRUE(lvl < 4);
348 217 openvdb::CoordBBox bbox;
349
1/2
✓ Branch 1 taken 217 times.
✗ Branch 2 not taken.
217 iter.getBoundingBox(bbox);
350
2/16
✓ Branch 2 taken 217 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 217 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.
217 EXPECT_EQ(bbox.extents(), openvdb::Coord(dim[lvl], dim[lvl], dim[lvl]));
351 }
352 }
353
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
354 }
355 {
356 Tree323f::ValueOffCIter iter = tree.cbeginValueOff();
357
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(iter.test());
358
359 // Read all inactive tile and voxel values through a const value iterator.
360 1 size_t numOff = 0;
361
3/4
✓ Branch 0 taken 2170 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 2170 times.
✗ Branch 4 not taken.
4341 for ( ; iter.test(); iter.next(), ++numOff) {
362
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2170 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.
2170 EXPECT_TRUE(!iter.isValueOn());
363 }
364
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
365 }
366 {
367 Tree323f::ValueOffIter iter = tree.beginValueOff();
368
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(iter.test());
369
370 // Read all inactive tile and voxel values through a non-const value iterator
371 // and overwrite the values.
372 1 size_t numOff = 0;
373
2/2
✓ Branch 0 taken 2170 times.
✓ Branch 1 taken 1 times.
4341 for ( ; iter; ++iter, ++numOff) {
374
1/2
✓ Branch 1 taken 2170 times.
✗ Branch 2 not taken.
2170 iter.setValue(iter.getValue() - 5);
375
1/2
✓ Branch 1 taken 2170 times.
✗ Branch 2 not taken.
2170 iter.setValueOff();
376 }
377
2/2
✓ Branch 1 taken 2170 times.
✓ Branch 2 taken 1 times.
4342 for (iter = tree.beginValueOff(); iter; ++iter, --numOff);
378
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), numOff);
379 }
380 1 }
381
382
383
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testModifyValue)
384 {
385 using openvdb::Coord;
386
387 const openvdb::Index DIM0 = 3, DIM1 = 2, DIM2 = 3;
388 {
389 typedef openvdb::tree::Tree4<int32_t, DIM2, DIM1, DIM0>::Type IntTree323f;
390
391 2 IntTree323f tree(/*background=*/256);
392
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/3, Coord(-1), /*value=*/ 4, /*active=*/true);
393
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/2, Coord(1 << (DIM0 + DIM1)), /*value=*/-3, /*active=*/true);
394
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/1, Coord(1 << DIM0), /*value=*/ 2, /*active=*/true);
395
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.addTile(/*level=*/0, Coord(0), /*value=*/-1, /*active=*/true);
396
397 1087 struct Local { static inline void negate(int32_t& n) { n = -n; } };
398
399
2/2
✓ Branch 0 taken 1087 times.
✓ Branch 1 taken 1 times.
1088 for (IntTree323f::ValueAllIter iter = tree.beginValueAll(); iter; ++iter) {
400 iter.modifyValue(Local::negate);
401 }
402
403
2/2
✓ Branch 0 taken 1087 times.
✓ Branch 1 taken 1 times.
1088 for (IntTree323f::ValueAllCIter iter = tree.cbeginValueAll(); iter; ++iter) {
404 1087 const int32_t val = *iter;
405
3/18
✓ Branch 0 taken 1085 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1085 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
1087 if (val < 0) EXPECT_TRUE((-val) % 2 == 0); // negative values are even
406
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2 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.
2 else EXPECT_TRUE(val % 2 == 1); // positive values are odd
407 }
408
409 // Because modifying values through a const iterator is not allowed,
410 // uncommenting the following line should result in a static assertion failure:
411 //tree.cbeginValueOn().modifyValue(Local::negate);
412 }
413 {
414 typedef openvdb::tree::Tree4<bool, DIM2, DIM1, DIM0>::Type BoolTree323f;
415
416 2 BoolTree323f tree;
417
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/3, Coord(-1), /*value=*/false, /*active=*/true);
418
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/2, Coord(1 << (DIM0 + DIM1)), /*value=*/ true, /*active=*/true);
419
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.addTile(/*level=*/1, Coord(1 << DIM0), /*value=*/false, /*active=*/true);
420
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 tree.addTile(/*level=*/0, Coord(0), /*value=*/ true, /*active=*/true);
421
422 1087 struct Local { static inline void negate(bool& b) { b = !b; } };
423
424
2/2
✓ Branch 0 taken 1087 times.
✓ Branch 1 taken 1 times.
1088 for (BoolTree323f::ValueAllIter iter = tree.beginValueAll(); iter; ++iter) {
425 iter.modifyValue(Local::negate);
426 }
427
428
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(!tree.getValue(Coord(0)));
429
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( tree.getValue(Coord(1 << DIM0)));
430
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(!tree.getValue(Coord(1 << (DIM0 + DIM1))));
431
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( tree.getValue(Coord(-1)));
432
433 // Because modifying values through a const iterator is not allowed,
434 // uncommenting the following line should result in a static assertion failure:
435 //tree.cbeginValueOn().modifyValue(Local::negate);
436 }
437 {
438 // @note StringTree types as native types are deprecated, but we can
439 // still test tool functionality with them
440 typedef openvdb::tree::Tree4<std::string, DIM2, DIM1, DIM0>::Type StringTree323f;
441
442
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 StringTree323f tree(/*background=*/"");
443
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 tree.addTile(/*level=*/3, Coord(-1), /*value=*/"abc", /*active=*/true);
444
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 tree.addTile(/*level=*/2, Coord(1 << (DIM0 + DIM1)), /*value=*/"abc", /*active=*/true);
445
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 tree.addTile(/*level=*/1, Coord(1 << DIM0), /*value=*/"abc", /*active=*/true);
446
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 tree.addTile(/*level=*/0, Coord(0), /*value=*/"abc", /*active=*/true);
447
448 4 struct Local { static inline void op(std::string& s) { s.append("def"); } };
449
450
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (StringTree323f::ValueOnIter iter = tree.beginValueOn(); iter; ++iter) {
451 iter.modifyValue(Local::op);
452 }
453
454
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 const std::string expectedVal("abcdef");
455
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
5 for (StringTree323f::ValueOnCIter iter = tree.cbeginValueOn(); iter; ++iter) {
456
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 4 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
4 EXPECT_EQ(expectedVal, *iter);
457 }
458
2/2
✓ Branch 0 taken 1083 times.
✓ Branch 1 taken 1 times.
1084 for (StringTree323f::ValueOffCIter iter = tree.cbeginValueOff(); iter; ++iter) {
459
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1083 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.
1083 EXPECT_TRUE((*iter).empty());
460 }
461 }
462 1 }
463
464
465
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeIterators, testDepthBounds)
466 {
467 const openvdb::Index DIM0 = 3, DIM1 = 2, DIM2 = 3;
468
469 typedef openvdb::tree::Tree4<float, DIM2, DIM1, DIM0>::Type Tree323f;
470
471 2 Tree323f tree(/*fillValue=*/256.0f);
472
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(4), 0.0f);
473
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tree.setValue(openvdb::Coord(-4), -1.0f);
474
475 const size_t
476 numDepth1 = 2 * ((1 << (3 * DIM2)) - 1), // 2 8x8x8 InternalNodes - 1 child pointer each
477 numDepth2 = 2 * ((1 << (3 * DIM1)) - 1), // 2 4x4x4 InternalNodes - 1 child pointer each
478 numDepth3 = 2 * ((1 << (3 * DIM0)) - 1), // 2 8x8x8 LeafNodes - 1 active value each
479
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 expectedNumOff = numDepth1 + numDepth2 + numDepth3;
480
481 {
482 Tree323f::ValueOffCIter iter = tree.cbeginValueOff();
483
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(iter.test());
484
485 // Read all inactive tile and voxel values through a non-const value iterator.
486 1 size_t numOff = 0;
487
2/2
✓ Branch 0 taken 2170 times.
✓ Branch 1 taken 1 times.
2171 for ( ; iter; ++iter) {
488
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 2170 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.
2170 EXPECT_TRUE(!iter.isValueOn());
489
1/2
✓ Branch 1 taken 2170 times.
✗ Branch 2 not taken.
2170 ++numOff;
490 }
491
1/14
✗ 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 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(expectedNumOff, numOff);
492 }
493 {
494 // Repeat, setting the minimum iterator depth to 2.
495 Tree323f::ValueOffCIter iter = tree.cbeginValueOff();
496
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(iter.test());
497
498 iter.setMinDepth(2);
499
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(iter.test());
500
501 1 size_t numOff = 0;
502
2/2
✓ Branch 0 taken 1148 times.
✓ Branch 1 taken 1 times.
1149 for ( ; iter; ++iter) {
503
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1148 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.
1148 EXPECT_TRUE(!iter.isValueOn());
504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148 times.
1148 ++numOff;
505 1148 const int depth = iter.getDepth();
506
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1148 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.
1148 EXPECT_TRUE(depth > 1);
507 }
508
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(expectedNumOff - numDepth1, numOff);
509 }
510 {
511 // Repeat, setting the minimum and maximum depths to 2.
512 Tree323f::ValueOffCIter iter = tree.cbeginValueOff();
513
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(iter.test());
514
515 iter.setMinDepth(2);
516
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(iter.test());
517
518 1 iter.setMaxDepth(2);
519
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(iter.test());
520
521 1 size_t numOff = 0;
522
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 1 times.
127 for ( ; iter; ++iter) {
523
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 126 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.
126 EXPECT_TRUE(!iter.isValueOn());
524
1/2
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
126 ++numOff;
525 126 const int depth = iter.getDepth();
526
2/16
✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 126 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.
126 EXPECT_EQ(2, depth);
527 }
528
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(expectedNumOff - numDepth1 - numDepth3, numOff);
529 }
530 {
531 // FX-7884 regression test
532 using namespace openvdb;
533
534 const float radius = 4.3f, voxelSize = 0.1f, width = 2.0f;
535 const Vec3f center(15.8f, 13.2f, 16.7f);
536 FloatGrid::Ptr sphereGrid = tools::createLevelSetSphere<FloatGrid>(
537
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 radius, center, voxelSize, width);
538 const FloatTree& sphereTree = sphereGrid->tree();
539
540 FloatGrid::ValueOffIter iter = sphereGrid->beginValueOff();
541 1 iter.setMaxDepth(2);
542
2/2
✓ Branch 0 taken 56675 times.
✓ Branch 1 taken 1 times.
56676 for ( ; iter; ++iter) {
543
1/2
✓ Branch 1 taken 56675 times.
✗ Branch 2 not taken.
56675 const Coord ijk = iter.getCoord();
544
3/18
✓ Branch 1 taken 56675 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 56675 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 56675 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.
56675 ASSERT_DOUBLES_EXACTLY_EQUAL(sphereTree.getValue(ijk), *iter);
545 }
546 }
547 {
548 // FX-10221 regression test
549 // This code generated an infinite loop in OpenVDB 5.1.0 and earlier:
550 2 openvdb::FloatTree emptyTree;
551 auto iter = emptyTree.cbeginValueAll();
552 iter.setMinDepth(2);
553
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(!iter);
554 }
555 1 }
556