GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestNodeManager.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 119 119 100.0%
Functions: 11 11 100.0%
Branches: 150 674 22.3%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include <openvdb/Exceptions.h>
5 #include <openvdb/Types.h>
6 #include <openvdb/tree/NodeManager.h>
7 #include <openvdb/tree/LeafManager.h>
8 #include "util.h" // for unittest_util::makeSphere()
9 #include <gtest/gtest.h>
10
11
12 3 class TestNodeManager: public ::testing::Test
13 {
14 public:
15 3 void SetUp() override { openvdb::initialize(); }
16 3 void TearDown() override { openvdb::uninitialize(); }
17 };
18
19
20 namespace {
21
22 template<typename TreeT>
23
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
4 struct NodeCountOp {
24
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.
3 NodeCountOp() : nodeCount(TreeT::DEPTH, 0), totalCount(0)
25 {
26 }
27 2 NodeCountOp(const NodeCountOp&, tbb::split)
28
1/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 : nodeCount(TreeT::DEPTH, 0), totalCount(0)
29 {
30 }
31 void join(const NodeCountOp& other)
32 {
33
2/16
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 8 times.
✓ Branch 15 taken 2 times.
10 for (size_t i = 0; i < nodeCount.size(); ++i) {
34 8 nodeCount[i] += other.nodeCount[i];
35 }
36 2 totalCount += other.totalCount;
37 }
38 // do nothing for the root node
39 bool operator()(const typename TreeT::RootNodeType&, size_t = 0)
40 {
41 return true;
42 }
43 // count the internal and leaf nodes
44 template<typename NodeT>
45 bool operator()(const NodeT&, size_t = 0)
46 {
47 828 ++(nodeCount[NodeT::LEVEL]);
48 828 ++totalCount;
49 return true;
50 }
51 std::vector<openvdb::Index64> nodeCount;
52 openvdb::Index64 totalCount;
53 };// NodeCountOp
54
55 }//unnamed namespace
56
57
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestNodeManager, testAll)
58 {
59 using openvdb::CoordBBox;
60 using openvdb::Coord;
61 using openvdb::Vec3f;
62 using openvdb::Index64;
63 using openvdb::FloatGrid;
64 using openvdb::FloatTree;
65
66 const Vec3f center(0.35f, 0.35f, 0.35f);
67 const float radius = 0.15f;
68 const int dim = 128, half_width = 5;
69 const float voxel_size = 1.0f/dim;
70
71
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/half_width*voxel_size);
72 FloatTree& tree = grid->tree();
73
3/6
✓ 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.
2 grid->setTransform(openvdb::math::Transform::createLinearTransform(/*voxel size=*/voxel_size));
74
75
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 unittest_util::makeSphere<FloatGrid>(Coord(dim), center,
76 radius, *grid, unittest_util::SPHERE_SPARSE_NARROW_BAND);
77
78
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(FloatTree::DEPTH));
79
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(3, int(openvdb::tree::NodeManager<FloatTree>::LEVELS));
80
81 std::vector<Index64> nodeCount;
82
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
5 for (openvdb::Index i=0; i<FloatTree::DEPTH; ++i) nodeCount.push_back(0);
83
3/4
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 208 times.
✗ Branch 4 not taken.
209 for (FloatTree::NodeCIter it = tree.cbeginNode(); it; ++it) ++(nodeCount[it.getLevel()]);
84
85 //for (size_t i=0; i<nodeCount.size(); ++i) {//includes the root node
86 // std::cerr << "Level=" << i << " nodes=" << nodeCount[i] << std::endl;
87 //}
88
89 {// test tree constructor
90
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 openvdb::tree::NodeManager<FloatTree> manager(tree);
91
92 //for (openvdb::Index i=0; i<openvdb::tree::NodeManager<FloatTree>::LEVELS; ++i) {
93 // std::cerr << "Level=" << i << " nodes=" << manager.nodeCount(i) << std::endl;
94 //}
95
96 1 Index64 totalCount = 0;
97
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (openvdb::Index i=0; i<FloatTree::RootNodeType::LEVEL; ++i) {//exclude root in nodeCount
98 //std::cerr << "Level=" << i << " expected=" << nodeCount[i]
99 // << " cached=" << manager.nodeCount(i) << std::endl;
100
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(nodeCount[i], manager.nodeCount(i));
101 3 totalCount += nodeCount[i];
102 }
103
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(totalCount, manager.nodeCount());
104
105 // test the map reduce functionality
106 NodeCountOp<FloatTree> bottomUpOp;
107 NodeCountOp<FloatTree> topDownOp;
108
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceBottomUp(bottomUpOp);
109
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceTopDown(topDownOp);
110
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (openvdb::Index i=0; i<FloatTree::RootNodeType::LEVEL; ++i) {//exclude root in nodeCount
111
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(bottomUpOp.nodeCount[i], manager.nodeCount(i));
112
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(topDownOp.nodeCount[i], manager.nodeCount(i));
113 }
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 EXPECT_EQ(bottomUpOp.totalCount, manager.nodeCount());
115
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(topDownOp.totalCount, manager.nodeCount());
116 }
117
118 {// test LeafManager constructor
119 typedef openvdb::tree::LeafManager<FloatTree> LeafManagerT;
120
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 LeafManagerT manager1(tree);
121
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(nodeCount[0], Index64(manager1.leafCount()));
122
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 openvdb::tree::NodeManager<LeafManagerT> manager2(manager1);
123 1 Index64 totalCount = 0;
124
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (openvdb::Index i=0; i<FloatTree::RootNodeType::LEVEL; ++i) {//exclude root in nodeCount
125 //std::cerr << "Level=" << i << " expected=" << nodeCount[i]
126 // << " cached=" << manager2.nodeCount(i) << std::endl;
127
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(nodeCount[i], Index64(manager2.nodeCount(i)));
128 3 totalCount += nodeCount[i];
129 }
130
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(totalCount, Index64(manager2.nodeCount()));
131
132 // test the map reduce functionality
133 NodeCountOp<FloatTree> bottomUpOp;
134 NodeCountOp<FloatTree> topDownOp;
135
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager2.reduceBottomUp(bottomUpOp);
136
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager2.reduceTopDown(topDownOp);
137
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (openvdb::Index i=0; i<FloatTree::RootNodeType::LEVEL; ++i) {//exclude root in nodeCount
138
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(bottomUpOp.nodeCount[i], manager2.nodeCount(i));
139
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(topDownOp.nodeCount[i], manager2.nodeCount(i));
140 }
141
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(bottomUpOp.totalCount, manager2.nodeCount());
142
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(topDownOp.totalCount, manager2.nodeCount());
143 }
144
145 1 }
146
147
148
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestNodeManager, testConst)
149 {
150 using namespace openvdb;
151
152 const Vec3f center(0.35f, 0.35f, 0.35f);
153 const int dim = 128, half_width = 5;
154 const float voxel_size = 1.0f/dim;
155
156
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 FloatGrid::Ptr grid = FloatGrid::create(/*background=*/half_width*voxel_size);
157 const FloatTree& tree = grid->constTree();
158
159
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 tree::NodeManager<const FloatTree> nodeManager(tree);
160
161 NodeCountOp<const FloatTree> topDownOp;
162
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 nodeManager.reduceTopDown(topDownOp);
163
164 std::vector<Index64> nodeCount;
165
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
5 for (openvdb::Index i=0; i<FloatTree::DEPTH; ++i) nodeCount.push_back(0);
166
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 for (FloatTree::NodeCIter it = tree.cbeginNode(); it; ++it) ++(nodeCount[it.getLevel()]);
167
168 1 Index64 totalCount = 0;
169
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (openvdb::Index i=0; i<FloatTree::RootNodeType::LEVEL; ++i) {//exclude root in nodeCount
170
2/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
3 EXPECT_EQ(nodeCount[i], nodeManager.nodeCount(i));
171 3 totalCount += nodeCount[i];
172 }
173
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(totalCount, nodeManager.nodeCount());
174
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(totalCount, topDownOp.totalCount);
175
176 // test DynamicNodeManager also works with a const tree
177
178 1 tree::DynamicNodeManager<const FloatTree> dynamicNodeManager(tree);
179
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dynamicNodeManager.reduceTopDown(topDownOp);
180
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(totalCount, topDownOp.totalCount);
181 1 }
182
183
184 namespace {
185
186 template<typename TreeT>
187 struct ExpandOp
188 {
189 using RootT = typename TreeT::RootNodeType;
190 using LeafT = typename TreeT::LeafNodeType;
191
192 2 explicit ExpandOp(bool zeroOnly = false) : mZeroOnly(zeroOnly) { }
193
194 // do nothing for the root node
195 bool operator()(RootT&, size_t = 1) const { return true; }
196
197 // count the internal and leaf nodes
198 template<typename NodeT>
199 38 bool operator()(NodeT& node, size_t idx = 1) const
200 {
201
2/2
✓ Branch 0 taken 163840 times.
✓ Branch 1 taken 19 times.
327718 for (auto iter = node.cbeginValueAll(); iter; ++iter) {
202 327680 const openvdb::Coord ijk = iter.getCoord();
203
6/6
✓ Branch 0 taken 71680 times.
✓ Branch 1 taken 92160 times.
✓ Branch 2 taken 65920 times.
✓ Branch 3 taken 5760 times.
✓ Branch 4 taken 65560 times.
✓ Branch 5 taken 360 times.
327680 if (ijk.x() < 256 && ijk.y() < 256 && ijk.z() < 256) {
204
2/4
✓ Branch 2 taken 65536 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65536 times.
✗ Branch 6 not taken.
131120 node.addChild(new typename NodeT::ChildNodeType(iter.getCoord(), NodeT::LEVEL, true));
205 }
206 }
207
208
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 10 times.
38 if (mZeroOnly) return idx == 0;
209 return true;
210 }
211
212 36864 bool operator()(LeafT& leaf, size_t /*idx*/ = 1) const
213 {
214
2/2
✓ Branch 1 taken 18874368 times.
✓ Branch 2 taken 36864 times.
18948096 for (auto iter = leaf.beginValueAll(); iter; ++iter) {
215 18874368 iter.setValue(iter.pos());
216 }
217
218 36864 return true;
219 }
220
221 bool mZeroOnly = false;
222 };// ExpandOp
223
224 template<typename TreeT>
225 struct RootOnlyOp
226 {
227 using RootT = typename TreeT::RootNodeType;
228
229 RootOnlyOp() = default;
230 RootOnlyOp(const RootOnlyOp&, tbb::split) { }
231 void join(const RootOnlyOp&) { }
232
233 // do nothing for the root node but return false
234 bool operator()(RootT&, size_t) const { return false; }
235
236 // throw on internal or leaf nodes
237 template<typename NodeOrLeafT>
238 bool operator()(NodeOrLeafT&, size_t) const
239 {
240 OPENVDB_THROW(openvdb::RuntimeError, "Should not process nodes below root.");
241 }
242 };// RootOnlyOp
243
244 template<typename TreeT>
245 struct SumOp {
246 using RootT = typename TreeT::RootNodeType;
247 using LeafT = typename TreeT::LeafNodeType;
248
249 4 explicit SumOp(bool zeroOnly = false) : mZeroOnly(zeroOnly) { }
250 13 SumOp(const SumOp& other, tbb::split): totalCount(0), mZeroOnly(other.mZeroOnly) { }
251 void join(const SumOp& other)
252 {
253 13 totalCount += other.totalCount;
254 }
255 // do nothing for the root node
256 bool operator()(const typename TreeT::RootNodeType&, size_t /*idx*/ = 0) { return true; }
257 // count the internal nodes
258 template<typename NodeT>
259 56 bool operator()(const NodeT& node, size_t idx = 0)
260 {
261
2/2
✓ Branch 0 taken 131040 times.
✓ Branch 1 taken 28 times.
262136 for (auto iter = node.cbeginValueAll(); iter; ++iter) {
262 262080 totalCount += *iter;
263 }
264
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 19 times.
56 if (mZeroOnly) return idx == 0;
265 return true;
266 }
267 // count the leaf nodes
268 69632 bool operator()(const LeafT& leaf, size_t /*idx*/ = 0)
269 {
270
2/2
✓ Branch 1 taken 35651584 times.
✓ Branch 2 taken 69632 times.
35790848 for (auto iter = leaf.cbeginValueAll(); iter; ++iter) {
271 35651584 totalCount += *iter;
272 }
273 69632 return true;
274 }
275 openvdb::Index64 totalCount = openvdb::Index64(0);
276 bool mZeroOnly = false;
277 };// SumOp
278
279 }//unnamed namespace
280
281
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestNodeManager, testDynamic)
282 {
283 using openvdb::Coord;
284 using openvdb::Index32;
285 using openvdb::Index64;
286 using openvdb::Int32Tree;
287
288 using RootNodeType = Int32Tree::RootNodeType;
289 using Internal1NodeType = RootNodeType::ChildNodeType;
290
291 2 Int32Tree sourceTree(0);
292
293 auto child =
294
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 std::make_unique<Internal1NodeType>(Coord(0, 0, 0), /*value=*/1.0f);
295
296
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(sourceTree.root().addChild(child.release()));
297
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(Index32(0), sourceTree.leafCount());
298
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(Index32(2), sourceTree.nonLeafCount());
299
300 ExpandOp<Int32Tree> expandOp;
301
302 { // use NodeManager::foreachTopDown
303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Int32Tree tree(sourceTree);
304
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 openvdb::tree::NodeManager<Int32Tree> manager(tree);
305
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(1), manager.nodeCount());
306
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.foreachTopDown(expandOp);
307
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(Index32(0), tree.leafCount());
308
309 // first level has been expanded, but node manager cache does not include the new nodes
310 SumOp<Int32Tree> sumOp;
311
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceBottomUp(sumOp);
312
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ 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 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_EQ(Index64(32760), sumOp.totalCount);
313 }
314
315 { // use DynamicNodeManager::foreachTopDown and filter out nodes below root
316
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Int32Tree tree(sourceTree);
317 1 openvdb::tree::DynamicNodeManager<Int32Tree> manager(tree);
318 RootOnlyOp<Int32Tree> rootOnlyOp;
319
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ 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 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_NO_THROW(manager.foreachTopDown(rootOnlyOp));
320
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ 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 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_NO_THROW(manager.reduceTopDown(rootOnlyOp));
321 }
322
323 { // use DynamicNodeManager::foreachTopDown
324
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Int32Tree tree(sourceTree);
325 1 openvdb::tree::DynamicNodeManager<Int32Tree> manager(tree);
326
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.foreachTopDown(expandOp, /*threaded=*/true, /*leafGrainSize=*/32, /*nonLeafGrainSize=*/8);
327
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(Index32(32768), tree.leafCount());
328
329 SumOp<Int32Tree> sumOp;
330
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceTopDown(sumOp);
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(Index64(4286611448), sumOp.totalCount);
332
333 SumOp<Int32Tree> zeroSumOp(true);
334
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceTopDown(zeroSumOp);
335
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(535855096), zeroSumOp.totalCount);
336 }
337
338 { // use DynamicNodeManager::foreachTopDown but filter nodes with non-zero index
339
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Int32Tree tree(sourceTree);
340 1 openvdb::tree::DynamicNodeManager<Int32Tree> manager(tree);
341 ExpandOp<Int32Tree> zeroExpandOp(true);
342
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.foreachTopDown(zeroExpandOp);
343
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(Index32(32768), tree.leafCount());
344
345 SumOp<Int32Tree> sumOp;
346
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 manager.reduceTopDown(sumOp);
347
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(550535160), sumOp.totalCount);
348 }
349 1 }
350