37 #ifndef OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED 38 #define OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED 44 #include <type_traits> 63 template<
typename TreeT>
66 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
68 size_t grainSize = 1);
79 template<
typename TreeT>
82 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
84 size_t grainSize = 1);
93 template<
typename TreeT>
95 pruneInactive(TreeT& tree,
bool threaded =
true,
size_t grainSize = 1);
105 template<
typename TreeT>
109 const typename TreeT::ValueType& value,
110 bool threaded =
true,
111 size_t grainSize = 1);
126 template<
typename TreeT>
129 bool threaded =
true,
130 size_t grainSize = 1);
149 template<
typename TreeT>
152 const typename TreeT::ValueType& outsideWidth,
153 const typename TreeT::ValueType& insideWidth,
154 bool threaded =
true,
155 size_t grainSize = 1);
161 template<
typename TreeT, Index TerminationLevel = 0>
165 using ValueT =
typename TreeT::ValueType;
166 using RootT =
typename TreeT::RootNodeType;
167 using LeafT =
typename TreeT::LeafNodeType;
168 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
172 tree.clearAllAccessors();
177 tree.clearAllAccessors();
184 template<
typename NodeT>
187 if (NodeT::LEVEL > TerminationLevel) {
188 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
189 if (it->isInactive()) node.addTile(it.pos(), mValue,
false);
197 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
198 if (it->isInactive()) root.addTile(it.getCoord(), mValue,
false);
200 root.eraseBackgroundTiles();
208 template<
typename TreeT, Index TerminationLevel = 0>
212 using ValueT =
typename TreeT::ValueType;
213 using RootT =
typename TreeT::RootNodeType;
214 using LeafT =
typename TreeT::LeafNodeType;
215 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
219 tree.clearAllAccessors();
227 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
228 if (this->isConstant(*it, value, state)) root.addTile(it.getCoord(), value, state);
230 root.eraseBackgroundTiles();
234 template<
typename NodeT>
237 if (NodeT::LEVEL > TerminationLevel) {
240 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
241 if (this->isConstant(*it, value, state)) node.addTile(it.pos(), value, state);
251 inline ValueT median(LeafT& leaf)
const {
return leaf.medianAll(leaf.buffer().data());}
254 template<
typename NodeT>
255 inline typename NodeT::ValueType median(NodeT& node)
const 257 using UnionT =
typename NodeT::UnionType;
258 UnionT* data = const_cast<UnionT*>(node.getTable());
259 static const size_t midpoint = (NodeT::NUM_VALUES - 1) >> 1;
260 auto op = [](
const UnionT& a,
const UnionT& b){
return a.getValue() < b.getValue();};
261 std::nth_element(data, data + midpoint, data + NodeT::NUM_VALUES, op);
262 return data[midpoint].getValue();
266 template<
typename NodeT>
268 typename std::enable_if<std::is_same<bool, typename NodeT::ValueType>::value,
bool>::type
269 isConstant(NodeT& node,
bool& value,
bool& state)
const 271 return node.isConstant(value, state, mTolerance);
275 template<
typename NodeT>
277 typename std::enable_if<!std::is_same<bool, typename NodeT::ValueType>::value,
bool>::type
278 isConstant(NodeT& node, ValueT& value,
bool& state)
const 281 const bool test = node.isConstant(value, tmp, state, mTolerance);
282 if (test) value = this->median(node);
286 const ValueT mTolerance;
290 template<
typename TreeT, Index TerminationLevel = 0>
294 using ValueT =
typename TreeT::ValueType;
295 using RootT =
typename TreeT::RootNodeType;
296 using LeafT =
typename TreeT::LeafNodeType;
297 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
300 : mOutside(tree.background())
305 "LevelSetPruneOp: the background value cannot be negative!");
307 tree.clearAllAccessors();
316 "LevelSetPruneOp: the outside value cannot be negative!");
320 "LevelSetPruneOp: the inside value must be negative!");
322 tree.clearAllAccessors();
329 template<
typename NodeT>
332 if (NodeT::LEVEL > TerminationLevel) {
333 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
334 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:109
NodeManager produces linear arrays of all tree nodes allowing for efficient threading and bottom-up p...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:108
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays,...
Definition: NodeManager.h:58
Definition: Exceptions.h:40
Definition: Exceptions.h:92
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:338