Skip to content

Commit 294f0f1

Browse files
committed
Use an enum to distinguish between sparse vs adaptive trees
Signed-off-by: Dan Bailey <[email protected]>
1 parent ed5046d commit 294f0f1

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

openvdb/openvdb/Types.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,27 @@ using make_index_sequence =
236236

237237
////////////////////////////////////////
238238

239-
/// @brief A Traits struct that can be used to query properties of an input T.
239+
/// @brief An enum to distinguish between different types of Tree representation.
240+
enum class TreeRepresentation : uint32_t {Unknown = 0, Sparse = 1, Adaptive = 2, End = 3};
240241

242+
/// @brief A TreeTraits struct that can be used to query properties of an input T.
241243
template<typename T>
242244
struct TreeTraits
243245
{
244-
static const bool IsSparse = false;
245-
static const bool IsAdaptive = false;
246+
constexpr static TreeRepresentation Representation = TreeRepresentation::Unknown;
246247
};
247248

249+
template <typename T>
250+
constexpr bool isSparseTree()
251+
{
252+
return TreeTraits<T>::Representation == TreeRepresentation::Sparse;
253+
}
254+
255+
template <typename T>
256+
constexpr bool isAdaptiveTree()
257+
{
258+
return TreeTraits<T>::Representation == TreeRepresentation::Adaptive;
259+
}
248260

249261
////////////////////////////////////////
250262

openvdb/openvdb/adaptive/AdaptiveGrid.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,21 @@ struct TreeAdapter<adaptive::AdaptiveAccessor<_TreeType> >
289289
template<typename ValueT>
290290
struct TreeTraits<adaptive::AdaptiveTree<ValueT>>
291291
{
292-
static const bool IsSparse = false;
293-
static const bool IsAdaptive = true;
292+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
294293
};
295294

296295
template<typename ValueT>
297296
struct TreeTraits<const adaptive::AdaptiveTree<ValueT>>
298297
{
299-
static const bool IsSparse = false;
300-
static const bool IsAdaptive = true;
298+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
301299
};
302300

303301
// Overload the TreeTraits struct to declare an AdaptiveAccessor as adaptive
304302

305303
template<typename TreeT>
306304
struct TreeTraits<adaptive::AdaptiveAccessor<TreeT>>
307305
{
308-
static const bool IsSparse = false;
309-
static const bool IsAdaptive = true;
306+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
310307
};
311308

312309

openvdb/openvdb/tools/Interpolation.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ BoxSampler::getValues(ValueT (&data)[N][N][N], const TreeT& inTree, Coord ijk)
631631
{
632632
// This algorithm is only defined for sparse grids
633633

634-
if constexpr (TreeTraits<TreeT>::IsSparse) {
634+
if constexpr (isSparseTree<TreeT>()) {
635635
data[0][0][0] = inTree.getValue(ijk); // i, j, k
636636

637637
ijk[2] += 1;
@@ -750,7 +750,7 @@ inline bool
750750
BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
751751
typename TreeT::ValueType& result)
752752
{
753-
if constexpr (TreeTraits<TreeT>::IsSparse) {
753+
if constexpr (isSparseTree<TreeT>()) {
754754
using ValueT = typename TreeT::ValueType;
755755

756756
const Vec3i inIdx = local_util::floorVec3(inCoord);
@@ -765,7 +765,7 @@ BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord,
765765
result = BoxSampler::trilinearInterpolation(data, uvw);
766766

767767
return hasActiveValues;
768-
} else if constexpr (TreeTraits<TreeT>::IsAdaptive) {
768+
} else if constexpr (isAdaptiveTree<TreeT>()) {
769769
// As an example, return the background value.
770770
// This is where the logic that could sample against an adaptive tree would live.
771771
// Extract the tree from the Tree or ValueAccessor
@@ -783,7 +783,7 @@ template<class TreeT>
783783
inline typename TreeT::ValueType
784784
BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
785785
{
786-
if constexpr (TreeTraits<TreeT>::IsSparse) {
786+
if constexpr (isSparseTree<TreeT>()) {
787787

788788
using ValueT = typename TreeT::ValueType;
789789

@@ -797,7 +797,7 @@ BoxSampler::sample(const TreeT& inTree, const Vec3R& inCoord)
797797
BoxSampler::getValues(data, inTree, Coord(inIdx));
798798

799799
return BoxSampler::trilinearInterpolation(data, uvw);
800-
} else if constexpr (TreeTraits<TreeT>::IsAdaptive) {
800+
} else if constexpr (isAdaptiveTree<TreeT>()) {
801801
// As an example, return the background value.
802802
// This is where the logic that could sample against an adaptive tree would live.
803803
// Extract the tree from the Tree or ValueAccessor

openvdb/openvdb/tree/Tree.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,15 +2134,13 @@ Tree<RootNodeType>::print(std::ostream& os, int verboseLevel) const
21342134
template<typename NodeT>
21352135
struct TreeTraits<tree::Tree<NodeT>>
21362136
{
2137-
static const bool IsSparse = true;
2138-
static const bool IsAdaptive = false;
2137+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
21392138
};
21402139

21412140
template<typename NodeT>
21422141
struct TreeTraits<const tree::Tree<NodeT>>
21432142
{
2144-
static const bool IsSparse = true;
2145-
static const bool IsAdaptive = false;
2143+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
21462144
};
21472145

21482146

openvdb/openvdb/tree/ValueAccessor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,7 @@ class ValueAccessorImpl final :
10301030
template<typename TreeT, bool IsSafeT, typename MutexT, typename IndexSequenceT>
10311031
struct TreeTraits<tree::ValueAccessorImpl<TreeT, IsSafeT, MutexT, IndexSequenceT>>
10321032
{
1033-
static const bool IsSparse = true;
1034-
static const bool IsAdaptive = false;
1033+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
10351034
};
10361035

10371036

0 commit comments

Comments
 (0)