An OpenVDB grid is essentially made up of three parts: a tree, a transform and metadata. The tree is basically just a collection of voxels (and so-called tiles), organized in a VDB tree structure and accessible by integer coordinates (e.g. i,j,k), and the transform defines the mapping from index space of the tree to world space, and the metadata is (as you correctly noted) largely optional. So when you ask "what is the size of a voxel" the answer depends on what space you're referring to - world space or index space? By design a voxel is the smallest addressable unit in index space so the voxel size is always one in index space. Consequently the size of a voxel in world space is uniquely given by the transform of the grid! So, if we assume (which is often the case) that the transform of a grid only has uniform scaling, this scaling factor is exactly the voxel size. Long story short, if someone gives you an OpenVDB grid and you're wondering what the voxel size is, all you have to do is inspect the transform of this grid. If the transform has uniform scaling (use grid.
hasUniformVoxels()) then the voxel size is simply by grid.voxelSize()[0]. (Else the voxel size may vary along the coordinate axis or even be a function of world space position, e.g. for frustrum transforms). On the other hand if you want to create a new grid with a specific voxel size simply do:
auto grid = openvdb::FloatGrid::create( 0.0f );// 0.0f is the "background value"
|
grid->setTransform(openvdb::math::Transform::createLinearTransform( 0.25f ));// 0.25f corresponds to the voxel size in world units (could be cm, meters or light-years - that's up to your application :)
Hope this clarifies things!? Ken
|