Skip to content

Commit 3b473dd

Browse files
authored
Merge pull request #1775 from danrbailey/tree_adapter_improvements
Update TreeAdapter to work with const inputs
2 parents 1f9a882 + 0a3de16 commit 3b473dd

File tree

2 files changed

+166
-29
lines changed

2 files changed

+166
-29
lines changed

openvdb/openvdb/Grid.h

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ struct TreeAdapter
10631063
using TreePtrType = typename TreeType::Ptr;
10641064
using ConstTreePtrType = typename TreeType::ConstPtr;
10651065
using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1066-
using GridType = Grid<TreeType>;
1066+
using GridType = Grid<NonConstTreeType>;
10671067
using NonConstGridType = Grid<NonConstTreeType>;
10681068
using GridPtrType = typename GridType::Ptr;
10691069
using NonConstGridPtrType = typename NonConstGridType::Ptr;
@@ -1073,14 +1073,14 @@ struct TreeAdapter
10731073
using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
10741074
using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
10751075

1076-
static TreeType& tree(TreeType& t) { return t; }
1077-
static TreeType& tree(GridType& g) { return g.tree(); }
1078-
static const TreeType& tree(const TreeType& t) { return t; }
1079-
static const TreeType& tree(const GridType& g) { return g.tree(); }
1080-
static const TreeType& constTree(TreeType& t) { return t; }
1081-
static const TreeType& constTree(GridType& g) { return g.constTree(); }
1082-
static const TreeType& constTree(const TreeType& t) { return t; }
1083-
static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1076+
static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1077+
static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1078+
static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1079+
static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1080+
static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1081+
static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1082+
static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1083+
static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
10841084
};
10851085

10861086

@@ -1103,19 +1103,19 @@ struct TreeAdapter<Grid<_TreeType> >
11031103
using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
11041104
using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
11051105

1106-
static TreeType& tree(TreeType& t) { return t; }
1107-
static TreeType& tree(GridType& g) { return g.tree(); }
1108-
static const TreeType& tree(const TreeType& t) { return t; }
1109-
static const TreeType& tree(const GridType& g) { return g.tree(); }
1110-
static const TreeType& constTree(TreeType& t) { return t; }
1111-
static const TreeType& constTree(GridType& g) { return g.constTree(); }
1112-
static const TreeType& constTree(const TreeType& t) { return t; }
1113-
static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1106+
static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1107+
static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1108+
static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1109+
static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1110+
static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1111+
static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1112+
static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1113+
static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
11141114
};
11151115

