Robowflex  v0.1
Making MoveIt Easy
hdf5.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_IO_HDF5_
4 #define ROBOWFLEX_IO_HDF5_
5 
6 #include <string>
7 #include <vector>
8 #include <map>
9 
10 #include <boost/variant.hpp>
11 
12 #include <H5Cpp.h>
13 
15 
16 namespace robowflex
17 {
18  namespace IO
19  {
20  /** \cond IGNORE */
21  ROBOWFLEX_CLASS_FORWARD(HDF5Data)
22  /** \endcond */
23 
24  /** \class robowflex::HDF5DataPtr
25  \brief A shared pointer wrapper for robowflex::IO::HDF5Data. */
26 
27  /** \class robowflex::HDF5DataConstPtr
28  \brief A const shared pointer wrapper for robowflex::IO::HDF5Data. */
29 
30  /** \brief A container class for HDF5 DataSets loaded by an HDF5File.
31  */
32  class HDF5Data
33  {
34  public:
35  /** \brief Constructor. Loads reads DataSet from file.
36  * \param[in] location Location to read data from.
37  * \param[in] name Name of object to read.
38  * \tparam H5 type to read.
39  */
40  template <typename T>
41  HDF5Data(const T &location, const std::string &name);
42 
43  /** \brief Destructor. Cleans up all read data.
44  */
45  ~HDF5Data();
46 
47  /** \brief Gets the dimensions of the data. Can be used to create the array necessary to store
48  * results.
49  * \return The dimensions of the data.
50  */
51  const std::vector<hsize_t> getDims() const;
52 
53  /** \brief Get a pointer to the underlying data array. It is of size type[dim0][dim1]...
54  * \return A pointer to the data array.
55  */
56  const void *getData() const;
57 
58  /** \brief Get a string describing the data.
59  * \return A string describing the data.
60  */
61  const std::string getStatus() const;
62 
63  /** \brief Get the value at an index.
64  * \param[in] index The indices at each dimension.
65  * \tparam The return type of the data.
66  * \return The value at the index in the data.
67  */
68  template <typename T>
69  const T &get(const std::vector<hsize_t> &index) const;
70 
71  private:
72  /** \brief Return information about the data type of the data.
73  * \return The H5 type, the size of, and the name of the data type.
74  */
76 
77  const H5::DataSet dataset_; ///< Dataset being read from.
78  const H5::DataSpace space_; ///< Size of the dataset.
79 
80  const H5T_class_t type_; ///< Type of the dataset.
81  const int rank_; ///< Rank of the dataset.
82  const hsize_t *dims_; ///< Dimensions of the dataset (rank_ dimensions)
83 
84  const void *data_; ///< Data itself.
85  };
86 
87  /** \brief An HDF5 File loaded into memory.
88  */
89  class HDF5File
90  {
91  public:
92  /** \brief A recursive map that has a dictionary-like structure to store HDF5 datasets.
93  */
94  typedef boost::make_recursive_variant<
96  /** \brief A specific map in the recursive set.
97  */
99 
100  /** \brief Constructor. Opens \a filename.
101  * \param[in] filename File to open.
102  */
103  HDF5File(const std::string &filename);
104 
105  /** \brief Get the dataset under the set of keys. Each key is applied successively.
106  * \param[in] keys The keys for the dataset to access.
107  * \return The loaded HDF5 dataset.
108  */
109  const HDF5DataPtr getData(const std::vector<std::string> &keys) const;
110 
111  /** \brief Gets all valid keys in the file.
112  * \return All keys in the file. Keys are vectors of strings.
113  */
115 
116  private:
117  /** \brief List the objects at the HDF5 location.
118  * \param[in] location The location to search
119  * \tparam T A HDF5 object.
120  */
121  template <typename T>
122  std::vector<std::string> listObjects(const T &location) const;
123 
124  /** \brief Loads the data in the object \a name at the HDF5 location. Recursive.
125  * \param[in] node The node to add data to.
126  * \param[in] location The location to search
127  * \param[in] name The name to search for.
128  * \tparam T A HDF5 object.
129  */
130  template <typename T>
131  void loadData(Node &node, const T &location, const std::string &name);
132 
133  const H5::H5File file_; ///< The loaded HDF5 file.
134  Node data_; ///< A recursive map of loaded data.
135  };
136  } // namespace IO
137 } // namespace robowflex
138 
139 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
A shared pointer wrapper for robowflex::IO::HDF5Data.
A container class for HDF5 DataSets loaded by an HDF5File.
Definition: hdf5.h:33
const hsize_t * dims_
Dimensions of the dataset (rank_ dimensions)
Definition: hdf5.h:82
const void * data_
Data itself.
Definition: hdf5.h:84
const H5::DataSet dataset_
Dataset being read from.
Definition: hdf5.h:77
const int rank_
Rank of the dataset.
Definition: hdf5.h:81
const H5T_class_t type_
Type of the dataset.
Definition: hdf5.h:80
const H5::DataSpace space_
Size of the dataset.
Definition: hdf5.h:78
An HDF5 File loaded into memory.
Definition: hdf5.h:90
boost::make_recursive_variant< HDF5DataPtr, std::map< std::string, boost::recursive_variant_ > >::type Node
A recursive map that has a dictionary-like structure to store HDF5 datasets.
Definition: hdf5.h:95
Node data_
A recursive map of loaded data.
Definition: hdf5.h:134
std::vector< std::string > listObjects(const T &location) const
List the objects at the HDF5 location.
Definition: hdf5.cpp:238
void loadData(Node &node, const T &location, const std::string &name)
Loads the data in the object name at the HDF5 location. Recursive.
Definition: hdf5.cpp:251
const std::vector< std::vector< std::string > > getKeys() const
Gets all valid keys in the file.
Definition: hdf5.cpp:226
const H5::H5File file_
The loaded HDF5 file.
Definition: hdf5.h:133
HDF5File(const std::string &filename)
Constructor. Opens filename.
Definition: hdf5.cpp:143
std::map< std::string, Node > NodeMap
A specific map in the recursive set.
Definition: hdf5.h:98
const HDF5DataPtr getData(const std::vector< std::string > &keys) const
Get the dataset under the set of keys. Each key is applied successively.
Definition: hdf5.cpp:220
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25