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);
255 inline ValueT median(LeafT& leaf)
const {
return leaf.medianAll(leaf.buffer().data());}
258 template<
typename NodeT>
259 inline typename NodeT::ValueType median(NodeT& node)
const 261 using UnionT =
typename NodeT::UnionType;
262 UnionT* data =
const_cast<UnionT*
>(node.getTable());
263 static const size_t midpoint = (NodeT::NUM_VALUES - 1) >> 1;
264 auto op = [](
const UnionT& a,
const UnionT& b){
return a.getValue() < b.getValue();};
265 std::nth_element(data, data + midpoint, data + NodeT::NUM_VALUES, op);
266 return data[midpoint].getValue();
270 template<
typename NodeT>
272 typename boost::enable_if<boost::is_same<bool, typename NodeT::ValueType>,
bool>::type
273 isConstant(NodeT& node,
bool& value,
bool& state)
const 275 return node.isConstant(value, state, mTolerance);
279 template<
typename NodeT>
281 typename boost::disable_if<boost::is_same<bool, typename NodeT::ValueType>,
bool>::type
282 isConstant(NodeT& node, ValueT& value,
bool& state)
const 285 const bool test = node.isConstant(value, tmp, state, mTolerance);
286 if (test) value = this->median(node);
290 const ValueT mTolerance;
294 template<
typename TreeT, Index TerminationLevel = 0>
298 typedef typename TreeT::ValueType
ValueT;
299 typedef typename TreeT::RootNodeType
RootT;
300 typedef typename TreeT::LeafNodeType
LeafT;
301 BOOST_STATIC_ASSERT(RootT::LEVEL > TerminationLevel);
304 : mOutside(tree.background())
309 "LevelSetPruneOp: the background value cannot be negative!");
311 tree.clearAllAccessors();
319 "LevelSetPruneOp: the outside value cannot be negative!");
323 "LevelSetPruneOp: the inside value must be negative!");
325 tree.clearAllAccessors();
330 template<
typename NodeT>
333 if (NodeT::LEVEL > TerminationLevel) {
334 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
335 if (it->isInactive()) node.addTile(it.pos(), this->getTileValue(it),
false);
342 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
343 if (it->isInactive()) root.addTile(it.getCoord(), this->getTileValue(it),
false);
345 root.eraseBackgroundTiles();
349 template <
typename IterT>
350 inline ValueT getTileValue(
const IterT& iter)
const 355 const ValueT mOutside, mInside;
359 template<
typename TreeT>
361 prune(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
365 nodes.foreachBottomUp(op, threaded, grainSize);
369 template<
typename TreeT>
371 pruneTiles(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
375 nodes.foreachBottomUp(op, threaded, grainSize);
379 template<
typename TreeT>
385 nodes.foreachBottomUp(op, threaded, grainSize);
389 template<
typename TreeT>
392 bool threaded,
size_t grainSize)
396 nodes.foreachBottomUp(op, threaded, grainSize);
400 template<
typename TreeT>
403 const typename TreeT::ValueType& outside,
404 const typename TreeT::ValueType& inside,
410 nodes.foreachBottomUp(op, threaded, grainSize);
414 template<
typename TreeT>
420 nodes.foreachBottomUp(op, threaded, grainSize);
427 #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:101
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:354
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
Definition: Exceptions.h:92
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
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