HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GridDescriptor.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
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 //
29 ///////////////////////////////////////////////////////////////////////////
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 
43 /// This structure stores useful information that describes a grid on disk.
44 /// It can be used to retrieve I/O information about the grid such as
45 /// offsets into the file where the grid is located, its type, etc.
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 
83  /// @brief Write out this descriptor's header information (all data except for
84  /// stream offsets).
85  void writeHeader(std::ostream&) const;
86 
87  /// @brief Since positions into the stream are known at a later time, they are
88  /// written out separately.
89  void writeStreamPos(std::ostream&) const;
90 
91  /// @brief Read a grid descriptor from the given stream.
92  /// @return an empty grid of the type specified by the grid descriptor.
93  GridBase::Ptr read(std::istream&);
94 
95  /// @brief Append the number @a n to the given name (separated by an ASCII
96  /// "record separator" character) and return the resulting name.
97  static Name addSuffix(const Name&, int n);
98  /// @brief Strip from the given name any suffix that is separated by an ASCII
99  /// "record separator" character and return the resulting name.
100  static Name stripSuffix(const Name&);
101  /// @brief Given a name with suffix N, return "name[N]", otherwise just return "name".
102  /// Use this to produce a human-readable string from a descriptor's unique name.
103  static std::string nameAsString(const Name&);
104  /// @brief Given a string of the form "name[N]", return "name" with the suffix N
105  /// separated by an ASCII "record separator" character). Otherwise just return
106  /// the string as is.
107  static Name stringAsUniqueName(const std::string&);
108 
109 private:
110  /// Name of the grid
111  Name mGridName;
112  /// Unique name for this descriptor
113  Name mUniqueName;
114  /// If nonempty, the name of another grid that shares this grid's tree
115  Name mInstanceParentName;
116  /// The type of the grid
117  Name mGridType;
118  /// Are floats quantized to 16 bits on disk?
119  bool mSaveFloatAsHalf;
120  /// Location in the stream where the grid data is stored
121  int64_t mGridPos;
122  /// Location in the stream where the grid blocks are stored
123  int64_t mBlockPos;
124  /// Location in the stream where the next grid descriptor begins
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/ )
Definition: ImfName.h:53
SharedPtr< GridBase > Ptr
Definition: Grid.h:107
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:189
void read(T &in, bool &v)
Definition: ImfXdr.h:611
GLdouble n
Definition: glcorearb.h:2007
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
GLuint const GLchar * name
Definition: glcorearb.h:785
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:135