11 #ifndef OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED 12 #define OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED 14 #include <openvdb/version.h> 25 template <
typename TreeT>
31 template <
typename TreeT>
36 template <
typename TreeT>
42 template <
typename TreeT>
47 template <
typename TreeT>
52 template <
typename TreeT>
57 template <
typename TreeT>
62 template <
typename TreeT>
70 namespace count_internal {
73 template<
typename TreeType>
74 struct ActiveVoxelCountOp
76 using LeafT =
typename TreeType::LeafNodeType;
78 ActiveVoxelCountOp() =
default;
79 ActiveVoxelCountOp(
const ActiveVoxelCountOp&, tbb::split) { }
82 template<
typename NodeT>
83 bool operator()(
const NodeT& node,
size_t)
85 for (
auto iter = node.cbeginValueOn(); iter; ++iter) {
86 count += NodeT::ChildNodeType::NUM_VOXELS;
92 bool operator()(
const LeafT& leaf,
size_t)
94 count += leaf.onVoxelCount();
98 void join(
const ActiveVoxelCountOp& other)
100 count += other.count;
108 template<
typename TreeType>
109 struct ActiveVoxelCountBBoxOp
111 using LeafT =
typename TreeType::LeafNodeType;
113 explicit ActiveVoxelCountBBoxOp(
const CoordBBox& bbox)
115 ActiveVoxelCountBBoxOp(
const ActiveVoxelCountBBoxOp& other, tbb::split)
116 : mBBox(other.mBBox) { }
119 template<
typename NodeT>
120 bool operator()(
const NodeT& node,
size_t)
122 if (!mBBox.hasOverlap(node.getNodeBoundingBox()))
return false;
125 for (
auto iter = node.cbeginValueOn(); iter; ++iter) {
126 CoordBBox bbox(CoordBBox::createCube(iter.getCoord(), NodeT::ChildNodeType::DIM));
128 if (!bbox.hasOverlap(mBBox)) {
131 }
else if (bbox.isInside(mBBox)) {
133 count += mBBox.volume();
134 }
else if (mBBox.isInside(bbox)) {
136 count += bbox.volume();
139 bbox.intersect(mBBox);
140 count += bbox.volume();
145 for (
auto iter = node.cbeginChildOn(); iter; ++iter) {
146 if (mBBox.hasOverlap(iter->getNodeBoundingBox()))
return true;
154 inline bool operator()(
const LeafT& leaf,
size_t)
158 CoordBBox bbox = leaf.getNodeBoundingBox();
160 if (mBBox.isInside(bbox)) {
162 count += leaf.onVoxelCount();
163 }
else if (!bbox.hasOverlap(mBBox)) {
166 }
else if (leaf.isDense()) {
168 bbox.intersect(mBBox);
169 count += bbox.volume();
172 for (
auto i = leaf.cbeginValueOn(); i; ++i) {
173 if (mBBox.isInside(i.getCoord())) ++count;
179 void join(
const ActiveVoxelCountBBoxOp& other)
181 count += other.count;
190 template<
typename TreeType>
191 struct InactiveVoxelCountOp
193 using RootT =
typename TreeType::RootNodeType;
194 using LeafT =
typename TreeType::LeafNodeType;
196 InactiveVoxelCountOp() =
default;
197 InactiveVoxelCountOp(
const InactiveVoxelCountOp&, tbb::split) { }
200 bool operator()(
const RootT& root,
size_t)
202 for (
auto iter = root.cbeginValueOff(); iter; ++iter) {
205 count += RootT::ChildNodeType::NUM_VOXELS;
212 template<
typename NodeT>
213 bool operator()(
const NodeT& node,
size_t)
215 for (
auto iter = node.cbeginValueOff(); iter; ++iter) {
216 if (node.isChildMaskOff(iter.pos())) {
217 count += NodeT::ChildNodeType::NUM_VOXELS;
224 bool operator()(
const LeafT& leaf,
size_t)
226 count += leaf.offVoxelCount();
230 void join(
const InactiveVoxelCountOp& other)
232 count += other.count;
239 template<
typename TreeType>
240 struct ActiveTileCountOp
242 using RootT =
typename TreeType::RootNodeType;
243 using LeafT =
typename TreeType::LeafNodeType;
245 ActiveTileCountOp() =
default;
246 ActiveTileCountOp(
const ActiveTileCountOp&, tbb::split) { }
249 bool operator()(
const RootT& root,
size_t)
251 for (
auto iter = root.cbeginValueOn(); iter; ++iter) count++;
256 template<
typename NodeT>
257 bool operator()(
const NodeT& node,
size_t)
259 count += node.getValueMask().countOn();
264 bool operator()(
const LeafT&,
size_t)
269 void join(
const ActiveTileCountOp& other)
271 count += other.count;
278 template<
typename TreeType>
281 using RootT =
typename TreeType::RootNodeType;
282 using LeafT =
typename TreeType::LeafNodeType;
284 MemUsageOp() =
default;
285 MemUsageOp(
const MemUsageOp&, tbb::split) { }
288 bool operator()(
const RootT& root,
size_t)
290 count +=
sizeof(root);
295 template<
typename NodeT>
296 bool operator()(
const NodeT& node,
size_t)
298 count += NodeT::NUM_VALUES *
sizeof(
typename NodeT::UnionType) +
299 node.getChildMask().memUsage() + node.getValueMask().memUsage() +
305 bool operator()(
const LeafT& leaf,
size_t)
307 count += leaf.memUsage();
311 void join(
const MemUsageOp& other)
313 count += other.count;
327 template <
typename TreeT>
330 count_internal::ActiveVoxelCountOp<TreeT> op;
337 template <
typename TreeT>
340 if (bbox.empty())
return Index64(0);
343 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
350 template <
typename TreeT>
353 count_internal::ActiveVoxelCountOp<TreeT> op;
356 leafManager.
reduce(op, threaded);
361 template <
typename TreeT>
364 if (bbox.empty())
return Index64(0);
367 count_internal::ActiveVoxelCountBBoxOp<TreeT> op(bbox);
370 leafManager.
reduce(op, threaded);
375 template <
typename TreeT>
378 count_internal::InactiveVoxelCountOp<TreeT> op;
385 template <
typename TreeT>
388 count_internal::InactiveVoxelCountOp<TreeT> op;
391 leafManager.
reduce(op, threaded);
396 template <
typename TreeT>
399 count_internal::ActiveTileCountOp<TreeT> op;
402 nodeManager.reduceTopDown(op, threaded);
407 template <
typename TreeT>
410 count_internal::MemUsageOp<TreeT> op;
413 return op.count +
sizeof(tree);
421 #endif // OPENVDB_TOOLS_COUNT_HAS_BEEN_INCLUDED
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1658
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:1043
uint64_t Index64
Definition: Types.h:53
Definition: Exceptions.h:13
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:84
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:407
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
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:116
Definition: NodeManager.h:36
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
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. Unlike foreach (defined above) this method performs a reduction on all the leaf nodes.
Definition: LeafManager.h:532