OpenVDB  1.2.0
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
LeafManager< TreeT > Class Template Reference

This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxiliary buffers (one or more per leaf) that can be swapped with the leaf nodes' voxel data buffers. More...

#include <LeafManager.h>

Classes

class  LeafRange
 

Public Types

typedef TreeT TreeType
 
typedef TreeType::LeafNodeType NonConstLeafType
 
typedef CopyConstness
< TreeType, NonConstLeafType >
::Type 
LeafType
 
typedef leafmgr::TreeTraits
< TreeT >::LeafIterType 
LeafIterType
 
typedef LeafType::Buffer NonConstBufferType
 
typedef CopyConstness
< TreeType, NonConstBufferType >
::Type 
BufferType
 
typedef tbb::blocked_range
< size_t > 
RangeType
 

Public Member Functions

 LeafManager (TreeType &tree, size_t auxBuffersPerLeaf=0, bool serial=false)
 Constructor from a tree reference and an auxiliary buffer count (default is no auxiliary buffers) More...
 
 LeafManager (const LeafManager &other)
 
virtual ~LeafManager ()
 
void rebuild (bool serial=false)
 (Re)initialize by resizing (if necessary) and repopulating the leaf array and by deleting existing auxiliary buffers and allocating new ones. More...
 
void rebuildAuxBuffers (size_t auxBuffersPerLeaf, bool serial=false)
 Change the number of auxiliary buffers. More...
 
void removeAuxBuffers ()
 Remove the auxiliary buffers, but don't rebuild the leaf array. More...
 
void rebuildLeafArray ()
 Remove the auxiliary buffers and rebuild the leaf array. More...
 
OPENVDB_DEPRECATED void rebuildLeafs ()
 
size_t auxBufferCount () const
 Return the total number of allocated auxiliary buffers. More...
 
size_t auxBuffersPerLeaf () const
 Return the number of auxiliary buffers per leaf node. More...
 
size_t leafCount () const
 Return the number of leaf nodes. More...
 
TreeTypetree ()
 Return the tree associated with this manager. More...
 
bool isConstTree () const
 Return true if the tree associated with this manager is immutable. More...
 
LeafTypeleaf (size_t leafIdx) const
 Return a pointer to the leaf node at index leafIdx in the array. More...
 
BufferTypegetBuffer (size_t leafIdx, size_t bufferIdx) const
 Return the leaf or auxiliary buffer for the leaf node at index leafIdx. If bufferIdx is zero, return the leaf buffer, otherwise return the nth auxiliary buffer, where n = bufferIdx - 1. More...
 
RangeType getRange (size_t grainsize=1) const
 Return a tbb::blocked_range of leaf array indices. More...
 
LeafRange leafRange (size_t grainsize=1) const
 Return a TBB-compatible LeafRange. More...
 
bool swapLeafBuffer (size_t bufferIdx, bool serial=false)
 Swap each leaf node's buffer with the nth corresponding auxiliary buffer, where n = bufferIdx. More...
 
bool swapBuffer (size_t bufferIdx1, size_t bufferIdx2, bool serial=false)
 Swap any two buffers for each leaf node. More...
 
bool syncAuxBuffer (size_t bufferIdx, bool serial=false)
 Sync up the specified auxiliary buffer with the corresponding leaf node buffer. More...
 
bool syncAllBuffers (bool serial=false)
 Sync up all auxiliary buffers with their corresponding leaf node buffers. More...
 
template<typename LeafOp >
void foreach (const LeafOp &op, bool threaded=true)
 Threaded method that applies a user-supplied functor to each leaf node in the LeafManager. More...
 
void operator() (const RangeType &r) const
 Used internally by tbb::parallel_for() - never call it directly! More...
 
void rebuild (size_t auxBuffersPerLeaf, bool serial=false)
 Repopulate the leaf array and delete and reallocate auxiliary buffers. More...
 
void rebuild (TreeType &tree, bool serial=false)
 Repopulate the leaf array and delete and reallocate auxiliary buffers. More...
 
