OpenVDB  6.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 {
40 namespace OPENVDB_VERSION_NAME {
41 namespace io {
42 
47 {
48 public:
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/ )
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:288
int64_t getEndPos() const
Definition: GridDescriptor.h:72
const Name & gridName() const
Definition: GridDescriptor.h:56
void setInstanceParentName(const Name &name)
Definition: GridDescriptor.h:60
void setGridPos(int64_t pos)
Definition: GridDescriptor.h:65
const Name & gridType() const
Definition: GridDescriptor.h:55
Definition: GridDescriptor.h:46
std::string Name
Definition: Name.h:44
void setBlockPos(int64_t pos)
Definition: GridDescriptor.h:68
void setEndPos(int64_t pos)
Definition: GridDescriptor.h:71
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
bool saveFloatAsHalf() const
Definition: GridDescriptor.h:63
Definition: Exceptions.h:40
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
int64_t getGridPos() const
Definition: GridDescriptor.h:66
int64_t getBlockPos() const
Definition: GridDescriptor.h:69
const Name & instanceParentName() const
Definition: GridDescriptor.h:59
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
const Name & uniqueName() const
Definition: GridDescriptor.h:57
bool isInstance() const
Definition: GridDescriptor.h:61