OpenVDB  1.1.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
ValueAccessor< _TreeType, CacheLevels, MutexType > Class Template Reference

#include <ValueAccessor.h>

Inherits ValueAccessorBase< _TreeType >.

Public Types

typedef _TreeType TreeType
 
typedef TreeType::RootNodeType RootNodeT
 
typedef TreeType::LeafNodeType LeafNodeT
 
typedef RootNodeT::ValueType ValueType
 
typedef ValueAccessorBase
< TreeType
BaseT
 
typedef MutexType::scoped_lock LockT
 

Public Member Functions

 BOOST_STATIC_ASSERT (CacheLevels<=_TreeType::DEPTH-1)
 
 ValueAccessor (TreeType &tree)
 
 ValueAccessor (const ValueAccessor &other)
 
ValueAccessoroperator= (const ValueAccessor &other)
 
virtual ~ValueAccessor ()
 
bool isCached (const Coord &xyz) const
 Return true if nodes along the path to the given voxel have been cached. More...
 
const ValueTypegetValue (const Coord &xyz) const
 Return the value of the voxel at the given coordinates. More...
 
bool isValueOn (const Coord &xyz) const
 Return the active state of the voxel at the given coordinates. More...
 
bool probeValue (const Coord &xyz, ValueType &value) const
 Return the active state of the voxel as well as its value. More...
 
int getValueDepth (const Coord &xyz) const
 
bool isVoxel (const Coord &xyz) const
 
void setValueOnly (const Coord &xyz, const ValueType &value)
 Set the value of the voxel at the given coordinate but preserves its active state. More...
 
void newSetValue (const Coord &xyz, const ValueType &value)
 
void setValueOff (const Coord &xyz, const ValueType &value)
 Set the value of the voxel at the given coordinates and mark the voxel as inactive. More...
 
void setValueOnSum (const Coord &xyz, const ValueType &value)
 
void setActiveState (const Coord &xyz, bool on=true)
 Set the active state of the voxel at the given coordinates without changing its value. More...
 
void setValueOn (const Coord &xyz)
 Mark the voxel at the given coordinates as active without changing its value. More...
 
void setValueOff (const Coord &xyz)
 Mark the voxel at the given coordinates as inactive without changing its value. More...
 
template<typename NodeType >
NodeType * getNode ()
 Return the cached node of type NodeType. [Mainly for internal use]. More...
 
template<typename NodeType >
void insertNode (const Coord &xyz, NodeType &node)
 
template<typename NodeType >
void eraseNode ()
 
LeafNodeTtouchLeaf (const Coord &xyz)
 
LeafNodeTprobeLeaf (const Coord &xyz)
 
const LeafNodeTprobeConstLeaf (const Coord &xyz)
 
virtual void clear ()
 Remove all nodes from this cache, then reinsert the root node. More...
 
_TreeType * getTree () const
 
void setValue (const Coord &xyz, const ValueType &value)
 Set the value of the voxel at the given coordinates and mark the voxel as active. More...
 
void setValueOn (const Coord &xyz, const ValueType &value)
 Set the value of the voxel at the given coordinates and mark the voxel as active. More...
 

Static Public Member Functions

static Index numCacheLevels ()
 Return the number of cache levels employed by this ValueAccessor. More...
 

Static Public Attributes

static const bool IsConstTree
 

Protected Attributes

_TreeType * mTree
 

Friends

template<typename >
class RootNode
 
template<typename , Index >
class InternalNode
 
template<typename , Index >
class LeafNode
 
template<typename >
class Tree
 

Detailed Description

template<typename _TreeType, Index CacheLevels = _TreeType::DEPTH-1, typename MutexType = tbb::null_mutex>
class openvdb::v1_1_0::tree::ValueAccessor< _TreeType, CacheLevels, MutexType >

When traversing a grid in a spatially coherent pattern (e.g., iterating over neighboring voxels), request a ValueAccessor from the grid (with Grid::getAccessor()) and use the accessor's getValue() and setValue() methods. These will typically be significantly faster than accessing voxels directly in the grid's tree.

Note
If MutexType is a TBB-compatible mutex, then multiple threads may safely access a single, shared accessor. However, it is highly recommended that, instead, each thread be assigned its own, non-mutex-protected accessor.

Conceptually this ValueAccessor is a node-cache with accessor methods. Specefically the tree nodes from a previous access are cached and re-used starting with the LeafNode and moving up throug the node levels of the tree. Thus this node caching essentiall leads to acceleration of spatially coherent access by means of inverted tree traversal!

