1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
4 // Sony Pictures Imageworks, Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 #include <Alembic/AbcCoreHDF5/HDF5HierarchyReader.h>
37 #include <Alembic/AbcCoreHDF5/HDF5Hierarchy.h>
38 #include <Alembic/AbcCoreHDF5/ReadUtil.h>
39
40 namespace Alembic {
41 namespace AbcCoreHDF5 {
42 namespace ALEMBIC_VERSION_NS {
43
44 //-*****************************************************************************
HDF5HierarchyReader(hid_t iFile,HDF5Hierarchy & iH5H,const bool iCacheHierarchy)45 HDF5HierarchyReader::HDF5HierarchyReader( hid_t iFile,
46 HDF5Hierarchy& iH5H,
47 const bool iCacheHierarchy )
48 : m_H5H( iH5H )
49 {
50 int enabled( 0 );
51 if (iCacheHierarchy && H5Aexists( iFile, "abc_ref_hierarchy" ))
52 {
53 size_t numRead = 0;
54 ReadSmallArray( iFile, "abc_ref_hierarchy", H5T_STD_I32LE,
55 H5T_NATIVE_INT32, 1, numRead, &enabled );
56 }
57
58 m_H5H.clear();
59 m_H5H.setEnabled( enabled != 0 );
60
61 if( enabled )
62 {
63 readHierarchy( iFile );
64 }
65
66 }
67
68 //-*****************************************************************************
readHierarchy(hid_t iFile)69 void HDF5HierarchyReader::readHierarchy( hid_t iFile )
70 {
71 std::vector<hobj_ref_t> objectRefs;
72
73 std::vector<uint32_t> childrenSizes;
74 std::vector<std::string> childrenNames;
75 std::vector<hobj_ref_t> childrenRefs;
76
77 std::vector<uint32_t> attrSizes;
78 std::vector<std::string> attrNames;
79 std::vector<char> hasMask;
80 std::vector<uint32_t> maskBits;
81 std::vector<char> hasMeta;
82 std::vector<std::string> metaStrs;
83
84 ReadReferences( iFile, "object_references", objectRefs );
85
86 size_t readValues = 0;
87
88 // Children
89 childrenSizes.resize( objectRefs.size() );
90 ReadSmallArray( iFile, "children_sizes", H5T_STD_U32LE, H5T_NATIVE_UINT32,
91 childrenSizes.size(), readValues, &childrenSizes.front() );
92
93 ReadReferences( iFile, "children_references", childrenRefs );
94
95 childrenNames.resize( childrenRefs.size() );
96 ReadStrings( iFile, "children_names",
97 childrenNames.size(), &childrenNames.front() );
98
99 // Attributes
100 attrSizes.resize( objectRefs.size() );
101 ReadSmallArray( iFile, "attr_sizes", H5T_STD_U32LE, H5T_NATIVE_UINT32,
102 attrSizes.size(), readValues, &attrSizes.front() );
103
104 size_t totalA(0);
105 for( size_t i=0; i < attrSizes.size(); ++i )
106 totalA += attrSizes[i];
107
108 attrNames.resize( totalA );
109 ReadStrings( iFile, "attr_names", totalA, &attrNames.front() );
110
111 // Masks
112 hasMask.resize( totalA );
113 ReadSmallArray( iFile, "mask_on", H5T_STD_I8LE, H5T_NATIVE_INT8,
114 hasMask.size(), readValues, &hasMask.front() );
115
116 size_t totalMask(0);
117 for( size_t i = 0; i < hasMask.size(); ++i )
118 totalMask += hasMask[i];
119
120 maskBits.resize( totalMask * 6 );
121 ReadSmallArray( iFile, "mask_bits", H5T_STD_U32LE, H5T_NATIVE_UINT32,
122 maskBits.size(), readValues, &maskBits.front() );
123
124 // MetaData
125 hasMeta.resize( totalA );
126 ReadSmallArray( iFile, "meta_on", H5T_STD_I8LE, H5T_NATIVE_INT8,
127 hasMeta.size(), readValues, &hasMeta.front() );
128 size_t totalMeta(0);
129 for( size_t i = 0; i < hasMeta.size(); ++i )
130 totalMeta += hasMeta[i];
131
132 metaStrs.resize( totalMeta );
133 ReadStrings( iFile, "meta_strs", totalMeta, &metaStrs.front() );
134
135 m_H5H.extractFromCompactObjectHierarchy( iFile, objectRefs,
136 childrenSizes, childrenNames,
137 childrenRefs,
138 attrSizes, attrNames,
139 hasMask, maskBits,
140 hasMeta, metaStrs );
141 }
142
143 } // End namespace ALEMBIC_VERSION_NS
144 } // End namespace AbcCoreHDF5
145 } // End namespace Alembic
146