Skip to content

Commit 27f6e19

Browse files
committed
Add back support for 221 VDB files
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent 2a54d6d commit 27f6e19

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

openvdb/openvdb/codecs/ScalarLeafCodec.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ void readScalarLeafBuffers(LeafT& leaf, std::istream& is, bool saveFloatAsHalf,
4848
if (seekable) valueMask.seek(is);
4949
else valueMask.load(is);
5050

51+
// Pre-node-mask-compression format stored the origin and buffer count
52+
// inline after the value mask.
53+
int8_t numBuffers = 1;
54+
if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
55+
Coord origin;
56+
is.read(reinterpret_cast<char*>(&origin), sizeof(Coord::ValueType) * 3);
57+
leaf.setOrigin(origin);
58+
59+
is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
60+
61+
if (numBuffers > 1) {
62+
OPENVDB_THROW(IoError, "Old file format 221 (FLOAT_FRUSTUM_BBOX) with multiple buffers is not supported");
63+
}
64+
}
65+
5166
if (skip) {
5267
if (seekable) {
5368
io::readCompressedValues<StorageValueT, NodeMaskT>(is, nullptr, SIZE, valueMask, saveFloatAsHalf);

openvdb/openvdb/codecs/TopologyCodec.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ struct ReadTopologyOp
182182
valueMask.load(is);
183183
node.setValueMaskUnsafe(valueMask);
184184

185-
const Index numValues = NodeT::NUM_VALUES;
185+
const bool oldVersion =
186+
(io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION);
187+
const Index numValues = (oldVersion ? childMask.countOff() : NodeT::NUM_VALUES);
186188
{
187189
// Read in (and uncompress, if necessary) all of this node's values
188190
// into a contiguous array.
@@ -191,13 +193,27 @@ struct ReadTopologyOp
191193
io::readCompressedValues(is, values, numValues, valueMask, saveFloatAsHalf);
192194

193195
// Copy values from the array into this node's table.
194-
if constexpr (std::is_same_v<ValueT, StorageValueT>) {
195-
for (auto iter = node.beginValueAll(); iter; ++iter) {
196-
node.setValueOnlyUnsafe(iter.pos(), values[iter.pos()]);
196+
if (oldVersion) {
197+
Index n = 0;
198+
if constexpr (std::is_same_v<ValueT, StorageValueT>) {
199+
for (auto iter = node.beginValueAll(); iter; ++iter) {
200+
node.setValueOnlyUnsafe(iter.pos(), values[n++]);
201+
}
202+
} else {
203+
for (auto iter = node.beginValueAll(); iter; ++iter) {
204+
node.setValueOnlyUnsafe(iter.pos(), static_cast<ValueT>(values[n++]));
205+
}
197206
}
207+
OPENVDB_ASSERT(n == numValues);
198208
} else {
199-
for (auto iter = node.beginValueAll(); iter; ++iter) {
200-
node.setValueOnlyUnsafe(iter.pos(), static_cast<ValueT>(values[iter.pos()]));
209+
if constexpr (std::is_same_v<ValueT, StorageValueT>) {
210+
for (auto iter = node.beginValueAll(); iter; ++iter) {
211+
node.setValueOnlyUnsafe(iter.pos(), values[iter.pos()]);
212+
}
213+
} else {
214+
for (auto iter = node.beginValueAll(); iter; ++iter) {
215+
node.setValueOnlyUnsafe(iter.pos(), static_cast<ValueT>(values[iter.pos()]));
216+
}
201217
}
202218
}
203219
}

0 commit comments

Comments
 (0)