HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS > Class Template Reference

To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree. More...

#include <NodeManager.h>

Public Types

typedef
TreeOrLeafManagerT::RootNodeType 
RootNodeType
 

Public Member Functions

 HBOOST_STATIC_ASSERT (LEVELS > 0)
 
 HBOOST_STATIC_ASSERT (RootNodeType::LEVEL >=LEVELS)
 
 NodeManager (TreeOrLeafManagerT &tree)
 
virtual ~NodeManager ()
 
void clear ()
 Clear all the cached tree nodes. More...
 
void rebuild ()
 Clear and recache all the tree nodes from the tree. This is required if tree nodes have been added or removed. More...
 
const RootNodeTyperoot () const
 Return a reference to the root node. More...
 
Index64 nodeCount () const
 Return the total number of cached nodes (excluding the root node) More...
 
Index64 nodeCount (Index i) const
 Return the number of cached nodes at level i, where 0 corresponds to the lowest level. More...
 
template<typename NodeOp >
void foreachBottomUp (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 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 >
OPENVDB_DEPRECATED void processBottomUp (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 >
OPENVDB_DEPRECATED void processTopDown (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 reduceBottomUp (NodeOp &op, bool threaded=true, size_t grainSize=1)
 Threaded method that processes nodes with a user supplied functor. 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
 
NodeManagerLink< typename
RootNodeType::ChildNodeType,
LEVELS-1 > 
mChain
 

Detailed Description

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
class openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >

To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree.

This implementation works with trees of any depth, but optimized specializations are provided for the most typical tree depths.

Definition at line 57 of file NodeManager.h.

Member Typedef Documentation

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
typedef TreeOrLeafManagerT::RootNodeType openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::RootNodeType

Definition at line 411 of file NodeManager.h.

Constructor & Destructor Documentation

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::NodeManager ( TreeOrLeafManagerT &  tree)
inline

Definition at line 414 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
virtual openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::~NodeManager ( )
inlinevirtual

Definition at line 416 of file NodeManager.h.

Member Function Documentation

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::clear ( void  )
inline

Clear all the cached tree nodes.

Definition at line 419 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::foreachBottomUp ( 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.
Warning
The functor object is deep-copied to create TBB tasks.
Example:
// Functor to offset all the inactive values of a tree. Note
// this implementation also illustrates how different
// computation can be applied to the different node types.
template<typename TreeType>
struct OffsetOp
{
typedef typename TreeT::ValueType ValueT;
typedef typename TreeT::RootNodeType RootT;
typedef typename TreeT::LeafNodeType LeafT;
OffsetOp(const ValueT& v) : mOffset(v) {}
// Processes the root node. Required by the NodeManager
void operator()(RootT& root) const
{
for (typename RootT::ValueOffIter i = root.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the leaf nodes. Required by the NodeManager
void operator()(LeafT& leaf) const
{
for (typename LeafT::ValueOffIter i = leaf.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the internal nodes. Required by the NodeManager
template<typename NodeT>
void operator()(NodeT& node) const
{
for (typename NodeT::ValueOffIter i = node.beginValueOff(); i; ++i) *i += mOffset;
}
private:
const ValueT mOffset;
};
// usage:
OffsetOp<FloatTree> op(3.0f);
tree::NodeManager<FloatTree> nodes(tree);
nodes.foreachBottomUp(op);
// or if a LeafManager already exists
typedef tree::LeafManager<FloatTree> T;
OffsetOp<T> op(3.0f);
tree::NodeManager<T> nodes(leafManager);
nodes.foreachBottomUp(op);

Definition at line 492 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::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.
Warning
The functor object is deep-copied to create TBB tasks.
Example:
// Functor to offset all the inactive values of a tree. Note
// this implementation also illustrates how different
// computation can be applied to the different node types.
template<typename TreeType>
struct OffsetOp
{
typedef typename TreeT::ValueType ValueT;
typedef typename TreeT::RootNodeType RootT;
typedef typename TreeT::LeafNodeType LeafT;
OffsetOp(const ValueT& v) : mOffset(v) {}
// Processes the root node. Required by the NodeManager
void operator()(RootT& root) const
{
for (typename RootT::ValueOffIter i = root.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the leaf nodes. Required by the NodeManager
void operator()(LeafT& leaf) const
{
for (typename LeafT::ValueOffIter i = leaf.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the internal nodes. Required by the NodeManager
template<typename NodeT>
void operator()(NodeT& node) const
{
for (typename NodeT::ValueOffIter i = node.beginValueOff(); i; ++i) *i += mOffset;
}
private:
const ValueT mOffset;
};
// usage:
OffsetOp<FloatTree> op(3.0f);
tree::NodeManager<FloatTree> nodes(tree);
nodes.foreachBottomUp(op);
// or if a LeafManager already exists
typedef tree::LeafManager<FloatTree> T;
OffsetOp<T> op(3.0f);
tree::NodeManager<T> nodes(leafManager);
nodes.foreachBottomUp(op);

Definition at line 498 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::HBOOST_STATIC_ASSERT ( LEVELS  ,
 
)
template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::HBOOST_STATIC_ASSERT ( RootNodeType::LEVEL >=  LEVELS)
template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
Index64 openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::nodeCount ( ) const
inline

Return the total number of cached nodes (excluding the root node)

Definition at line 429 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
Index64 openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::nodeCount ( Index  i) const
inline

Return the number of cached nodes at level i, where 0 corresponds to the lowest level.

Definition at line 433 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
OPENVDB_DEPRECATED void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::processBottomUp ( 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.
Warning
The functor object is deep-copied to create TBB tasks.
Example:
// Functor to offset all the inactive values of a tree. Note
// this implementation also illustrates how different
// computation can be applied to the different node types.
template<typename TreeType>
struct OffsetOp
{
typedef typename TreeT::ValueType ValueT;
typedef typename TreeT::RootNodeType RootT;
typedef typename TreeT::LeafNodeType LeafT;
OffsetOp(const ValueT& v) : mOffset(v) {}
// Processes the root node. Required by the NodeManager
void operator()(RootT& root) const
{
for (typename RootT::ValueOffIter i = root.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the leaf nodes. Required by the NodeManager
void operator()(LeafT& leaf) const
{
for (typename LeafT::ValueOffIter i = leaf.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the internal nodes. Required by the NodeManager
template<typename NodeT>
void operator()(NodeT& node) const
{
for (typename NodeT::ValueOffIter i = node.beginValueOff(); i; ++i) *i += mOffset;
}
private:
const ValueT mOffset;
};
// usage:
OffsetOp<FloatTree> op(3.0f);
tree::NodeManager<FloatTree> nodes(tree);
nodes.foreachBottomUp(op);
// or if a LeafManager already exists
typedef tree::LeafManager<FloatTree> T;
OffsetOp<T> op(3.0f);
tree::NodeManager<T> nodes(leafManager);
nodes.foreachBottomUp(op);

Definition at line 504 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
OPENVDB_DEPRECATED void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::processTopDown ( 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.
Warning
The functor object is deep-copied to create TBB tasks.
Example:
// Functor to offset all the inactive values of a tree. Note
// this implementation also illustrates how different
// computation can be applied to the different node types.
template<typename TreeType>
struct OffsetOp
{
typedef typename TreeT::ValueType ValueT;
typedef typename TreeT::RootNodeType RootT;
typedef typename TreeT::LeafNodeType LeafT;
OffsetOp(const ValueT& v) : mOffset(v) {}
// Processes the root node. Required by the NodeManager
void operator()(RootT& root) const
{
for (typename RootT::ValueOffIter i = root.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the leaf nodes. Required by the NodeManager
void operator()(LeafT& leaf) const
{
for (typename LeafT::ValueOffIter i = leaf.beginValueOff(); i; ++i) *i += mOffset;
}
// Processes the internal nodes. Required by the NodeManager
template<typename NodeT>
void operator()(NodeT& node) const
{
for (typename NodeT::ValueOffIter i = node.beginValueOff(); i; ++i) *i += mOffset;
}
private:
const ValueT mOffset;
};
// usage:
OffsetOp<FloatTree> op(3.0f);
tree::NodeManager<FloatTree> nodes(tree);
nodes.foreachBottomUp(op);
// or if a LeafManager already exists
typedef tree::LeafManager<FloatTree> T;
OffsetOp<T> op(3.0f);
tree::NodeManager<T> nodes(leafManager);
nodes.foreachBottomUp(op);

Definition at line 509 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::rebuild ( )
inline

Clear and recache all the tree nodes from the tree. This is required if tree nodes have been added or removed.

Definition at line 423 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::reduceBottomUp ( 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.
Warning
The functor object is deep-copied to create TBB tasks.
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
void operator()(const typename TreeT::RootNodeType& node)
{
}
// count the internal and leaf nodes
template<typename NodeT>
void operator()(const NodeT& node)
{
++(nodeCount[NodeT::LEVEL]);
++totalCount;
}
std::vector<openvdb::Index64> nodeCount;
openvdb::Index64 totalCount;
};
// usage:
NodeCountOp<FloatTree> op;
tree::NodeManager<FloatTree> nodes(tree);
nodes.reduceBottomUp(op);
// or if a LeafManager already exists
NodeCountOp<FloatTree> op;
typedef tree::LeafManager<FloatTree> T;
T leafManager(tree);
tree::NodeManager<T> nodes(leafManager);
nodes.reduceBottomUp(op);

Definition at line 574 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
template<typename NodeOp >
void openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::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.
Warning
The functor object is deep-copied to create TBB tasks.
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
void operator()(const typename TreeT::RootNodeType& node)
{
}
// count the internal and leaf nodes
template<typename NodeT>
void operator()(const NodeT& node)
{
++(nodeCount[NodeT::LEVEL]);
++totalCount;
}
std::vector<openvdb::Index64> nodeCount;
openvdb::Index64 totalCount;
};
// usage:
NodeCountOp<FloatTree> op;
tree::NodeManager<FloatTree> nodes(tree);
nodes.reduceBottomUp(op);
// or if a LeafManager already exists
NodeCountOp<FloatTree> op;
typedef tree::LeafManager<FloatTree> T;
T leafManager(tree);
tree::NodeManager<T> nodes(leafManager);
nodes.reduceBottomUp(op);

Definition at line 581 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
const RootNodeType& openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::root ( void  ) const
inline

Return a reference to the root node.

Definition at line 426 of file NodeManager.h.

Member Data Documentation

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
const Index openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::LEVELS = _LEVELS
static

Definition at line 409 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
NodeManagerLink<typename RootNodeType::ChildNodeType, LEVELS-1> openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::mChain
protected

Definition at line 590 of file NodeManager.h.

template<typename TreeOrLeafManagerT, Index LEVELS = TreeOrLeafManagerT::RootNodeType::LEVEL>
RootNodeType& openvdb::OPENVDB_VERSION_NAME::tree::NodeManager< TreeOrLeafManagerT, LEVELS >::mRoot
protected

Definition at line 589 of file NodeManager.h.


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