OpenVDB  2.3.0
GridDescriptor.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_GRIDDESCRIPTOR_HAS_BEEN_INCLUDED
32 #define OPENVDB_IO_GRIDDESCRIPTOR_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Grid.h>
35 #include <iostream>
36 #include <boost/cstdint.hpp>
37 
38 namespace openvdb {
40 namespace OPENVDB_VERSION_NAME {
41 namespace io {
42 
47 {
48 public:
50  GridDescriptor(const Name& name, const Name& gridType, bool saveFloatAsHalf = false);
51 
52  ~GridDescriptor();
53 
54  const Name& gridType() const { return mGridType; }
55  const Name& gridName() const { return mGridName; }
56  const Name& uniqueName() const { return mUniqueName; }
57 
58  const Name& instanceParentName() const { return mInstanceParentName; }
59  void setInstanceParentName(const Name& name) { mInstanceParentName = name; }
60  bool isInstance() const { return !mInstanceParentName.empty(); }
61 
62  bool saveFloatAsHalf() const { return mSaveFloatAsHalf; }
63 
64  void setGridPos(boost::int64_t pos) { mGridPos = pos; }
65  boost::int64_t getGridPos() const { return mGridPos; }
66 
67  void setBlockPos(boost::int64_t pos) { mBlockPos = pos; }
68  boost::int64_t getBlockPos() const { return mBlockPos; }
69 
70  void setEndPos(boost::int64_t pos) { mEndPos = pos; }
71  boost::int64_t getEndPos() const { return mEndPos; }
72 
73  // These methods seek to the right position in the given stream.
74  void seekToGrid(std::istream&) const;
75  void seekToBlocks(std::istream&) const;
76  void seekToEnd(std::istream&) const;
77 
78  void seekToGrid(std::ostream&) const;
79  void seekToBlocks(std::ostream&) const;
80  void seekToEnd(std::ostream&) const;
81 
84  void writeHeader(std::ostream&) const;
85 
88  void writeStreamPos(std::ostream&) const;
89 
92  GridBase::Ptr read(std::istream&);
93 
96  static Name addSuffix(const Name&, int n);
99  static Name stripSuffix(const Name&);
102  static std::string nameAsString(const Name&);
106  static Name stringAsUniqueName(const std::string&);
107 
108 private:
110  Name mGridName;
112  Name mUniqueName;
114  Name mInstanceParentName;
116  Name mGridType;
118  bool mSaveFloatAsHalf;
120  boost::int64_t mGridPos;
122  boost::int64_t mBlockPos;
124  boost::int64_t mEndPos;
125 };
126 
127 } // namespace io
128 } // namespace OPENVDB_VERSION_NAME
129 } // namespace openvdb
130 
131 #endif // OPENVDB_IO_GRIDDESCRIPTOR_HAS_BEEN_INCLUDED
132 
133 // Copyright (c) 2012-2013 DreamWorks Animation LLC
134 // All rights reserved. This software is distributed under the
135 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
const Name & gridName() const
Definition: GridDescriptor.h:55
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:187
boost::int64_t getBlockPos() const
Definition: GridDescriptor.h:68
void setGridPos(boost::int64_t pos)
Definition: GridDescriptor.h:64
void setBlockPos(boost::int64_t pos)
Definition: GridDescriptor.h:67
Definition: GridDescriptor.h:46
const Name & uniqueName() const
Definition: GridDescriptor.h:56
boost::shared_ptr< GridBase > Ptr
Definition: Grid.h:106
void setInstanceParentName(const Name &name)
Definition: GridDescriptor.h:59
const Name & gridType() const
Definition: GridDescriptor.h:54
void setEndPos(boost::int64_t pos)
Definition: GridDescriptor.h:70
#define OPENVDB_VERSION_NAME
Definition: version.h:45
const Name & instanceParentName() const
Definition: GridDescriptor.h:58
boost::int64_t getEndPos() const
Definition: GridDescriptor.h:71
boost::int64_t getGridPos() const
Definition: GridDescriptor.h:65
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
std::string Name
Definition: Name.h:44
bool isInstance() const
Definition: GridDescriptor.h:60
bool saveFloatAsHalf() const
Definition: GridDescriptor.h:62