c++voxelopenvdb

How to downsample grid in OpenVDB


Is there any good way to downsample voxels grid in OpenVDB?

For example I have grid 8x8x8 with voxel size - 1.0, and I want to get grid 4x4x4 with voxel size - 2.0: each voxel of new grid is some interpolation of original voxels, e. g. [0,0,0] voxel of new grid is average value of [0,0,0]-[1,1,1] (8 voxels) of original grid)

P.S. There is way to do it manually but I bet openvdb has its own implementation


Solution

  • The thing I was looking for is resampleToMatch

        openvdb::FloatGrid::Ptr dest = openvdb::FloatGrid::create();
        dest->setTransform( openvdb::math::Transform::createLinearTransform( 2.0f ) ); // org voxel size is 1.0f
        openvdb::tools::resampleToMatch<openvdb::tools::BoxSampler>( *org, *dest );