Let's say I want to modify every value on my grid by multiplying each by 2. I can define a functor and pass this and my tree to foreach(). However I notice for large grids there is a long lag before any multicore processing begins.
struct ScalarTimes {
float fac;
ScalarTimes(const float s): fac(s) {}
inline void operator()(const openvdb::FloatGrid::ValueAllIter& iter) const {
iter.setValue(fac * (*iter));
}
};
openvdb::FloatGrid::Ptr grid = openvdb::tools::createLevelSetSphere<openvdb::FloatGrid>(1.0, openvdb::Vec3f(0.0, 0.0, 0.0), 0.0005, 3.0);
openvdb::tools::foreach(grid->beginValueAll(), ScalarTimes(2.0));
This example creates a level set with ~300,000,000 voxels, and on my machine the call to foreach() takes ~17 seconds. However on my 56 core machine only 1 thread is fired up during most of the computation.
Here is a plot of cpu usage over time (5600% is the max):