Skip to content

Commit

Permalink
Introduce a TreeTraits struct to differentiate between sparse and ada…
Browse files Browse the repository at this point in the history
…ptive trees

Signed-off-by: Dan Bailey <[email protected]>
  • Loading branch information
danrbailey committed Mar 12, 2024
1 parent 77a4243 commit 6145b10
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions openvdb/openvdb/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ using make_index_sequence =
std::decay_t<decltype(make_index_sequence_impl<N>())>;


////////////////////////////////////////

/// @brief A Traits struct that can be used to query properties of an input T.

template<typename T>
struct TreeTraits
{
static const bool IsSparse = false;
static const bool IsAdaptive = false;
};


////////////////////////////////////////


Expand Down
28 changes: 28 additions & 0 deletions openvdb/openvdb/adaptive/AdaptiveGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,34 @@ struct TreeAdapter<adaptive::AdaptiveAccessor<_TreeType> >
};


////////////////////////////////////////

// Overload the TreeTraits struct to declare a const/non-const AdaptiveTree as adaptive

template<typename ValueT>
struct TreeTraits<adaptive::AdaptiveTree<ValueT>>
{
static const bool IsSparse = false;
static const bool IsAdaptive = true;
};

template<typename ValueT>
struct TreeTraits<const adaptive::AdaptiveTree<ValueT>>
{
static const bool IsSparse = false;
static const bool IsAdaptive = true;
};

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

template<typename TreeT>
struct TreeTraits<adaptive::AdaptiveAccessor<TreeT>>
{
static const bool IsSparse = false;
static const bool IsAdaptive = true;
};


////////////////////////////////////////


Expand Down
24 changes: 24 additions & 0 deletions openvdb/openvdb/tree/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,30 @@ Tree<RootNodeType>::print(std::ostream& os, int verboseLevel) const
}

} // namespace tree


////////////////////////////////////////

// Overload the TreeTraits struct to declare a const/non-const Tree as sparse

template<typename NodeT>
struct TreeTraits<tree::Tree<NodeT>>
{
static const bool IsSparse = true;
static const bool IsAdaptive = false;
};

template<typename NodeT>
struct TreeTraits<const tree::Tree<NodeT>>
{
static const bool IsSparse = true;
static const bool IsAdaptive = false;
};


////////////////////////////////////////


} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb

Expand Down
14 changes: 14 additions & 0 deletions openvdb/openvdb/tree/ValueAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,20 @@ class ValueAccessorImpl final :
}; // ValueAccessorImpl

} // namespace tree


////////////////////////////////////////

// Overload the TreeTraits struct to declare a const/non-const ValueAccessorImpl as sparse

template<typename TreeT, bool IsSafeT, typename MutexT, typename IndexSequenceT>
struct TreeTraits<tree::ValueAccessorImpl<TreeT, IsSafeT, MutexT, IndexSequenceT>>
{
static const bool IsSparse = true;
static const bool IsAdaptive = false;
};


} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb

Expand Down

0 comments on commit 6145b10

Please sign in to comment.