37 #ifndef OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED 38 #define OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED 42 #include <boost/utility/enable_if.hpp> 43 #include <boost/static_assert.hpp> 44 #include <boost/type_traits/is_floating_point.hpp> 68 template<
typename TreeT>
71 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
73 size_t grainSize = 1);
84 template<
typename TreeT>
87 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
89 size_t grainSize = 1);
98 template<
typename TreeT>
100 pruneInactive(TreeT& tree,
bool threaded =
true,
size_t grainSize = 1);
110 template<
typename TreeT>
114 const typename TreeT::ValueType& value,
115 bool threaded =
true,
116 size_t grainSize = 1);
131 template<
typename TreeT>
134 bool threaded =
true,
135 size_t grainSize = 1);
154 template<
typename TreeT>
157 const typename TreeT::ValueType& outsideWidth,
158 const typename TreeT::ValueType& insideWidth,
159 bool threaded =
true,
160 size_t grainSize = 1);
166 template<
typename TreeT, Index TerminationLevel = 0>
170 typedef typename TreeT::ValueType
ValueT;
171 typedef typename TreeT::RootNodeType
RootT;
172 typedef typename TreeT::LeafNodeType
LeafT;
173 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
177 tree.clearAllAccessors();
182 tree.clearAllAccessors();
188 template<
typename NodeT>
191 if (NodeT::LEVEL > TerminationLevel) {
192 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
193 if (it->isInactive()) node.addTile(it.pos(), mValue,
false);
200 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
201 if (it->isInactive()) root.addTile(it.getCoord(), mValue,
false);
203 root.eraseBackgroundTiles();
211 template<
typename TreeT, Index TerminationLevel = 0>
215 typedef typename TreeT::ValueType
ValueT;
216 typedef typename TreeT::RootNodeType
RootT;
217 typedef typename TreeT::LeafNodeType
LeafT;
218 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
222 tree.clearAllAccessors();
230 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
231 if (this->isConstant(*it, value, state)) root.addTile(it.getCoord(), value, state);
233 root.eraseBackgroundTiles();
237 template<
typename NodeT>
240 if (NodeT::LEVEL > TerminationLevel) {
243 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
244 if (this->isConstant(*it, value, state)) node.addTile(it.pos(), value, state);
254 template<
typename NodeT>
257 typedef typename NodeT::UnionType T;
258 inline bool operator()(
const T& a,
const T& b)
const {
return a.getValue() < b.getValue();}
262 inline ValueT median(LeafT& leaf)
const 264 ValueT* data = leaf.buffer().data();
265 static const size_t midpoint = (LeafT::NUM_VALUES - 1) >> 1;
266 std::nth_element(data, data + midpoint, data + LeafT::NUM_VALUES);
267 return data[midpoint];
271 template<
typename NodeT>
272 inline typename NodeT::ValueType median(NodeT& node)
const 274 typedef typename NodeT::UnionType UnionT;
275 UnionT* data =
const_cast<UnionT*
>(node.getTable());
276 static const size_t midpoint = (NodeT::NUM_VALUES - 1) >> 1;
278 std::nth_element(data, data + midpoint, data + NodeT::NUM_VALUES, op);
279 return data[midpoint].getValue();
283 template<
typename NodeT>
285 typename boost::enable_if<boost::is_same<bool, typename NodeT::ValueType>,
bool>::type
286 isConstant(NodeT& node,
bool& value,
bool& state)
const 288 return node.isConstant(value, state, mTolerance);
292 template<
typename NodeT>
294 typename boost::disable_if<boost::is_same<bool, typename NodeT::ValueType>,
bool>::type
295 isConstant(NodeT& node, ValueT& value,
bool& state)
const 298 const bool test = node.isConstant(value, tmp, state, mTolerance);
299 if (test) value = this->median(node);
303 const ValueT mTolerance;
307 template<
typename TreeT, Index TerminationLevel = 0>
311 typedef typename TreeT::ValueType
ValueT;
312 typedef typename TreeT::RootNodeType
RootT;
313 typedef typename TreeT::LeafNodeType
LeafT;
314 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
317 : mOutside(tree.background())
322 "LevelSetPruneOp: the background value cannot be negative!");
324 tree.clearAllAccessors();
332 "LevelSetPruneOp: the outside value cannot be negative!");
336 "LevelSetPruneOp: the inside value must be negative!");
338 tree.clearAllAccessors();
343 template<
typename NodeT>
346 if (NodeT::LEVEL > TerminationLevel) {
347 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
348 if (it->isInactive()) node.addTile(it.pos(), this->getTileValue(it),
false);
355 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
356 if (it->isInactive()) root.addTile(it.getCoord(), this->getTileValue(it),
false);
358 root.eraseBackgroundTiles();
362 template <
typename IterT>
363 inline ValueT getTileValue(
const IterT& iter)
const 368 const ValueT mOutside, mInside;
372 template<
typename TreeT>
374 prune(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
378 nodes.foreachBottomUp(op, threaded, grainSize);
382 template<
typename TreeT>
384 pruneTiles(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
388 nodes.foreachBottomUp(op, threaded, grainSize);
392 template<
typename TreeT>
398 nodes.foreachBottomUp(op, threaded, grainSize);
402 template<
typename TreeT>
405 bool threaded,
size_t grainSize)
409 nodes.foreachBottomUp(op, threaded, grainSize);
413 template<
typename TreeT>
416 const typename TreeT::ValueType& outside,
417 const typename TreeT::ValueType& inside,
423 nodes.foreachBottomUp(op, threaded, grainSize);
427 template<
typename TreeT>
433 nodes.foreachBottomUp(op, threaded, grainSize);
440 #endif // OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
#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
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:57
Definition: Exceptions.h:88
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:354
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71