OpenVDB 5.1.0

GridDescriptor.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 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 <string>
37
38 namespace openvdb {
39 OPENVDB_USE_VERSION_NAMESPACE
40 namespace OPENVDB_VERSION_NAME {
41 namespace io {
42
46 class OPENVDB_API GridDescriptor
47 {
48 public:
49 GridDescriptor();
50 GridDescriptor(const Name& name, const Name& gridType, bool saveFloatAsHalf = false);
51 GridDescriptor(const GridDescriptor&) = default;
52 GridDescriptor& operator=(const GridDescriptor&) = default;
53 ~GridDescriptor();
54
55 const Name& gridType() const { return mGridType; }
56 const Name& gridName() const { return mGridName; }
57 const Name& uniqueName() const { return mUniqueName; }
58
59 const Name& instanceParentName() const { return mInstanceParentName; }
60 void setInstanceParentName(const Name& name) { mInstanceParentName = name; }
61 bool isInstance() const { return !mInstanceParentName.empty(); }
62
63 bool saveFloatAsHalf() const { return mSaveFloatAsHalf; }
64
65 void setGridPos(int64_t pos) { mGridPos = pos; }
66 int64_t getGridPos() const { return mGridPos; }
67
68 void setBlockPos(int64_t pos) { mBlockPos = pos; }
69 int64_t getBlockPos() const { return mBlockPos; }
70
71 void setEndPos(int64_t pos) { mEndPos = pos; }
72 int64_t getEndPos() const { return mEndPos; }
73
74 // These methods seek to the right position in the given stream.
75 void seekToGrid(std::istream&) const;
76 void seekToBlocks(std::istream&) const;
77 void seekToEnd(std::istream&) const;
78
79 void seekToGrid(std::ostream&) const;
80 void seekToBlocks(std::ostream&) const;
81 void seekToEnd(std::ostream&) const;
82
85 void writeHeader(std::ostream&) const;
86
89 void writeStreamPos(std::ostream&) const;
90
93 GridBase::Ptr read(std::istream&);
94
97 static Name addSuffix(const Name&, int n);
100 static Name stripSuffix(const Name&);
103 static std::string nameAsString(const Name&);
107 static Name stringAsUniqueName(const std::string&);
108
109 private:
111 Name mGridName;
113 Name mUniqueName;
115 Name mInstanceParentName;
117 Name mGridType;
119 bool mSaveFloatAsHalf;
121 int64_t mGridPos;
123 int64_t mBlockPos;
125 int64_t mEndPos;
126 };
127
128 } // namespace io
129 } // namespace OPENVDB_VERSION_NAME
130 } // namespace openvdb
131
132 #endif // OPENVDB_IO_GRIDDESCRIPTOR_HAS_BEEN_INCLUDED
133
134 // Copyright (c) 2012-2018 DreamWorks Animation LLC
135 // All rights reserved. This software is distributed under the
136 // 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:194
openvdb::v5_1::Name
std::string Name
Definition: Name.h:44
openvdb::v5_1::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
openvdb::v5_1::io::GridDescriptor::gridType
const Name & gridType() const
Definition: GridDescriptor.h:55
openvdb::v5_1::io::GridDescriptor::saveFloatAsHalf
bool saveFloatAsHalf() const
Definition: GridDescriptor.h:63
openvdb::v5_1::io::GridDescriptor::gridName
const Name & gridName() const
Definition: GridDescriptor.h:56
openvdb::v5_1::io::GridDescriptor::setEndPos
void setEndPos(int64_t pos)
Definition: GridDescriptor.h:71
openvdb::v5_1::io::GridDescriptor::getBlockPos
int64_t getBlockPos() const
Definition: GridDescriptor.h:69
openvdb::v5_1::io::GridDescriptor
Definition: GridDescriptor.h:46
openvdb::v5_1::io::GridDescriptor::uniqueName
const Name & uniqueName() const
Definition: GridDescriptor.h:57
openvdb::v5_1::io::GridDescriptor::setInstanceParentName
void setInstanceParentName(const Name &name)
Definition: GridDescriptor.h:60
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_1::io::GridDescriptor::isInstance
bool isInstance() const
Definition: GridDescriptor.h:61
openvdb::v5_1::io::GridDescriptor::getEndPos
int64_t getEndPos() const
Definition: GridDescriptor.h:72
openvdb
Definition: Exceptions.h:40
openvdb::v5_1::io::GridDescriptor::setGridPos
void setGridPos(int64_t pos)
Definition: GridDescriptor.h:65
openvdb::v5_1::io::GridDescriptor::instanceParentName
const Name & instanceParentName() const
Definition: GridDescriptor.h:59
Grid.h
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v5_1::io::GridDescriptor::setBlockPos
void setBlockPos(int64_t pos)
Definition: GridDescriptor.h:68
openvdb::v5_1::io::GridDescriptor::getGridPos
int64_t getGridPos() const
Definition: GridDescriptor.h:66