void rebuild (TreeType &tree, size_t auxBuffersPerLeaf, bool serial=false)
 Repopulate the leaf array and delete and reallocate auxiliary buffers. More...
 

Static Public Attributes

static const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree
 

Detailed Description

template<typename TreeT>
class openvdb::v1_2_0::tree::LeafManager< TreeT >

This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxiliary buffers (one or more per leaf) that can be swapped with the leaf nodes' voxel data buffers.

The leaf array is useful for multithreaded computations over leaf voxels in a tree with static topology but varying voxel values. The auxiliary buffers are convenient for temporal integration. Efficient methods are provided for multithreaded swapping and sync'ing (i.e., copying the contents) of these buffers.

Note
Buffer index 0 denotes a leaf node's internal voxel data buffer. Any auxiliary buffers are indexed starting from one.

Member Typedef Documentation

typedef LeafType::Buffer NonConstBufferType
typedef TreeType::LeafNodeType NonConstLeafType
typedef tbb::blocked_range<size_t> RangeType
typedef TreeT TreeType

Constructor & Destructor Documentation

LeafManager ( TreeType tree,
size_t  auxBuffersPerLeaf = 0,
bool  serial = false 
)
inline

Constructor from a tree reference and an auxiliary buffer count (default is no auxiliary buffers)

LeafManager ( const LeafManager< TreeT > &  other)
inline

Shallow copy constructor called by tbb::parallel_for() threads

Note
This should never get called directly
virtual ~LeafManager ( )
inlinevirtual

Member Function Documentation

size_t auxBufferCount ( ) const
inline

Return the total number of allocated auxiliary buffers.

size_t auxBuffersPerLeaf ( ) const
inline

Return the number of auxiliary buffers per leaf node.

void foreach ( const LeafOp &  op,
bool  threaded = true 
)
inline

Threaded method that applies a user-supplied functor to each leaf node in the LeafManager.

Parameters
opuser-supplied functor, see examples for interface details.
threadedoptional toggle to disable threading, on by default.
Warning
The functor object is deep-copied to create TBB tasks.
Example:
// Functor to offset a tree's voxel values with values from another tree.
template<typename TreeType>
struct OffsetOp
{
typedef tree::ValueAccessor<const TreeType> Accessor;
OffsetOp(const TreeType& tree): mRhsTreeAcc(tree) {}
template <typename LeafNodeType>
void operator()(LeafNodeType &lhsLeaf, size_t) const
{
const LeafNodeType * rhsLeaf = mRhsTreeAcc.probeConstLeaf(lhsLeaf.getOrigin());
if (rhsLeaf) {
typename LeafNodeType::ValueOnIter iter = lhsLeaf.beginValueOn();
for (; iter; ++iter) {
iter.setValue(iter.getValue() + rhsLeaf->getValue(iter.pos()));
}
}
}
private:
Accessor mRhsTreeAcc;
};
// usage:
tree::LeafManager<FloatTree> leafNodes(lhsTree);
leafNodes.foreach(OffsetOp<FloatTree>(rhsTree));
// A functor that performs a min operation between different auxiliary buffers.
template<typename LeafManagerType>
struct MinOp
{
typedef typename LeafManagerType::BufferType BufferType;
MinOp(LeafManagerType& leafNodes): mLeafs(leafNodes) {}
template <typename LeafNodeType>
void operator()(LeafNodeType &leaf, size_t leafIndex) const
{
// get the first buffer
BufferType& buffer = mLeafs.getBuffer(leafIndex, 1);
// min ...
}
private:
LeafManagerType& mLeafs;
};
BufferType& getBuffer ( size_t  leafIdx,
size_t  bufferIdx 
) const
inline

Return the leaf or auxiliary buffer for the leaf node at index leafIdx. If bufferIdx is zero, return the leaf buffer, otherwise return the nth auxiliary buffer, where n = bufferIdx - 1.

Note
For performance reasons no range checks are performed on the inputs (other than assertions)! Since auxiliary buffers, unlike leaf buffers, might not exist, be especially careful when specifying the bufferIdx.
For const trees, this method always returns a reference to a const buffer. It is safe to const_cast and modify any auxiliary buffer (bufferIdx > 0), but it is not safe to modify the leaf buffer (bufferIdx = 0).
RangeType getRange ( size_t  grainsize = 1) const
inline

