Skip to content

VDBObject : Don't bake in automatic metadata when querying metadata #1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
10.5.x.x (relative to 10.5.15.1)
========

Fixes
-----

- VDBObject : Fixed worldBound() result when bbox metadata not already present.

API
---

- SConstruct : Install "private" headers.
- VDBObject : Marked metadata() as deprecated

10.5.15.1 (relative to 10.5.15.0)
=========
Expand Down
6 changes: 6 additions & 0 deletions include/IECoreVDB/VDBObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class IECOREVDB_API VDBObject : public IECoreScene::VisibleRenderable
Imath::Box3f bound() const override;
void render( IECoreScene::Renderer *renderer ) const override;

// \deprecated
// Not threadsafe ( it computes statistics if not present and stores them on the grids ).
// Instead, use the VDB api, for example:
// findGrid( name )->beginMeta() to iterate the metadata,
// or
// findGrid( name )->evalActiveVoxelBoundingBox() or activeVoxelCount() to compute statistics
IECore::CompoundObjectPtr metadata( const std::string &name );

//! Are the grids in this VDBObject unmodified from the vdb file in filename?
Expand Down
18 changes: 15 additions & 3 deletions src/IECoreVDB/VDBObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,23 @@ namespace
template<typename T>
Imath::Box<Imath::Vec3<T> > worldBound( const openvdb::GridBase *grid, float padding = 0.50f )
{
openvdb::Vec3i min = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN );
openvdb::Vec3i max = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX );
openvdb::CoordBBox vdbBbox;
try
{
vdbBbox.min() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN ) );
vdbBbox.max() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX ) );
}
catch( ... )
{
// If we don't have metadata available, then hopefully it's because the vdb was freshly created and
// hasn't been saved to file yet, which should mean it's fully loaded, and we can call
// evalActiveVoxelBoundingBox.
// \todo : Can we guarantee that every VDB either is loaded, or has metadata?
vdbBbox = grid->evalActiveVoxelBoundingBox();
}

openvdb::Vec3d offset = openvdb::Vec3d( padding );
openvdb::BBoxd indexBounds = openvdb::BBoxd( min - offset, max + offset );
openvdb::BBoxd indexBounds = openvdb::BBoxd( vdbBbox.min() - offset, vdbBbox.max() + offset );
openvdb::BBoxd worldBounds = grid->transform().indexToWorld( indexBounds );
openvdb::Vec3d minBB = worldBounds.min();
openvdb::Vec3d maxBB = worldBounds.max();
Expand Down