Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust existing grid API to move ValueAccessor methods to the tree #1789

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions openvdb/openvdb/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,10 @@ class Grid: public GridBase
using ValueAllIter = typename _TreeType::ValueAllIter;
using ValueAllCIter = typename _TreeType::ValueAllCIter;

using Accessor = typename tree::ValueAccessor<_TreeType, true>;
using ConstAccessor = typename tree::ValueAccessor<const _TreeType, true>;
using UnsafeAccessor = typename tree::ValueAccessor<_TreeType, false>;
using ConstUnsafeAccessor = typename tree::ValueAccessor<const _TreeType, false>;
using Accessor = typename _TreeType::Accessor;
using ConstAccessor = typename _TreeType::ConstAccessor;
using UnsafeAccessor = typename _TreeType::UnsafeAccessor;
using ConstUnsafeAccessor = typename _TreeType::ConstUnsafeAccessor;

/// @brief ValueConverter<T>::Type is the type of a grid having the same
/// hierarchy as this grid but a different value type, T.
Expand Down Expand Up @@ -729,27 +729,27 @@ class Grid: public GridBase
/// @brief Return an accessor that provides random read and write access
/// to this grid's voxels.
/// @details The accessor is safe in the sense that it is registered with this grid's tree.
Accessor getAccessor() { return Accessor(tree()); }
Accessor getAccessor() { return mTree->getAccessor(); }
/// @brief Return an unsafe accessor that provides random read and write access
/// to this grid's voxels.
/// @details The accessor is unsafe in the sense that it is not registered
/// with this grid's tree. In some rare cases this can give a performance advantage
/// over a registered accessor, but it is unsafe if the tree topology is modified.
/// @warning Only use this method if you're an expert and know the
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
UnsafeAccessor getUnsafeAccessor() { return UnsafeAccessor(tree()); }
UnsafeAccessor getUnsafeAccessor() { return mTree->getUnsafeAccessor(); }
/// Return an accessor that provides random read-only access to this grid's voxels.
ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
ConstAccessor getAccessor() const { return mTree->getConstAccessor(); }
/// Return an accessor that provides random read-only access to this grid's voxels.
ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
ConstAccessor getConstAccessor() const { return mTree->getConstAccessor(); }
/// @brief Return an unsafe accessor that provides random read-only access
/// to this grid's voxels.
/// @details The accessor is unsafe in the sense that it is not registered
/// with this grid's tree. In some rare cases this can give a performance advantage
/// over a registered accessor, but it is unsafe if the tree topology is modified.
/// @warning Only use this method if you're an expert and know the
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
ConstUnsafeAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
ConstUnsafeAccessor getConstUnsafeAccessor() const { return mTree->getConstUnsafeAccessor(); }

/// Return an iterator over all of this grid's active values (tile and voxel).
ValueOnIter beginValueOn() { return tree().beginValueOn(); }
Expand Down
65 changes: 65 additions & 0 deletions openvdb/openvdb/tree/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ class Tree: public TreeBase

static const Index DEPTH = RootNodeType::LEVEL + 1;

using Accessor = ValueAccessor<Tree, true>;
using ConstAccessor = ValueAccessor<const Tree, true>;
using UnsafeAccessor = ValueAccessor<Tree, false>;
using ConstUnsafeAccessor = ValueAccessor<const Tree, false>;

/// @brief ValueConverter<T>::Type is the type of a tree having the same
/// hierarchy as this tree but a different value type, T.
///
Expand Down Expand Up @@ -623,6 +628,31 @@ class Tree: public TreeBase
/// Remove all tiles from this tree and all nodes other than the root node.
void clear();

/// @brief Return an accessor that provides random read and write access
/// to this tree's voxels.
/// @details The accessor is safe in the sense that it is registered with this tree.
Accessor getAccessor();
/// @brief Return an unsafe accessor that provides random read and write access
/// to this tree's voxels.
/// @details The accessor is unsafe in the sense that it is not registered
/// with this tree's tree. In some rare cases this can give a performance advantage
/// over a registered accessor, but it is unsafe if the tree topology is modified.
/// @warning Only use this method if you're an expert and know the
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
UnsafeAccessor getUnsafeAccessor();
/// Return an accessor that provides random read-only access to this tree's voxels.
ConstAccessor getAccessor() const;
/// Return an accessor that provides random read-only access to this tree's voxels.
ConstAccessor getConstAccessor() const;
/// @brief Return an unsafe accessor that provides random read-only access
/// to this tree's voxels.
/// @details The accessor is unsafe in the sense that it is not registered
/// with this tree. In some rare cases this can give a performance advantage
/// over a registered accessor, but it is unsafe if the tree topology is modified.
/// @warning Only use this method if you're an expert and know the
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
ConstUnsafeAccessor getConstUnsafeAccessor();

/// Clear all registered accessors.
void clearAllAccessors();

Expand Down Expand Up @@ -1318,6 +1348,41 @@ Tree<RootNodeType>::clear()
////////////////////////////////////////


template<typename RootNodeType>
typename Tree<RootNodeType>::Accessor
Tree<RootNodeType>::getAccessor()
{
return Accessor(*this);
}

template<typename RootNodeType>
typename Tree<RootNodeType>::UnsafeAccessor
Tree<RootNodeType>::getUnsafeAccessor()
{
return UnsafeAccessor(*this);
}

template<typename RootNodeType>
typename Tree<RootNodeType>::ConstAccessor
Tree<RootNodeType>::getAccessor() const
{
return ConstAccessor(*this);
}

template<typename RootNodeType>
typename Tree<RootNodeType>::ConstAccessor
Tree<RootNodeType>::getConstAccessor() const
{
return ConstAccessor(*this);
}

template<typename RootNodeType>
typename Tree<RootNodeType>::ConstUnsafeAccessor
Tree<RootNodeType>::getConstUnsafeAccessor()
{
return ConstUnsafeAccessor(*this);
}

template<typename RootNodeType>
inline void
Tree<RootNodeType>::attachAccessor(ValueAccessorBase<Tree, true>& accessor) const
Expand Down
5 changes: 5 additions & 0 deletions openvdb/openvdb/unittest/TestGrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class ProxyTree: public openvdb::TreeBase
using Ptr = openvdb::SharedPtr<ProxyTree>;
using ConstPtr = openvdb::SharedPtr<const ProxyTree>;

using Accessor = void;
using ConstAccessor = void;
using UnsafeAccessor = void;
using ConstUnsafeAccessor = void;

static const openvdb::Index DEPTH;
static const ValueType backg;

Expand Down
3 changes: 3 additions & 0 deletions pendingchanges/value_accessors_tree.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OpenVDB:
Improvements:
- ValueAccessors are now defined and created in the Tree class instead of in the Grid class so that custom Tree implementations may define and create their own ValueAccessors if desired.
Loading