Skip to content

Commit 2621268

Browse files
committed
Merge remote-tracking branch 'upstream/feature/io' into io_scalar_codecs
2 parents 94e20c0 + e7b7014 commit 2621268

14 files changed

Lines changed: 713 additions & 77 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ getFormatVersion(std::ios_base& is)
448448
void
449449
checkFormatVersion(std::ios_base& is)
450450
{
451-
if (getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION ) {
451+
if (getFormatVersion(is) < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX ) {
452452
OPENVDB_THROW(IoError,
453-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported. "
453+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported. "
454454
"To read older VDB files, please use VDB 12.x or older and then write "
455455
"them out again to produce files that are compatible with 13.0 and above.");
456456
}
@@ -750,9 +750,9 @@ Archive::readHeader(std::istream& is)
750750
if (mFileVersion > OPENVDB_FILE_VERSION) {
751751
OPENVDB_LOG_WARN("unsupported VDB file format (expected version "
752752
<< OPENVDB_FILE_VERSION << " or earlier, got version " << mFileVersion << ")");
753-
} else if (mFileVersion < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
753+
} else if (mFileVersion < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
754754
OPENVDB_THROW(IoError,
755-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
755+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
756756
}
757757

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

openvdb/openvdb/io/Codec.h

Lines changed: 296 additions & 33 deletions
Large diffs are not rendered by default.

openvdb/openvdb/io/Compression.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,14 @@ readCompressedValues(std::istream& is, ValueT* destBuf, Index destCount,
465465

466466
int8_t metadata = NO_MASK_AND_ALL_VALS;
467467

468-
// Read the flag that specifies what, if any, additional metadata
469-
// (selection mask and/or inactive value(s)) is saved.
470-
if (seek && !maskCompressed) {
471-
is.seekg(/*bytes=*/1, std::ios_base::cur);
472-
} else {
473-
is.read(reinterpret_cast<char*>(&metadata), /*bytes=*/1);
468+
if (getFormatVersion(is) >= OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
469+
// Read the flag that specifies what, if any, additional metadata
470+
// (selection mask and/or inactive value(s)) is saved.
471+
if (seek && !maskCompressed) {
472+
is.seekg(/*bytes=*/1, std::ios_base::cur);
473+
} else {
474+
is.read(reinterpret_cast<char*>(&metadata), /*bytes=*/1);
475+
}
474476
}
475477

476478
ValueT background = zeroVal<ValueT>();

openvdb/openvdb/io/File.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ File::readAllGridMetadata()
365365
OPENVDB_THROW(IoError, mFilename << " is not open for reading");
366366
}
367367

368-
if (fileVersion() < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
368+
if (fileVersion() < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
369369
OPENVDB_THROW(IoError,
370-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
370+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
371371
}
372372

373373
GridPtrVecPtr ret(new GridPtrVec);
@@ -406,9 +406,9 @@ File::readGridMetadata(const Name& name)
406406
OPENVDB_THROW(IoError, mFilename << " is not open for reading.");
407407
}
408408

409-
if (fileVersion() < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
409+
if (fileVersion() < OPENVDB_FILE_VERSION_FLOAT_FRUSTUM_BBOX) {
410410
OPENVDB_THROW(IoError,
411-
"VDB file version < 222 (NODE_MASK_COMPRESSION) is no longer supported.");
411+
"VDB file version < 221 (FLOAT_FRUSTUM_BBOX) is no longer supported.");
412412
}
413413

414414
GridBase::ConstPtr ret;

openvdb/openvdb/thread/Threading.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
#endif
1515

1616

17-
/// @note tbb/blocked_range.h is the ONLY include that persists from TBB 2020
18-
/// to TBB 2021 that itself includes the TBB specific version header files.
19-
/// In TBB 2020, the version header was called tbb/stddef.h. In 2021, it's
20-
/// called tbb/version.h. We include tbb/blocked_range.h here to indirectly
21-
/// access the version defines in a consistent way so that downstream
22-
/// software doesn't need to provide compile time defines.
2317
#include <tbb/blocked_range.h>
2418
#include <tbb/task.h>
19+
/// @note tbb/task_arena.h is the ONLY include that persists from TBB 2020
20+
/// to TBB 2021 to TBB 2023 that itself includes the TBB specific version
21+
/// header files.
22+
/// In TBB 2020, the version header was called tbb/stddef.h. In 2021+, it's
23+
/// called tbb/version.h. We include tbb/task_arena.h here to indirectly
24+
/// access the version defines in a consistent way so that downstream
25+
/// software doesn't need to provide compile time defines.
26+
#include <tbb/task_arena.h>
2527
#include <tbb/task_group.h>
2628

2729
namespace openvdb {

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
@@ -1381,6 +1381,13 @@ LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bo
13811381
}
13821382

13831383
int8_t numBuffers = 1;
1384+
if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
1385+
// Read in the origin.
1386+
is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1387+
1388+
// Read in the number of buffers, which should now always be one.
1389+
is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1390+
}
13841391

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

openvdb/openvdb/tree/Tree.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ class OPENVDB_API TreeBase
151151
/// @brief Read the tree topology from a stream.
152152
///
153153
/// This will read the tree structure and tile values, but not voxel data.
154-
virtual void readTopology(std::istream&, bool saveFloatAsHalf = false);
154+
virtual void readTopology(std::istream&, bool saveFloatAsHalf = false) = 0;
155155
/// @brief Write the tree topology to a stream.
156156
///
157157
/// This will write the tree structure and tile values, but not voxel data.
158-
virtual void writeTopology(std::ostream&, bool saveFloatAsHalf = false) const;
158+
virtual void writeTopology(std::ostream&, bool saveFloatAsHalf = false) const = 0;
159159

160160
/// Read all data buffers for this tree.
161161
virtual void readBuffers(std::istream&, bool saveFloatAsHalf = false) = 0;
@@ -1130,23 +1130,6 @@ struct Tree5 {
11301130
////////////////////////////////////////
11311131

11321132

1133-
inline void
1134-
TreeBase::readTopology(std::istream& is, bool /*saveFloatAsHalf*/)
1135-
{
1136-
int32_t bufferCount;
1137-
is.read(reinterpret_cast<char*>(&bufferCount), sizeof(int32_t));
1138-
if (bufferCount != 1) OPENVDB_LOG_WARN("multi-buffer trees are no longer supported");
1139-
}
1140-
1141-
1142-
inline void
1143-
TreeBase::writeTopology(std::ostream& os, bool /*saveFloatAsHalf*/) const
1144-
{
1145-
int32_t bufferCount = 1;
1146-
os.write(reinterpret_cast<char*>(&bufferCount), sizeof(int32_t));
1147-
}
1148-
1149-
11501133
inline void
11511134
TreeBase::print(std::ostream& os, int /*verboseLevel*/) const
11521135
{
@@ -1273,7 +1256,9 @@ void
12731256
Tree<RootNodeType>::readTopology(std::istream& is, bool saveFloatAsHalf)
12741257
{
12751258
this->clearAllAccessors();
1276-
TreeBase::readTopology(is, saveFloatAsHalf);
1259+
int32_t bufferCount;
1260+
is.read(reinterpret_cast<char*>(&bufferCount), sizeof(int32_t));
1261+
if (bufferCount != 1) OPENVDB_LOG_WARN("multi-buffer trees are no longer supported");
12771262
mRoot.readTopology(is, saveFloatAsHalf);
12781263
}
12791264

@@ -1282,7 +1267,8 @@ template<typename RootNodeType>
12821267
void
12831268
Tree<RootNodeType>::writeTopology(std::ostream& os, bool saveFloatAsHalf) const
12841269
{
1285-
TreeBase::writeTopology(os, saveFloatAsHalf);
1270+
int32_t bufferCount = 1;
1271+
os.write(reinterpret_cast<char*>(&bufferCount), sizeof(int32_t));
12861272
mRoot.writeTopology(os, saveFloatAsHalf);
12871273
}
12881274

pendingchanges/iooptions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
OpenVDB:
2+
API changes:
3+
- Added optional trailing WriteOptions parameter to io::File::write() and io::Stream::write().
4+
No changes in behavior.
5+
- Added optional trailing ReadOptions parameter to io::File::getGrids() and io::File::readGrid().
6+
No changes in behavior.

pendingchanges/iorefactor.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OpenVDB:
2+
API changes:
3+
- GridDescriptor::read() has been deprecated, use GridDescriptor::readHeader()
4+
followed by GridDescriptor::readStreamPos() instead.
5+
6+
Improvements:
7+
- Large refactor of I/O classes, many private and protected member functions have
8+
been modified. No change in behavior for io::File and io::Stream.

0 commit comments

Comments
 (0)