OpenVDB 3.2.0

File.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 //
32
33 #ifndef OPENVDB_IO_FILE_HAS_BEEN_INCLUDED
34 #define OPENVDB_IO_FILE_HAS_BEEN_INCLUDED
35
36 #include "io.h" // for MappedFile::Notifier
37 #include "Archive.h"
38 #include "GridDescriptor.h"
39 #include <iosfwd>
40 #include <map>
41 #include <string>
42 #include <boost/scoped_ptr.hpp>
43
44
45 class TestFile;
46 class TestStream;
47
48 namespace openvdb {
49 OPENVDB_USE_VERSION_NAMESPACE
50 namespace OPENVDB_VERSION_NAME {
51 namespace io {
52
54 class OPENVDB_API File: public Archive
55 {
56 public:
57 typedef std::multimap<Name, GridDescriptor> NameMap;
58 typedef NameMap::const_iterator NameMapCIter;
59
60 explicit File(const std::string& filename);
61 virtual ~File();
62
66 File(const File& other);
70 File& operator=(const File& other);
71
75 virtual boost::shared_ptr<Archive> copy() const;
76
79 const std::string& filename() const;
80
90 bool open(bool delayLoad = true, const MappedFile::Notifier& = MappedFile::Notifier());
91
93 bool isOpen() const;
94
96 void close();
97
100 Index64 getSize() const;
101
104 Index64 copyMaxBytes() const;
116 void setCopyMaxBytes(Index64 bytes);
117
119 bool hasGrid(const Name&) const;
120
122 MetaMap::Ptr getMetadata() const;
123
125 GridPtrVecPtr getGrids() const;
126
130 GridPtrVecPtr readAllGridMetadata();
131
136 GridBase::Ptr readGridMetadata(const Name&);
137
144 GridBase::ConstPtr readGridPartial(const Name&);
145
147 GridBase::Ptr readGrid(const Name&);
148 #ifndef OPENVDB_2_ABI_COMPATIBLE
149 GridBase::Ptr readGrid(const Name&, const BBoxd&);
152 #endif
153
156
159 virtual void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const;
160
163 template<typename GridPtrContainerT>
164 void write(const GridPtrContainerT&, const MetaMap& = MetaMap()) const;
165
168 class NameIterator
169 {
170 public:
171 NameIterator(const NameMapCIter& iter): mIter(iter) {}
172 ~NameIterator() {}
173
174 NameIterator& operator++() { mIter++; return *this; }
175
176 bool operator==(const NameIterator& iter) const { return mIter == iter.mIter; }
177 bool operator!=(const NameIterator& iter) const { return mIter != iter.mIter; }
178
179 Name operator*() const { return this->gridName(); }
180
181 Name gridName() const { return GridDescriptor::nameAsString(mIter->second.uniqueName()); }
182
183 private:
184 NameMapCIter mIter;
185 };
186
188 NameIterator beginName() const;
189
191 NameIterator endName() const;
192
193 private:
195 void readGridDescriptors(std::istream&);
196
199 NameMapCIter findDescriptor(const Name&) const;
200
202 GridBase::Ptr createGrid(const GridDescriptor&) const;
203
206 GridBase::Ptr readGridByName(const Name&, const BBoxd&);
207
209 GridBase::ConstPtr readGridPartial(const GridDescriptor&, bool readTopology) const;
210
212 GridBase::Ptr readGrid(const GridDescriptor&) const;
213 #ifndef OPENVDB_2_ABI_COMPATIBLE
214 GridBase::Ptr readGrid(const GridDescriptor&, const BBoxd&) const;
219 GridBase::Ptr readGrid(const GridDescriptor&, const CoordBBox&) const;
220 #endif
221
224 void readGridPartial(GridBase::Ptr, std::istream&, bool isInstance, bool readTopology) const;
225
229 GridBase::Ptr retrieveCachedGrid(const Name&) const;
230
231 void writeGrids(const GridCPtrVec&, const MetaMap&) const;
232
233 MetaMap::Ptr fileMetadata();
234 MetaMap::ConstPtr fileMetadata() const;
235
236 const NameMap& gridDescriptors() const;
237 NameMap& gridDescriptors();
238
239 std::istream& inputStream() const;
240
241 friend class ::TestFile;
242 friend class ::TestStream;
243
244 struct Impl;
245 boost::scoped_ptr<Impl> mImpl;
246 };
247
248
250
251
252 inline void
253 File::write(const GridCPtrVec& grids, const MetaMap& meta) const
254 {
255 this->writeGrids(grids, meta);
256 }
257
258
259 template<typename GridPtrContainerT>
260 inline void
261 File::write(const GridPtrContainerT& container, const MetaMap& meta) const
262 {
263 GridCPtrVec grids;
264 std::copy(container.begin(), container.end(), std::back_inserter(grids));
265 this->writeGrids(grids, meta);
266 }
267
268 } // namespace io
269 } // namespace OPENVDB_VERSION_NAME
270 } // namespace openvdb
271
272 #endif // OPENVDB_IO_FILE_HAS_BEEN_INCLUDED
273
274 // Copyright (c) 2012-2016 DreamWorks Animation LLC
275 // All rights reserved. This software is distributed under the
276 // 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
Archive.h
openvdb::v3_2_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
openvdb::v3_2_0::io::File::NameIterator::operator!=
bool operator!=(const NameIterator &iter) const
Definition: File.h:177
openvdb::v3_2_0::io::File::NameMap
std::multimap< Name, GridDescriptor > NameMap
Definition: File.h:57
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::File::NameIterator::~NameIterator
~NameIterator()
Definition: File.h:172
openvdb::v3_2_0::GridPtrVecPtr
boost::shared_ptr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:423
io.h
openvdb::v3_2_0::math::BBox< Vec3d >
openvdb::v3_2_0::io::File::NameIterator::operator++
NameIterator & operator++()
Definition: File.h:174
openvdb::v3_2_0::io::File::NameIterator::operator*
Name operator*() const
Definition: File.h:179
openvdb::v3_2_0::io::GridDescriptor
Definition: GridDescriptor.h:46
openvdb::v3_2_0::io::File
Grid archive associated with a file on disk.
Definition: File.h:54
openvdb::v3_2_0::io::File::NameIterator::operator==
bool operator==(const NameIterator &iter) const
Definition: File.h:176
openvdb::v3_2_0::Index64
uint64_t Index64
Definition: Types.h:57
GridDescriptor.h
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb
Definition: Exceptions.h:39
openvdb::v3_2_0::io::File::NameIterator::gridName
Name gridName() const
Definition: File.h:181
openvdb::v3_2_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
openvdb::v3_2_0::io::File::NameIterator
Definition: File.h:168
openvdb::v3_2_0::io::File::NameMapCIter
NameMap::const_iterator NameMapCIter
Definition: File.h:58
openvdb::v3_2_0::GridBase::Ptr
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
openvdb::v3_2_0::io::File::NameIterator::NameIterator
NameIterator(const NameMapCIter &iter)
Definition: File.h:171
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_2_0::io::MappedFile::Notifier
boost::function< void(std::string)> Notifier
Definition: io.h:153
openvdb::v3_2_0::createGrid
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1380
openvdb::v3_2_0::MetaMap::ConstPtr
boost::shared_ptr< const MetaMap > ConstPtr
Definition: MetaMap.h:50
openvdb::v3_2_0::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:59
openvdb::v3_2_0::MetaMap::Ptr
boost::shared_ptr< MetaMap > Ptr
Definition: MetaMap.h:49