-
Improvement
-
Resolution: Done
-
Medium
-
None
It's not currently possible in the OpenVDB API to do a shallow copy of a const grid while modifying the transform or metadata.
Discussed with kmuseth and pcucka shortly after ABI=5 was released and we talking about revisiting this for ABI=6 (but I think we all forgot).
This was pcucka's suggested work-around at the time:
I suppose it would be good to add optional Transform and MetaMap arguments to GridBase::copyGrid() and Grid::copy(). That would be an ABI-breaking change, though. For the time being, you could write your own copy function—maybe something like this:
template<typename GridType> inline typename GridType::ConstPtr copyGrid( const GridType& grid, const openvdb::math::Transform::ConstPtr& transform = openvdb::math::Transform::ConstPtr{}, const openvdb::MetaMap& metadata = openvdb::MetaMap{}) { auto copyOfGrid = openvdb::StaticPtrCast<const GridType>(grid.copyGrid()); openvdb::ConstPtrCast<GridType>(copyOfGrid)->insertMeta(metadata); if (transform) { openvdb::ConstPtrCast<GridType>(copyOfGrid)->setTransform( openvdb::ConstPtrCast<openvdb::math::Transform>(transform)); } return copyOfGrid; }
I'm tagging this ticket for ABI=7 so we can look at the changes to GridBase::copyGrid() and Grid::copy() sometime closer to the release of 7.0.0.