OpenVDB: Archive.h Source File

OpenVDB 3.2.0

Archive.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 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/scoped_ptr.hpp>
41 #include <boost/shared_ptr.hpp>
42 #include <openvdb/Grid.h>
43 #include <openvdb/metadata/MetaMap.h>
44 #include <openvdb/version.h> // for VersionId
45 #include "Compression.h" // for COMPRESS_ZIP, etc.
46
47
48 class TestFile;
49
50 namespace openvdb {
51 OPENVDB_USE_VERSION_NAMESPACE
52 namespace OPENVDB_VERSION_NAME {
53 namespace io {
54
55 class GridDescriptor;
56
57
59 class OPENVDB_API Archive
60 {
61 public:
62 typedef boost::shared_ptr<Archive> Ptr;
63 typedef boost::shared_ptr<const Archive> ConstPtr;
64
65 static const uint32_t DEFAULT_COMPRESSION_FLAGS;
66
67 Archive();
68 virtual ~Archive();
69
71 virtual Ptr copy() const;
72
75 std::string getUniqueTag() const;
77 bool isIdentical(const std::string& uuidStr) const;
78
80 uint32_t fileVersion() const { return mFileVersion; }
83 VersionId libraryVersion() const { return mLibraryVersion; }
86 std::string version() const;
87
90 bool isInstancingEnabled() const { return mEnableInstancing; }
94 void setInstancingEnabled(bool b) { mEnableInstancing = b; }
95
97 static bool hasBloscCompression();
98
100 uint32_t compression() const { return mCompression; }
105 void setCompression(uint32_t c) { mCompression = c; }
106
109 bool isGridStatsMetadataEnabled() const { return mEnableGridStats; }
112 void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
113
115 virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const {}
116
122 static bool isDelayedLoadingEnabled();
123
124 protected:
127 bool inputHasGridOffsets() const { return mInputHasGridOffsets; }
128 void setInputHasGridOffsets(bool b) { mInputHasGridOffsets = b; }
129
134 void setFormatVersion(std::istream&);
135
141 void setLibraryVersion(std::istream&);
142
145 void setDataCompression(std::istream&);
146
149 void setGridCompression(std::ostream&, const GridBase&) const;
152 static void readGridCompression(std::istream&);
153
155 static int32_t readGridCount(std::istream&);
156
158 static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&);
159 #ifndef OPENVDB_2_ABI_COMPATIBLE
160 static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&, const BBoxd&);
165 static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&, const CoordBBox&);
166 #endif
167
168 typedef std::map<Name /*uniqueName*/, GridBase::Ptr> NamedGridMap;
169
172 void connectInstance(const GridDescriptor&, const NamedGridMap&) const;
173
177 void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
182 void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
183 std::ostream&, bool seekable) const;
184
187 bool readHeader(std::istream&);
191 void writeHeader(std::ostream&, bool seekable) const;
192
194 void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
196 void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
198
199 private:
200 friend class ::TestFile;
201
203 uint32_t mFileVersion;
205 VersionId mLibraryVersion;
207 mutable boost::uuids::uuid mUuid;// needs to be mutable since writeHeader is const!
210 bool mInputHasGridOffsets;
213 bool mEnableInstancing;
215 uint32_t mCompression;
217 bool mEnableGridStats;
218 }; // class Archive
219
220 } // namespace io
221 } // namespace OPENVDB_VERSION_NAME
222 } // namespace openvdb
223
224 #endif // OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
225
226 // Copyright (c) 2012-2016 DreamWorks Animation LLC
227 // All rights reserved. This software is distributed under the
228 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:195
openvdb::v3_2_0::GridBase::ConstPtr
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
Compression.h
openvdb::v3_2_0::GridBase
Abstract base class for typed grids.
Definition: Grid.h:103
openvdb::v3_2_0::GridPtrVec
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:420
openvdb::v3_2_0::io::setDataCompression
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.
MetaMap.h
openvdb::v3_2_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
openvdb::v3_2_0::Name
std::string Name
Definition: Name.h:44
openvdb::v3_2_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
openvdb::v3_2_0::io::Archive::Ptr
boost::shared_ptr< Archive > Ptr
Definition: Archive.h:62
openvdb::v3_2_0::io::Archive::ConstPtr
boost::shared_ptr< const Archive > ConstPtr
Definition: Archive.h:63
openvdb::v3_2_0::io::Archive::setInstancingEnabled
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:94
openvdb::v3_2_0::io::Archive::DEFAULT_COMPRESSION_FLAGS
static const uint32_t DEFAULT_COMPRESSION_FLAGS
Definition: Archive.h:65
openvdb::v3_2_0::io::Archive::isGridStatsMetadataEnabled
bool isGridStatsMetadataEnabled() const
Return true if grid statistics (active voxel count and bounding box, etc.) are computed and written a...
Definition: Archive.h:109
openvdb::v3_2_0::io::Archive::setInputHasGridOffsets
void setInputHasGridOffsets(bool b)
Definition: Archive.h:128
openvdb::v3_2_0::math::BBox< Vec3d >
openvdb::v3_2_0::io::Archive::setCompression
void setCompression(uint32_t c)
Specify whether and how the data stream should be compressed.
Definition: Archive.h:105
openvdb::v3_2_0::io::GridDescriptor
Definition: GridDescriptor.h:46
openvdb::v3_2_0::io::Archive::inputHasGridOffsets
bool inputHasGridOffsets() const
Return true if the input stream contains grid offsets that allow for random access or partial reading...
Definition: Archive.h:127
openvdb::v3_2_0::io::Archive::setGridStatsMetadataEnabled
void setGridStatsMetadataEnabled(bool b)
Specify whether grid statistics (active voxel count and bounding box, etc.) should be computed and wr...
Definition: Archive.h:112
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_2_0::VersionId
Definition: version.h:120
openvdb::v3_2_0::io::Archive::libraryVersion
VersionId libraryVersion() const
Return the (major, minor) version number of the library that was used to write the input stream...
Definition: Archive.h:83
openvdb::v3_2_0::io::Archive::fileVersion
uint32_t fileVersion() const
Return the file format version number of the input stream.
Definition: Archive.h:80
openvdb
Definition: Exceptions.h:39
version.h
openvdb::v3_2_0::io::Archive::write
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:115
openvdb::v3_2_0::io::Archive::compression
uint32_t compression() const
Return a bit mask specifying compression options for the data stream.
Definition: Archive.h:100
openvdb::v3_2_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
Grid.h
openvdb::v3_2_0::GridBase::Ptr
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_2_0::io::Archive::NamedGridMap
std::map< Name, GridBase::Ptr > NamedGridMap
Definition: Archive.h:168
openvdb::v3_2_0::io::Archive::isInstancingEnabled
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:90
openvdb::v3_2_0::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:59
Platform.h