10 #ifndef OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
11 #define OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
17 #include <type_traits>
36 template<
typename TreeT>
39 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
41 size_t grainSize = 1);
52 template<
typename TreeT>
55 typename TreeT::ValueType tolerance = zeroVal<typename TreeT::ValueType>(),
57 size_t grainSize = 1);
66 template<
typename TreeT>
68 pruneInactive(TreeT& tree,
bool threaded =
true,
size_t grainSize = 1);
78 template<
typename TreeT>
82 const typename TreeT::ValueType&
value,
84 size_t grainSize = 1);
99 template<
typename TreeT>
102 bool threaded =
true,
103 size_t grainSize = 1);
122 template<
typename TreeT>
125 const typename TreeT::ValueType& outsideWidth,
126 const typename TreeT::ValueType& insideWidth,
127 bool threaded =
true,
128 size_t grainSize = 1);
134 template<
typename TreeT, Index TerminationLevel = 0>
138 using ValueT =
typename TreeT::ValueType;
139 using RootT =
typename TreeT::RootNodeType;
140 using LeafT =
typename TreeT::LeafNodeType;
141 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
145 tree.clearAllAccessors();
150 tree.clearAllAccessors();
157 template<
typename NodeT>
160 if (NodeT::LEVEL > TerminationLevel) {
161 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
162 if (it->isInactive()) node.addTile(it.pos(), mValue,
false);
170 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
171 if (it->isInactive()) root.addTile(it.getCoord(), mValue,
false);
173 root.eraseBackgroundTiles();
181 template<
typename TreeT, Index TerminationLevel = 0>
185 using ValueT =
typename TreeT::ValueType;
186 using RootT =
typename TreeT::RootNodeType;
187 using LeafT =
typename TreeT::LeafNodeType;
188 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
192 tree.clearAllAccessors();
200 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
201 if (this->isConstant(*it, value, state)) root.addTile(it.getCoord(),
value, state);
203 root.eraseBackgroundTiles();
207 template<
typename NodeT>
210 if (NodeT::LEVEL > TerminationLevel) {
213 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
214 if (this->isConstant(*it, value, state)) node.addTile(it.pos(),
value, state);
224 inline ValueT median(
LeafT& leaf)
const {
return leaf.medianAll(leaf.buffer().data());}
227 template<
typename NodeT>
228 inline typename NodeT::ValueType median(NodeT& node)
const
230 using UnionT =
typename NodeT::UnionType;
231 UnionT*
data =
const_cast<UnionT*
>(node.getTable());
232 static const size_t midpoint = (NodeT::NUM_VALUES - 1) >> 1;
233 auto op = [](
const UnionT&
a,
const UnionT&
b){
return a.getValue() <
b.getValue();};
234 std::nth_element(data, data + midpoint, data + NodeT::NUM_VALUES, op);
235 return data[midpoint].getValue();
239 template<
typename NodeT>
242 isConstant(NodeT& node,
bool&
value,
bool& state)
const
244 return node.isConstant(value, state, mTolerance);
248 template<
typename NodeT>
251 isConstant(NodeT& node,
ValueT& value,
bool& state)
const
254 const bool test = node.isConstant(value, tmp, state, mTolerance);
255 if (test) value = this->median(node);
263 template<
typename TreeT, Index TerminationLevel = 0>
267 using ValueT =
typename TreeT::ValueType;
268 using RootT =
typename TreeT::RootNodeType;
269 using LeafT =
typename TreeT::LeafNodeType;
270 static_assert(RootT::LEVEL > TerminationLevel,
"TerminationLevel out of range");
273 : mOutside(tree.background())
278 "LevelSetPruneOp: the background value cannot be negative!");
280 tree.clearAllAccessors();
289 "LevelSetPruneOp: the outside value cannot be negative!");
293 "LevelSetPruneOp: the inside value must be negative!");
295 tree.clearAllAccessors();
302 template<
typename NodeT>
305 if (NodeT::LEVEL > TerminationLevel) {
306 for (
typename NodeT::ChildOnIter it=node.beginChildOn(); it; ++it) {
307 if (it->isInactive()) node.addTile(it.pos(), this->getTileValue(it),
false);
315 for (
typename RootT::ChildOnIter it = root.beginChildOn(); it; ++it) {
316 if (it->isInactive()) root.addTile(it.getCoord(), this->getTileValue(it),
false);
318 root.eraseBackgroundTiles();
322 template <
typename IterT>
323 inline ValueT getTileValue(
const IterT& iter)
const
328 const ValueT mOutside, mInside;
332 template<
typename TreeT>
334 prune(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
338 nodes.foreachBottomUp(op, threaded, grainSize);
342 template<
typename TreeT>
344 pruneTiles(TreeT& tree,
typename TreeT::ValueType tol,
bool threaded,
size_t grainSize)
348 nodes.foreachBottomUp(op, threaded, grainSize);
352 template<
typename TreeT>
358 nodes.foreachBottomUp(op, threaded, grainSize);
362 template<
typename TreeT>
365 bool threaded,
size_t grainSize)
369 nodes.foreachBottomUp(op, threaded, grainSize);
373 template<
typename TreeT>
376 const typename TreeT::ValueType& outside,
377 const typename TreeT::ValueType& inside,
383 nodes.foreachBottomUp(op, threaded, grainSize);
387 template<
typename TreeT>
393 nodes.foreachBottomUp(op, threaded, grainSize);
400 #endif // OPENVDB_TOOLS_PRUNE_HAS_BEEN_INCLUDED
cvex test(vector P=0;int unbound=3;export float s=0;export vector Cf=0;)
T negative(const T &val)
Return the unary negation of the given value.
GLboolean GLboolean GLboolean GLboolean a
#define OPENVDB_USE_VERSION_NAMESPACE
bool isNegative(const Type &x)
Return true if x is less than zero.
To facilitate threading over the nodes of a tree, cache node pointers in linear arrays, one for each level of the tree.
GLint GLenum GLsizei GLint GLsizei const void * data
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
GLuint GLuint GLsizei GLenum type
GLdouble GLdouble GLdouble b
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.
GLsizei const GLfloat * value
#define OPENVDB_THROW(exception, message)