Return a tbb::blocked_range of leaf array indices.

Note
Consider using leafRange() instead, which provides access methods to leaf nodes and buffers.
bool isConstTree ( ) const
inline

Return true if the tree associated with this manager is immutable.

LeafType& leaf ( size_t  leafIdx) const
inline

Return a pointer to the leaf node at index leafIdx in the array.

Note
For performance reasons no range check is performed (other than an assertion)!
size_t leafCount ( ) const
inline

Return the number of leaf nodes.

LeafRange leafRange ( size_t  grainsize = 1) const
inline

Return a TBB-compatible LeafRange.

void operator() ( const RangeType r) const
inline

Used internally by tbb::parallel_for() - never call it directly!

void rebuild ( bool  serial = false)
inline

(Re)initialize by resizing (if necessary) and repopulating the leaf array and by deleting existing auxiliary buffers and allocating new ones.

Call this method if the tree's topology, and therefore the number of leaf nodes, changes. New auxiliary buffers are initialized with copies of corresponding leaf node buffers.

void rebuild ( size_t  auxBuffersPerLeaf,
bool  serial = false 
)
inline

Repopulate the leaf array and delete and reallocate auxiliary buffers.

void rebuild ( TreeType tree,
bool  serial = false 
)
inline

Repopulate the leaf array and delete and reallocate auxiliary buffers.

void rebuild ( TreeType tree,
size_t  auxBuffersPerLeaf,
bool  serial = false 
)
inline

Repopulate the leaf array and delete and reallocate auxiliary buffers.

void rebuildAuxBuffers ( size_t  auxBuffersPerLeaf,
bool  serial = false 
)
inline

Change the number of auxiliary buffers.

If auxBuffersPerLeaf is 0, all existing auxiliary buffers are deleted. New auxiliary buffers are initialized with copies of corresponding leaf node buffers. This method does not rebuild the leaf array.

void rebuildLeafArray ( )
inline

Remove the auxiliary buffers and rebuild the leaf array.

OPENVDB_DEPRECATED void rebuildLeafs ( )
inline
void removeAuxBuffers ( )
inline

Remove the auxiliary buffers, but don't rebuild the leaf array.

bool swapBuffer ( size_t  bufferIdx1,
size_t  bufferIdx2,
bool  serial = false 
)
inline

Swap any two buffers for each leaf node.

Note
Recall that the indexing of auxiliary buffers is 1-based, since buffer index 0 denotes the leaf node buffer. So buffer index 1 denotes the first auxiliary buffer.
bool swapLeafBuffer ( size_t  bufferIdx,
bool  serial = false 
)
inline

Swap each leaf node's buffer with the nth corresponding auxiliary buffer, where n = bufferIdx.

Returns
true if the swap was successful
Parameters
bufferIdxindex of the buffer that will be swapped with the corresponding leaf node buffer
serialif false, swap buffers in parallel using multiple threads.
Note
Recall that the indexing of auxiliary buffers is 1-based, since buffer index 0 denotes the leaf node buffer. So buffer index 1 denotes the first auxiliary buffer.
bool syncAllBuffers ( bool  serial = false)
inline

Sync up all auxiliary buffers with their corresponding leaf node buffers.

Returns
true if the sync was successful
Parameters
serialif false, sync buffers in parallel using multiple threads.
bool syncAuxBuffer ( size_t  bufferIdx,
bool  serial = false 
)
inline

Sync up the specified auxiliary buffer with the corresponding leaf node buffer.

Returns
true if the sync was successful
Parameters
bufferIdxindex of the buffer that will contain a copy of the corresponding leaf node buffer
serialif false, sync buffers in parallel using multiple threads.
Note
Recall that the indexing of auxiliary buffers is 1-based, since buffer index 0 denotes the leaf node buffer. So buffer index 1 denotes the first auxiliary buffer.
TreeType& tree ( )
inline

Return the tree associated with this manager.

Member Data Documentation

const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree
static

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