diff --git a/openvdb/openvdb/Grid.h b/openvdb/openvdb/Grid.h index 14aad39122..c90b9e730a 100644 --- a/openvdb/openvdb/Grid.h +++ b/openvdb/openvdb/Grid.h @@ -1063,7 +1063,7 @@ struct TreeAdapter using TreePtrType = typename TreeType::Ptr; using ConstTreePtrType = typename TreeType::ConstPtr; using NonConstTreePtrType = typename NonConstTreeType::Ptr; - using GridType = Grid; + using GridType = Grid; using NonConstGridType = Grid; using GridPtrType = typename GridType::Ptr; using NonConstGridPtrType = typename NonConstGridType::Ptr; @@ -1073,14 +1073,14 @@ struct TreeAdapter using ConstAccessorType = typename tree::ValueAccessor; using NonConstAccessorType = typename tree::ValueAccessor; - static TreeType& tree(TreeType& t) { return t; } - static TreeType& tree(GridType& g) { return g.tree(); } - static const TreeType& tree(const TreeType& t) { return t; } - static const TreeType& tree(const GridType& g) { return g.tree(); } - static const TreeType& constTree(TreeType& t) { return t; } - static const TreeType& constTree(GridType& g) { return g.constTree(); } - static const TreeType& constTree(const TreeType& t) { return t; } - static const TreeType& constTree(const GridType& g) { return g.constTree(); } + static NonConstTreeType& tree(NonConstTreeType& t) { return t; } + static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); } + static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); } }; @@ -1103,19 +1103,19 @@ struct TreeAdapter > using ConstAccessorType = typename tree::ValueAccessor; using NonConstAccessorType = typename tree::ValueAccessor; - static TreeType& tree(TreeType& t) { return t; } - static TreeType& tree(GridType& g) { return g.tree(); } - static const TreeType& tree(const TreeType& t) { return t; } - static const TreeType& tree(const GridType& g) { return g.tree(); } - static const TreeType& constTree(TreeType& t) { return t; } - static const TreeType& constTree(GridType& g) { return g.constTree(); } - static const TreeType& constTree(const TreeType& t) { return t; } - static const TreeType& constTree(const GridType& g) { return g.constTree(); } + static NonConstTreeType& tree(NonConstTreeType& t) { return t; } + static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); } + static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); } }; -/// Partial specialization for ValueAccessor types +/// Partial specialization for const Grid types template -struct TreeAdapter > +struct TreeAdapter > { using TreeType = _TreeType; using NonConstTreeType = typename std::remove_const::type; @@ -1132,16 +1132,51 @@ struct TreeAdapter > using ConstAccessorType = typename tree::ValueAccessor; using NonConstAccessorType = typename tree::ValueAccessor; - static TreeType& tree(TreeType& t) { return t; } - static TreeType& tree(GridType& g) { return g.tree(); } - static TreeType& tree(AccessorType& a) { return a.tree(); } - static const TreeType& tree(const TreeType& t) { return t; } - static const TreeType& tree(const GridType& g) { return g.tree(); } - static const TreeType& tree(const AccessorType& a) { return a.tree(); } - static const TreeType& constTree(TreeType& t) { return t; } - static const TreeType& constTree(GridType& g) { return g.constTree(); } - static const TreeType& constTree(const TreeType& t) { return t; } - static const TreeType& constTree(const GridType& g) { return g.constTree(); } + static NonConstTreeType& tree(NonConstTreeType& t) { return t; } + static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); } + static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); } +}; + +/// Partial specialization for ValueAccessor types +template +struct TreeAdapter > +{ + using TreeType = _TreeType; + using NonConstTreeType = typename std::remove_const::type; + using TreePtrType = typename TreeType::Ptr; + using ConstTreePtrType = typename TreeType::ConstPtr; + using NonConstTreePtrType = typename NonConstTreeType::Ptr; + using GridType = Grid; + using NonConstGridType = Grid; + using GridPtrType = typename GridType::Ptr; + using NonConstGridPtrType = typename NonConstGridType::Ptr; + using ConstGridPtrType = typename GridType::ConstPtr; + using ValueType = typename TreeType::ValueType; + using AccessorType = typename tree::ValueAccessor; + using ConstAccessorType = typename tree::ValueAccessor; + using NonConstAccessorType = typename tree::ValueAccessor; + + static NonConstTreeType& tree(NonConstTreeType& t) { return t; } + static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); } + static NonConstTreeType& tree(NonConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& tree(ConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); } + static const NonConstTreeType& tree(const NonConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& tree(const ConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); } + static const NonConstTreeType& constTree(NonConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& constTree(ConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; } + static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); } + static const NonConstTreeType& constTree(const NonConstAccessorType& a) { return a.tree(); } + static const NonConstTreeType& constTree(const ConstAccessorType& a) { return a.tree(); } }; //@} diff --git a/openvdb/openvdb/unittest/TestGrid.cc b/openvdb/openvdb/unittest/TestGrid.cc index 1e9d058b77..f769f2f384 100644 --- a/openvdb/openvdb/unittest/TestGrid.cc +++ b/openvdb/openvdb/unittest/TestGrid.cc @@ -512,3 +512,105 @@ TEST_F(TestGrid, testApply) EXPECT_EQ(4, n); } } + +TEST_F(TestGrid, testAdapter) +{ + openvdb::FloatGrid floatGrid; + const openvdb::FloatGrid constFloatGrid = floatGrid; + openvdb::FloatTree& floatTree = floatGrid.tree(); + const openvdb::FloatTree& constFloatTree = floatGrid.constTree(); + openvdb::tree::ValueAccessor floatAcc(floatGrid.tree()); + openvdb::tree::ValueAccessor constFloatAcc(floatGrid.constTree()); + + { + // test TreeAdapter + + using AdapterT = openvdb::TreeAdapter; + + AdapterT::tree(floatTree); + AdapterT::tree(floatGrid); + AdapterT::tree(constFloatTree); + AdapterT::tree(constFloatGrid); + AdapterT::constTree(floatTree); + AdapterT::constTree(floatGrid); + AdapterT::constTree(constFloatTree); + AdapterT::constTree(constFloatGrid); + + // test TreeAdapter + + using ConstAdapterT = openvdb::TreeAdapter; + + ConstAdapterT::tree(floatTree); + ConstAdapterT::tree(floatGrid); + ConstAdapterT::tree(constFloatTree); + ConstAdapterT::tree(constFloatGrid); + ConstAdapterT::constTree(floatTree); + ConstAdapterT::constTree(floatGrid); + ConstAdapterT::constTree(constFloatTree); + ConstAdapterT::constTree(constFloatGrid); + } + + { + // test TreeAdapter + + using AdapterT = openvdb::TreeAdapter; + + AdapterT::tree(floatTree); + AdapterT::tree(floatGrid); + AdapterT::tree(constFloatTree); + AdapterT::tree(constFloatGrid); + AdapterT::constTree(floatTree); + AdapterT::constTree(floatGrid); + AdapterT::constTree(constFloatTree); + AdapterT::constTree(constFloatGrid); + + // test TreeAdapter + + using ConstAdapterT = openvdb::TreeAdapter; + + ConstAdapterT::tree(floatTree); + ConstAdapterT::tree(floatGrid); + ConstAdapterT::tree(constFloatTree); + ConstAdapterT::tree(constFloatGrid); + ConstAdapterT::constTree(floatTree); + ConstAdapterT::constTree(floatGrid); + ConstAdapterT::constTree(constFloatTree); + ConstAdapterT::constTree(constFloatGrid); + } + + { + // test TreeAdapter> + + using AdapterT = openvdb::TreeAdapter>; + + AdapterT::tree(floatTree); + AdapterT::tree(floatGrid); + AdapterT::tree(floatAcc); + AdapterT::tree(constFloatAcc); + AdapterT::tree(constFloatTree); + AdapterT::tree(constFloatGrid); + AdapterT::constTree(floatTree); + AdapterT::constTree(floatGrid); + AdapterT::constTree(floatAcc); + AdapterT::constTree(constFloatAcc); + AdapterT::constTree(constFloatTree); + AdapterT::constTree(constFloatGrid); + + // test TreeAdapter> + + using AdapterConstT = openvdb::TreeAdapter>; + + AdapterConstT::tree(floatTree); + AdapterConstT::tree(floatGrid); + AdapterConstT::tree(floatAcc); + AdapterConstT::tree(constFloatAcc); + AdapterConstT::tree(constFloatTree); + AdapterConstT::tree(constFloatGrid); + AdapterConstT::constTree(floatTree); + AdapterConstT::constTree(floatGrid); + AdapterConstT::constTree(floatAcc); + AdapterConstT::constTree(constFloatAcc); + AdapterConstT::constTree(constFloatTree); + AdapterConstT::constTree(constFloatGrid); + } +}