|
34 | 34 | #include <openvdb/math/Math.h> // for Abs() and isExactlyEqual() |
35 | 35 | #include <openvdb/math/Stencils.h> // for GradStencil |
36 | 36 | #include <openvdb/tree/LeafManager.h> |
| 37 | +#include <openvdb/tree/NodeManager.h> // for PruneMinMaxFltKernel |
37 | 38 |
|
38 | 39 | #include "LevelSetUtil.h" |
39 | 40 | #include "Morphology.h" |
40 | | -#include "ValueTransformer.h" // for PruneMinMaxFltKernel |
41 | | -#include <openvdb/openvdb.h> |
42 | 41 |
|
43 | 42 | #include "Statistics.h" |
44 | 43 | #ifdef BENCHMARK_FAST_SWEEPING |
@@ -893,7 +892,9 @@ void FastSweeping<SdfGridT, ExtValueT>::sweep(int nIter, bool finalize) |
893 | 892 | auto e = kernel.run(*mSdfGrid);//multi-threaded |
894 | 893 | //auto e = extrema(mGrid->beginValueOn());// 100x slower!!!! |
895 | 894 | 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*/); |
897 | 898 | } |
898 | 899 | #ifdef BENCHMARK_FAST_SWEEPING |
899 | 900 | std::cerr << "Min = " << e.min() << " Max = " << e.max() << std::endl; |
@@ -958,18 +959,37 @@ struct FastSweeping<SdfGridT, ExtValueT>::MinMaxKernel |
958 | 959 | /// float min. |
959 | 960 | template <typename SdfGridT, typename ExtValueT> |
960 | 961 | struct FastSweeping<SdfGridT, ExtValueT>::PruneMinMaxFltKernel { |
| 962 | + PruneMinMaxFltKernel(SdfValueT min, SdfValueT max) : mMin(min), mMax(max) {} |
961 | 963 |
|
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 { } |
963 | 966 |
|
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 | + } |
970 | 979 | } |
971 | | - } |
972 | 980 |
|
| 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 | + } |
973 | 993 | SdfValueT mMin, mMax; |
974 | 994 | };// FastSweeping::PruneMinMaxFltKernel |
975 | 995 |
|
|
0 commit comments