11#ifndef OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
12#define OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
14#include <openvdb/version.h>
26template <
typename TreeT>
32template <
typename TreeT>
37template <
typename TreeT>
43template <
typename TreeT>
48template <
typename TreeT>
53template <
typename TreeT>
58template <
typename TreeT>
63template <
typename TreeT>
70template <
typename TreeT>
71math::MinMax<typename TreeT::ValueType>
minMax(
const TreeT& tree,
bool threaded =
true);
78namespace count_internal {
81template<
typename TreeType>
82struct ActiveVoxelCountOp
84 using LeafT =
typename TreeType::LeafNodeType;
86 ActiveVoxelCountOp() =
default;
87 ActiveVoxelCountOp(
const ActiveVoxelCountOp&, tbb::split) { }
90 template<
typename NodeT>
91 bool operator()(
const NodeT& node,
size_t)
93 for (
auto iter = node.cbeginValueOn(); iter; ++iter) {
94 count += NodeT::ChildNodeType::NUM_VOXELS;
100 bool operator()(
const LeafT& leaf,
size_t)
102 count += leaf.onVoxelCount();
106 void join(
const ActiveVoxelCountOp& other)
108 count += other.count;
116template<
typename TreeType>
117struct ActiveVoxelCountBBoxOp
119 using LeafT =
typename TreeType::LeafNodeType;
121 explicit ActiveVoxelCountBBoxOp(
const CoordBBox& bbox)
123 ActiveVoxelCountBBoxOp(
const ActiveVoxelCountBBoxOp& other, tbb::split)
124 : mBBox(other.mBBox) { }
127 template<
typename NodeT>
128 bool operator()(
const NodeT& node,
size_t)
130 if (!mBBox.hasOverlap(node.getNodeBoundingBox()))
return false;
133 for (
auto iter = node.cbeginValueOn(); iter; ++iter) {
134 CoordBBox bbox(CoordBBox::createCube(iter.getCoord(), NodeT::ChildNodeType::DIM));
136 if (!bbox.hasOverlap(mBBox)) {
139 }
else if (bbox.isInside(mBBox)) {
141 count += mBBox.volume();
142 }
else if (mBBox.isInside(bbox)) {
144 count += bbox.volume();
147 bbox.intersect(mBBox);
148 count += bbox.volume();
153 for (
auto iter = node.cbeginChildOn(); iter; ++iter) {
154 if (mBBox.hasOverlap(iter->getNodeBoundingBox()))
return true;
162 inline bool operator()(
const LeafT& leaf,
size_t)
166 CoordBBox bbox = leaf.getNodeBoundingBox();
168 if (mBBox.isInside(bbox)) {
170 count += leaf.onVoxelCount();
171 }
else if (!bbox.hasOverlap(mBBox)) {
174 }
else if (leaf.isDense()) {
176 bbox.intersect(mBBox);
177 count += bbox.volume();
180 for (
auto i = leaf.cbeginValueOn(); i; ++i) {
181 if (mBBox.isInside(i.getCoord())) ++count;
187 void join(
const ActiveVoxelCountBBoxOp& other)
189 count += other.count;
198template<
typename TreeType>
199struct InactiveVoxelCountOp
201 using RootT =
typename TreeType::RootNodeType;
202 using LeafT =
typename TreeType::LeafNodeType;
204 InactiveVoxelCountOp() =
default;
205 InactiveVoxelCountOp(
const InactiveVoxelCountOp&, tbb::split) { }
208 bool operator()(
const RootT& root,
size_t)
210 for (
auto iter = root.cbeginValueOff(); iter; ++iter) {
212 if (!math::isApproxEqual(*iter, root.background())) {
213 count += RootT::ChildNodeType::NUM_VOXELS;
220 template<
typename NodeT>
221 bool operator()(
const NodeT& node,
size_t)
223 for (
auto iter = node.cbeginValueOff(); iter; ++iter) {
224 if (node.isChildMaskOff(iter.pos())) {
225 count += NodeT::ChildNodeType::NUM_VOXELS;
232 bool operator()(
const LeafT& leaf,
size_t)
234 count += leaf.offVoxelCount();
238 void join(
const InactiveVoxelCountOp& other)
240 count += other.count;
247template<
typename TreeType>
248struct ActiveTileCountOp
250 using RootT =
typename TreeType::RootNodeType;
251 using LeafT =
typename TreeType::LeafNodeType;
253 ActiveTileCountOp() =
default;
254 ActiveTileCountOp(
const ActiveTileCountOp&, tbb::split) { }
257 bool operator()(
const RootT& root,
size_t)
259 for (
auto iter = root.cbeginValueOn(); iter; ++iter) count++;
264 template<
typename NodeT>
265 bool operator()(
const NodeT& node,
size_t)
267 count += node.getValueMask().countOn();
272 bool operator()(
const LeafT&,
size_t)
277 void join(
const ActiveTileCountOp& other)
279 count += other.count;
286template<
typename TreeType>
289 using RootT =
typename TreeType::RootNodeType;
290 using LeafT =
typename TreeType::LeafNodeType;
292 MemUsageOp() =
default;
293 MemUsageOp(
const MemUsageOp& other) =
default;
294 MemUsageOp(
const MemUsageOp&, tbb::split) : mCount(0) {}
297 bool operator()(
const RootT& root,
size_t)
299 mCount +=
sizeof(root);
304 template<
typename NodeT>
305 bool operator()(
const NodeT& node,
size_t)
307 mCount += NodeT::NUM_VALUES *
sizeof(
typename NodeT::UnionType) +
308 node.getChildMask().memUsage() + node.getValueMask().memUsage() +
314 bool operator()(
const LeafT& leaf,
size_t)
316 mCount += leaf.memUsage();
320 void join(
const MemUsageOp& other)
322 mCount += other.mCount;
329template<
typename TreeType>
332 using ValueT =
typename TreeType::ValueType;
334 explicit MinMaxValuesOp()
337 , seen_value(false) {}
339 MinMaxValuesOp(
const MinMaxValuesOp&, tbb::split)
340 : MinMaxValuesOp() {}
342 template <
typename NodeType>
343 bool operator()(NodeType& node,
size_t)
345 if (
auto iter = node.cbeginValueOn()) {
352 for (; iter; ++iter) {
353 const ValueT val = *iter;
355 if (math::cwiseLessThan(val, min))
358 if (math::cwiseGreaterThan(val, max))
366 bool join(
const MinMaxValuesOp& other)
368 if (!other.seen_value)
return true;
375 if (math::cwiseLessThan(other.min, min))
377 if (math::cwiseGreaterThan(other.max, max))
400template <
typename TreeT>
403 count_internal::ActiveVoxelCountOp<TreeT> op;
410template <
typename TreeT>
416 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
423template <
typename TreeT>
426 count_internal::ActiveVoxelCountOp<TreeT> op;
429 leafManager.
reduce(op, threaded);
434template <
typename TreeT>
440 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
443 leafManager.
reduce(op, threaded);
448template <
typename TreeT>
451 count_internal::InactiveVoxelCountOp<TreeT> op;
458template <
typename TreeT>
461 count_internal::InactiveVoxelCountOp<TreeT> op;
464 leafManager.
reduce(op, threaded);
469template <
typename TreeT>
472 count_internal::ActiveTileCountOp<TreeT> op;
475 nodeManager.reduceTopDown(op, threaded);
480template <
typename TreeT>
483 count_internal::MemUsageOp<TreeT> op;
486 return op.mCount +
sizeof(
tree);
490template <
typename TreeT>
493 using ValueT =
typename TreeT::ValueType;
495 count_internal::MinMaxValuesOp<TreeT> op;
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Classes to compute statistics and histograms.
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition Coord.h:322
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition Coord.h:359
Templated class to compute the minimum and maximum values.
Definition Stats.h:32
Definition NodeManager.h:891
void reduceTopDown(NodeOp &op, bool threaded=true, size_t leafGrainSize=1, size_t nonLeafGrainSize=1)
Threaded method that processes nodes with a user supplied functor.
Definition NodeManager.h:1044
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition LeafManager.h:86
void reduce(LeafOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager....
Definition LeafManager.h:533
math::BBox< Coord > CoordBBox
Definition Math.h:2838
Definition PointDataGrid.h:48
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
uint64_t Index64
Definition Types.h:33
Definition Exceptions.h:13
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:291