OpenVDB  3.1.0
io.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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_IO_HAS_BEEN_INCLUDED
32 #define OPENVDB_IO_IO_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Platform.h>
35 #include <openvdb/version.h>
36 #include <boost/any.hpp>
37 #include <boost/function.hpp>
38 #include <boost/scoped_ptr.hpp>
39 #include <boost/shared_ptr.hpp>
40 #include <iosfwd> // for std::ios_base
41 #include <map>
42 #include <string>
43 
44 
45 namespace openvdb {
47 namespace OPENVDB_VERSION_NAME {
48 
49 class MetaMap;
50 
51 namespace io {
52 
57 {
58 public:
59  typedef boost::shared_ptr<StreamMetadata> Ptr;
60  typedef boost::shared_ptr<const StreamMetadata> ConstPtr;
61 
64  explicit StreamMetadata(std::ios_base&);
65  ~StreamMetadata();
66 
67  StreamMetadata& operator=(const StreamMetadata&);
68 
71  void transferTo(std::ios_base&) const;
72 
73  uint32_t fileVersion() const;
74  void setFileVersion(uint32_t);
75 
76  VersionId libraryVersion() const;
77  void setLibraryVersion(VersionId);
78 
79  uint32_t compression() const;
80  void setCompression(uint32_t);
81 
82  uint32_t gridClass() const;
83  void setGridClass(uint32_t);
84 
85  const void* backgroundPtr() const;
86  void setBackgroundPtr(const void*);
87 
88  bool halfFloat() const;
89  void setHalfFloat(bool);
90 
91  bool writeGridStats() const;
92  void setWriteGridStats(bool);
93 
95  MetaMap& gridMetadata();
101  const MetaMap& gridMetadata() const;
103 
104  typedef std::map<std::string, boost::any> AuxDataMap;
106  AuxDataMap& auxData();
108  const AuxDataMap& auxData() const;
110 
112  std::string str() const;
113 
114 private:
115  struct Impl;
116  boost::scoped_ptr<Impl> mImpl;
117 }; // class StreamMetadata
118 
119 
121 std::ostream& operator<<(std::ostream&, const StreamMetadata&);
122 
123 std::ostream& operator<<(std::ostream&, const StreamMetadata::AuxDataMap&);
124 
125 
127 
128 
129 class File;
130 
133 {
134 public:
135  typedef boost::shared_ptr<MappedFile> Ptr;
136 
137  ~MappedFile();
138 
140  std::string filename() const;
141 
151  boost::shared_ptr<std::streambuf> createBuffer() const;
152 
153  typedef boost::function<void(std::string /*filename*/)> Notifier;
156  void setNotifier(const Notifier&);
158  void clearNotifier();
159 
160 private:
161  friend class File;
162 
163  explicit MappedFile(const std::string& filename, bool autoDelete = false);
164 
165  MappedFile(const MappedFile&); // not copyable
166  MappedFile& operator=(const MappedFile&); // not copyable
167 
168  class Impl;
169  boost::scoped_ptr<Impl> mImpl;
170 }; // class MappedFile
171 
172 
174 
175 
177 std::string getErrorString(int errorNum);
178 
179 
181 std::string getErrorString();
182 
183 
185 
186 
189 OPENVDB_API uint32_t getFormatVersion(std::ios_base&);
190 
193 OPENVDB_API VersionId getLibraryVersion(std::ios_base&);
194 
197 OPENVDB_API std::string getVersion(std::ios_base&);
198 
200 OPENVDB_API void setCurrentVersion(std::istream&);
201 
205 OPENVDB_API void setVersion(std::ios_base&, const VersionId& libraryVersion, uint32_t fileVersion);
206 
210 OPENVDB_API uint32_t getDataCompression(std::ios_base&);
214 OPENVDB_API void setDataCompression(std::ios_base&, uint32_t compressionFlags);
215 
218 OPENVDB_API uint32_t getGridClass(std::ios_base&);
221 OPENVDB_API void setGridClass(std::ios_base&, uint32_t);
222 
225 OPENVDB_API bool getHalfFloat(std::ios_base&);
228 OPENVDB_API void setHalfFloat(std::ios_base&, bool);
229 
232 OPENVDB_API const void* getGridBackgroundValuePtr(std::ios_base&);
236 OPENVDB_API void setGridBackgroundValuePtr(std::ios_base&, const void* background);
237 
240 OPENVDB_API bool getWriteGridStatsMetadata(std::ios_base&);
243 OPENVDB_API void setWriteGridStatsMetadata(std::ios_base&, bool writeGridStats);
244 
247 OPENVDB_API boost::shared_ptr<MappedFile> getMappedFilePtr(std::ios_base&);
251 OPENVDB_API void setMappedFilePtr(std::ios_base&, boost::shared_ptr<MappedFile>&);
252 
255 OPENVDB_API boost::shared_ptr<StreamMetadata> getStreamMetadataPtr(std::ios_base&);
263 OPENVDB_API void setStreamMetadataPtr(std::ios_base&,
264  boost::shared_ptr<StreamMetadata>&, bool transfer = true);
267 OPENVDB_API boost::shared_ptr<StreamMetadata> clearStreamMetadataPtr(std::ios_base&);
268 
269 } // namespace io
270 } // namespace OPENVDB_VERSION_NAME
271 } // namespace openvdb
272 
273 #endif // OPENVDB_IO_IO_HAS_BEEN_INCLUDED
274 
275 // Copyright (c) 2012-2015 DreamWorks Animation LLC
276 // All rights reserved. This software is distributed under the
277 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Grid archive associated with a file on disk.
Definition: File.h:54
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:195
std::string getErrorString()
Return a string (possibly empty) describing the most recent system error.
boost::shared_ptr< MappedFile > Ptr
Definition: io.h:135
OPENVDB_API VersionId getLibraryVersion(std::ios_base &)
Return the (major, minor) library version number associated with the given input stream.
Container for metadata describing how to unserialize grids from and/or serialize grids to a stream (w...
Definition: io.h:56
OPENVDB_API 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...
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
OPENVDB_API void setHalfFloat(std::ios_base &, bool)
Specify whether floating-point values should be quantized to 16 bits when writing to the given stream...
std::map< std::string, boost::any > AuxDataMap
Definition: io.h:104
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.
OPENVDB_API void setVersion(std::ios_base &, const VersionId &libraryVersion, uint32_t fileVersion)
Associate specific file format and library version numbers with the given stream. ...
OPENVDB_API void setStreamMetadataPtr(std::ios_base &, boost::shared_ptr< StreamMetadata > &, bool transfer=true)
Associate the given stream with (a shared pointer to) an object that stores metadata (file format...
OPENVDB_API 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...
OPENVDB_API boost::shared_ptr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
boost::shared_ptr< const StreamMetadata > ConstPtr
Definition: io.h:60
#define OPENVDB_VERSION_NAME
Definition: version.h:43
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
Definition: version.h:120
OPENVDB_API 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_API bool getWriteGridStatsMetadata(std::ios_base &)
Return true if grid statistics (active voxel count and bounding box, etc.) should be computed and sto...
Definition: Exceptions.h:39
OPENVDB_API 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.
boost::shared_ptr< StreamMetadata > Ptr
Definition: io.h:59
Handle to control the lifetime of a memory-mapped .vdb file.
Definition: io.h:132
OPENVDB_API void setMappedFilePtr(std::ios_base &, boost::shared_ptr< MappedFile > &)
Associate the given stream with (a shared pointer to) a memory-mapped file.
OPENVDB_API boost::shared_ptr< StreamMetadata > clearStreamMetadataPtr(std::ios_base &)
Dissociate the given stream from its metadata object (if it has one) and return a shared pointer to t...
OPENVDB_API void setWriteGridStatsMetadata(std::ios_base &, bool writeGridStats)
Specify whether to compute grid statistics (active voxel count and bounding box, etc.) and store them as grid metadata when writing to the given stream.
OPENVDB_API boost::shared_ptr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated, or a null pointer if the stream is not associated with a memory-mapped file.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
OPENVDB_API 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_API void setCurrentVersion(std::istream &)
Associate the current file format and library version numbers with the given input stream...
OPENVDB_API bool getHalfFloat(std::ios_base &)
Return true if floating-point values should be quantized to 16 bits when writing to the given stream ...
std::ostream & operator<<(std::ostream &, const StreamMetadata::AuxDataMap &)
OPENVDB_API std::string getVersion(std::ios_base &)
Return a string of the form "<major>.<minor>/<format>", giving the library and file format version nu...
boost::function< void(std::string)> Notifier
Definition: io.h:153