1116-
/// Partial specialization for ValueAccessor types
1116+
/// Partial specialization for const Grid types
11171117
template<typename _TreeType>
1118-
struct TreeAdapter<tree::ValueAccessor<_TreeType> >
1118+
struct TreeAdapter<const Grid<_TreeType> >
11191119
{
11201120
using TreeType = _TreeType;
11211121
using NonConstTreeType = typename std::remove_const<TreeType>::type;
@@ -1132,16 +1132,51 @@ struct TreeAdapter<tree::ValueAccessor<_TreeType> >
11321132
using ConstAccessorType = typename tree::ValueAccessor<const TreeType>;
11331133
using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
11341134

1135-
static TreeType& tree(TreeType& t) { return t; }
1136-
static TreeType& tree(GridType& g) { return g.tree(); }
1137-
static TreeType& tree(AccessorType& a) { return a.tree(); }
1138-
static const TreeType& tree(const TreeType& t) { return t; }
1139-
static const TreeType& tree(const GridType& g) { return g.tree(); }
1140-
static const TreeType& tree(const AccessorType& a) { return a.tree(); }
1141-
static const TreeType& constTree(TreeType& t) { return t; }
1142-
static const TreeType& constTree(GridType& g) { return g.constTree(); }
1143-
static const TreeType& constTree(const TreeType& t) { return t; }
1144-
static const TreeType& constTree(const GridType& g) { return g.constTree(); }
1135+
static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1136+
static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1137+
static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1138+
static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1139+
static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1140+
static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1141+
static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1142+
static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1143+
};
1144+
1145+
/// Partial specialization for ValueAccessor types
1146+
template<typename _TreeType>
1147+
struct TreeAdapter<tree::ValueAccessor<_TreeType> >
1148+
{
1149+
using TreeType = _TreeType;
1150+
using NonConstTreeType = typename std::remove_const<TreeType>::type;
1151+
using TreePtrType = typename TreeType::Ptr;
1152+
using ConstTreePtrType = typename TreeType::ConstPtr;
1153+
using NonConstTreePtrType = typename NonConstTreeType::Ptr;
1154+
using GridType = Grid<NonConstTreeType>;
1155+
using NonConstGridType = Grid<NonConstTreeType>;
1156+
using GridPtrType = typename GridType::Ptr;
1157+
using NonConstGridPtrType = typename NonConstGridType::Ptr;
1158+
using ConstGridPtrType = typename GridType::ConstPtr;
1159+
using ValueType = typename TreeType::ValueType;
1160+
using AccessorType = typename tree::ValueAccessor<TreeType>;
1161+
using ConstAccessorType = typename tree::ValueAccessor<const NonConstTreeType>;
1162+
using NonConstAccessorType = typename tree::ValueAccessor<NonConstTreeType>;
1163+
1164+
static NonConstTreeType& tree(NonConstTreeType& t) { return t; }
1165+
static NonConstTreeType& tree(NonConstGridType& g) { return g.tree(); }
1166+
static NonConstTreeType& tree(NonConstAccessorType& a) { return a.tree(); }
1167+
static const NonConstTreeType& tree(ConstAccessorType& a) { return a.tree(); }
1168+
static const NonConstTreeType& tree(const NonConstTreeType& t) { return t; }
1169+
static const NonConstTreeType& tree(const NonConstGridType& g) { return g.tree(); }
1170+
static const NonConstTreeType& tree(const NonConstAccessorType& a) { return a.tree(); }
1171+
static const NonConstTreeType& tree(const ConstAccessorType& a) { return a.tree(); }
1172+
static const NonConstTreeType& constTree(NonConstTreeType& t) { return t; }
1173+
static const NonConstTreeType& constTree(NonConstGridType& g) { return g.constTree(); }
1174+
static const NonConstTreeType& constTree(NonConstAccessorType& a) { return a.tree(); }
1175+
static const NonConstTreeType& constTree(ConstAccessorType& a) { return a.tree(); }
1176+
static const NonConstTreeType& constTree(const NonConstTreeType& t) { return t; }
1177+
static const NonConstTreeType& constTree(const NonConstGridType& g) { return g.constTree(); }
1178+
static const NonConstTreeType& constTree(const NonConstAccessorType& a) { return a.tree(); }
1179+
static const NonConstTreeType& constTree(const ConstAccessorType& a) { return a.tree(); }
11451180
};
11461181

11471182
//@}

