Skip to content

Commit 7f0610c

Browse files
FIX : worldBound
1 parent dd57c91 commit 7f0610c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/IECoreVDB/VDBObject.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,23 @@ namespace
5757
template<typename T>
5858
Imath::Box<Imath::Vec3<T> > worldBound( const openvdb::GridBase *grid, float padding = 0.50f )
5959
{
60-
openvdb::Vec3i min = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN );
61-
openvdb::Vec3i max = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX );
60+
openvdb::CoordBBox vdbBbox;
61+
try
62+
{
63+
vdbBbox.min() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN ) );
64+
vdbBbox.max() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX ) );
65+
}
66+
catch( ... )
67+
{
68+
// If we don't have metadata available, then hopefully it's because the vdb was freshly created and
69+
// hasn't been saved to file yet, which should mean it's fully loaded, and we can call
70+
// evalActiveVoxelBoundingBox.
71+
// \todo : Can we guarantee that every VDB either is loaded, or has metadata?
72+
vdbBbox = grid->evalActiveVoxelBoundingBox();
73+
}
6274

6375
openvdb::Vec3d offset = openvdb::Vec3d( padding );
64-
openvdb::BBoxd indexBounds = openvdb::BBoxd( min - offset, max + offset );
76+
openvdb::BBoxd indexBounds = openvdb::BBoxd( vdbBbox.min() - offset, vdbBbox.max() + offset );
6577
openvdb::BBoxd worldBounds = grid->transform().indexToWorld( indexBounds );
6678
openvdb::Vec3d minBB = worldBounds.min();
6779
openvdb::Vec3d maxBB = worldBounds.max();

0 commit comments

Comments
 (0)