Skip to content

Commit 1f9a882

Browse files
authored
Merge pull request #1789 from danrbailey/move_value_accessors_to_tree
Adjust existing grid API to move ValueAccessor methods to the tree
2 parents 355120c + 289c99a commit 1f9a882

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

openvdb/openvdb/Grid.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ class Grid: public GridBase
586586
using ValueAllIter = typename _TreeType::ValueAllIter;
587587
using ValueAllCIter = typename _TreeType::ValueAllCIter;
588588

589-
using Accessor = typename tree::ValueAccessor<_TreeType, true>;
590-
using ConstAccessor = typename tree::ValueAccessor<const _TreeType, true>;
591-
using UnsafeAccessor = typename tree::ValueAccessor<_TreeType, false>;
592-
using ConstUnsafeAccessor = typename tree::ValueAccessor<const _TreeType, false>;
589+
using Accessor = typename _TreeType::Accessor;
590+
using ConstAccessor = typename _TreeType::ConstAccessor;
591+
using UnsafeAccessor = typename _TreeType::UnsafeAccessor;
592+
using ConstUnsafeAccessor = typename _TreeType::ConstUnsafeAccessor;
593593

594594
/// @brief ValueConverter<T>::Type is the type of a grid having the same
595595
/// hierarchy as this grid but a different value type, T.
@@ -729,27 +729,27 @@ class Grid: public GridBase
729729
/// @brief Return an accessor that provides random read and write access
730730
/// to this grid's voxels.
731731
/// @details The accessor is safe in the sense that it is registered with this grid's tree.
732-
Accessor getAccessor() { return Accessor(tree()); }
732+
Accessor getAccessor() { return mTree->getAccessor(); }
733733
/// @brief Return an unsafe accessor that provides random read and write access
734734
/// to this grid's voxels.
735735
/// @details The accessor is unsafe in the sense that it is not registered
736736
/// with this grid's tree. In some rare cases this can give a performance advantage
737737
/// over a registered accessor, but it is unsafe if the tree topology is modified.
738738
/// @warning Only use this method if you're an expert and know the
739739
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
740-
UnsafeAccessor getUnsafeAccessor() { return UnsafeAccessor(tree()); }
740+
UnsafeAccessor getUnsafeAccessor() { return mTree->getUnsafeAccessor(); }
741741
/// Return an accessor that provides random read-only access to this grid's voxels.
742-
ConstAccessor getAccessor() const { return ConstAccessor(tree()); }
742+
ConstAccessor getAccessor() const { return mTree->getConstAccessor(); }
743743
/// Return an accessor that provides random read-only access to this grid's voxels.
744-
ConstAccessor getConstAccessor() const { return ConstAccessor(tree()); }
744+
ConstAccessor getConstAccessor() const { return mTree->getConstAccessor(); }
745745
/// @brief Return an unsafe accessor that provides random read-only access
746746
/// to this grid's voxels.
747747
/// @details The accessor is unsafe in the sense that it is not registered
748748
/// with this grid's tree. In some rare cases this can give a performance advantage
749749
/// over a registered accessor, but it is unsafe if the tree topology is modified.
750750
/// @warning Only use this method if you're an expert and know the
751751
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
752-
ConstUnsafeAccessor getConstUnsafeAccessor() const { return ConstUnsafeAccessor(tree()); }
752+
ConstUnsafeAccessor getConstUnsafeAccessor() const { return mTree->getConstUnsafeAccessor(); }
753753

754754
/// Return an iterator over all of this grid's active values (tile and voxel).
755755
ValueOnIter beginValueOn() { return tree().beginValueOn(); }

openvdb/openvdb/tree/Tree.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ class Tree: public TreeBase
188188

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

191+
using Accessor = ValueAccessor<Tree, true>;
192+
using ConstAccessor = ValueAccessor<const Tree, true>;
193+
using UnsafeAccessor = ValueAccessor<Tree, false>;
194+
using ConstUnsafeAccessor = ValueAccessor<const Tree, false>;
195+
191196
/// @brief ValueConverter<T>::Type is the type of a tree having the same
192197
/// hierarchy as this tree but a different value type, T.
193198
///
@@ -623,6 +628,31 @@ class Tree: public TreeBase
623628
/// Remove all tiles from this tree and all nodes other than the root node.
624629
void clear();
625630

