Skip to content

Commit 68ec51e

Browse files
authored
Merge pull request #1423 from danieldresser-ie/noVdbStats
VDBObject : Don't bake in automatic metadata when querying metadata
2 parents 39e1c91 + e47a401 commit 68ec51e

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
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

712
- SConstruct : Install "private" headers.
13+
- VDBObject : Marked metadata() as deprecated
814

915
10.5.15.1 (relative to 10.5.15.0)
1016
=========

include/IECoreVDB/VDBObject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class IECOREVDB_API VDBObject : public IECoreScene::VisibleRenderable
8888
Imath::Box3f bound() const override;
8989
void render( IECoreScene::Renderer *renderer ) const override;
9090

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

9399
//! Are the grids in this VDBObject unmodified from the vdb file in filename?

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)