OpenVDB  0.104.0
Archive.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2012 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 
73 OPENVDB_API bool getWriteGridStatsMetadata(std::ostream&);
74 
78 OPENVDB_API uint32_t getDataCompression(std::ios_base&);
79 
82 OPENVDB_API uint32_t getGridClass(std::ios_base&);
83 
86 OPENVDB_API const void* getGridBackgroundValuePtr(std::ios_base&);
87 
91 OPENVDB_API void setGridBackgroundValuePtr(std::ios_base&, const void* background);
92 
93 
96 {
97 public:
98  // Indices into a stream's internal extensible array of values of use to readers and writers
99  // (VC9 requires these declarations to be on separate lines.)
100  static const int sFormatVersionIndex;
101  static const int sLibraryMajorVersionIndex;
102  static const int sLibraryMinorVersionIndex;
103  static const int sDataCompressionIndex;
105  static const int sGridBackgroundIndex;
106  static const int sGridClassIndex;
107 
108  static const uint32_t DEFAULT_COMPRESSION_FLAGS;
109 
110  Archive();
111  virtual ~Archive();
112 
115  std::string getUniqueTag() const;
117  bool isIdentical(const std::string& uuidStr) const;
118 
120  uint32_t fileVersion() const { return mFileVersion; }
123  VersionId libraryVersion() const { return mLibraryVersion; }
126  std::string version() const;
127 
130  bool isInstancingEnabled() const { return mEnableInstancing; }
134  void setInstancingEnabled(bool b) { mEnableInstancing = b; }
135 
137  bool isCompressionEnabled() const;
141  void setCompressionEnabled(bool);
142 
144  uint32_t compressionFlags() const { return mCompression; }
150  void setCompressionFlags(uint32_t c) { mCompression = c; }
151 
154  bool isGridStatsMetadataEnabled() const { return mEnableGridStats; }
157  void setGridStatsMetadataEnabled(bool b) { mEnableGridStats = b; }
158 
159 protected:
162  bool inputHasGridOffsets() const { return mInputHasGridOffsets; }
163  void setInputHasGridOffsets(bool b) { mInputHasGridOffsets = b; }
164 
169  void setFormatVersion(std::istream&);
170 
176  void setLibraryVersion(std::istream&);
177 
180  void setDataCompression(std::istream&);
181 
184  void setGridCompression(std::ostream&, const GridBase&) const;
187  static void readGridCompression(std::istream&);
188 
191  void setWriteGridStatsMetadata(std::ostream&);
192 
194  static int readGridCount(std::istream&);
195 
197  static void readGrid(GridBase::Ptr, const GridDescriptor&, std::istream&);
198 
199  typedef std::map<Name /*uniqueName*/, GridBase::Ptr> NamedGridMap;
200 
203  void connectInstance(const GridDescriptor&, const NamedGridMap&) const;
204 
208  void writeGrid(GridDescriptor&, GridBase::ConstPtr, std::ostream&, bool seekable) const;
213  void writeGridInstance(GridDescriptor&, GridBase::ConstPtr,
214  std::ostream&, bool seekable) const;
215 
218  bool readHeader(std::istream&);
222  void writeHeader(std::ostream&, bool seekable) const;
223 
225 
226  void write(std::ostream&, const GridPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
227  void write(std::ostream&, const GridCPtrVec&, bool seekable, const MetaMap& = MetaMap()) const;
229 
230 private:
231  friend class ::TestFile;
232 
234  uint32_t mFileVersion;
236  VersionId mLibraryVersion;
238  mutable boost::uuids::uuid mUuid;// needs to mutable since writeHeader is const!
241  bool mInputHasGridOffsets;
244  bool mEnableInstancing;
246  uint32_t mCompression;
248  bool mEnableGridStats;
249 }; // class Archive
250 
251 } // namespace io
252 } // namespace OPENVDB_VERSION_NAME
253 } // namespace openvdb
254 
255 #endif // OPENVDB_IO_ARCHIVE_HAS_BEEN_INCLUDED
256 
257 // Copyright (c) 2012 DreamWorks Animation LLC
258 // All rights reserved. This software is distributed under the
259 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )