Skip to content

Commit 84fc1e6

Browse files
authored
Merge pull request #2193 from danrbailey/io_float_frustum_bbox
Add support for reading file version 221 (FLOAT_FRUSTUM_BBOX)
2 parents 85bd0e5 + 226ac86 commit 84fc1e6

5 files changed

Lines changed: 39 additions & 20 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,9 @@ getFormatVersion(std::ios_base& is)
630630
void
631631
checkFormatVersion(std::ios_base& is)
632632
{
633-
if (getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION ) {
633+
if (getFormatVersion(is) < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX ) {
634634
OPENVDB_THROW(IoError,
635-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported. "
635+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported. "
636636
"To read older VDB files, please use VDB 12.x or older and then write "
637637
"them out again to produce files that are compatible with 13.0 and above.");
638638
}
@@ -951,9 +951,9 @@ Archive::readHeader(std::istream& is)
951951
if (mFileVersion > OPENVDB_FILE_VERSION) {
952952
OPENVDB_LOG_WARN("unsupported VDB file format (expected version "
953953
<< OPENVDB_FILE_VERSION << " or earlier, got version " << mFileVersion << ")");
954-
} else if (mFileVersion < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
954+
} else if (mFileVersion < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
955955
OPENVDB_THROW(IoError,
956-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
956+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
957957
}
958958

959959
// 3) Read the library version numbers (not stored prior to file format version 211).

openvdb/openvdb/io/Compression.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,17 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
488488

489489
int8_t metadata = NO_MASK_AND_ALL_VALS;
490490

491-
// Read the flag that specifies what, if any, additional metadata
492-
// (selection mask and/or inactive value(s)) is saved.
493-
if (seek && !maskCompressed) {
494-
is.seekg(/*bytes=*/1, std::ios_base::cur);
495-
} else if (seek && delayLoadMeta) {
496-
metadata = delayLoadMeta->getMask(leafIndex);
497-
is.seekg(/*bytes=*/1, std::ios_base::cur);
498-
} else {
499-
is.read(reinterpret_cast<char*>(&metadata), /*bytes=*/1);
491+
if (getFormatVersion(is) >= OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
492+
// Read the flag that specifies what, if any, additional metadata
493+
// (selection mask and/or inactive value(s)) is saved.
494+
if (seek && !maskCompressed) {
495+
is.seekg(/*bytes=*/1, std::ios_base::cur);
496+
} else if (seek && delayLoadMeta) {
497+
metadata = delayLoadMeta->getMask(leafIndex);
498+
is.seekg(/*bytes=*/1, std::ios_base::cur);
499+
} else {
500+
is.read(reinterpret_cast<char*>(&metadata), /*bytes=*/1);
501+
}
500502
}
501503

502504
ValueT background = zeroVal<ValueT>();

openvdb/openvdb/io/File.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,9 @@ File::readAllGridMetadata()
523523
OPENVDB_THROW(IoError, filename() << " is not open for reading");
524524
}
525525

526-
if (fileVersion() < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
526+
if (fileVersion() < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
527527
OPENVDB_THROW(IoError,
528-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
528+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
529529
}
530530

531531
GridPtrVecPtr ret(new GridPtrVec);
@@ -560,9 +560,9 @@ File::readGridMetadata(const Name& name)
560560
OPENVDB_THROW(IoError, filename() << " is not open for reading.");
561561
}
562562

563-
if (fileVersion() < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
563+
if (fileVersion() < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
564564
OPENVDB_THROW(IoError,
565-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
565+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
566566
}
567567

568568
GridBase::ConstPtr ret;

openvdb/openvdb/tree/InternalNode.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,9 @@ InternalNode<ChildT, Log2Dim>::readTopology(std::istream& is, bool fromHalf)
24262426
mChildMask.load(is);
24272427
mValueMask.load(is);
24282428

2429-
const Index numValues = NUM_VALUES;
2429+
const bool oldVersion =
2430+
(io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION);
2431+
const Index numValues = (oldVersion ? mChildMask.countOff() : NUM_VALUES);
24302432
{
24312433
// Read in (and uncompress, if necessary) all of this node's values
24322434
// into a contiguous array.
@@ -2435,8 +2437,16 @@ InternalNode<ChildT, Log2Dim>::readTopology(std::istream& is, bool fromHalf)
24352437
io::readCompressedValues(is, values, numValues, mValueMask, fromHalf);
24362438

24372439
// Copy values from the array into this node's table.
2438-
for (ValueAllIter iter = this->beginValueAll(); iter; ++iter) {
2439-
mNodes[iter.pos()].setValue(values[iter.pos()]);
2440+
if (oldVersion) {
2441+
Index n = 0;
2442+
for (ValueAllIter iter = this->beginValueAll(); iter; ++iter) {
2443+
mNodes[iter.pos()].setValue(values[n++]);
2444+
}
2445+
OPENVDB_ASSERT(n == numValues);
2446+
} else {
2447+
for (ValueAllIter iter = this->beginValueAll(); iter; ++iter) {
2448+
mNodes[iter.pos()].setValue(values[iter.pos()]);
2449+
}
24402450
}
24412451
}
24422452

openvdb/openvdb/tree/LeafNode.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,13 @@ LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bo
13881388
}
13891389

13901390
int8_t numBuffers = 1;
1391+
if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
1392+
// Read in the origin.
1393+
is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1394+
1395+
// Read in the number of buffers, which should now always be one.
1396+
is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1397+
}
13911398

13921399
CoordBBox nodeBBox = this->getNodeBoundingBox();
13931400
if (!clipBBox.hasOverlap(nodeBBox)) {

0 commit comments

Comments
 (0)