11 #ifndef OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
12 #define OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
29 template<
typename Gr
idOrTree>
34 const bool threaded =
true
40 template<
typename Gr
idOrTree>
45 const bool threaded =
true
54 namespace activate_internal {
56 template<
typename TreeT,
bool IgnoreTolerance = false>
60 using RootT =
typename TreeT::RootNodeType;
61 using LeafT =
typename TreeT::LeafNodeType;
64 explicit ActivateOp(
const ValueT& value,
65 const ValueT& tolerance = zeroVal<ValueT>())
67 , mTolerance(tolerance) { }
69 inline bool check(
const ValueT& value)
const {
72 if (IgnoreTolerance)
return value == mValue;
76 bool operator()(RootT& root,
size_t)
const
78 for (
auto it = root.beginValueOff(); it; ++it) {
79 if (check(*it)) it.setValueOn(
true);
84 template<
typename NodeT>
85 bool operator()(NodeT& node,
size_t)
const
88 if (!node.isValueMaskOn()) {
89 for (
auto it = node.beginValueOff(); it; ++it) {
90 if (check(*it)) it.setValueOn(
true);
94 return !node.isChildMaskOff();
97 bool operator()(LeafT& leaf,
size_t)
const
100 if (leaf.isValueMaskOn())
return true;
101 for (
auto it = leaf.beginValueOff(); it; ++it) {
102 if (check(*it)) it.setValueOn(
true);
109 const ValueT mTolerance;
112 template<
typename TreeT,
bool IgnoreTolerance = false>
116 using RootT =
typename TreeT::RootNodeType;
117 using LeafT =
typename TreeT::LeafNodeType;
120 explicit DeactivateOp(
const ValueT& value,
121 const ValueT& tolerance = zeroVal<ValueT>())
123 , mTolerance(tolerance) { }
125 inline bool check(
const ValueT& value)
const {
126 if (IgnoreTolerance)
return value == mValue;
130 bool operator()(RootT& root,
size_t)
const
132 for (
auto it = root.beginValueOn(); it; ++it) {
133 if (check(*it)) it.setValueOn(
false);
138 template<
typename NodeT>
139 bool operator()(NodeT& node,
size_t)
const
142 if (!node.isValueMaskOff()) {
143 for (
auto it = node.beginValueOn(); it; ++it) {
144 if (check(*it)) it.setValueOn(
false);
148 return !node.isChildMaskOff();
151 bool operator()(LeafT& leaf,
size_t)
const
154 if (leaf.isValueMaskOff())
return true;
155 for (
auto it = leaf.beginValueOn(); it; ++it) {
156 if (check(*it)) it.setValueOn(
false);
163 const ValueT mTolerance;
174 template<
typename Gr
idOrTree>
181 using TreeType =
typename Adapter::TreeType;
184 TreeType& tree = Adapter::tree(gridOrTree);
188 if (tolerance == zeroVal<ValueType>()) {
189 activate_internal::ActivateOp<TreeType,
true> op(value);
192 activate_internal::ActivateOp<TreeType> op(value, tolerance);
198 template<
typename Gr
idOrTree>
205 using TreeType =
typename Adapter::TreeType;
208 TreeType& tree = Adapter::tree(gridOrTree);
212 if (tolerance == zeroVal<ValueType>()) {
213 activate_internal::DeactivateOp<TreeType,
true> op(value);
216 activate_internal::DeactivateOp<TreeType> op(value, tolerance);
227 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
229 #ifdef OPENVDB_INSTANTIATE_ACTIVATE
233 #define _FUNCTION(TreeT) \
234 void activate(TreeT&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
238 #define _FUNCTION(TreeT) \
239 void activate(Grid<TreeT>&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
243 #define _FUNCTION(TreeT) \
244 void deactivate(TreeT&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
248 #define _FUNCTION(TreeT) \
249 void deactivate(Grid<TreeT>&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
253 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
260 #endif // OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
#define OPENVDB_USE_VERSION_NAMESPACE
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
#define OPENVDB_ALL_TREE_INSTANTIATE(Function)
void foreachTopDown(const NodeOp &op, bool threaded=true, size_t leafGrainSize=1, size_t nonLeafGrainSize=1)
Threaded method that applies a user-supplied functor to all the nodes in the tree.
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...