631+
/// @brief Return an accessor that provides random read and write access
632+
/// to this tree's voxels.
633+
/// @details The accessor is safe in the sense that it is registered with this tree.
634+
Accessor getAccessor();
635+
/// @brief Return an unsafe accessor that provides random read and write access
636+
/// to this tree's voxels.
637+
/// @details The accessor is unsafe in the sense that it is not registered
638+
/// with this tree's tree. In some rare cases this can give a performance advantage
639+
/// over a registered accessor, but it is unsafe if the tree topology is modified.
640+
/// @warning Only use this method if you're an expert and know the
641+
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
642+
UnsafeAccessor getUnsafeAccessor();
643+
/// Return an accessor that provides random read-only access to this tree's voxels.
644+
ConstAccessor getAccessor() const;
645+
/// Return an accessor that provides random read-only access to this tree's voxels.
646+
ConstAccessor getConstAccessor() const;
647+
/// @brief Return an unsafe accessor that provides random read-only access
648+
/// to this tree's voxels.
649+
/// @details The accessor is unsafe in the sense that it is not registered
650+
/// with this tree. In some rare cases this can give a performance advantage
651+
/// over a registered accessor, but it is unsafe if the tree topology is modified.
652+
/// @warning Only use this method if you're an expert and know the
653+
/// risks of using an unregistered accessor (see tree/ValueAccessor.h)
654+
ConstUnsafeAccessor getConstUnsafeAccessor();
655+
626656
/// Clear all registered accessors.
627657
void clearAllAccessors();
628658

@@ -1318,6 +1348,41 @@ Tree<RootNodeType>::clear()
13181348
////////////////////////////////////////
13191349

13201350

1351+
template<typename RootNodeType>
1352+
typename Tree<RootNodeType>::Accessor
1353+
Tree<RootNodeType>::getAccessor()
1354+
{
1355+
return Accessor(*this);
1356+
}
1357+
1358+
template<typename RootNodeType>
1359+
typename Tree<RootNodeType>::UnsafeAccessor
1360+
Tree<RootNodeType>::getUnsafeAccessor()
1361+
{
1362+
return UnsafeAccessor(*this);
1363+
}
1364+
1365+
template<typename RootNodeType>
1366+
typename Tree<RootNodeType>::ConstAccessor
1367+
Tree<RootNodeType>::getAccessor() const
1368+
{
1369+
return ConstAccessor(*this);
1370+
}
1371+
1372+
template<typename RootNodeType>
1373+
typename Tree<RootNodeType>::ConstAccessor
1374+
Tree<RootNodeType>::getConstAccessor() const
1375+
{
1376+
return ConstAccessor(*this);
1377+
}
1378+
1379+
template<typename RootNodeType>
1380+
typename Tree<RootNodeType>::ConstUnsafeAccessor
1381+
Tree<RootNodeType>::getConstUnsafeAccessor()
1382+
{
1383+
return ConstUnsafeAccessor(*this);
1384+
}
1385+
13211386
template<typename RootNodeType>
13221387
inline void
13231388
Tree<RootNodeType>::attachAccessor(ValueAccessorBase<Tree, true>& accessor) const

openvdb/openvdb/unittest/TestGrid.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class ProxyTree: public openvdb::TreeBase
4040
using Ptr = openvdb::SharedPtr<ProxyTree>;
4141
using ConstPtr = openvdb::SharedPtr<const ProxyTree>;
4242

43+
using Accessor = void;
44+
using ConstAccessor = void;
45+
using UnsafeAccessor = void;
46+
using ConstUnsafeAccessor = void;
47+
4348
static const openvdb::Index DEPTH;
4449
static const ValueType backg;
4550

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OpenVDB:
2+
Improvements:
3+
- 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.

0 commit comments

Comments
 (0)