OpenVDB  2.0.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 <openvdb/Grid.h>
41 #include <openvdb/metadata/MetaMap.h>
42 #include <openvdb/version.h> // for VersionId
43 #include "Compression.h" // for COMPRESS_ZIP, etc.
44 
45 
46 class TestFile;
47 
48 namespace openvdb {
50 namespace OPENVDB_VERSION_NAME {
51 namespace io {
52 
53 class GridDescriptor;
54 
55 
58 OPENVDB_API uint32_t getFormatVersion(std::istream&);
59 
62 OPENVDB_API VersionId getLibraryVersion(std::istream&);
63 
66 OPENVDB_API std::string getVersion(std::istream&);
67 
69 OPENVDB_API void setCurrentVersion(std::istream&);
70 
74 OPENVDB_API void setVersion(std::ios_base&, const VersionId& libraryVersion, uint32_t fileVersion);
75 
78 OPENVDB_API bool getWriteGridStatsMetadata(std::ostream&);
79 
83 OPENVDB_API uint32_t getDataCompression(std::ios_base&);
84 
88 OPENVDB_API void setDataCompression(std::ios_base&, uint32_t compressionFlags);
89 
92 OPENVDB_API uint32_t getGridClass(std::ios_base&);
93 
96 OPENVDB_API void setGridClass(std::ios_base&, uint32_t);
97 
100 OPENVDB_API const void* getGridBackgroundValuePtr(std::ios_base&);
101 
105 OPENVDB_API void setGridBackgroundValuePtr(std::ios_base&, const void* background);
106 
107 
109 
110 
113 {
114 public:
115  static const uint32_t DEFAULT_COMPRESSION_FLAGS;
116 
117  Archive();
118  virtual ~Archive();
119 
122  std::string getUniqueTag() const;
124  bool isIdentical(const std::string& uuidStr) const;
125 
127  uint32_t fileVersion() const { return mFileVersion; }
130  VersionId libraryVersion() const { return mLibraryVersion; }
133  std::string version() const;
134 
137  bool isInstancingEnabled() const { return mEnableInstancing; }
141  void setInstancingEnabled(bool b) { mEnableInstancing = b; }
142 
144  bool isCompressionEnabled() const;
148  void setCompressionEnabled(bool);
149 
151  uint32_t compressionFlags() const { return mCompression; }
157  void setCompressionFlags(uint32_t c) { mCompression = c; }
158 
161  bool isGridStatsMetadataEnabled() const { return mEnableGridStats; }
164  void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
165 
166 protected:
169  bool inputHasGridOffsets() const { return mInputHasGridOffsets; }
170  void setInputHasGridOffsets(bool b) { mInputHasGridOffsets = b; }
171 
176  void setFormatVersion(std::istream&);
177 
183  void setLibraryVersion(std::istream&);
184 
187  void setDataCompression(std::istream&);
188 
191  void setGridCompression(std::ostream&, const GridBase&) const;
194  static void readGridCompression(std::istream&);
195 
198  void setWriteGridStatsMetadata(std::ostream&);
199 
201  static int32_t readGridCount(std::istream&);
202 
204  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&);
205 
206  typedef std::map<Name /*uniqueName*/, GridBase::Ptr> NamedGridMap;
207 
210  void connectInstance(const GridDescriptor&, const NamedGridMap&) const;
211 
215  void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
220  void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
221  std::ostream&, bool seekable) const;
222 
225  bool readHeader(std::istream&);
229  void writeHeader(std::ostream&, bool seekable) const;
230 
232  void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
234  void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
236 
237 private:
238  friend class ::TestFile;
239 
241  uint32_t mFileVersion;
243  VersionId mLibraryVersion;
245  mutable boost::uuids::uuid mUuid;// needs to mutable since writeHeader is const!
248  bool mInputHasGridOffsets;
251  bool mEnableInstancing;
253  uint32_t mCompression;
255  bool mEnableGridStats;
256 }; // class Archive
257 
258 } // namespace io
259 } // namespace OPENVDB_VERSION_NAME
260 } // namespace openvdb
261 
262 #endif // OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
263 
264 // Copyright (c) 2012-2013 DreamWorks Animation LLC
265 // All rights reserved. This software is distributed under the
266 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:162
OPENVDB_IMPORT VersionId getLibraryVersion(std::istream &)
Return the (major, minor) library version number associated with the given input stream.
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:401
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:141
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. ...
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 ...
OPENVDB_IMPORT void setCurrentVersion(std::istream &)
Associate the current file format and library version numbers with the given input stream...
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:396
Definition: GridDescriptor.h:46
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.
void setInputHasGridOffsets(bool b)
Definition: Archive.h:170
OPENVDB_API bool getWriteGridStatsMetadata(std::ostream &)
void setCompressionFlags(uint32_t c)
Specify whether and how the data stream should be compressed. [Mainly for internal use]...
Definition: Archive.h:157
OPENVDB_IMPORT std::string getVersion(std::istream &)
Return a string of the form &quot;&lt;major&gt;.&lt;minor&gt;/&lt;format&gt;&quot;, giving the library and file format version nu...
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
std::string Name
Definition: Name.h:44
Abstract base class for typed grids.
Definition: Grid.h:103
#define OPENVDB_VERSION_NAME
Definition: version.h:45
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:137
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...
uint32_t compressionFlags() const
Return a bit mask specifying compression options for the data stream.
Definition: Archive.h:151
static const uint32_t DEFAULT_COMPRESSION_FLAGS
Definition: Archive.h:115
Provides functionality storing type agnostic metadata information. Grids and other structures can inh...
Definition: MetaMap.h:48
std::map< Name, GridBase::Ptr > NamedGridMap
Definition: Archive.h:206
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.
uint32_t fileVersion() const
Return the file format version number of the input stream.
Definition: Archive.h:127
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
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...
VersionId libraryVersion() const
Return the (major, minor) version number of the library that was used to write the input stream...
Definition: Archive.h:130
Grid serializer/unserializer.
Definition: Archive.h:112
void setGridStatsMetadataEnabled(bool b)
Specify whether grid statistics (active voxel count and bounding box, etc.) should be computed and wr...
Definition: Archive.h:164
bool inputHasGridOffsets() const
Return true if the input stream contains grid offsets that allow for random access or partial reading...
Definition: Archive.h:169
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
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...
Definition: version.h:96
bool isGridStatsMetadataEnabled() const
Return true if grid statistics (active voxel count and bounding box, etc.) are computed and written a...
Definition: Archive.h:161
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106