Parameters
_TreeTypeThis is the only template paramter that always has to be specified.
CacheLevelsUsed to specify the number of bottom nodes that are cached. The default caches all (non-root) nodes. The maximum allowed number of CacheLevels correspond to the number of non-root nodes, i.e. CacheLevels <= DEPTH-1!
MutexTypeThis defines the type of mutex-lock and should almost always be left untouched (unless you're and expert!)

Member Typedef Documentation

typedef TreeType::LeafNodeType LeafNodeT
typedef MutexType::scoped_lock LockT
typedef TreeType::RootNodeType RootNodeT
typedef _TreeType TreeType
typedef RootNodeT::ValueType ValueType

Constructor & Destructor Documentation

ValueAccessor ( TreeType tree)
inline
ValueAccessor ( const ValueAccessor< _TreeType, CacheLevels, MutexType > &  other)
inline
virtual ~ValueAccessor ( )
inlinevirtual

Member Function Documentation

BOOST_STATIC_ASSERT ( CacheLevels<=_TreeType::DEPTH-  1)
virtual void clear ( )
inlinevirtual

Remove all nodes from this cache, then reinsert the root node.

Implements ValueAccessorBase< _TreeType >.

void eraseNode ( )
inline

If a node of the given type exists in the cache, remove it, so that isCached(xyz) returns false for any voxel (x, y, z) contained in that node. [Mainly for internal use]

NodeType* getNode ( )
inline

Return the cached node of type NodeType. [Mainly for internal use].

_TreeType * getTree ( ) const
inlineinherited
Returns
a pointer to the tree associated by this ValueAccessor
const ValueType& getValue ( const Coord xyz) const
inline

Return the value of the voxel at the given coordinates.

int getValueDepth ( const Coord xyz) const
inline

Return the tree depth (0 = root) at which the value of voxel (x, y, z) resides, or -1 if (x, y, z) isn't explicitly represented in the tree (i.e., if it is implicitly a background voxel).

void insertNode ( const Coord xyz,
NodeType &  node 
)
inline

Cache the given node, which should lie along the path from the root node to the node containing voxel (x, y, z). [Mainly for internal use]

bool isCached ( const Coord xyz) const
inline

Return true if nodes along the path to the given voxel have been cached.

bool isValueOn ( const Coord xyz) const
inline

Return the active state of the voxel at the given coordinates.

bool isVoxel ( const Coord xyz) const
inline

Return true if the value of voxel (x, y, z) resides at the leaf level of the tree, i.e., if it is not a tile value.

void newSetValue ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinates and mark the voxel as active. [Experimental]

static Index numCacheLevels ( )
inlinestatic

Return the number of cache levels employed by this ValueAccessor.

ValueAccessor& operator= ( const ValueAccessor< _TreeType, CacheLevels, MutexType > &  other)
inline
const LeafNodeT* probeConstLeaf ( const Coord xyz)
inline
Returns
a const pointer to the leaf node that contains voxel (x, y, z) and if it doesn't exist, return NULL.
LeafNodeT* probeLeaf ( const Coord xyz)
inline
Returns
a pointer to the leaf node that contains voxel (x, y, z) and if it doesn't exist, return NULL.
bool probeValue ( const Coord xyz,
ValueType value 
) const
inline

Return the active state of the voxel as well as its value.

void setActiveState ( const Coord xyz,
bool  on = true 
)
inline

Set the active state of the voxel at the given coordinates without changing its value.

void setValue ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinates and mark the voxel as active.

void setValueOff ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinates and mark the voxel as inactive.

void setValueOff ( const Coord xyz)
inline

Mark the voxel at the given coordinates as inactive without changing its value.

void setValueOn ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinates and mark the voxel as active.

void setValueOn ( const Coord xyz)
inline

Mark the voxel at the given coordinates as active without changing its value.

void setValueOnly ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinate but preserves its active state.

void setValueOnSum ( const Coord xyz,
const ValueType value 
)
inline

Set the value of the voxel at the given coordinates to the sum of its current value and the given value, and mark the voxel as active.

LeafNodeT* touchLeaf ( const Coord xyz)
inline
Returns
the leaf node that contains voxel (x, y, z) and if it doesn't exist, create it, but preserve the values and active states of all voxels.

Use this method to preallocate a static tree topology over which to safely perform multithreaded processing.

Friends And Related Function Documentation

friend class InternalNode
friend
friend class LeafNode
friend
friend class RootNode
friend
friend class Tree
friend

Member Data Documentation

const bool IsConstTree
staticinherited
_TreeType * mTree
protectedinherited

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