OpenVDB 11.0.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
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 <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
| NodeManager (TreeOrLeafManagerT &tree, bool serial=false)
| NodeManager (const NodeManager &)=delete
void | clear ()
| Clear all the cached tree nodes.
void | rebuild (bool serial=false)
| Clear and recache all the tree nodes from the tree. This is required if tree nodes have been added or removed.
const RootNodeType & | root () const
| Return a reference to the root node.
Index64 | nodeCount () const
| Return the total number of cached nodes (excluding the root node)
Index64 | nodeCount (Index i) const
| Return the number of cached nodes at level i, where 0 corresponds to the lowest level.
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.
template<typename NodeOp >
void | foreachTopDown (const NodeOp &op, bool threaded=true, size_t grainSize=1)
template<typename NodeOp >
void | reduceBottomUp (NodeOp &op, bool threaded=true, size_t grainSize=1)
| Threaded method that processes nodes with a user supplied functor.
template<typename NodeOp >
void | reduceTopDown (NodeOp &op, bool threaded=true, size_t grainSize=1)

## Static Public Attributes
static const Index | LEVELS = _LEVELS

## Protected Attributes
RootNodeType & | mRoot
NodeManagerLink< ChildNodeType, LEVELS-1 > | mChain

## Detailed Description

template<typename TreeOrLeafManagerT, Index _LEVELS>
class openvdb::v11_0::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.

## Member Typedef Documentation

## ◆ ChildNodeType

template<typename TreeOrLeafManagerT , Index _LEVELS>

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

## ◆ NonConstChildNodeType

template<typename TreeOrLeafManagerT , Index _LEVELS>

using NonConstChildNodeType = typename RootNodeType::ChildNodeType

## ◆ NonConstRootNodeType

template<typename TreeOrLeafManagerT , Index _LEVELS>

using NonConstRootNodeType = typename TreeOrLeafManagerT::RootNodeType

## ◆ RootNodeType

template<typename TreeOrLeafManagerT , Index _LEVELS>

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

## Constructor & Destructor Documentation

## ◆ NodeManager() [1/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

NodeManager | ( | TreeOrLeafManagerT & | tree,
|  | bool | serial = `false`
| ) |  |
| inline

## ◆ NodeManager() [2/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

NodeManager | ( | const NodeManager< TreeOrLeafManagerT, _LEVELS > & |  | ) |
| delete

## Member Function Documentation

## ◆ clear()

template<typename TreeOrLeafManagerT , Index _LEVELS>

void clear | ( |  | ) |
| inline

Clear all the cached tree nodes.

## ◆ foreachBottomUp()

template<typename TreeOrLeafManagerT , Index _LEVELS>
template<typename NodeOp >

void 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

  op | user-supplied functor, see examples for interface details.
  threaded | optional toggle to disable threading, on by default.
  grainSize | optional 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
  {
  using ValueT = typename TreeT::ValueType;
  using RootT = typename TreeT::RootNodeType;
  using LeafT = typename TreeT::LeafNodeType;
  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
  using T = tree::LeafManager<FloatTree>;
  OffsetOp<T> op(3.0f);
  tree::NodeManager<T> nodes(leafManager);
  nodes.foreachBottomUp(op);

## ◆ foreachTopDown()

template<typename TreeOrLeafManagerT , Index _LEVELS>
template<typename NodeOp >

void foreachTopDown | ( | const NodeOp & | op,
|  | bool | threaded = `true`,
|  | size_t | grainSize = `1`
| ) |  |
| inline

## ◆ nodeCount() [1/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

Index64 nodeCount | ( |  | ) | const
| inline

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

## ◆ nodeCount() [2/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

Index64 nodeCount | ( | Index | i | ) | const
| inline

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

## ◆ rebuild()

template<typename TreeOrLeafManagerT , Index _LEVELS>

void rebuild | ( | bool | serial = `false` | ) |
| inline

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

## ◆ reduceBottomUp()

template<typename TreeOrLeafManagerT , Index _LEVELS>
template<typename NodeOp >

void reduceBottomUp | ( | NodeOp & | op,
|  | bool | threaded = `true`,
|  | size_t | grainSize = `1`
| ) |  |
| inline

Threaded method that processes nodes with a user supplied functor.

Parameters

  op | user-supplied functor, see examples for interface details.
  threaded | optional toggle to disable threading, on by default.
  grainSize | optional 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;
  using T = tree::LeafManager<FloatTree>;
  T leafManager(tree);
  tree::NodeManager<T> nodes(leafManager);
  nodes.reduceBottomUp(op);
  openvdb::v11_0::Index64
  uint64_t Index64
  Definition Types.h:53

## ◆ reduceTopDown()

template<typename TreeOrLeafManagerT , Index _LEVELS>
template<typename NodeOp >

void reduceTopDown | ( | NodeOp & | op,
|  | bool | threaded = `true`,
|  | size_t | grainSize = `1`
| ) |  |
| inline

## ◆ root()

template<typename TreeOrLeafManagerT , Index _LEVELS>

const RootNodeType & root | ( |  | ) | const
| inline

Return a reference to the root node.

## Member Data Documentation

## ◆ LEVELS

template<typename TreeOrLeafManagerT , Index _LEVELS>

const Index LEVELS = _LEVELS
| static

## ◆ mChain

template<typename TreeOrLeafManagerT , Index _LEVELS>

NodeManagerLink<ChildNodeType, LEVELS-1> mChain
| protected

## ◆ mRoot

template<typename TreeOrLeafManagerT , Index _LEVELS>

RootNodeType& mRoot
| protected