Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
HDF5Utils.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
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
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 
39 #ifndef HDF5UTILS_H_
40 #define HDF5UTILS_H_
41 
42 #include "CommonTypes.h"
43 
44 
45 namespace H5 {
46 class CommonFG;
47 class Group;
48 class H5File;
49 class H5Object;
50 class DataSet;
51 }
52 
53 namespace statismo {
54 
58 class HDF5Utils {
59  public:
60 
61 
62 
66  static H5::H5File openOrCreateFile(const std::string filename);
67 
68 
77  static H5::Group openPath(H5::H5File& fg, const std::string& path, bool createPath=false);
78 
85  static void readMatrix(const H5::CommonFG& fg, const char* name, MatrixType& matrix);
86 
94  static void readMatrix(const H5::CommonFG& fg, const char* name, unsigned nCols, MatrixType& matrix);
95 
102  template <class T>
103  static void readMatrixOfType(const H5::CommonFG& fg, const char* name, typename GenericEigenType<T>::MatrixType& matrix);
104 
111  static H5::DataSet writeMatrix(const H5::CommonFG& fg, const char* name, const MatrixType& matrix);
112 
119  template <class T>
120  static H5::DataSet writeMatrixOfType(const H5::CommonFG& fg, const char* name, const typename GenericEigenType<T>::MatrixType& matrix);
121 
122 
130  static void readVector(const H5::CommonFG& fg, const char* name, unsigned nElements, VectorType& vector);
131 
139  static void readVector(const H5::CommonFG& fg, const char* name, VectorType& vector);
140 
141  template <class T>
142  static void readVectorOfType(const H5::CommonFG& fg, const char* name, typename GenericEigenType<T>::VectorType& vector);
143 
150  static H5::DataSet writeVector(const H5::CommonFG& fg, const char* name, const VectorType& vector);
151 
152  template <class T>
153  static H5::DataSet writeVectorOfType(const H5::CommonFG& fg, const char* name, const typename GenericEigenType<T>::VectorType& vector);
154 
155 
162  static void dumpFileToHDF5( const char* filename, const H5::CommonFG& fg, const char* name);
163 
170  static void getFileFromHDF5(const H5::CommonFG& fg, const char* name, const char* filename);
171 
177  static H5::DataSet writeString(const H5::CommonFG& fg, const char* name, const std::string& s);
178 
184  static std::string readString(const H5::CommonFG& fg, const char* name);
185 
191  static void writeStringAttribute(const H5::H5Object& group, const char* name, const std::string& s);
192 
198  static void writeIntAttribute(const H5::H5Object& fg, const char* name, int value);
199 
200 
201 
207  static std::string readStringAttribute(const H5::H5Object& group, const char* name);
208 
214  static int readIntAttribute(const H5::H5Object& group, const char* name);
215 
216 
222  static int readInt(const H5::CommonFG& fg, const char* name);
223 
229  static H5::DataSet writeInt(const H5::CommonFG& fg, const char* name, int value);
230 
236  static float readFloat(const H5::CommonFG& fg, const char* name);
237 
243  static H5::DataSet writeFloat(const H5::CommonFG& fg, const char* name, float value);
244 
250  template<typename T>
251  static void readArray(const H5::CommonFG& fg, const char* name, std::vector<T> & array);
252 
258  template<typename T>
259  static H5::DataSet writeArray(const H5::CommonFG& fg, const char* name, std::vector<T> const& array );
260 
261 
264  static bool existsObjectWithName(const H5::CommonFG& fg, const std::string& name);
265 
266 };
267 
268 } // namespace statismo
269 
270 #include "HDF5Utils.hxx"
271 
272 #endif /* HDF5UTILS_H_ */
static bool existsObjectWithName(const H5::CommonFG &fg, const std::string &name)
Definition: HDF5Utils.hxx:542
static H5::DataSet writeArray(const H5::CommonFG &fg, const char *name, std::vector< T > const &array)
Definition: HDF5Utils.hxx:515
static void writeIntAttribute(const H5::H5Object &fg, const char *name, int value)
Definition: HDF5Utils.hxx:406
static H5::H5File openOrCreateFile(const std::string filename)
Definition: HDF5Utils.hxx:56
static void readMatrix(const H5::CommonFG &fg, const char *name, MatrixType &matrix)
Definition: HDF5Utils.hxx:154
static H5::DataSet writeMatrix(const H5::CommonFG &fg, const char *name, const MatrixType &matrix)
Definition: HDF5Utils.hxx:248
static void dumpFileToHDF5(const char *filename, const H5::CommonFG &fg, const char *name)
Definition: HDF5Utils.hxx:482
static std::string readString(const H5::CommonFG &fg, const char *name)
Definition: HDF5Utils.hxx:379
static std::string readStringAttribute(const H5::H5Object &group, const char *name)
Definition: HDF5Utils.hxx:397
static void readArray(const H5::CommonFG &fg, const char *name, std::vector< T > &array)
Definition: HDF5Utils.hxx:507
static void writeStringAttribute(const H5::H5Object &group, const char *name, const std::string &s)
Definition: HDF5Utils.hxx:387
static H5::DataSet writeString(const H5::CommonFG &fg, const char *name, const std::string &s)
Definition: HDF5Utils.hxx:369
static float readFloat(const H5::CommonFG &fg, const char *name)
Definition: HDF5Utils.hxx:452
static H5::DataSet writeInt(const H5::CommonFG &fg, const char *name, int value)
Definition: HDF5Utils.hxx:426
static H5::DataSet writeMatrixOfType(const H5::CommonFG &fg, const char *name, const typename GenericEigenType< T >::MatrixType &matrix)
Definition: HDF5Utils.hxx:197
static H5::Group openPath(H5::H5File &fg, const std::string &path, bool createPath=false)
Definition: HDF5Utils.hxx:76
static void readVector(const H5::CommonFG &fg, const char *name, unsigned nElements, VectorType &vector)
Definition: HDF5Utils.hxx:296
static H5::DataSet writeVector(const H5::CommonFG &fg, const char *name, const VectorType &vector)
Definition: HDF5Utils.hxx:363
static H5::DataSet writeFloat(const H5::CommonFG &fg, const char *name, float value)
Definition: HDF5Utils.hxx:444
static void getFileFromHDF5(const H5::CommonFG &fg, const char *name, const char *filename)
Definition: HDF5Utils.hxx:462
static void readMatrixOfType(const H5::CommonFG &fg, const char *name, typename GenericEigenType< T >::MatrixType &matrix)
Definition: HDF5Utils.hxx:112
static int readInt(const H5::CommonFG &fg, const char *name)
Definition: HDF5Utils.hxx:434
Utility methods to read and store common types to a HDF5 File.
Definition: HDF5Utils.h:58
static int readIntAttribute(const H5::H5Object &group, const char *name)
Definition: HDF5Utils.hxx:416