Skip to content

Commit 1e2fc39

Browse files
committed
Pass writeOptions as an argument to all the I/O write routines
Signed-off-by: Dan Bailey <danbailey@ilm.com>
1 parent 05b5543 commit 1e2fc39

6 files changed

Lines changed: 48 additions & 31 deletions

File tree

openvdb/openvdb/io/Archive.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -959,15 +959,15 @@ Archive::readGrid(const GridDescriptor& gd, std::istream& is, const BBoxd& world
959959

960960
void
961961
Archive::write(std::ostream& os, const GridPtrVec& grids, bool seekable,
962-
const MetaMap& metadata) const
962+
const MetaMap& metadata, const io::WriteOptions& writeOptions) const
963963
{
964-
this->write(os, GridCPtrVec(grids.begin(), grids.end()), seekable, metadata);
964+
this->write(os, GridCPtrVec(grids.begin(), grids.end()), seekable, metadata, writeOptions);
965965
}
966966

967967

968968
void
969969
Archive::write(std::ostream& os, const GridCPtrVec& grids, bool seekable,
970-
const MetaMap& metadata) const
970+
const MetaMap& metadata, const io::WriteOptions& writeOptions) const
971971
{
972972
// Set stream flags so that downstream functions can reference them.
973973
io::StreamMetadata::Ptr streamMetadata = io::getStreamMetadataPtr(os);
@@ -1039,7 +1039,7 @@ Archive::write(std::ostream& os, const GridCPtrVec& grids, bool seekable,
10391039
// Get the name of the other grid.
10401040
gd.setInstanceParentName(mapIter->second.uniqueName());
10411041
// Write out this grid's descriptor and metadata, but not its tree.
1042-
writeGridInstance(gd, grid, os, seekable);
1042+
writeGridInstance(gd, grid, os, seekable, writeOptions);
10431043

10441044
OPENVDB_LOG_DEBUG_RUNTIME("io::Archive::write(): "
10451045
<< GridDescriptor::nameAsString(gd.uniqueName())
@@ -1048,7 +1048,7 @@ Archive::write(std::ostream& os, const GridCPtrVec& grids, bool seekable,
10481048
<< GridDescriptor::nameAsString(gd.instanceParentName()));
10491049
} else {
10501050
// Write out the grid descriptor and its associated grid.
1051-
writeGrid(gd, grid, os, seekable);
1051+
writeGrid(gd, grid, os, seekable, writeOptions);
10521052
// Record the grid's tree pointer so that the tree doesn't get written
10531053
// more than once.
10541054
treeMap[treePtr] = gd;
@@ -1064,7 +1064,7 @@ Archive::write(std::ostream& os, const GridCPtrVec& grids, bool seekable,
10641064

10651065
void
10661066
Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
1067-
std::ostream& os, bool seekable) const
1067+
std::ostream& os, bool seekable, const io::WriteOptions& writeOptions) const
10681068
{
10691069
// Restore file-level stream metadata on exit.
10701070
struct OnExit {
@@ -1143,7 +1143,7 @@ Archive::writeGrid(GridDescriptor& gd, GridBase::ConstPtr grid,
11431143

11441144
void
11451145
Archive::writeGridInstance(GridDescriptor& gd, GridBase::ConstPtr grid,
1146-
std::ostream& os, bool seekable) const
1146+
std::ostream& os, bool seekable, const io::WriteOptions& writeOptions) const
11471147
{
11481148
// Write out the Descriptor's header information (grid name, type
11491149
// and instance parent name).

openvdb/openvdb/io/Archive.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#define OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
66

77
#include <openvdb/version.h>
8-
#include "Compression.h" // for COMPRESS_ZIP, etc.
98
#include <openvdb/Grid.h>
109
#include <openvdb/MetaMap.h>
1110
#include <openvdb/Platform.h>
1211
#include <openvdb/version.h> // for VersionId
12+
13+
#include "Codec.h"
14+
#include "Compression.h" // for COMPRESS_ZIP, etc.
15+
1316
#include <cstdint>
1417
#include <iosfwd>
1518
#include <map>
@@ -89,7 +92,8 @@ class OPENVDB_API Archive
8992
void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
9093

9194
/// @brief Write the grids in the given container to this archive's output stream.
92-
virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const {}
95+
virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap(),
96+
const io::WriteOptions& = io::WriteOptions{}) const {}
9397

9498
/// @brief Return @c false (delayed loading has been removed).
9599
static bool isDelayedLoadingEnabled() { return false; }
@@ -141,13 +145,14 @@ class OPENVDB_API Archive
141145
/// Write the given grid descriptor and grid to an output stream
142146
/// and update the GridDescriptor offsets.
143147
/// @param seekable if true, the output stream supports seek operations
144-
void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
148+
void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable,
149+
const io::WriteOptions& writeOptions = io::WriteOptions{}) const;
145150
/// Write the given grid descriptor and grid metadata to an output stream
146151
/// and update the GridDescriptor offsets, but don't write the grid's tree,
147152
/// since it is shared with another grid.
148153
/// @param seekable if true, the output stream supports seek operations
149154
void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
150-
std::ostream&, bool seekable) const;
155+
std::ostream&, bool seekable, const io::WriteOptions& writeOptions = io::WriteOptions{}) const;
151156

152157
/// @brief Read the magic number, version numbers, UUID, etc. from the given input stream.
153158
/// @return @c true if the input UUID differs from the previously-read UUID.
@@ -159,8 +164,10 @@ class OPENVDB_API Archive
159164

160165
//@{
161166
/// Write the given grids to an output stream.
162-
void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
163-
void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
167+
void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap&,
168+
const io::WriteOptions& writeOptions = io::WriteOptions{}) const;
169+
void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap&,
170+
const io::WriteOptions& writeOptions = io::WriteOptions{}) const;
164171
//@}
165172

