Skip to content

Commit 13aa50a

Browse files
committed
Introduce a TreeTraits struct to differentiate between sparse and adaptive trees
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent 77a4243 commit 13aa50a

4 files changed

Lines changed: 84 additions & 0 deletions

File tree

openvdb/openvdb/Types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,30 @@ using make_index_sequence =
236236

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

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};
241+
242+
/// @brief A TreeTraits struct that can be used to query properties of an input T.
243+
template<typename T>
244+
struct TreeTraits
245+
{
246+
constexpr static TreeRepresentation Representation = TreeRepresentation::Unknown;
247+
};
248+
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+
}
260+
261+
////////////////////////////////////////
262+
239263

240264
template<typename T, bool = IsSpecializationOf<T, math::Vec2>::value ||
241265
IsSpecializationOf<T, math::Vec3>::value ||

openvdb/openvdb/adaptive/AdaptiveGrid.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,31 @@ struct TreeAdapter<adaptive::AdaptiveAccessor<_TreeType> >
282282
};
283283

284284

285+
////////////////////////////////////////
286+
287+
// Overload the TreeTraits struct to declare a const/non-const AdaptiveTree as adaptive
288+
289+
template<typename ValueT>
290+
struct TreeTraits<adaptive::AdaptiveTree<ValueT>>
291+
{
292+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
293+
};
294+
295+
template<typename ValueT>
296+
struct TreeTraits<const adaptive::AdaptiveTree<ValueT>>
297+
{
298+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
299+
};
300+
301+
// Overload the TreeTraits struct to declare an AdaptiveAccessor as adaptive
302+
303+
template<typename TreeT>
304+
struct TreeTraits<adaptive::AdaptiveAccessor<TreeT>>
305+
{
306+
constexpr static TreeRepresentation Representation = TreeRepresentation::Adaptive;
307+
};
308+
309+
285310
////////////////////////////////////////
286311

287312

openvdb/openvdb/tree/Tree.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,28 @@ Tree<RootNodeType>::print(std::ostream& os, int verboseLevel) const
21252125
}
21262126

21272127
} // namespace tree
2128+
2129+
2130+
////////////////////////////////////////
2131+
2132+
// Overload the TreeTraits struct to declare a const/non-const Tree as sparse
2133+
2134+
template<typename NodeT>
2135+
struct TreeTraits<tree::Tree<NodeT>>
2136+
{
2137+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
2138+
};
2139+
2140+
template<typename NodeT>
2141+
struct TreeTraits<const tree::Tree<NodeT>>
2142+
{
2143+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
2144+
};
2145+
2146+
2147+
////////////////////////////////////////
2148+
2149+
21282150
} // namespace OPENVDB_VERSION_NAME
21292151
} // namespace openvdb
21302152

openvdb/openvdb/tree/ValueAccessor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,19 @@ class ValueAccessorImpl final :
10211021
}; // ValueAccessorImpl
10221022

10231023
} // namespace tree
1024+
1025+
1026+
////////////////////////////////////////
1027+
1028+
// Overload the TreeTraits struct to declare a const/non-const ValueAccessorImpl as sparse
1029+
1030+
template<typename TreeT, bool IsSafeT, typename MutexT, typename IndexSequenceT>
1031+
struct TreeTraits<tree::ValueAccessorImpl<TreeT, IsSafeT, MutexT, IndexSequenceT>>
1032+
{
1033+
constexpr static TreeRepresentation Representation = TreeRepresentation::Sparse;
1034+
};
1035+
1036+
10241037
} // namespace OPENVDB_VERSION_NAME
10251038
} // namespace openvdb
10261039

0 commit comments

Comments
 (0)