Uploaded image for project: 'OpenVDB'
  1. OpenVDB
  2. OVDB-54

Modify Transform and/or Metadata on Copy of Const Grid?

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Medium Medium
    • OpenVDB_7.0.0
    • None
    • Core

      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.

            danrbailey danrbailey
            danrbailey danrbailey
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: