OpenVDB  7.0.0
Archive.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #ifndef OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
5 #define OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
6 
7 #include <openvdb/version.h>
8 #include "Compression.h" // for COMPRESS_ZIP, etc.
9 #include <openvdb/Grid.h>
10 #include <openvdb/MetaMap.h>
11 #include <openvdb/Platform.h>
12 #include <openvdb/version.h> // for VersionId
13 #include <boost/uuid/uuid.hpp>
14 #include <cstdint>
15 #include <iosfwd>
16 #include <map>
17 #include <memory>
18 #include <string>
19 
20 
21 class TestFile;
22 
23 namespace openvdb {
25 namespace OPENVDB_VERSION_NAME {
26 namespace io {
27 
28 class GridDescriptor;
29 
30 
33 {
34 public:
37 
38  static const uint32_t DEFAULT_COMPRESSION_FLAGS;
39 
40  Archive();
41  Archive(const Archive&) = default;
42  Archive& operator=(const Archive&) = default;
43  virtual ~Archive();
44 
46  virtual Ptr copy() const;
47 
50  std::string getUniqueTag() const;
52  bool isIdentical(const std::string& uuidStr) const;
53 
55  uint32_t fileVersion() const { return mFileVersion; }
58  VersionId libraryVersion() const { return mLibraryVersion; }
61  std::string version() const;
62 
65  bool isInstancingEnabled() const { return mEnableInstancing; }
69  void setInstancingEnabled(bool b) { mEnableInstancing = b; }
70 
72  static bool hasBloscCompression();
73 
75  uint32_t compression() const { return mCompression; }
80  void setCompression(uint32_t c) { mCompression = c; }
81 
84  bool isGridStatsMetadataEnabled() const { return mEnableGridStats; }
87  void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
88 
90  virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const {}
91 
97  static bool isDelayedLoadingEnabled();
98 
99 protected:
102  bool inputHasGridOffsets() const { return mInputHasGridOffsets; }
103  void setInputHasGridOffsets(bool b) { mInputHasGridOffsets = b; }
104 
109  void setFormatVersion(std::istream&);
110 
116  void setLibraryVersion(std::istream&);
117 
120  void setDataCompression(std::istream&);
121 
124  void setGridCompression(std::ostream&, const GridBase&) const;
127  static void readGridCompression(std::istream&);
128 
130  static int32_t readGridCount(std::istream&);
131 
133  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&);
136  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&, const BBoxd&);
139  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&, const CoordBBox&);
140 
141  using NamedGridMap = std::map<Name /*uniqueName*/, GridBase::Ptr>;
142 
145  void connectInstance(const GridDescriptor&, const NamedGridMap&) const;
146 
150  void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
155  void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
156  std::ostream&, bool seekable) const;
157 
160  bool readHeader(std::istream&);
164  void writeHeader(std::ostream&, bool seekable) const;
165 
167  void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
169  void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
171 
172 private:
173  friend class ::TestFile;
174 
176  uint32_t mFileVersion;
178  VersionId mLibraryVersion;
180  mutable boost::uuids::uuid mUuid;// needs to be mutable since writeHeader is const!
183  bool mInputHasGridOffsets;
186  bool mEnableInstancing;
188  uint32_t mCompression;
190  bool mEnableGridStats;
191 }; // class Archive
192 
193 } // namespace io
194 } // namespace OPENVDB_VERSION_NAME
195 } // namespace openvdb
196 
197 #endif // OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
Definition: GridDescriptor.h:19
Abstract base class for typed grids.
Definition: Grid.h:77
VersionId libraryVersion() const
Return the (major, minor) version number of the library that was used to write the input stream...
Definition: Archive.h:58
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
bool isInstancingEnabled() const
Return true if trees shared by multiple grids are written out only once, false if they are written ou...
Definition: Archive.h:65
std::string Name
Definition: Name.h:17
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
static const uint32_t DEFAULT_COMPRESSION_FLAGS
Definition: Archive.h:38
uint32_t fileVersion() const
Return the file format version number of the input stream.
Definition: Archive.h:55
void setGridStatsMetadataEnabled(bool b)
Specify whether grid statistics (active voxel count and bounding box, etc.) should be computed and wr...
Definition: Archive.h:87
OPENVDB_API void setDataCompression(std::ios_base &, uint32_t compressionFlags)
Associate with the given stream a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK, etc.) specifying whether and how input data is compressed or output data should be compressed.
virtual void write(const GridCPtrVec &, const MetaMap &=MetaMap()) const
Write the grids in the given container to this archive&#39;s output stream.
Definition: Archive.h:90
Grid serializer/unserializer.
Definition: Archive.h:32
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:19
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
bool isGridStatsMetadataEnabled() const
Return true if grid statistics (active voxel count and bounding box, etc.) are computed and written a...
Definition: Archive.h:84
void setCompression(uint32_t c)
Specify whether and how the data stream should be compressed.
Definition: Archive.h:80
Definition: Exceptions.h:13
Library and file format version numbers.
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:509
void setInputHasGridOffsets(bool b)
Definition: Archive.h:103
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
SharedPtr< const Archive > ConstPtr
Definition: Archive.h:36
uint32_t compression() const
Return a bit mask specifying compression options for the data stream.
Definition: Archive.h:75
Definition: version.h:210
std::map< Name, GridBase::Ptr > NamedGridMap
Definition: Archive.h:141
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
SharedPtr< Archive > Ptr
Definition: Archive.h:35
bool inputHasGridOffsets() const
Return true if the input stream contains grid offsets that allow for random access or partial reading...
Definition: Archive.h:102
void setInstancingEnabled(bool b)
Specify whether trees shared by multiple grids should be written out only once (true) or once per gri...
Definition: Archive.h:69