Skip to content

Commit 6f61199

Browse files
committed
Change the use of tools::foreach with NodeManager.
Signed-off-by: Andre Pradhana <[email protected]>
1 parent 1c0e7ad commit 6f61199

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

openvdb/openvdb/tools/FastSweeping.h

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@
3434
#include <openvdb/math/Math.h> // for Abs() and isExactlyEqual()
3535
#include <openvdb/math/Stencils.h> // for GradStencil
3636
#include <openvdb/tree/LeafManager.h>
37+
#include <openvdb/tree/NodeManager.h> // for PruneMinMaxFltKernel
3738

3839
#include "LevelSetUtil.h"
3940
#include "Morphology.h"
40-
#include "ValueTransformer.h" // for PruneMinMaxFltKernel
41-
#include <openvdb/openvdb.h>
4241

4342
#include "Statistics.h"
4443
#ifdef BENCHMARK_FAST_SWEEPING
@@ -893,7 +892,9 @@ void FastSweeping<SdfGridT, ExtValueT>::sweep(int nIter, bool finalize)
893892
auto e = kernel.run(*mSdfGrid);//multi-threaded
894893
//auto e = extrema(mGrid->beginValueOn());// 100x slower!!!!
895894
if (kernel.mFltMinExists || kernel.mFltMaxExists) {
896-
openvdb::tools::foreach (mSdfGrid->beginValueAll(), PruneMinMaxFltKernel(e.min(), e.max()));
895+
tree::NodeManager<SdfTreeT> nodeManager(mSdfGrid->tree());
896+
PruneMinMaxFltKernel op(e.min(), e.max());
897+
nodeManager.foreachTopDown(op, true /* = threaded*/, 1 /* = grainSize*/);
897898
}
898899
#ifdef BENCHMARK_FAST_SWEEPING
899900
std::cerr << "Min = " << e.min() << " Max = " << e.max() << std::endl;
@@ -958,18 +959,37 @@ struct FastSweeping<SdfGridT, ExtValueT>::MinMaxKernel
958959
/// float min.
959960
template <typename SdfGridT, typename ExtValueT>
960961
struct FastSweeping<SdfGridT, ExtValueT>::PruneMinMaxFltKernel {
962+
PruneMinMaxFltKernel(SdfValueT min, SdfValueT max) : mMin(min), mMax(max) {}
961963

962-
PruneMinMaxFltKernel(SdfValueT min, SdfValueT max) : mMin(min), mMax(max) {}
964+
// Do nothing for the root node
965+
void operator()(typename SdfTreeT::RootNodeType&, size_t = 1) const { }
963966

964-
inline void operator()(const typename SdfGridT::ValueAllIter &iter) const {
965-
if (*iter == -std::numeric_limits<SdfValueT>::max()) {
966-
iter.setValue(mMin);
967-
}
968-
if (*iter == std::numeric_limits<SdfValueT>::max()) {
969-
iter.setValue(mMax);
967+
// Internal nodes
968+
template<typename NodeT>
969+
void operator()(NodeT& node, size_t idx = 1) const
970+
{
971+
for (auto iter = node.beginValueAll(); iter; ++iter) {
972+
if (*iter == -std::numeric_limits<SdfValueT>::max()) {
973+
iter.setValue(mMin);
974+
}
975+
if (*iter == std::numeric_limits<SdfValueT>::max()) {
976+
iter.setValue(mMax);
977+
}
978+
}
970979
}
971-
}
972980

981+
// Leaf nodes
982+
void operator()(typename SdfTreeT::LeafNodeType& leaf, size_t idx = 1) const
983+
{
984+
for (auto iter = leaf.beginValueOn(); iter; ++iter) {
985+
if (*iter == -std::numeric_limits<SdfValueT>::max()) {
986+
iter.setValue(mMin);
987+
}
988+
if (*iter == std::numeric_limits<SdfValueT>::max()) {
989+
iter.setValue(mMax);
990+
}
991+
}
992+
}
973993
SdfValueT mMin, mMax;
974994
};// FastSweeping::PruneMinMaxFltKernel
975995

0 commit comments

Comments
 (0)