openvdb resampleToMatch()

193 Views Asked by At

I want to decrease the voxel density of an openvdb grid. Inspired by this answer, I tried the following code:

const auto dim = grid->evalActiveVoxelDim().asVec3i();
std::cout << dim.x() << " " << dim.y() << " " << dim.z() << std::endl;

T::Ptr dest = T::create();
dest->setTransform(openvdb::math::Transform::createLinearTransform(1.0f));
openvdb::tools::resampleToMatch<openvdb::tools::BoxSampler>(*grid, *dest);

const auto dd = dest->evalActiveVoxelDim().asVec3i();

std::cout << dd.x() << " " << dd.y() << " " << dd.z() << std::endl;

The printed output with the grid I tried is the following:

86 93 82
8 8 6

I don't understand what this means. With scaling 1.0 I expected the same voxel density. Does the original grid include some scaling that I need to consider?

Also, is there a way to do this operation multi-threaded?

1

There are 1 best solutions below

0
On

I realized that scaling 1.0 is not neutral, because the grid can start out with an arbitrary voxel scale, that can be queried with voxelSize().

So resampling the grid so the voxels are twice as large could look something like this:

T::Ptr dest = T::create();
dest->setTransform(openvdb::math::Transform::createLinearTransform(grid->voxelSize().x() * 2));
openvdb::tools::resampleToMatch<openvdb::tools::BoxSampler>(*grid, *dest);

I believe it is multi-threaded by default, but has a long single-threaded passage at the end of the operation.