10#ifndef OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
11#define OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
37template<
typename TreeT>
40 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
42 size_t grainSize = 1);
53template<
typename TreeT>
56 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
58 size_t grainSize = 1);
67template<
typename TreeT>
69pruneInactive(TreeT& tree,
bool threaded =
true,
size_t grainSize = 1);
79template<
typename TreeT>
83 const typename TreeT::ValueType& value,
85 size_t grainSize = 1);
100template<
typename TreeT>
103 bool threaded =
true,
104 size_t grainSize = 1);
123template<
typename TreeT>
126 const typename TreeT::ValueType& outsideWidth,
127 const typename TreeT::ValueType& insideWidth,
128 bool threaded =
true,
129 size_t grainSize = 1);
135template<
typename TreeT, Index TerminationLevel = 0>
139 using ValueT =
typename TreeT::ValueType;
140 using RootT =
typename TreeT::RootNodeType;
141 using LeafT =
typename TreeT::LeafNodeType;
142 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
146 tree.clearAllAccessors();
151 tree.clearAllAccessors();
158 template<
typename NodeT>
161 if (NodeT::LEVEL > TerminationLevel) {
162 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
163 if (it->isInactive()) node.addTile(it.pos(), mValue,
false);
171 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
172 if (it->isInactive()) root.addTile(it.getCoord(), mValue,
false);
174 root.eraseBackgroundTiles();
182template<
typename TreeT, Index TerminationLevel = 0>
186 using ValueT =
typename TreeT::ValueType;
187 using RootT =
typename TreeT::RootNodeType;
188 using LeafT =
typename TreeT::LeafNodeType;
189 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
193 tree.clearAllAccessors();
201 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
202 if (this->isConstant(*it, value, state)) root.addTile(it.getCoord(), value, state);
204 root.eraseBackgroundTiles();
208 template<
typename NodeT>
211 if (NodeT::LEVEL > TerminationLevel) {
214 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
215 if (this->isConstant(*it, value, state)) node.addTile(it.pos(), value, state);
225 inline ValueT median(LeafT& leaf)
const {
return leaf.medianAll(leaf.buffer().data());}
228 template<
typename NodeT>
229 inline typename NodeT::ValueType median(NodeT& node)
const
231 using UnionT =
typename NodeT::UnionType;
232 UnionT* data =
const_cast<UnionT*
>(node.getTable());
233 static const size_t midpoint = (NodeT::NUM_VALUES - 1) >> 1;
234 auto op = [](
const UnionT& a,
const UnionT& b) {
237 std::nth_element(data, data + midpoint, data + NodeT::NUM_VALUES, op);
238 return data[midpoint].getValue();
242 template<
typename NodeT>
244 typename std::enable_if<std::is_same<bool, typename NodeT::ValueType>::value,
bool>::type
245 isConstant(NodeT& node,
bool& value,
bool& state)
const
247 return node.isConstant(value, state, mTolerance);
251 template<
typename NodeT>
253 typename std::enable_if<!std::is_same<bool, typename NodeT::ValueType>::value,
bool>::type
254 isConstant(NodeT& node, ValueT& value,
bool& state)
const
257 const bool test = node.isConstant(value, tmp, state, mTolerance);
258 if (test) value = this->median(node);
262 const ValueT mTolerance;
266template<
typename TreeT, Index TerminationLevel = 0>
270 using ValueT =
typename TreeT::ValueType;
271 using RootT =
typename TreeT::RootNodeType;
272 using LeafT =
typename TreeT::LeafNodeType;
273 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
276 : mOutside(
tree.background())
277 , mInside(
math::negative(mOutside))
281 "LevelSetPruneOp: the background value cannot be negative!");
283 tree.clearAllAccessors();
292 "LevelSetPruneOp: the outside value cannot be negative!");
296 "LevelSetPruneOp: the inside value must be negative!");
298 tree.clearAllAccessors();
305 template<
typename NodeT>
308 if (NodeT::LEVEL > TerminationLevel) {
309 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
310 if (it->isInactive()) node.addTile(it.pos(), this->getTileValue(it),
false);
318 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
319 if (it->isInactive()) root.addTile(it.getCoord(), this->getTileValue(it),
false);
321 root.eraseBackgroundTiles();
325 template <
typename IterT>
326 inline ValueT getTileValue(
const IterT& iter)
const
331 const ValueT mOutside, mInside;
335template<
typename TreeT>
337prune(TreeT&
tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
341 nodes.foreachBottomUp(op, threaded, grainSize);
345template<
typename TreeT>
347pruneTiles(TreeT&
tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
351 nodes.foreachBottomUp(op, threaded, grainSize);
355template<
typename TreeT>
361 nodes.foreachBottomUp(op, threaded, grainSize);
365template<
typename TreeT>
368 bool threaded,
size_t grainSize)
372 nodes.foreachBottomUp(op, threaded, grainSize);
376template<
typename TreeT>
379 const typename TreeT::ValueType& outside,
380 const typename TreeT::ValueType& inside,
386 nodes.foreachBottomUp(op, threaded, grainSize);
390template<
typename TreeT>
396 nodes.foreachBottomUp(op, threaded, grainSize);
405#ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
407#ifdef OPENVDB_INSTANTIATE_PRUNE
411#define _FUNCTION(TreeT) \
412 void prune(TreeT&, TreeT::ValueType, bool, size_t)
416#define _FUNCTION(TreeT) \
417 void pruneTiles(TreeT&, TreeT::ValueType, bool, size_t)
421#define _FUNCTION(TreeT) \
422 void pruneInactive(TreeT&, bool, size_t)
426#define _FUNCTION(TreeT) \
427 void pruneInactiveWithValue(TreeT&, const TreeT::ValueType&, bool, size_t)
431#define _FUNCTION(TreeT) \
432 void pruneLevelSet(TreeT&, bool, size_t)
436#define _FUNCTION(TreeT) \
437 void pruneLevelSet(TreeT&, const TreeT::ValueType&, const TreeT::ValueType&, bool, size_t)
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition Exceptions.h:65
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays,...
Definition NodeManager.h:532
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition Mat.h:1015
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition Math.h:377
Definition PointDataGrid.h:170
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
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.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:284
#define OPENVDB_REAL_TREE_INSTANTIATE(Function)
Definition version.h.in:228
#define OPENVDB_VOLUME_TREE_INSTANTIATE(Function)
Definition version.h.in:231