166173
private:

openvdb/openvdb/io/File.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ File::readGrid(const Name& name, const BBoxd& bbox)
498498

499499

500500
void
501-
File::writeGrids(const GridCPtrVec& grids, const MetaMap& meta) const
501+
File::writeGrids(const GridCPtrVec& grids, const MetaMap& meta, const io::WriteOptions& writeOptions) const
502502
{
503503
if (mIsOpen) {
504504
OPENVDB_THROW(IoError,
@@ -515,7 +515,7 @@ File::writeGrids(const GridCPtrVec& grids, const MetaMap& meta) const
515515
}
516516

517517
// Write out the vdb.
518-
Archive::write(file, grids, /*seekable=*/true, meta);
518+
Archive::write(file, grids, /*seekable=*/true, meta, writeOptions);
519519

520520
file.close();
521521
}

openvdb/openvdb/io/File.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ class OPENVDB_API File: public Archive
110110

111111
/// @brief Write the grids in the given container to the file whose name
112112
/// was given in the constructor.
113-
void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const override;
113+
void write(const GridCPtrVec&, const MetaMap& = MetaMap(),
114+
const io::WriteOptions& = io::WriteOptions{}) const override;
114115

115116
/// @brief Write the grids in the given container to the file whose name
116117
/// was given in the constructor.
117118
template<typename GridPtrContainerT>
118-
void write(const GridPtrContainerT&, const MetaMap& = MetaMap()) const;
119+
void write(const GridPtrContainerT&, const MetaMap& = MetaMap(),
120+
const io::WriteOptions& = io::WriteOptions{}) const;
119121

120122
/// A const iterator that iterates over all names in the file. This is only
121123
/// valid once the file has been opened.
@@ -155,7 +157,7 @@ class OPENVDB_API File: public Archive
155157
/// @throw KeyError if no grid with the given name exists in this file.
156158
GridBase::Ptr retrieveCachedGrid(const Name&) const;
157159

158-
void writeGrids(const GridCPtrVec&, const MetaMap&) const;
160+
void writeGrids(const GridCPtrVec&, const MetaMap&, const io::WriteOptions&) const;
159161

160162
MetaMap::Ptr fileMetadata();
161163
MetaMap::ConstPtr fileMetadata() const;
@@ -191,19 +193,21 @@ class OPENVDB_API File: public Archive
191193

192194

193195
inline void
194-
File::write(const GridCPtrVec& grids, const MetaMap& meta) const
196+
File::write(const GridCPtrVec& grids, const MetaMap& meta,
197+
const io::WriteOptions& writeOptions) const
195198
{
196-
this->writeGrids(grids, meta);
199+
this->writeGrids(grids, meta, writeOptions);
197200
}
198201

199202

200203
template<typename GridPtrContainerT>
201204
inline void
202-
File::write(const GridPtrContainerT& container, const MetaMap& meta) const
205+
File::write(const GridPtrContainerT& container, const MetaMap& meta,
206+
const io::WriteOptions& writeOptions) const
203207
{
204208
GridCPtrVec grids;
205209
std::copy(container.begin(), container.end(), std::back_inserter(grids));
206-
this->writeGrids(grids, meta);
210+
this->writeGrids(grids, meta, writeOptions);
207211
}
208212

209213
} // namespace io

