Skip to content

Commit dbc7089

Browse files
VDBObject : Fix worldBound() when bbox metadata not present
1 parent 39e1c91 commit dbc7089

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
10.5.x.x (relative to 10.5.15.1)
22
========
33

4+
Fixes
5+
-----
6+
7+
- VDBObject : Fixed worldBound() result when bbox metadata not already present.
8+
49
API
510
---
611

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)