11 #ifndef OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
12 #define OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
27 template<
typename Gr
idOrTree>
30 const typename GridOrTree::ValueType& value,
31 const typename GridOrTree::ValueType& tolerance = zeroVal<typename GridOrTree::ValueType>(),
32 const bool threaded =
true
38 template<
typename Gr
idOrTree>
41 const typename GridOrTree::ValueType& value,
42 const typename GridOrTree::ValueType& tolerance = zeroVal<typename GridOrTree::ValueType>(),
43 const bool threaded =
true
52 namespace activate_internal {
54 template<
typename TreeT,
bool IgnoreTolerance = false>
58 using RootT =
typename TreeT::RootNodeType;
59 using LeafT =
typename TreeT::LeafNodeType;
60 using ValueT =
typename TreeT::ValueType;
62 explicit ActivateOp(
const ValueT& value,
63 const ValueT& tolerance = zeroVal<ValueT>())
65 , mTolerance(tolerance) { }
67 inline bool check(
const ValueT& value)
const {
70 if (IgnoreTolerance)
return value == mValue;
74 bool operator()(RootT& root,
size_t)
const
76 for (
auto it = root.beginValueOff(); it; ++it) {
77 if (check(*it)) it.setValueOn(
true);
82 template<
typename NodeT>
83 bool operator()(NodeT& node,
size_t)
const
86 if (!node.isValueMaskOn()) {
87 for (
auto it = node.beginValueOff(); it; ++it) {
88 if (check(*it)) it.setValueOn(
true);
92 return !node.isChildMaskOff();
95 bool operator()(LeafT& leaf,
size_t)
const
98 if (leaf.isValueMaskOn())
return true;
99 for (
auto it = leaf.beginValueOff(); it; ++it) {
100 if (check(*it)) it.setValueOn(
true);
107 const ValueT mTolerance;
110 template<
typename TreeT,
bool IgnoreTolerance = false>
114 using RootT =
typename TreeT::RootNodeType;
115 using LeafT =
typename TreeT::LeafNodeType;
116 using ValueT =
typename TreeT::ValueType;
118 explicit DeactivateOp(
const ValueT& value,
119 const ValueT& tolerance = zeroVal<ValueT>())
121 , mTolerance(tolerance) { }
123 inline bool check(
const ValueT& value)
const {
124 if (IgnoreTolerance)
return value == mValue;
128 bool operator()(RootT& root,
size_t)
const
130 for (
auto it = root.beginValueOn(); it; ++it) {
131 if (check(*it)) it.setValueOn(
false);
136 template<
typename NodeT>
137 bool operator()(NodeT& node,
size_t)
const
140 if (!node.isValueMaskOff()) {
141 for (
auto it = node.beginValueOn(); it; ++it) {
142 if (check(*it)) it.setValueOn(
false);
146 return !node.isChildMaskOff();
149 bool operator()(LeafT& leaf,
size_t)
const
152 if (leaf.isValueMaskOff())
return true;
153 for (
auto it = leaf.beginValueOn(); it; ++it) {
154 if (check(*it)) it.setValueOn(
false);
161 const ValueT mTolerance;
172 template<
typename Gr
idOrTree>
174 activate(GridOrTree& gridOrTree,
const typename GridOrTree::ValueType& value,
175 const typename GridOrTree::ValueType& tolerance,
179 using TreeType =
typename Adapter::TreeType;
180 using ValueType =
typename TreeType::ValueType;
182 TreeType& tree = Adapter::tree(gridOrTree);
186 if (tolerance == zeroVal<ValueType>()) {
187 activate_internal::ActivateOp<TreeType,
true> op(value);
190 activate_internal::ActivateOp<TreeType> op(value, tolerance);
196 template<
typename Gr
idOrTree>
198 deactivate(GridOrTree& gridOrTree,
const typename GridOrTree::ValueType& value,
199 const typename GridOrTree::ValueType& tolerance,
203 using TreeType =
typename Adapter::TreeType;
204 using ValueType =
typename TreeType::ValueType;
206 TreeType& tree = Adapter::tree(gridOrTree);
210 if (tolerance == zeroVal<ValueType>()) {
211 activate_internal::DeactivateOp<TreeType,
true> op(value);
214 activate_internal::DeactivateOp<TreeType> op(value, tolerance);
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
Definition: NodeManager.h:890
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.
Definition: NodeManager.h:976
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:407
Definition: Exceptions.h:13
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1071
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:180