Skip to content

Commit 40383fe

Browse files
committed
Pass readOptions as an argument to all the I/O read routines
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent 4d8355c commit 40383fe

5 files changed

Lines changed: 28 additions & 21 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ Archive::connectInstance(const GridDescriptor& gd, const NamedGridMap& grids) co
887887

888888

889889
GridBase::Ptr
890-
Archive::readGrid(const GridDescriptor& gd, std::istream& is, const BBoxd& worldBBox, bool partial/* = false*/)
890+
Archive::readGrid(const GridDescriptor& gd, std::istream& is, const io::ReadOptions& readOptions)
891891
{
892892
// Read the compression settings for this grid and tag the stream with them
893893
// so that downstream functions can reference them.
@@ -939,8 +939,9 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const BBoxd& world
939939
io::setGridClass(is, gridClass);
940940

941941
grid->readTransform(is);
942-
if (!partial && !gd.isInstance()) {
942+
if (readOptions.readMode != io::ReadMode::TopologyOnly && !gd.isInstance()) {
943943
grid->readTopology(is);
944+
const auto& worldBBox = readOptions.clipBBox;
944945
const bool clip = worldBBox.isSorted();
945946
if (clip) {
946947
const auto indexBBox = grid->constTransform().worldToIndexNodeCentered(worldBBox);

openvdb/openvdb/io/Archive.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ class OPENVDB_API Archive
132132
static int32_t readGridCount(std::istream&);
133133

134134
/// @brief Read in and create the grid represented by the given grid descriptor using the
135-
/// given input stream, but only where it intersects the given world-space bounding box.
136-
/// @param partial If true, only read the metadata and transform of the grid.
137-
static GridBase::Ptr readGrid(const GridDescriptor&, std::istream&, const BBoxd&, bool partial = false);
135+
/// given input stream, using the provided options if given.
136+
static GridBase::Ptr readGrid(const GridDescriptor&, std::istream&,
137+
const io::ReadOptions& readOptions = io::ReadOptions{});
138138

139139
using NamedGridMap = std::map<Name /*uniqueName*/, GridBase::Ptr>;
140140

openvdb/openvdb/io/File.cc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ File::open()
224224
gd.readHeader(inputStream());
225225
gd.readStreamPos(inputStream());
226226

227-
GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), BBoxd());
227+
GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), io::ReadOptions{});
228228

229229
mGridDescriptors.insert(std::make_pair(gd.gridName(), gd));
230230
mGrids->push_back(grid);
@@ -298,7 +298,7 @@ File::getMetadata() const
298298

299299

300300
GridPtrVecPtr
301-
File::getGrids() const
301+
File::getGrids(const io::ReadOptions& readOptions) const
302302
{
303303
if (!mIsOpen) {
304304
OPENVDB_THROW(IoError, mFilename << " is not open for reading");
@@ -319,7 +319,7 @@ File::getGrids() const
319319
const GridDescriptor& gd = i->second;
320320
// Seek to the grid in the file.
321321
gd.seekToGrid(inputStream());
322-
GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), BBoxd());
322+
GridBase::Ptr grid = Archive::readGrid(gd, inputStream(), readOptions);
323323
ret->push_back(grid);
324324
namedGrids[gd.uniqueName()] = grid;
325325
}
@@ -385,7 +385,9 @@ File::readAllGridMetadata()
385385
const GridDescriptor& gd = i->second;
386386
// Seek to the grid in the file.
387387
gd.seekToGrid(inputStream());
388-
GridBase::ConstPtr grid = Archive::readGrid(gd, inputStream(), BBoxd(), /*partial=*/true);
388+
io::ReadOptions readOptions;
389+
readOptions.readMode = io::ReadMode::TopologyOnly;
390+
GridBase::ConstPtr grid = Archive::readGrid(gd, inputStream(), readOptions);
389391
// Return copies of the grids, but with empty trees.
390392
// (As of 0.98.0, at least, it would suffice to just const cast
391393
// the grid pointers returned by readGrid(partial=true), but shallow
@@ -423,7 +425,9 @@ File::readGridMetadata(const Name& name)
423425
// Seek to and read in the grid from the file.
424426
const GridDescriptor& gd = it->second;
425427
gd.seekToGrid(inputStream());
426-
ret = Archive::readGrid(gd, inputStream(), BBoxd(), /*partial=*/true);
428+
io::ReadOptions readOptions;
429+
readOptions.readMode = io::ReadMode::TopologyOnly;
430+
ret = Archive::readGrid(gd, inputStream(), readOptions);
427431
}
428432
return ret->copyGridWithNewTree();
429433
}
@@ -433,26 +437,28 @@ File::readGridMetadata(const Name& name)
433437

