Skip to content

Commit

Permalink
Fix bug when using multi-pass I/O and bbox clipping together
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bailey committed Nov 10, 2016
1 parent c3b154d commit 4e14bd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openvdb/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,11 @@ Grid<TreeT>::readBuffers(std::istream& is, const CoordBBox& bbox)
assert(bool(meta));
for (uint32_t pass = 0; pass < uint32_t(numPasses); ++pass) {
meta->setPass(pass);
tree().readBuffers(is, bbox, saveFloatAsHalf());
tree().readBuffers(is, CoordBBox::inf(), saveFloatAsHalf());
}
// cannot clip inside readBuffers() when using multiple passes, so instead
// use an infinite CoordBBox and clip afterwards
tree().clip(bbox);
}
}

Expand Down
17 changes: 17 additions & 0 deletions openvdb/unittest/TestFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,7 @@ TestFile::testMultiPassIO()
// Create a multi-buffer grid.
const MultiPassGrid::Ptr grid = openvdb::createGrid<MultiPassGrid>();
grid->setName("test");
grid->setTransform(math::Transform::createLinearTransform(1.0));
MultiPassGrid::TreeType& tree = grid->tree();
tree.setValue(Coord(0, 0, 0), 5);
tree.setValue(Coord(0, 10, 0), 5);
Expand Down Expand Up @@ -2005,6 +2006,22 @@ TestFile::testMultiPassIO()
CPPUNIT_ASSERT_EQUAL(1, leafIter->mReadPasses[1]);
CPPUNIT_ASSERT_EQUAL(2, leafIter->mReadPasses[2]);
}
{
// Verify that when using multi-pass and bbox clipping that each leaf node
// is still being read before being clipped
io::File file(filename);
file.open();
const auto newGrid = GridBase::grid<MultiPassGrid>(file.readGrid("test", BBoxd(Vec3d(0), Vec3d(1))));
CPPUNIT_ASSERT_EQUAL(Index32(1), newGrid->tree().leafCount());

auto leafIter = newGrid->tree().beginLeaf();
CPPUNIT_ASSERT_EQUAL(3, int(leafIter->mReadPasses.size()));
CPPUNIT_ASSERT_EQUAL(0, leafIter->mReadPasses[0]);
CPPUNIT_ASSERT_EQUAL(1, leafIter->mReadPasses[1]);
CPPUNIT_ASSERT_EQUAL(2, leafIter->mReadPasses[2]);
++leafIter;
CPPUNIT_ASSERT(!leafIter); // second leaf node has now been clipped
}

// Clear the pass data.
writePasses.clear();
Expand Down

0 comments on commit 4e14bd4

Please sign in to comment.