37 #ifndef OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
38 #define OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
40 #include <boost/utility/enable_if.hpp>
41 #include <boost/static_assert.hpp>
42 #include <boost/type_traits/is_floating_point.hpp>
67 template<
typename TreeT>
70 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
72 size_t grainSize = 1);
83 template<
typename TreeT>
86 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
88 size_t grainSize = 1);
97 template<
typename TreeT>
99 pruneInactive(TreeT& tree,
bool threaded =
true,
size_t grainSize = 1);
109 template<
typename TreeT>
113 const typename TreeT::ValueType& value,
114 bool threaded =
true,
115 size_t grainSize = 1);
130 template<
typename TreeT>
133 bool threaded =
true,
134 size_t grainSize = 1);
153 template<
typename TreeT>
156 const typename TreeT::ValueType& outsideWidth,
157 const typename TreeT::ValueType& insideWidth,
158 bool threaded =
true,
159 size_t grainSize = 1);
165 template<
typename TreeT, Index TerminationLevel = 0>
169 typedef typename TreeT::ValueType
ValueT;
170 typedef typename TreeT::RootNodeType
RootT;
171 typedef typename TreeT::LeafNodeType
LeafT;
172 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
176 tree.clearAllAccessors();
181 tree.clearAllAccessors();
187 template<
typename NodeT>
190 if (NodeT::LEVEL > TerminationLevel) {
191 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
192 if (it->isInactive()) node.addTile(it.pos(), mValue,
false);
199 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
200 if (it->isInactive()) root.addTile(it.getCoord(), mValue,
false);
202 root.eraseBackgroundTiles();
210 template<
typename TreeT, Index TerminationLevel = 0>
214 typedef typename TreeT::ValueType
ValueT;
215 typedef typename TreeT::RootNodeType
RootT;
216 typedef typename TreeT::LeafNodeType
LeafT;
217 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
221 tree.clearAllAccessors();
229 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
230 if (this->isConstant(*it, value, state)) root.addTile(it.getCoord(), value, state);
232 root.eraseBackgroundTiles();
236 template<
typename NodeT>
239 if (NodeT::LEVEL > TerminationLevel) {
242 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
243 if (this->isConstant(*it, value, state)) node.addTile(it.pos(), value, state);
255 template<
typename NodeT>
257 typename boost::enable_if<boost::is_floating_point<typename NodeT::ValueType>,
bool>::type
258 isConstant(
const NodeT& node, ValueT& value,
bool& state)
const
261 const bool test = node.isConstant(value, tmp, state, mTolerance);
262 if (test) value = ValueT(0.5f)*(value + tmp);
268 template<
typename NodeT>
270 typename boost::disable_if<boost::is_floating_point<typename NodeT::ValueType>,
bool>::type
271 isConstant(
const NodeT& node, ValueT& value,
bool& state)
const
273 return node.isConstant(value, state, mTolerance);
276 const ValueT mTolerance;
280 template<
typename TreeT, Index TerminationLevel = 0>
284 typedef typename TreeT::ValueType
ValueT;
285 typedef typename TreeT::RootNodeType
RootT;
286 typedef typename TreeT::LeafNodeType
LeafT;
287 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
290 : mOutside(tree.background())
295 "LevelSetPruneOp: the background value cannot be negative!");
297 tree.clearAllAccessors();
305 "LevelSetPruneOp: the outside value cannot be negative!");
309 "LevelSetPruneOp: the inside value must be negative!");
311 tree.clearAllAccessors();
316 template<
typename NodeT>
319 if (NodeT::LEVEL > TerminationLevel) {
320 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
321 if (it->isInactive()) node.addTile(it.pos(), this->getTileValue(it),
false);
328 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
329 if (it->isInactive()) root.addTile(it.getCoord(), this->getTileValue(it),
false);
331 root.eraseBackgroundTiles();
335 template <
typename IterT>
336 inline ValueT getTileValue(
const IterT& iter)
const
341 const ValueT mOutside, mInside;
345 template<
typename TreeT>
347 prune(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
351 nodes.processBottomUp(op, threaded, grainSize);
355 template<
typename TreeT>
357 pruneTiles(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
361 nodes.processBottomUp(op, threaded, grainSize);
365 template<
typename TreeT>
371 nodes.processBottomUp(op, threaded, grainSize);
375 template<
typename TreeT>
378 bool threaded,
size_t grainSize)
382 nodes.processBottomUp(op, threaded, grainSize);
386 template<
typename TreeT>
389 const typename TreeT::ValueType& outside,
390 const typename TreeT::ValueType& inside,
396 nodes.processBottomUp(op, threaded, grainSize);
400 template<
typename TreeT>
406 nodes.processBottomUp(op, threaded, grainSize);
413 #endif // OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:116
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition: Exceptions.h:88
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:354
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree.
Definition: NodeManager.h:56
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71