11 #ifndef OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
12 #define OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
29 template<
typename Gr
idOrTree>
40 template<
typename Gr
idOrTree>
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) {
93 if (node.isChildMaskOn(it.pos()))
continue;
94 if (check(*it)) it.setValueOn(
true);
98 return !node.isChildMaskOff();
101 bool operator()(LeafT& leaf,
size_t)
const
104 if (leaf.isValueMaskOn())
return true;
105 for (
auto it = leaf.beginValueOff(); it; ++it) {
106 if (check(*it)) it.setValueOn(
true);
113 const ValueT mTolerance;
116 template<
typename TreeT,
bool IgnoreTolerance = false>
120 using RootT =
typename TreeT::RootNodeType;
121 using LeafT =
typename TreeT::LeafNodeType;
124 explicit DeactivateOp(
const ValueT& value,
125 const ValueT& tolerance = zeroVal<ValueT>())
127 , mTolerance(tolerance) { }
129 inline bool check(
const ValueT& value)
const {
130 if (IgnoreTolerance)
return value == mValue;
134 bool operator()(RootT& root,
size_t)
const
136 for (
auto it = root.beginValueOn(); it; ++it) {
137 if (check(*it)) it.setValueOn(
false);
142 template<
typename NodeT>
143 bool operator()(NodeT& node,
size_t)
const
146 if (!node.isValueMaskOff()) {
147 for (
auto it = node.beginValueOn(); it; ++it) {
148 if (check(*it)) it.setValueOn(
false);
152 return !node.isChildMaskOff();
155 bool operator()(LeafT& leaf,
size_t)
const
158 if (leaf.isValueMaskOff())
return true;
159 for (
auto it = leaf.beginValueOn(); it; ++it) {
160 if (check(*it)) it.setValueOn(
false);
167 const ValueT mTolerance;
178 template<
typename Gr
idOrTree>
185 using TreeType =
typename Adapter::TreeType;
188 TreeType& tree = Adapter::tree(gridOrTree);
192 if (tolerance == zeroVal<ValueType>()) {
193 activate_internal::ActivateOp<TreeType,
true>
op(value);
196 activate_internal::ActivateOp<TreeType>
op(value, tolerance);
202 template<
typename Gr
idOrTree>
209 using TreeType =
typename Adapter::TreeType;
212 TreeType& tree = Adapter::tree(gridOrTree);
216 if (tolerance == zeroVal<ValueType>()) {
217 activate_internal::DeactivateOp<TreeType,
true>
op(value);
220 activate_internal::DeactivateOp<TreeType>
op(value, tolerance);
231 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
233 #ifdef OPENVDB_INSTANTIATE_ACTIVATE
237 #define _FUNCTION(TreeT) \
238 void activate(TreeT&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
242 #define _FUNCTION(TreeT) \
243 void activate(Grid<TreeT>&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
247 #define _FUNCTION(TreeT) \
248 void deactivate(TreeT&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
252 #define _FUNCTION(TreeT) \
253 void deactivate(Grid<TreeT>&, const TreeT::ValueType&, const TreeT::ValueType&, const bool)
257 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
264 #endif // OPENVDB_TOOLS_ACTIVATE_HAS_BEEN_INCLUDED
GLsizei const GLfloat * value
#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...