434438

435439
GridBase::Ptr
436-
File::readGrid(const Name& name)
440+
File::readGrid(const Name& name, const BBoxd& bbox)
437441
{
438-
return readGrid(name, BBoxd());
442+
io::ReadOptions readOptions;
443+
readOptions.clipBBox = bbox;
444+
return readGrid(name, readOptions);
439445
}
440446

441447

442448
GridBase::Ptr
443-
File::readGrid(const Name& name, const BBoxd& bbox)
449+
File::readGrid(const Name& name, const io::ReadOptions& readOptions)
444450
{
445451
if (!mIsOpen) {
446452
OPENVDB_THROW(IoError, mFilename << " is not open for reading.");
447453
}
448454

449-
const bool clip = bbox.isSorted();
450-
451455
// If a grid with the given name was already read and cached
452456
// (along with the entire contents of the file, because the file
453457
// doesn't support random access), retrieve and return it.
454458
GridBase::Ptr grid = retrieveCachedGrid(name);
455459
if (grid) {
460+
const auto& bbox = readOptions.clipBBox;
461+
const bool clip = bbox.isSorted();
456462
if (clip) {
457463
grid = grid->deepCopyGrid();
458464
grid->clipGrid(bbox);
@@ -471,7 +477,7 @@ File::readGrid(const Name& name, const BBoxd& bbox)
471477
OPENVDB_ASSERT(inputHasGridOffsets());
472478
// Seek to the grid in the file.
473479
gd.seekToGrid(inputStream());
474-
grid = Archive::readGrid(gd, inputStream(), bbox);
480+
grid = Archive::readGrid(gd, inputStream(), readOptions);
475481

476482
if (gd.isInstance()) {
477483
/// @todo Refactor to share code with Archive::connectInstance()?
@@ -487,7 +493,7 @@ File::readGrid(const Name& name, const BBoxd& bbox)
487493
GridBase::Ptr parent;
488494
OPENVDB_ASSERT(inputHasGridOffsets());
489495
parentIt->second.seekToGrid(inputStream());
490-
parent = Archive::readGrid(parentIt->second, inputStream(), bbox);
496+
parent = Archive::readGrid(parentIt->second, inputStream(), readOptions);
491497
if (parent) grid->setTree(parent->baseTreePtr());
492498
}
493499
return grid;

openvdb/openvdb/io/File.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class OPENVDB_API File: public Archive
8787
MetaMap::Ptr getMetadata() const;
8888

8989
/// Read the entire contents of the file and return a list of grid pointers.
90-
GridPtrVecPtr getGrids() const;
90+
GridPtrVecPtr getGrids(const io::ReadOptions& readOptions = io::ReadOptions{}) const;
9191

9292
/// @brief Read just the grid metadata and transforms from the file and return a list
9393
/// of pointers to grids that are empty except for their metadata and transforms.
@@ -100,8 +100,8 @@ class OPENVDB_API File: public Archive
100100
/// @throw KeyError if no grid with the given name exists in this file.
101101
GridBase::Ptr readGridMetadata(const Name&);
102102

103-
/// Read an entire grid, including all of its data blocks.
104-
GridBase::Ptr readGrid(const Name&);
103+
/// Read an entire grid, including all of its data blocks, using the provided options if given.
104+
GridBase::Ptr readGrid(const Name&, const io::ReadOptions& readOptions = io::ReadOptions{});
105105
/// @brief Read a grid, including its data blocks, but only where it
106106
/// intersects the given world-space bounding box.
107107
GridBase::Ptr readGrid(const Name&, const BBoxd&);

openvdb/openvdb/io/Stream.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Stream::Stream(std::istream& is)
5151
gd.readHeader(is);
5252
gd.readStreamPos(is);
5353
descriptors.push_back(gd);
54-
GridBase::Ptr grid = Archive::readGrid(gd, is, BBoxd());
54+
GridBase::Ptr grid = Archive::readGrid(gd, is, io::ReadOptions{});
5555
mGrids->push_back(grid);
5656
namedGrids[gd.uniqueName()] = grid;
5757
}

0 commit comments

Comments
 (0)