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

#include <NodeManager.h>

Public Types

using RootNodeType = typename TreeOrLeafManagerT::RootNodeType
 

Public Member Functions

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

Static Public Attributes

static const Index LEVELS = _LEVELS
 

Protected Attributes

RootNodeTypemRoot
 
DynamicNodeManagerLink< typename RootNodeType::ChildNodeType, LEVELS-1 > mChain
 

Member Typedef Documentation

using RootNodeType = typename TreeOrLeafManagerT::RootNodeType

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  grainSize = 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.
grainSizeoptional parameter to specify the grainsize for threading, 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 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  grainSize = 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.
grainSizeoptional parameter to specify the grainsize for threading, 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 RootNodeType& root ( ) const
inline

Return a reference to the root node.

Member Data Documentation

const Index LEVELS = _LEVELS
static
DynamicNodeManagerLink<typename RootNodeType::ChildNodeType, LEVELS-1> mChain
protected
RootNodeType& mRoot
protected

The documentation for this class was generated from the following file: