OpenVDB  9.0.1
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
DynamicNodeManager< TreeOrLeafManagerT, _LEVELS > Class Template Reference

#include <openvdb/tree/NodeManager.h>

Public Types

using NonConstRootNodeType = typename TreeOrLeafManagerT::RootNodeType
 
using RootNodeType = typename CopyConstness< TreeOrLeafManagerT, NonConstRootNodeType >::Type
 
using NonConstChildNodeType = typename RootNodeType::ChildNodeType
 
using ChildNodeType = typename CopyConstness< TreeOrLeafManagerT, NonConstChildNodeType >::Type
 

Public Member Functions

 DynamicNodeManager (TreeOrLeafManagerT &tree)
 
 DynamicNodeManager (const DynamicNodeManager &)=delete
 
const NonConstRootNodeTyperoot () const
 Return a reference to the root node. More...
 
template<typename NodeOp >
void foreachTopDown (const NodeOp &op, bool threaded=true, size_t leafGrainSize=1, size_t nonLeafGrainSize=1)
 Threaded method that applies a user-supplied functor to all the nodes in the tree. More...
 
template<typename NodeOp >
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. More...
 

Static Public Attributes

static const Index LEVELS = _LEVELS
 

Protected Attributes

RootNodeTypemRoot
 
DynamicNodeManagerLink< ChildNodeType, LEVELS-1 > mChain
 

Member Typedef Documentation

using ChildNodeType = typename CopyConstness<TreeOrLeafManagerT, NonConstChildNodeType>::Type
using NonConstChildNodeType = typename RootNodeType::ChildNodeType
using NonConstRootNodeType = typename TreeOrLeafManagerT::RootNodeType
using RootNodeType = typename CopyConstness<TreeOrLeafManagerT, NonConstRootNodeType>::Type

Constructor & Destructor Documentation

DynamicNodeManager ( TreeOrLeafManagerT &  tree)
inlineexplicit
DynamicNodeManager ( const DynamicNodeManager< TreeOrLeafManagerT, _LEVELS > &  )
delete

Member Function Documentation

void foreachTopDown ( const NodeOp &  op,
bool  threaded = true,
size_t  leafGrainSize = 1,
size_t  nonLeafGrainSize = 1 
)
inline

Threaded method that applies a user-supplied functor to all the nodes in the tree.

Parameters
opuser-supplied functor, see examples for interface details.
threadedoptional toggle to disable threading, on by default.
leafGrainSizeoptional parameter to specify the grainsize for threading over leaf nodes, one by default.
nonLeafGrainSizeoptional parameter to specify the grainsize for threading over non-leaf nodes, one by default.
Note
There are two key differences to the interface of the user-supplied functor to the NodeManager class - (1) the operator() method aligns with the LeafManager class in expecting the index of the node in a linear array of identical node types, (2) the operator() method returns a boolean termination value with true indicating that children of this node should be processed, false indicating the early-exit termination should occur.
Unlike the NodeManager, the foreach() method of the DynamicNodeManager uses copy-by-reference for the user-supplied functor. This can be an issue when using a shared Accessor or shared Sampler in the operator as they are not inherently thread-safe. For these use cases, it is recommended to create the Accessor or Sampler in the operator execution itself.
Example:
// Functor to densify the first child node in a linear array. Note
// this implementation also illustrates how different
// computation can be applied to the different node types.
template<typename TreeT>
struct DensifyOp
{
using RootT = typename TreeT::RootNodeType;
using LeafT = typename TreeT::LeafNodeType;
DensifyOp() = default;
// Processes the root node. Required by the DynamicNodeManager
bool operator()(RootT&, size_t) const { return true; }
// Processes the internal nodes. Required by the DynamicNodeManager
template<typename NodeT>
bool operator()(NodeT& node, size_t idx) const
{
// densify child
for (auto iter = node.cbeginValueAll(); iter; ++iter) {
const openvdb::Coord ijk = iter.getCoord();
node.addChild(new typename NodeT::ChildNodeType(iter.getCoord(), NodeT::LEVEL, true));
}
// early-exit termination for all non-zero index children
return idx == 0;
}
// Processes the leaf nodes. Required by the DynamicNodeManager
bool operator()(LeafT&, size_t) const
{
return true;
}
};// DensifyOp
// usage:
DensifyOp<FloatTree> op;
tree::DynamicNodeManager<FloatTree> nodes(tree);
nodes.foreachTopDown(op);
void reduceTopDown ( NodeOp &  op,
bool  threaded = true,
size_t  leafGrainSize = 1,
size_t  nonLeafGrainSize = 1 
)
inline

Threaded method that processes nodes with a user supplied functor.

Parameters
opuser-supplied functor, see examples for interface details.
threadedoptional toggle to disable threading, on by default.
leafGrainSizeoptional parameter to specify the grainsize for threading over leaf nodes, one by default.
nonLeafGrainSizeoptional parameter to specify the grainsize for threading over non-leaf nodes, one by default.
Note
There are two key differences to the interface of the user-supplied functor to the NodeManager class - (1) the operator() method aligns with the LeafManager class in expecting the index of the node in a linear array of identical node types, (2) the operator() method returns a boolean termination value with true indicating that children of this node should be processed, false indicating the early-exit termination should occur.
Example:
// Functor to count nodes in a tree
template<typename TreeType>
struct NodeCountOp
{
NodeCountOp() : nodeCount(TreeType::DEPTH, 0), totalCount(0)
{
}
NodeCountOp(const NodeCountOp& other, tbb::split) :
nodeCount(TreeType::DEPTH, 0), totalCount(0)
{
}
void join(const NodeCountOp& other)
{
for (size_t i = 0; i < nodeCount.size(); ++i) {
nodeCount[i] += other.nodeCount[i];
}
totalCount += other.totalCount;
}
// do nothing for the root node
bool operator()(const typename TreeT::RootNodeType& node, size_t)
{
return true;
}
// count the internal and leaf nodes
template<typename NodeT>
bool operator()(const NodeT& node, size_t)
{
++(nodeCount[NodeT::LEVEL]);
++totalCount;
return true;
}
std::vector<openvdb::Index64> nodeCount;
openvdb::Index64 totalCount;
};
// usage:
NodeCountOp<FloatTree> op;
tree::DynamicNodeManager<FloatTree> nodes(tree);
nodes.reduceTopDown(op);
const NonConstRootNodeType& root ( ) const
inline

Return a reference to the root node.

Member Data Documentation

const Index LEVELS = _LEVELS
static
RootNodeType& mRoot
protected