openvdb/openvdb/io/Stream.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,21 @@ Stream::copy() const
102102

103103

104104
void
105-
Stream::write(const GridCPtrVec& grids, const MetaMap& metadata) const
105+
Stream::write(const GridCPtrVec& grids, const MetaMap& metadata,
106+
const io::WriteOptions& writeOptions) const
106107
{
107108
if (mOutputStream == nullptr) {
108109
OPENVDB_THROW(ValueError, "no output stream was specified");
109110
}
110-
this->writeGrids(*mOutputStream, grids, metadata);
111+
this->writeGrids(*mOutputStream, grids, metadata, writeOptions);
111112
}
112113

113114

114115
void
115-
Stream::writeGrids(std::ostream& os, const GridCPtrVec& grids, const MetaMap& metadata) const
116+
Stream::writeGrids(std::ostream& os, const GridCPtrVec& grids, const MetaMap& metadata,
117+
const io::WriteOptions& writeOptions) const
116118
{
117-
Archive::write(os, grids, /*seekable=*/false, metadata);
119+
Archive::write(os, grids, /*seekable=*/false, metadata, writeOptions);
118120
}
119121

120122

openvdb/openvdb/io/Stream.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ class OPENVDB_API Stream: public Archive
4949

5050
/// @brief Write the grids in the given container to this archive's output stream.
5151
/// @throw ValueError if this archive was constructed without specifying an output stream.
52-
void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const override;
52+
void write(const GridCPtrVec&, const MetaMap& = MetaMap(),
53+
const io::WriteOptions& = io::WriteOptions{}) const override;
5354

5455
/// @brief Write the grids in the given container to this archive's output stream.
5556
/// @throw ValueError if this archive was constructed without specifying an output stream.
5657
template<typename GridPtrContainerT>
57-
void write(const GridPtrContainerT&, const MetaMap& = MetaMap()) const;
58+
void write(const GridPtrContainerT&, const MetaMap& = MetaMap(),
59+
const io::WriteOptions& = io::WriteOptions{}) const;
5860

5961
private:
60-
void writeGrids(std::ostream&, const GridCPtrVec&, const MetaMap&) const;
62+
void writeGrids(std::ostream&, const GridCPtrVec&, const MetaMap&,
63+
const io::WriteOptions&) const;
6164

6265
MetaMap::Ptr mMeta;
6366
GridPtrVecPtr mGrids;
@@ -70,11 +73,12 @@ class OPENVDB_API Stream: public Archive
7073

7174
template<typename GridPtrContainerT>
7275
inline void
73-
Stream::write(const GridPtrContainerT& container, const MetaMap& metadata) const
76+
Stream::write(const GridPtrContainerT& container, const MetaMap& metadata,
77+
const io::WriteOptions& writeOptions) const
7478
{
7579
GridCPtrVec grids;
7680
std::copy(container.begin(), container.end(), std::back_inserter(grids));
77-
this->write(grids, metadata);
81+
this->write(grids, metadata, writeOptions);
7882
}
7983

8084
} // namespace io

0 commit comments

Comments
 (0)