OpenVDB  2.3.0
Archive.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
32 #define OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Platform.h>
35 #include <iosfwd>
36 #include <map>
37 #include <string>
38 #include <boost/uuid/uuid.hpp>
39 #include <boost/cstdint.hpp>
40 #include <boost/shared_ptr.hpp>
41 #include <openvdb/Grid.h>
42 #include <openvdb/metadata/MetaMap.h>
43 #include <openvdb/version.h> // for VersionId
44 #include "Compression.h" // for COMPRESS_ZIP, etc.
45 
46 
47 class TestFile;
48 
49 namespace openvdb {
51 namespace OPENVDB_VERSION_NAME {
52 namespace io {
53 
54 class GridDescriptor;
55 
56 
59 OPENVDB_API uint32_t getFormatVersion(std::istream&);
60 
63 OPENVDB_API VersionId getLibraryVersion(std::istream&);
64 
67 OPENVDB_API std::string getVersion(std::istream&);
68 
70 OPENVDB_API void setCurrentVersion(std::istream&);
71 
75 OPENVDB_API void setVersion(std::ios_base&, const VersionId& libraryVersion, uint32_t fileVersion);
76 
79 OPENVDB_API bool getWriteGridStatsMetadata(std::ostream&);
80 
84 OPENVDB_API uint32_t getDataCompression(std::ios_base&);
85 
89 OPENVDB_API void setDataCompression(std::ios_base&, uint32_t compressionFlags);
90 
93 OPENVDB_API uint32_t getGridClass(std::ios_base&);
94 
97 OPENVDB_API void setGridClass(std::ios_base&, uint32_t);
98 
101 OPENVDB_API const void* getGridBackgroundValuePtr(std::ios_base&);
102 
106 OPENVDB_API void setGridBackgroundValuePtr(std::ios_base&, const void* background);
107 
108 
110 
111 
114 {
115 public:
116  static const uint32_t DEFAULT_COMPRESSION_FLAGS;
117 
118  Archive();
119  virtual ~Archive();
120 
122  virtual boost::shared_ptr<Archive> copy() const;
123 
126  std::string getUniqueTag() const;
128  bool isIdentical(const std::string& uuidStr) const;
129 
131  uint32_t fileVersion() const { return mFileVersion; }
134  VersionId libraryVersion() const { return mLibraryVersion; }
137  std::string version() const;
138 
141  bool isInstancingEnabled() const { return mEnableInstancing; }
145  void setInstancingEnabled(bool b) { mEnableInstancing = b; }
146 
148  bool isCompressionEnabled() const;
152  void setCompressionEnabled(bool);
153 
155  uint32_t compressionFlags() const { return mCompression; }
161  void setCompressionFlags(uint32_t c) { mCompression = c; }
162 
165  bool isGridStatsMetadataEnabled() const { return mEnableGridStats; }
168  void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
169 
171  virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const {}
172 
173 protected:
176  bool inputHasGridOffsets() const { return mInputHasGridOffsets; }
177  void setInputHasGridOffsets(bool b) { mInputHasGridOffsets = b; }
178 
183  void setFormatVersion(std::istream&);
184 
190  void setLibraryVersion(std::istream&);
191 
194  void setDataCompression(std::istream&);
195 
198  void setGridCompression(std::ostream&, const GridBase&) const;
201  static void readGridCompression(std::istream&);
202 
205  void setWriteGridStatsMetadata(std::ostream&);
206 
208  static int32_t readGridCount(std::istream&);
209 
211  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&);
212 
213  typedef std::map<Name /*uniqueName*/, GridBase::Ptr> NamedGridMap;
214 
217  void connectInstance(const GridDescriptor&, const NamedGridMap&) const;
218 
222  void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
227  void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
228  std::ostream&, bool seekable) const;
229 
232  bool readHeader(std::istream&);
236  void writeHeader(std::ostream&, bool seekable) const;
237 
239  void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
241  void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
243 
244 private:
245  friend class ::TestFile;
246 
248  uint32_t mFileVersion;
250  VersionId mLibraryVersion;
252  mutable boost::uuids::uuid mUuid;// needs to be mutable since writeHeader is const!
255  bool mInputHasGridOffsets;
258  bool mEnableInstancing;
260  uint32_t mCompression;
262  bool mEnableGridStats;
263 }; // class Archive
264 
265 } // namespace io
266 } // namespace OPENVDB_VERSION_NAME
267 } // namespace openvdb
268 
269 #endif // OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
270 
271 // Copyright (c) 2012-2013 DreamWorks Animation LLC
272 // All rights reserved. This software is distributed under the
273 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
std::map< Name, GridBase::Ptr > NamedGridMap
Definition: Archive.h:213
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:187
OPENVDB_IMPORT uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
OPENVDB_IMPORT void setVersion(std::ios_base &, const VersionId &libraryVersion, uint32_t fileVersion)
Associate specific file format and library version numbers with the given stream. ...
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:141
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:145
bool inputHasGridOffsets() const
Return true if the input stream contains grid offsets that allow for random access or partial reading...
Definition: Archive.h:176
OPENVDB_IMPORT std::string getVersion(std::istream &)
Return a string of the form "./", giving the library and file format version nu...
void setCompressionFlags(uint32_t c)
Specify whether and how the data stream should be compressed. [Mainly for internal use]...
Definition: Archive.h:161
Definition: GridDescriptor.h:46
bool isGridStatsMetadataEnabled() const
Return true if grid statistics (active voxel count and bounding box, etc.) are computed and written a...
Definition: Archive.h:165
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
OPENVDB_API bool getWriteGridStatsMetadata(std::ostream &)
OPENVDB_IMPORT VersionId getLibraryVersion(std::istream &)
Return the (major, minor) library version number associated with the given input stream.
Abstract base class for typed grids.
Definition: Grid.h:103
void setInputHasGridOffsets(bool b)
Definition: Archive.h:177
VersionId libraryVersion() const
Return the (major, minor) version number of the library that was used to write the input stream...
Definition: Archive.h:134
#define OPENVDB_VERSION_NAME
Definition: version.h:45
OPENVDB_IMPORT void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
uint32_t compressionFlags() const
Return a bit mask specifying compression options for the data stream.
Definition: Archive.h:155
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
OPENVDB_IMPORT void setCurrentVersion(std::istream &)
Associate the current file format and library version numbers with the given input stream...
Definition: version.h:110
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:401
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:396
Provides functionality storing type agnostic metadata information. Grids and other structures can inh...
Definition: MetaMap.h:48
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
void setGridStatsMetadataEnabled(bool b)
Specify whether grid statistics (active voxel count and bounding box, etc.) should be computed and wr...
Definition: Archive.h:168
static const uint32_t DEFAULT_COMPRESSION_FLAGS
Definition: Archive.h:116
virtual void write(const GridCPtrVec &, const MetaMap &=MetaMap()) const
Write the grids in the given container to this archive's output stream.
Definition: Archive.h:171
OPENVDB_IMPORT 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.
OPENVDB_IMPORT const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
Grid serializer/unserializer.
Definition: Archive.h:113
uint32_t fileVersion() const
Return the file format version number of the input stream.
Definition: Archive.h:131
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
OPENVDB_IMPORT void setGridBackgroundValuePtr(std::ios_base &, const void *background)
Specify (a pointer to) the background value of the grid currently being read from or written to the g...
OPENVDB_IMPORT uint32_t getDataCompression(std::ios_base &)
Return 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.
std::string Name
Definition: Name.h:44