Skip to content

Commit d2cf953

Browse files
committed
Introduce a TreeTraits struct to differentiate between sparse and adaptive trees
Signed-off-by: Dan Bailey <[email protected]>
1 parent e36a4a6 commit d2cf953

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

openvdb/openvdb/Types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ using make_index_sequence =
234234
std::decay_t<decltype(make_index_sequence_impl<N>())>;
235235

236236

237+
////////////////////////////////////////
238+
239+
/// @brief A Traits struct that can be used to query properties of an input T.
240+
241+
template<typename T>
242+
struct TreeTraits
243+
{
244+
static const bool IsSparse = false;
245+
static const bool IsAdaptive = false;
246+
};
247+
248+
237249
////////////////////////////////////////
238250

239251

openvdb/openvdb/adaptive/AdaptiveGrid.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,34 @@ 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+
static const bool IsSparse = false;
293+
static const bool IsAdaptive = true;
294+
};
295+
296+
template<typename ValueT>
297+
struct TreeTraits<const adaptive::AdaptiveTree<ValueT>>
298+
{
299+
static const bool IsSparse = false;
300+
static const bool IsAdaptive = true;
301+
};
302+
303+
// Overload the TreeTraits struct to declare an AdaptiveAccessor as adaptive
304+
305+
template<typename TreeT>
306+
struct TreeTraits<adaptive::AdaptiveAccessor<TreeT>>
307+
{
308+
static const bool IsSparse = false;
309+
static const bool IsAdaptive = true;
310+
};
311+
312+
285313
////////////////////////////////////////
286314

287315

openvdb/openvdb/tree/Tree.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,30 @@ 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+
static const bool IsSparse = true;
2138+
static const bool IsAdaptive = false;
2139+
};
2140+
2141+
template<typename NodeT>
2142+
struct TreeTraits<const tree::Tree<NodeT>>
2143+
{
2144+
static const bool IsSparse = true;
2145+
static const bool IsAdaptive = false;
2146+
};
2147+
2148+
2149+
////////////////////////////////////////
2150+
2151+
21282152
} // namespace OPENVDB_VERSION_NAME
21292153
} // namespace openvdb
21302154

openvdb/openvdb/tree/ValueAccessor.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,20 @@ 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+
static const bool IsSparse = true;
1034+
static const bool IsAdaptive = false;
1035+
};
1036+
1037+
10241038
} // namespace OPENVDB_VERSION_NAME
10251039
} // namespace openvdb
10261040

0 commit comments

Comments
 (0)