GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestTreeVisitor.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 119 120 99.2%
Functions: 109 125 87.2%
Branches: 224 854 26.2%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @file TestTreeVisitor.h
5 ///
6 /// @author Peter Cucka
7
8 #include <openvdb/openvdb.h>
9 #include <openvdb/tree/Tree.h>
10
11 #include <gtest/gtest.h>
12
13 #include <map>
14 #include <set>
15 #include <sstream>
16 #include <type_traits>
17
18
19 6 class TestTreeVisitor: public ::testing::Test
20 {
21 public:
22 6 void SetUp() override { openvdb::initialize(); }
23 6 void TearDown() override { openvdb::uninitialize(); }
24
25 void testVisitTreeBool() { visitTree<openvdb::BoolTree>(); }
26 void testVisitTreeInt32() { visitTree<openvdb::Int32Tree>(); }
27 void testVisitTreeFloat() { visitTree<openvdb::FloatTree>(); }
28 void testVisitTreeVec2I() { visitTree<openvdb::Vec2ITree>(); }
29 void testVisitTreeVec3S() { visitTree<openvdb::VectorTree>(); }
30 void testVisit2Trees();
31
32 protected:
33 template<typename TreeT> TreeT createTestTree() const;
34 template<typename TreeT> void visitTree();
35 };
36
37
38 ////////////////////////////////////////
39
40
41 template<typename TreeT>
42 TreeT
43 14 TestTreeVisitor::createTestTree() const
44 {
45 using ValueT = typename TreeT::ValueType;
46 14 const ValueT zero = openvdb::zeroVal<ValueT>(), one = zero + 1;
47
48 // Create a sparse test tree comprising the eight corners of
49 // a 200 x 200 x 200 cube.
50 14 TreeT tree(/*background=*/one);
51
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord( 0, 0, 0), /*value=*/zero);
52
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord(200, 0, 0), zero);
53
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord( 0, 200, 0), zero);
54
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord( 0, 0, 200), zero);
55
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord(200, 0, 200), zero);
56
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord( 0, 200, 200), zero);
57
1/2
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
14 tree.setValue(openvdb::Coord(200, 200, 0), zero);
58 tree.setValue(openvdb::Coord(200, 200, 200), zero);
59
60 // Verify that the bounding box of all On values is 200 x 200 x 200.
61 14 openvdb::CoordBBox bbox;
62
2/18
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 7 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.
14 EXPECT_TRUE(tree.evalActiveVoxelBoundingBox(bbox));
63
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 7 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.
14 EXPECT_TRUE(bbox.min() == openvdb::Coord(0, 0, 0));
64
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 7 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.
14 EXPECT_TRUE(bbox.max() == openvdb::Coord(200, 200, 200));
65
66 14 return tree;
67 }
68
69
70 ////////////////////////////////////////
71
72
73 namespace {
74
75 /// Single-tree visitor that accumulates node counts
76 class Visitor
77 {
78 public:
79 using NodeMap = std::map<openvdb::Index, std::set<const void*> >;
80
81 15 Visitor(): mSkipLeafNodes(false) { reset(); }
82
83 void reset()
84 {
85 mSkipLeafNodes = false;
86 mNodes.clear();
87
10/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 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
10 mNonConstIterUseCount = mConstIterUseCount = 0;
88 }
89
90
5/10
✓ 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 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
5 void setSkipLeafNodes(bool b) { mSkipLeafNodes = b; }
91
92 template<typename IterT>
93 2048030 bool operator()(IterT& iter)
94 {
95 incrementIterUseCount(std::is_const<typename IterT::NodeType>::value);
96
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1024015 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.
2048030 EXPECT_TRUE(iter.getParentNode() != nullptr);
97
98
2/2
✓ Branch 0 taken 327685 times.
✓ Branch 1 taken 696330 times.
2048030 if (mSkipLeafNodes && iter.parent().getLevel() == 1) return true;
99
100 using ValueT = typename IterT::NonConstValueType;
101 using ChildT = typename IterT::ChildNodeType;
102 ValueT value;
103
2/2
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 819000 times.
1720320 if (const ChildT* child = iter.probeChild(value)) {
104 430 insertChild<ChildT>(child);
105 }
106 return false;
107 }
108
109 15 openvdb::Index leafCount() const
110 {
111
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 5 times.
15 NodeMap::const_iterator it = mNodes.find(0);
112
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
15 return openvdb::Index((it != mNodes.end()) ? it->second.size() : 0);
113 }
114 15 openvdb::Index nonLeafCount() const
115 {
116 openvdb::Index count = 1; // root node
117
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 15 times.
55 for (NodeMap::const_iterator i = mNodes.begin(), e = mNodes.end(); i != e; ++i) {
118
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10 times.
40 if (i->first != 0) count = openvdb::Index(count + i->second.size());
119 }
120 15 return count;
121 }
122
123 bool usedOnlyConstIterators() const
124 {
125
20/40
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✓ Branch 39 taken 1 times.
10 return (mConstIterUseCount > 0 && mNonConstIterUseCount == 0);
126 }
127 bool usedOnlyNonConstIterators() const
128 {
129
10/20
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
5 return (mConstIterUseCount == 0 && mNonConstIterUseCount > 0);
130 }
131
132 private:
133 template<typename ChildT>
134 430 void insertChild(const ChildT* child)
135 {
136
1/2
✓ Branch 0 taken 215 times.
✗ Branch 1 not taken.
430 if (child != nullptr) {
137 430 const openvdb::Index level = child->getLevel();
138
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
160 if (!mSkipLeafNodes || level > 0) {
139 430 mNodes[level].insert(child);
140 }
141 }
142 430 }
143
144 void incrementIterUseCount(bool isConst)
145 {
146
40/80
✗ Branch 0 not taken.
✓ Branch 1 taken 4096 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4096 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4096 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4096 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4096 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 4096 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 4096 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4096 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 4096 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 32768 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 65536 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 32768 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 65536 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 32768 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 65536 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 32768 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 65536 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 32768 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 65536 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 32768 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 65536 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 32768 times.
✗ Branch 46 not taken.
✓ Branch 47 taken 65536 times.
✗ Branch 48 not taken.
✓ Branch 49 taken 32768 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 65536 times.
✗ Branch 52 not taken.
✓ Branch 53 taken 32768 times.
✗ Branch 54 not taken.
✓ Branch 55 taken 65536 times.
✗ Branch 56 not taken.
✓ Branch 57 taken 32768 times.
✗ Branch 58 not taken.
✓ Branch 59 taken 65536 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 63 taken 2 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 1 times.
✗ Branch 66 not taken.
✓ Branch 67 taken 2 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 1 times.
✗ Branch 70 not taken.
✓ Branch 71 taken 2 times.
✗ Branch 72 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 75 taken 2 times.
✗ Branch 76 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 79 taken 2 times.
1024015 if (isConst) ++mConstIterUseCount; else ++mNonConstIterUseCount;
147 }
148
149 bool mSkipLeafNodes;
150 NodeMap mNodes;
151 int mNonConstIterUseCount, mConstIterUseCount;
152 };
153
154 /// Specialization for LeafNode iterators, whose ChildNodeType is void
155 /// (therefore can't call child->getLevel())
156 template<> inline void Visitor::insertChild<void>(const void*) {}
157
158 } // unnamed namespace
159
160
161 template<typename TreeT>
162 void
163 10 TestTreeVisitor::visitTree()
164 {
165 OPENVDB_NO_DEPRECATION_WARNING_BEGIN
166
167 20 TreeT tree = createTestTree<TreeT>();
168 {
169 // Traverse the tree, accumulating node counts.
170 Visitor visitor;
171 const_cast<const TreeT&>(tree).visit(visitor);
172
173
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 5 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(visitor.usedOnlyConstIterators());
174
3/18
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 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.
10 EXPECT_EQ(tree.leafCount(), visitor.leafCount());
175
3/18
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 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.
10 EXPECT_EQ(tree.nonLeafCount(), visitor.nonLeafCount());
176 }
177 {
178 // Traverse the tree, accumulating node counts as above,
179 // but using non-const iterators.
180 Visitor visitor;
181 tree.visit(visitor);
182
183
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 5 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(visitor.usedOnlyNonConstIterators());
184
3/18
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 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.
10 EXPECT_EQ(tree.leafCount(), visitor.leafCount());
185
3/18
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 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.
10 EXPECT_EQ(tree.nonLeafCount(), visitor.nonLeafCount());
186 }
187 {
188 // Traverse the tree, accumulating counts of non-leaf nodes only.
189 Visitor visitor;
190 visitor.setSkipLeafNodes(true);
191 const_cast<const TreeT&>(tree).visit(visitor);
192
193
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 5 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(visitor.usedOnlyConstIterators());
194
2/16
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 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.
10 EXPECT_EQ(0U, visitor.leafCount()); // leaf nodes were skipped
195
3/18
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 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.
10 EXPECT_EQ(tree.nonLeafCount(), visitor.nonLeafCount());
196 }
197
198 OPENVDB_NO_DEPRECATION_WARNING_END
199 10 }
200
201
202 ////////////////////////////////////////
203
204
205 namespace {
206
207 /// Two-tree visitor that accumulates node counts
208 class Visitor2
209 {
210 public:
211 using NodeMap = std::map<openvdb::Index, std::set<const void*> >;
212
213 1 Visitor2() { reset(); }
214
215 5 void reset()
216 {
217 5 mSkipALeafNodes = mSkipBLeafNodes = false;
218 mANodeCount.clear();
219 mBNodeCount.clear();
220 5 }
221
222
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 void setSkipALeafNodes(bool b) { mSkipALeafNodes = b; }
223
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 void setSkipBLeafNodes(bool b) { mSkipBLeafNodes = b; }
224
225 5 openvdb::Index aLeafCount() const { return leafCount(/*useA=*/true); }
226 5 openvdb::Index bLeafCount() const { return leafCount(/*useA=*/false); }
227 5 openvdb::Index aNonLeafCount() const { return nonLeafCount(/*useA=*/true); }
228 5 openvdb::Index bNonLeafCount() const { return nonLeafCount(/*useA=*/false); }
229
230 template<typename AIterT, typename BIterT>
231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 497161 times.
994322 int operator()(AIterT& aIter, BIterT& bIter)
232 {
233
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 497161 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.
994322 EXPECT_TRUE(aIter.getParentNode() != nullptr);
234
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 497161 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.
994322 EXPECT_TRUE(bIter.getParentNode() != nullptr);
235
236 994322 typename AIterT::NodeType& aNode = aIter.parent();
237 994322 typename BIterT::NodeType& bNode = bIter.parent();
238
239 994322 const openvdb::Index aLevel = aNode.getLevel(), bLevel = bNode.getLevel();
240 994322 mANodeCount[aLevel].insert(&aNode);
241 994322 mBNodeCount[bLevel].insert(&bNode);
242
243 int skipBranch = 0;
244
4/4
✓ Branch 0 taken 172032 times.
✓ Branch 1 taken 325129 times.
✓ Branch 2 taken 36864 times.
✓ Branch 3 taken 135168 times.
994322 if (aLevel == 1 && mSkipALeafNodes) skipBranch = (skipBranch | 1);
245
4/4
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 316937 times.
✓ Branch 2 taken 40960 times.
✓ Branch 3 taken 139264 times.
994322 if (bLevel == 1 && mSkipBLeafNodes) skipBranch = (skipBranch | 2);
246 994322 return skipBranch;
247 }
248
249 private:
250 10 openvdb::Index leafCount(bool useA) const
251 {
252
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 const NodeMap& theMap = (useA ? mANodeCount : mBNodeCount);
253
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 2 times.
10 NodeMap::const_iterator it = theMap.find(0);
254
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 if (it != theMap.end()) return openvdb::Index(it->second.size());
255 return 0;
256 }
257 10 openvdb::Index nonLeafCount(bool useA) const
258 {
259 openvdb::Index count = 0;
260
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 const NodeMap& theMap = (useA ? mANodeCount : mBNodeCount);
261
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 10 times.
48 for (NodeMap::const_iterator i = theMap.begin(), e = theMap.end(); i != e; ++i) {
262
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 8 times.
38 if (i->first != 0) count = openvdb::Index(count + i->second.size());
263 }
264 10 return count;
265 }
266
267 bool mSkipALeafNodes, mSkipBLeafNodes;
268 NodeMap mANodeCount, mBNodeCount;
269 };
270
271 } // unnamed namespace
272
273
274
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestTreeVisitor, testVisitTreeBool) { visitTree<openvdb::BoolTree>(); }
275
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestTreeVisitor, testVisitTreeInt32) { visitTree<openvdb::Int32Tree>(); }
276
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestTreeVisitor, testVisitTreeFloat) { visitTree<openvdb::FloatTree>(); }
277
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestTreeVisitor, testVisitTreeVec2I) { visitTree<openvdb::Vec2ITree>(); }
278
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestTreeVisitor, testVisitTreeVec3S) { visitTree<openvdb::VectorTree>(); }
279
280
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestTreeVisitor, testVisit2Trees)
281 {
282 OPENVDB_NO_DEPRECATION_WARNING_BEGIN
283
284 using TreeT = openvdb::FloatTree;
285 using Tree2T = openvdb::VectorTree;
286 using ValueT = TreeT::ValueType;
287
288 // Create a test tree.
289 2 TreeT tree = createTestTree<TreeT>();
290 // Create another test tree of a different type but with the same topology.
291
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Tree2T tree2 = createTestTree<Tree2T>();
292
293 // Traverse both trees.
294 1 Visitor2 visitor;
295 tree.visit2(tree2, visitor);
296
297 //EXPECT_TRUE(visitor.usedOnlyConstIterators());
298
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(tree.leafCount(), visitor.aLeafCount());
299
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(tree2.leafCount(), visitor.bLeafCount());
300
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(tree.nonLeafCount(), visitor.aNonLeafCount());
301
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(tree2.nonLeafCount(), visitor.bNonLeafCount());
302
303 1 visitor.reset();
304
305 // Change the topology of the first tree.
306
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(-200, -200, -200), openvdb::zeroVal<ValueT>());
307
308 // Traverse both trees.
309 tree.visit2(tree2, visitor);
310
311
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(tree.leafCount(), visitor.aLeafCount());
312
4/20
✓ 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 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_EQ(tree2.leafCount(), visitor.bLeafCount());
313
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(tree.nonLeafCount(), visitor.aNonLeafCount());
314
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(tree2.nonLeafCount(), visitor.bNonLeafCount());
315
316 1 visitor.reset();
317
318 // Traverse the two trees in the opposite order.
319 tree2.visit2(tree, visitor);
320
321
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(tree2.leafCount(), visitor.aLeafCount());
322
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(tree.leafCount(), visitor.bLeafCount());
323
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(tree2.nonLeafCount(), visitor.aNonLeafCount());
324
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(tree.nonLeafCount(), visitor.bNonLeafCount());
325
326 // Repeat, skipping leaf nodes of tree2.
327 1 visitor.reset();
328 visitor.setSkipALeafNodes(true);
329 tree2.visit2(tree, visitor);
330
331
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(0U, visitor.aLeafCount());
332
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(tree.leafCount(), visitor.bLeafCount());
333
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(tree2.nonLeafCount(), visitor.aNonLeafCount());
334
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(tree.nonLeafCount(), visitor.bNonLeafCount());
335
336 // Repeat, skipping leaf nodes of tree.
337 1 visitor.reset();
338 visitor.setSkipBLeafNodes(true);
339 tree2.visit2(tree, visitor);
340
341
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(tree2.leafCount(), visitor.aLeafCount());
342
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(0U, visitor.bLeafCount());
343
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(tree2.nonLeafCount(), visitor.aNonLeafCount());
344
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(tree.nonLeafCount(), visitor.bNonLeafCount());
345
346 OPENVDB_NO_DEPRECATION_WARNING_END
347 1 }
348