openvdb/openvdb/unittest/TestGrid.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,105 @@ TEST_F(TestGrid, testApply)
517517
EXPECT_EQ(4, n);
518518
}
519519
}
520+
521+
TEST_F(TestGrid, testAdapter)
522+
{
523+
openvdb::FloatGrid floatGrid;
524+
const openvdb::FloatGrid constFloatGrid = floatGrid;
525+
openvdb::FloatTree& floatTree = floatGrid.tree();
526+
const openvdb::FloatTree& constFloatTree = floatGrid.constTree();
527+
openvdb::tree::ValueAccessor<openvdb::FloatTree> floatAcc(floatGrid.tree());
528+
openvdb::tree::ValueAccessor<const openvdb::FloatTree> constFloatAcc(floatGrid.constTree());
529+
530+
{
531+
// test TreeAdapter<Tree>
532+
533+
using AdapterT = openvdb::TreeAdapter<openvdb::FloatTree>;
534+
535+
AdapterT::tree(floatTree);
536+
AdapterT::tree(floatGrid);
537+
AdapterT::tree(constFloatTree);
538+
AdapterT::tree(constFloatGrid);
539+
AdapterT::constTree(floatTree);
540+
AdapterT::constTree(floatGrid);
541+
AdapterT::constTree(constFloatTree);
542+
AdapterT::constTree(constFloatGrid);
543+
544+
// test TreeAdapter<const Tree>
545+
546+
using ConstAdapterT = openvdb::TreeAdapter<const openvdb::FloatTree>;
547+
548+
ConstAdapterT::tree(floatTree);
549+
ConstAdapterT::tree(floatGrid);
550+
ConstAdapterT::tree(constFloatTree);
551+
ConstAdapterT::tree(constFloatGrid);
552+
ConstAdapterT::constTree(floatTree);
553+
ConstAdapterT::constTree(floatGrid);
554+
ConstAdapterT::constTree(constFloatTree);
555+
ConstAdapterT::constTree(constFloatGrid);
556+
}
557+
558+
{
559+
// test TreeAdapter<Grid>
560+
561+
using AdapterT = openvdb::TreeAdapter<openvdb::FloatGrid>;
562+
563+
AdapterT::tree(floatTree);
564+
AdapterT::tree(floatGrid);
565+
AdapterT::tree(constFloatTree);
566+
AdapterT::tree(constFloatGrid);
567+
AdapterT::constTree(floatTree);
568+
AdapterT::constTree(floatGrid);
569+
AdapterT::constTree(constFloatTree);
570+
AdapterT::constTree(constFloatGrid);
571+
572+
// test TreeAdapter<const Grid>
573+
574+
using ConstAdapterT = openvdb::TreeAdapter<const openvdb::FloatGrid>;
575+
576+
ConstAdapterT::tree(floatTree);
577+
ConstAdapterT::tree(floatGrid);
578+
ConstAdapterT::tree(constFloatTree);
579+
ConstAdapterT::tree(constFloatGrid);
580+
ConstAdapterT::constTree(floatTree);
581+
ConstAdapterT::constTree(floatGrid);
582+
ConstAdapterT::constTree(constFloatTree);
583+
ConstAdapterT::constTree(constFloatGrid);
584+
}
585+
586+
{
587+
// test TreeAdapter<ValueAccessor<Tree>>
588+
589+
using AdapterT = openvdb::TreeAdapter<openvdb::tree::ValueAccessor<openvdb::FloatTree>>;
590+
591+
AdapterT::tree(floatTree);
592+
AdapterT::tree(floatGrid);
593+
AdapterT::tree(floatAcc);
594+
AdapterT::tree(constFloatAcc);
595+
AdapterT::tree(constFloatTree);
596+
AdapterT::tree(constFloatGrid);
597+
AdapterT::constTree(floatTree);
598+
AdapterT::constTree(floatGrid);
599+
AdapterT::constTree(floatAcc);
600+
AdapterT::constTree(constFloatAcc);
601+
AdapterT::constTree(constFloatTree);
602+
AdapterT::constTree(constFloatGrid);
603+
604+
// test TreeAdapter<ValueAccessor<const Tree>>
605+
606+
using AdapterConstT = openvdb::TreeAdapter<openvdb::tree::ValueAccessor<const openvdb::FloatTree>>;
607+
608+
AdapterConstT::tree(floatTree);
609+
AdapterConstT::tree(floatGrid);
610+
AdapterConstT::tree(floatAcc);
611+
AdapterConstT::tree(constFloatAcc);
612+
AdapterConstT::tree(constFloatTree);
613+
AdapterConstT::tree(constFloatGrid);
614+
AdapterConstT::constTree(floatTree);
615+
AdapterConstT::constTree(floatGrid);
616+
AdapterConstT::constTree(floatAcc);
617+
AdapterConstT::constTree(constFloatAcc);
618+
AdapterConstT::constTree(constFloatTree);
619+
AdapterConstT::constTree(constFloatGrid);
620+
}
621+
}

0 commit comments

Comments
 (0)