GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/tools/Count.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 125 138 90.6%
Functions: 134 881 15.2%
Branches: 83 301 27.6%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @file Count.h
5 ///
6 /// @brief Functions to count tiles, nodes or voxels in a grid
7 ///
8 /// @author Dan Bailey
9 ///
10
11 #ifndef OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
12 #define OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
13
14 #include <openvdb/version.h>
15 #include <openvdb/math/Stats.h>
16 #include <openvdb/tree/LeafManager.h>
17 #include <openvdb/tree/NodeManager.h>
18
19 namespace openvdb {
20 OPENVDB_USE_VERSION_NAMESPACE
21 namespace OPENVDB_VERSION_NAME {
22 namespace tools {
23
24
25 /// @brief Return the total number of active voxels in the tree.
26 template <typename TreeT>
27 Index64 countActiveVoxels(const TreeT& tree, bool threaded = true);
28
29
30 /// @brief Return the total number of active voxels in the tree that intersects
31 /// a bounding box.
32 template <typename TreeT>
33 Index64 countActiveVoxels(const TreeT& tree, const CoordBBox& bbox, bool threaded = true);
34
35
36 /// @brief Return the total number of active voxels stored in leaf nodes.
37 template <typename TreeT>
38 Index64 countActiveLeafVoxels(const TreeT& tree, bool threaded = true);
39
40
41 /// @brief Return the total number of active voxels stored in leaf nodes that intersects
42 /// a bounding box.
43 template <typename TreeT>
44 Index64 countActiveLeafVoxels(const TreeT& tree, const CoordBBox& bbox, bool threaded = true);
45
46
47 /// @brief Return the total number of inactive voxels in the tree.
48 template <typename TreeT>
49 Index64 countInactiveVoxels(const TreeT& tree, bool threaded = true);
50
51
52 /// @brief Return the total number of inactive voxels stored in leaf nodes.
53 template <typename TreeT>
54 Index64 countInactiveLeafVoxels(const TreeT& tree, bool threaded = true);
55
56
57 /// @brief Return the total number of active tiles in the tree.
58 template <typename TreeT>
59 Index64 countActiveTiles(const TreeT& tree, bool threaded = true);
60
61
62 /// @brief Return the total amount of memory in bytes occupied by this tree.
63 /// @details This method returns the total in-core memory usage which can be
64 /// different to the maximum possible memory usage for trees which have not
65 /// been fully deserialized (via delay-loading). Thus, this is the current
66 /// true memory consumption.
67 template <typename TreeT>
68 Index64 memUsage(const TreeT& tree, bool threaded = true);
69
70
71 /// @brief Return the deserialized memory usage of this tree. This is not
72 /// necessarily equal to the current memory usage (returned by tools::memUsage)
73 /// if delay-loading is enabled. See File::open.
74 template <typename TreeT>
75 Index64 memUsageIfLoaded(const TreeT& tree, bool threaded = true);
76
77
78 /// @brief Return the minimum and maximum active values in this tree.
79 /// @note Returns zeroVal<ValueType> for empty trees.
80 template <typename TreeT>
81 math::MinMax<typename TreeT::ValueType> minMax(const TreeT& tree, bool threaded = true);
82
83
84 ////////////////////////////////////////
85
86 /// @cond OPENVDB_DOCS_INTERNAL
87
88 namespace count_internal {
89
90 /// @brief A DynamicNodeManager operator to count active voxels in a tree
91 template<typename TreeType>
92 struct ActiveVoxelCountOp
93 {
94 using LeafT = typename TreeType::LeafNodeType;
95
96 ActiveVoxelCountOp() = default;
97 6510 ActiveVoxelCountOp(const ActiveVoxelCountOp&, tbb::split) { }
98
99 // accumulate all voxels in active tile children
100 template<typename NodeT>
101 142662 bool operator()(const NodeT& node, size_t)
102 {
103
3/3
✓ Branch 0 taken 4465260 times.
✓ Branch 1 taken 64695 times.
✓ Branch 2 taken 11007 times.
9103938 for (auto iter = node.cbeginValueOn(); iter; ++iter) {
104 8939262 count += NodeT::ChildNodeType::NUM_VOXELS;
105 }
106 142662 return true;
107 }
108
109 // accumulate all active voxels in the leaf
110 bool operator()(const LeafT& leaf, size_t)
111 {
112 20412411 count += leaf.onVoxelCount();
113 return false;
114 }
115
116 void join(const ActiveVoxelCountOp& other)
117 {
118 6510 count += other.count;
119 }
120
121 openvdb::Index64 count{0};
122 }; // struct ActiveVoxelCountOp
123
124 /// @brief A DynamicNodeManager operator to count active voxels in a tree
125 /// that fall within a provided bounding box
126 template<typename TreeType>
127 struct ActiveVoxelCountBBoxOp
128 {
129 using LeafT = typename TreeType::LeafNodeType;
130
131 6 explicit ActiveVoxelCountBBoxOp(const CoordBBox& bbox)
132
1/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
3 : mBBox(bbox) { }
133 23 ActiveVoxelCountBBoxOp(const ActiveVoxelCountBBoxOp& other, tbb::split)
134 23 : mBBox(other.mBBox) { }
135
136 // accumulate all voxels in active tile children bounded by the bbox
137 template<typename NodeT>
138 102 bool operator()(const NodeT& node, size_t)
139 {
140 192 if (!mBBox.hasOverlap(node.getNodeBoundingBox())) return false;
141
142 // count any overlapping regions in active tiles
143
3/3
✓ Branch 0 taken 18915 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 3 times.
37938 for (auto iter = node.cbeginValueOn(); iter; ++iter) {
144
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 16137 times.
✓ Branch 2 taken 2778 times.
37830 CoordBBox bbox(CoordBBox::createCube(iter.getCoord(), NodeT::ChildNodeType::DIM));
145
146 12930 if (!bbox.hasOverlap(mBBox)) {
147 // box is completely outside the active tile
148 12930 continue;
149 } else if (bbox.isInside(mBBox)) {
150 // bbox is completely inside the active tile
151 count += mBBox.volume();
152 } else if (mBBox.isInside(bbox)) {
153 // active tile is completely inside bbox
154 24588 count += bbox.volume();
155 } else {
156 // partial overlap between tile and bbox
157 312 bbox.intersect(mBBox);
158 312 count += bbox.volume();
159 }
160 }
161
162 // return true if any child nodes overlap with the bounding box
163
2/3
✓ Branch 0 taken 3612 times.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
7252 for (auto iter = node.cbeginChildOn(); iter; ++iter) {
164 14460 if (mBBox.hasOverlap(iter->getNodeBoundingBox())) return true;
165 }
166
167 // otherwise return false to prevent recursion along this branch
168 16 return false;
169 }
170
171 // accumulate all active voxels in the leaf bounded by the bbox
172 16315 inline bool operator()(const LeafT& leaf, size_t)
173 {
174 // note: the true/false return value does nothing
175
176 16315 CoordBBox bbox = leaf.getNodeBoundingBox();
177
178 if (mBBox.isInside(bbox)) {
179 // leaf node is completely inside bbox
180 10680 count += leaf.onVoxelCount();
181 } else if (!bbox.hasOverlap(mBBox)) {
182 // bbox is completely outside the leaf node
183 return false;
184
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 448 times.
536 } else if (leaf.isDense()) {
185 // partial overlap between dense leaf node and bbox
186 88 bbox.intersect(mBBox);
187 88 count += bbox.volume();
188 } else {
189 // partial overlap between sparse leaf node and bbox
190
2/2
✓ Branch 0 taken 107072 times.
✓ Branch 1 taken 448 times.
107520 for (auto i = leaf.cbeginValueOn(); i; ++i) {
191 214144 if (mBBox.isInside(i.getCoord())) ++count;
192 }
193 }
194 return false;
195 }
196
197 void join(const ActiveVoxelCountBBoxOp& other)
198 {
199 23 count += other.count;
200 }
201
202 openvdb::Index64 count{0};
203 private:
204 CoordBBox mBBox;
205 }; // struct ActiveVoxelCountBBoxOp
206
207 /// @brief A DynamicNodeManager operator to count inactive voxels in a tree
208 template<typename TreeType>
209 struct InactiveVoxelCountOp
210 {
211 using RootT = typename TreeType::RootNodeType;
212 using LeafT = typename TreeType::LeafNodeType;
213
214 InactiveVoxelCountOp() = default;
215 51 InactiveVoxelCountOp(const InactiveVoxelCountOp&, tbb::split) { }
216
217 // accumulate all inactive voxels in the root node
218 18 bool operator()(const RootT& root, size_t)
219 {
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
36 for (auto iter = root.cbeginValueOff(); iter; ++iter) {
221 // background tiles are not considered to contain inactive voxels
222 if (!math::isApproxEqual(*iter, root.background())) {
223 count += RootT::ChildNodeType::NUM_VOXELS;
224 }
225 }
226 18 return true;
227 }
228
229 // accumulate all voxels in inactive tile children
230 template<typename NodeT>
231 368 bool operator()(const NodeT& node, size_t)
232 {
233
2/2
✓ Branch 0 taken 2620622 times.
✓ Branch 1 taken 184 times.
5241612 for (auto iter = node.cbeginValueOff(); iter; ++iter) {
234
2/2
✓ Branch 0 taken 2599926 times.
✓ Branch 1 taken 20696 times.
5241244 if (node.isChildMaskOff(iter.pos())) {
235 5199852 count += NodeT::ChildNodeType::NUM_VOXELS;
236 }
237 }
238 368 return true;
239 }
240
241 // accumulate all inactive voxels in the leaf
242 bool operator()(const LeafT& leaf, size_t)
243 {
244 20580 count += leaf.offVoxelCount();
245 return false;
246 }
247
248 void join(const InactiveVoxelCountOp& other)
249 {
250 51 count += other.count;
251 }
252
253 openvdb::Index64 count{0};
254 }; // struct InactiveVoxelCountOp
255
256 /// @brief A DynamicNodeManager operator to count active tiles in a tree
257 template<typename TreeType>
258 struct ActiveTileCountOp
259 {
260 using RootT = typename TreeType::RootNodeType;
261 using LeafT = typename TreeType::LeafNodeType;
262
263 ActiveTileCountOp() = default;
264 141 ActiveTileCountOp(const ActiveTileCountOp&, tbb::split) { }
265
266 // accumulate all active tiles in root node
267 444 bool operator()(const RootT& root, size_t)
268 {
269
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 222 times.
924 for (auto iter = root.cbeginValueOn(); iter; ++iter) count++;
270 444 return true;
271 }
272
273 // accumulate all active tiles in internal node
274 template<typename NodeT>
275 bool operator()(const NodeT& node, size_t)
276 {
277 2304 count += node.getValueMask().countOn();
278 return true;
279 }
280
281 // do nothing (leaf nodes cannot contain tiles)
282 bool operator()(const LeafT&, size_t)
283 {
284 return false;
285 }
286
287 void join(const ActiveTileCountOp& other)
288 {
289 141 count += other.count;
290 }
291
292 openvdb::Index64 count{0};
293 }; // struct ActiveTileCountOp
294
295 /// @brief A DynamicNodeManager operator to sum the number of bytes of memory used
296 template<typename TreeType>
297 struct MemUsageOp
298 {
299 using RootT = typename TreeType::RootNodeType;
300 using LeafT = typename TreeType::LeafNodeType;
301
302 179 MemUsageOp(const bool inCoreOnly) : mInCoreOnly(inCoreOnly) {}
303 109 MemUsageOp(const MemUsageOp& other) : mCount(0), mInCoreOnly(other.mInCoreOnly) {}
304 MemUsageOp(const MemUsageOp& other, tbb::split) : MemUsageOp(other) {}
305
306 // accumulate size of the root node in bytes
307 bool operator()(const RootT& root, size_t)
308 {
309 179 mCount += sizeof(root);
310 return true;
311 }
312
313 // accumulate size of all child nodes in bytes
314 template<typename NodeT>
315 bool operator()(const NodeT& node, size_t)
316 {
317 928 mCount += NodeT::NUM_VALUES * sizeof(typename NodeT::UnionType) +
318 node.getChildMask().memUsage() + node.getValueMask().memUsage() +
319 sizeof(Coord);
320 return true;
321 }
322
323 // accumulate size of leaf node in bytes
324 bool operator()(const LeafT& leaf, size_t)
325 {
326
7/65
✓ Branch 0 taken 36212 times.
✓ Branch 1 taken 6526 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1766 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26904 times.
✓ Branch 6 taken 370 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4100 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4212 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 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.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
80090 if (mInCoreOnly) mCount += leaf.memUsage();
327 6526 else mCount += leaf.memUsageIfLoaded();
328 return false;
329 }
330
331 void join(const MemUsageOp& other)
332 {
333 109 mCount += other.mCount;
334 }
335
336 openvdb::Index64 mCount{0};
337 const bool mInCoreOnly;
338 }; // struct MemUsageOp
339
340 /// @brief A DynamicNodeManager operator to find the minimum and maximum active values in this tree.
341 template<typename TreeType>
342 struct MinMaxValuesOp
343 {
344 using ValueT = typename TreeType::ValueType;
345
346 110 explicit MinMaxValuesOp()
347 38 : min(zeroVal<ValueT>())
348 38 , max(zeroVal<ValueT>())
349
0/8
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
71 , seen_value(false) {}
350
351 8 MinMaxValuesOp(const MinMaxValuesOp&, tbb::split)
352
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
8 : MinMaxValuesOp() {}
353
354 template <typename NodeType>
355 3886 bool operator()(NodeType& node, size_t)
356 {
357
3/3
✓ Branch 0 taken 1753 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 46 times.
3978 if (auto iter = node.cbeginValueOn()) {
358
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1673 times.
3506 if (!seen_value) {
359 160 seen_value = true;
360 160 min = max = *iter;
361 ++iter;
362 }
363
364
2/2
✓ Branch 0 taken 421271 times.
✓ Branch 1 taken 1753 times.
846048 for (; iter; ++iter) {
365
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 421259 times.
842542 const ValueT val = *iter;
366
367
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 421269 times.
842540 if (math::cwiseLessThan(val, min))
368 4 min = val;
369
370
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 421261 times.
842540 if (math::cwiseGreaterThan(val, max))
371 18 max = val;
372 }
373 }
374
375 3886 return true;
376 }
377
378 14 bool join(const MinMaxValuesOp& other)
379 {
380
7/18
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ 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 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
19 if (!other.seen_value) return true;
381
382
5/36
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 30 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 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.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
43 if (!seen_value) {
383 min = other.min;
384 max = other.max;
385 }
386 else {
387
6/36
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 30 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 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.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
43 if (math::cwiseLessThan(other.min, min))
388 1 min = other.min;
389
7/36
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 30 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 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.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
43 if (math::cwiseGreaterThan(other.max, max))
390 8 max = other.max;
391 }
392
393 43 seen_value = true;
394 43 return true;
395 }
396
397 ValueT min, max;
398
399 private:
400
401 bool seen_value;
402 }; // struct MinMaxValuesOp
403
404 } // namespace count_internal
405
406 /// @endcond
407
408
409 ////////////////////////////////////////
410
411
412 template <typename TreeT>
413 21989 Index64 countActiveVoxels(const TreeT& tree, bool threaded)
414 {
415
1/2
✓ Branch 1 taken 11007 times.
✗ Branch 2 not taken.
21989 count_internal::ActiveVoxelCountOp<TreeT> op;
416 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
417
1/2
✓ Branch 1 taken 11007 times.
✗ Branch 2 not taken.
21989 nodeManager.reduceTopDown(op, threaded);
418
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
21989 return op.count;
419 }
420
421
422 template <typename TreeT>
423
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Index64 countActiveVoxels(const TreeT& tree, const CoordBBox& bbox, bool threaded)
424 {
425 if (bbox.empty()) return Index64(0);
426 6 else if (bbox == CoordBBox::inf()) return countActiveVoxels(tree, threaded);
427
428 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
429 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
430
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 nodeManager.reduceTopDown(op, threaded);
431 3 return op.count;
432 }
433
434
435 template <typename TreeT>
436 34 Index64 countActiveLeafVoxels(const TreeT& tree, bool threaded)
437 {
438 34 count_internal::ActiveVoxelCountOp<TreeT> op;
439 // use a leaf manager instead of a node manager
440 34 tree::LeafManager<const TreeT> leafManager(tree);
441
1/2
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
34 leafManager.reduce(op, threaded);
442 34 return op.count;
443 }
444
445
446 template <typename TreeT>
447
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Index64 countActiveLeafVoxels(const TreeT& tree, const CoordBBox& bbox, bool threaded)
448 {
449 if (bbox.empty()) return Index64(0);
450 6 else if (bbox == CoordBBox::inf()) return countActiveLeafVoxels(tree, threaded);
451
452 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
453 // use a leaf manager instead of a node manager
454 3 tree::LeafManager<const TreeT> leafManager(tree);
455
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 leafManager.reduce(op, threaded);
456 3 return op.count;
457 }
458
459
460 template <typename TreeT>
461 18 Index64 countInactiveVoxels(const TreeT& tree, bool threaded)
462 {
463
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 count_internal::InactiveVoxelCountOp<TreeT> op;
464 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
465
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 nodeManager.reduceTopDown(op, threaded);
466
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
18 return op.count;
467 }
468
469
470 template <typename TreeT>
471 18 Index64 countInactiveLeafVoxels(const TreeT& tree, bool threaded)
472 {
473 18 count_internal::InactiveVoxelCountOp<TreeT> op;
474 // use a leaf manager instead of a node manager
475 18 tree::LeafManager<const TreeT> leafManager(tree);
476
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
18 leafManager.reduce(op, threaded);
477 18 return op.count;
478 }
479
480
481 template <typename TreeT>
482 444 Index64 countActiveTiles(const TreeT& tree, bool threaded)
483 {
484
1/2
✓ Branch 1 taken 222 times.
✗ Branch 2 not taken.
444 count_internal::ActiveTileCountOp<TreeT> op;
485 // exclude leaf nodes as they cannot contain tiles
486 tree::DynamicNodeManager<const TreeT, TreeT::DEPTH-2> nodeManager(tree);
487
1/2
✓ Branch 1 taken 222 times.
✗ Branch 2 not taken.
444 nodeManager.reduceTopDown(op, threaded);
488
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
444 return op.count;
489 }
490
491
492 template <typename TreeT>
493
1/2
✓ Branch 1 taken 177 times.
✗ Branch 2 not taken.
354 Index64 memUsage(const TreeT& tree, bool threaded)
494 {
495 count_internal::MemUsageOp<TreeT> op(true);
496 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
497
1/2
✓ Branch 1 taken 177 times.
✗ Branch 2 not taken.
354 nodeManager.reduceTopDown(op, threaded);
498
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
354 return op.mCount + sizeof(tree);
499 }
500
501 template <typename TreeT>
502
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 Index64 memUsageIfLoaded(const TreeT& tree, bool threaded)
503 {
504 /// @note For numeric (non-point) grids this really doesn't need to
505 /// traverse the tree and could instead be computed from the node counts.
506 /// We do so anyway as it ties this method into the tree data structure
507 /// which makes sure that changes to the tree/nodes are reflected/kept in
508 /// sync here.
509 count_internal::MemUsageOp<TreeT> op(false);
510 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
511
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 nodeManager.reduceTopDown(op, threaded);
512 2 return op.mCount + sizeof(tree);
513 }
514
515 template <typename TreeT>
516
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
46 math::MinMax<typename TreeT::ValueType> minMax(const TreeT& tree, bool threaded)
517 {
518 using ValueT = typename TreeT::ValueType;
519
520 15 count_internal::MinMaxValuesOp<TreeT> op;
521 9 tree::DynamicNodeManager<const TreeT> nodeManager(tree);
522
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
46 nodeManager.reduceTopDown(op, threaded);
523
524 46 return math::MinMax<ValueT>(op.min, op.max);
525 }
526
527
528 } // namespace tools
529 } // namespace OPENVDB_VERSION_NAME
530 } // namespace openvdb
531
532 #endif // OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
533