Loading...
Searching...
No Matches
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 NonConstRootNodeType & | root () const
| Return a reference to the root node.
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.
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.

## Static Public Attributes

static const Index | LEVELS = _LEVELS

## Protected Attributes

RootNodeType & | mRoot
DynamicNodeManagerLink< ChildNodeType, LEVELS-1 > | mChain

## 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

## DynamicNodeManager() [1/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

DynamicNodeManager | ( | TreeOrLeafManagerT & | tree | ) |

inlineexplicit

## DynamicNodeManager() [2/2]

template<typename TreeOrLeafManagerT , Index _LEVELS>

DynamicNodeManager | ( | const DynamicNodeManager< TreeOrLeafManagerT, _LEVELS > & |  | ) |

delete

## Member Function Documentation

## foreachTopDown()

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

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

  op | user-supplied functor, see examples for interface details.
  threaded | optional toggle to disable threading, on by default.
  leafGrainSize | optional parameter to specify the grainsize for threading over leaf nodes, one by default.
  nonLeafGrainSize | optional 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);
  openvdb::v11_0::math::Coord
  Signed (x, y, z) 32-bit integer coordinates.
  Definition Coord.h:25

## reduceTopDown()

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

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

  op | user-supplied functor, see examples for interface details.
  threaded | optional toggle to disable threading, on by default.
  leafGrainSize | optional parameter to specify the grainsize for threading over leaf nodes, one by default.
  nonLeafGrainSize | optional 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);
  openvdb::v11_0::Index64
  uint64_t Index64
  Definition Types.h:53

## root()

template<typename TreeOrLeafManagerT , Index _LEVELS>

const NonConstRootNodeType & 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>

DynamicNodeManagerLink<ChildNodeType, LEVELS-1> mChain

protected

## mRoot

template<typename TreeOrLeafManagerT , Index _LEVELS>

RootNodeType& mRoot

protected