HDF5IO.hpp
Go to the documentation of this file.
1 
28 #ifndef HDF5IO_HPP_
29 #define HDF5IO_HPP_
30 
31 #include "BaseIO.hpp"
32 #include "DataStruct.hpp"
33 
36 // #include "lvr2/types/Hyperspectral.hpp"
38 #include "lvr2/types/ScanTypes.hpp"
39 
40 #include <opencv2/core/core.hpp>
41 #include <opencv2/highgui/highgui.hpp>
42 
43 #include <H5Tpublic.h>
44 #include <hdf5_hl.h>
45 #include <highfive/H5DataSet.hpp>
46 #include <highfive/H5DataSpace.hpp>
47 #include <highfive/H5File.hpp>
48 
49 
50 #include <string>
51 
52 namespace lvr2
53 {
54 
55 class HDF5IO : public BaseIO, public AttributeMeshIOBase
56 {
57  public:
58 
59  static const std::string vertices_name;
60  static const std::string indices_name;
61  static const std::string meshes_group;
62 
67  virtual ModelPtr read(std::string filename);
68 
69  ModelPtr read(std::string filename, size_t scanNr);
70 
71  bool readPointCloud(ModelPtr model_ptr);
72 
73  bool readMesh(ModelPtr model_ptr);
74 
75 
81  virtual void save(std::string filename);
82 
83  virtual void save(ModelPtr model, std::string filename);
84 
85  bool saveMesh(ModelPtr model_ptr);
86 
87 
88 
93  HDF5IO() {}
94 
95  HDF5IO(std::string filename, int open_flags = HighFive::File::ReadWrite);
96 
106  HDF5IO(const std::string filename, const std::string part_name, int open_flags = HighFive::File::ReadOnly);
107 
108  virtual ~HDF5IO();
109 
110  bool open(std::string filename, int open_flag);
111 
112  Texture getImage(std::string groupName, std::string datasetName);
113 
114  ScanPtr getSingleRawScan(int nr, bool load_points = true);
115 
116  ScanImage getSingleRawCamData(int scan_id, int img_id, bool load_image_data = true);
117 
118  std::vector<ScanPtr> getRawScans(bool load_points = true);
119 
120  std::vector<std::vector<ScanImage> > getRawCamData(bool load_image_data = true);
121 
122  floatArr getFloatChannelFromRawScan(std::string name,
123  int nr, unsigned int& n, unsigned& w);
124 
125 
126 
127  void addImage(
128  std::string groupName, std::string name, cv::Mat& img);
129 
130  void addRawScan(int nr, ScanPtr scan);
131 
135  void addRawCamData( int scan_id, int img_id, ScanImage& cam_data );
136 
137  void addFloatChannelToRawScan(std::string name, int nr, size_t n, unsigned w, floatArr data);
138 
139  void addRawDataHeader(std::string description, Matrix4<BaseVector<float>> &referenceFrame);
140 
141 // void addHyperspectralCalibration(int position, const HyperspectralPanorama& hyperspectral);
142 
143  void setCompress(bool compress);
144  void setChunkSize(const size_t& size);
145  void setPreviewReductionFactor(const unsigned int factor);
146  void setUsePreviews(bool use);
147 
148  bool compress();
149 
155  bool deleteDataset(const char* name);
156 
157  size_t chunkSize();
158 
159  template<typename T>
160  boost::shared_array<T> getArray(
161  std::string groupName, std::string datasetName,
162  unsigned int& size);
163 
164  template<typename T>
165  boost::shared_array<T> getArray(
166  std::string groupName, std::string datasetName,
167  std::vector<size_t>& dim);
168 
169  template<typename T>
170  void addArray(
171  std::string groupName,
172  std::string datasetName,
173  unsigned int size,
174  boost::shared_array<T> data);
175 
176  template<typename T>
177  void addArray(
178  std::string groupName,
179  std::string datasetName,
180  std::vector<size_t>& dimensions,
181  boost::shared_array<T> data);
182 
183  template<typename T>
184  void addArray(
185  std::string groupName,
186  std::string datasetName,
187  std::vector<size_t>& dimensions,
188  std::vector<hsize_t>& chunkSize,
189  boost::shared_array<T> data);
190 
191  private:
192 
198 
204 
209  virtual bool addVertices(const FloatChannel& channel_ptr);
210 
215  virtual bool addIndices(const IndexChannel& channel_ptr);
216 
217  template <typename T>
218  bool getChannel(const std::string group, const std::string name, boost::optional<AttributeChannel<T>>& channel);
219 
227  virtual bool getChannel(const std::string group, const std::string name, FloatChannelOptional& channel);
228 
236  virtual bool getChannel(const std::string group, const std::string name, IndexChannelOptional& channel);
237 
245  virtual bool getChannel(const std::string group, const std::string name, UCharChannelOptional& channel);
246 
247  template <typename T>
248  bool addChannel(const std::string group, const std::string name, const AttributeChannel<T>& channel);
249 
257  virtual bool addChannel(const std::string group, const std::string name, const FloatChannel& channel);
258 
266  virtual bool addChannel(const std::string group, const std::string name, const IndexChannel& channel);
267 
275  virtual bool addChannel(const std::string group, const std::string name, const UCharChannel& channel);
276 
277  boost::optional<HighFive::Group> getMeshGroup(bool create = false);
278 
279  template<typename T>
280  boost::shared_array<T> getArray(HighFive::Group& g, std::string datasetName, std::vector<size_t>& dim);
281 
282  Texture getImage(HighFive::Group& g, std::string datasetName);
283 
284  template<typename T>
285  void addArray(HighFive::Group& g,
286  std::string datasetName,
287  std::vector<size_t>& dim,
288  std::vector<hsize_t>& chunkSize,
289  boost::shared_array<T>& data);
290 
291  void addImage(HighFive::Group& g, std::string datasetName, cv::Mat& img);
292 
293  void getImage(HighFive::Group& g, std::string datasetName, cv::Mat& img);
294 
295 
296 
297  std::vector<std::string> splitGroupNames(const std::string &groupName);
298 
299  bool exist(const std::string &groupName);
300 
301  void write_base_structure();
302 
303  bool isGroup(HighFive::Group grp, std::string objName);
304 
305 
306  HighFive::Group getGroup(const std::string& groupName, bool create = true);
307 
308  HighFive::Group getGroup(HighFive::Group& g, const std::string& groupName, bool create = true);
309 
310  template <typename T>
311  boost::shared_array<T> reduceData(boost::shared_array<T> data,
312  size_t dataCount,
313  size_t dataWidth,
314  unsigned int reductionFactor,
315  size_t *reducedDataCount);
316 
318 
320  size_t m_chunkSize;
323  std::string m_part_name;
324  std::string m_mesh_path;
325 };
326 
327 } // namespace lvr2
328 
329 #include "HDF5IO.tcc"
330 
331 #endif /* !HDF5IO_HPP_ */
void setCompress(bool compress)
Definition: HDF5IO.cpp:78
bool readPointCloud(ModelPtr model_ptr)
Definition: HDF5IO.cpp:146
bool deleteDataset(const char *name)
deletes a dataset permanently from the hdf file
Definition: HDF5IO.cpp:110
void addRawCamData(int scan_id, int img_id, ScanImage &cam_data)
add recorded image referenced to a scan pose
Definition: HDF5IO.cpp:927
Datastructures for holding loaded data.
void addArray(std::string groupName, std::string datasetName, unsigned int size, boost::shared_array< T > data)
virtual void save(std::string filename)
Save the loaded elements to the given file.
Definition: HDF5IO.cpp:282
bool readMesh(ModelPtr model_ptr)
Definition: HDF5IO.cpp:191
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
void setPreviewReductionFactor(const unsigned int factor)
Definition: HDF5IO.cpp:88
virtual ModelPtr read(std::string filename)
Parse the given file and load supported elements.
Definition: HDF5IO.cpp:121
std::string m_mesh_path
Definition: HDF5IO.hpp:324
static const std::string indices_name
Definition: HDF5IO.hpp:60
HighFive::File * m_hdf5_file
Definition: HDF5IO.hpp:317
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
Texture getImage(std::string groupName, std::string datasetName)
Definition: HDF5IO.cpp:360
void addRawDataHeader(std::string description, Matrix4< BaseVector< float >> &referenceFrame)
Definition: HDF5IO.cpp:979
unsigned int m_previewReductionFactor
Definition: HDF5IO.hpp:322
virtual bool addVertices(const FloatChannel &channel_ptr)
Persistence layer interface, Writes the vertices of the mesh to the persistence layer.
Definition: HDF5IO.cpp:1187
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98
std::vector< ScanPtr > getRawScans(bool load_points=true)
Definition: HDF5IO.cpp:414
void setUsePreviews(bool use)
Definition: HDF5IO.cpp:100
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
void addImage(std::string groupName, std::string name, cv::Mat &img)
Definition: HDF5IO.cpp:674
size_t m_chunkSize
Definition: HDF5IO.hpp:320
static const int ReadOnly
Open flag: Read only access.
Definition: H5File.hpp:30
File class.
Definition: H5File.hpp:25
std::vector< std::vector< ScanImage > > getRawCamData(bool load_image_data=true)
Definition: HDF5IO.cpp:466
bool isGroup(HighFive::Group grp, std::string objName)
Definition: HDF5IO.cpp:1129
virtual bool addIndices(const IndexChannel &channel_ptr)
Persistence layer interface, Writes the face indices of the mesh to the persistence layer...
Definition: HDF5IO.cpp:1194
boost::shared_array< T > reduceData(boost::shared_array< T > data, size_t dataCount, size_t dataWidth, unsigned int reductionFactor, size_t *reducedDataCount)
BaseHDF5IO::AddFeatures< lvr2::hdf5features::ScanProjectIO, lvr2::hdf5features::ArrayIO > HDF5IO
bool m_usePreviews
Definition: HDF5IO.hpp:321
virtual FloatChannelOptional getVertices()
Persistence layer interface, Accesses the vertices of the mesh in the persistence layer...
Definition: HDF5IO.cpp:1156
boost::shared_array< T > getArray(std::string groupName, std::string datasetName, unsigned int &size)
This class represents a texture.
Definition: Texture.hpp:54
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
bool saveMesh(ModelPtr model_ptr)
Definition: HDF5IO.cpp:299
std::vector< std::string > splitGroupNames(const std::string &groupName)
Definition: HDF5IO.cpp:984
floatArr getFloatChannelFromRawScan(std::string name, int nr, unsigned int &n, unsigned &w)
Definition: HDF5IO.cpp:644
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
void addFloatChannelToRawScan(std::string name, int nr, size_t n, unsigned w, floatArr data)
Definition: HDF5IO.cpp:720
bool compress()
Definition: HDF5IO.cpp:105
Base interface for all I/O related classes.
static const std::string vertices_name
Definition: HDF5IO.hpp:59
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
std::string m_part_name
Definition: HDF5IO.hpp:323
bool exist(const std::string &groupName)
Definition: HDF5IO.cpp:1092
static const std::string meshes_group
Definition: HDF5IO.hpp:61
virtual ~HDF5IO()
Definition: HDF5IO.cpp:70
virtual IndexChannelOptional getIndices()
Persistence layer interface, Accesses the face indices of the mesh in the persistence layer...
Definition: HDF5IO.cpp:1172
bool getChannel(const std::string group, const std::string name, boost::optional< AttributeChannel< T >> &channel)
size_t chunkSize()
Definition: HDF5IO.cpp:116
void write_base_structure()
Definition: HDF5IO.cpp:260
bool open(std::string filename, int open_flag)
Definition: HDF5IO.cpp:232
HighFive::Group getGroup(const std::string &groupName, bool create=true)
Definition: HDF5IO.cpp:1012
bool addChannel(const std::string group, const std::string name, const AttributeChannel< T > &channel)
HDF5IO()
Construct a new HDF5IO object. Do not use this. Only used by ModelFactory.
Definition: HDF5IO.hpp:93
ScanPtr getSingleRawScan(int nr, bool load_points=true)
Definition: HDF5IO.cpp:507
void addRawScan(int nr, ScanPtr scan)
Definition: HDF5IO.cpp:799
ScanImage getSingleRawCamData(int scan_id, int img_id, bool load_image_data=true)
Definition: HDF5IO.cpp:591
bool m_compress
Definition: HDF5IO.hpp:319
boost::optional< HighFive::Group > getMeshGroup(bool create=false)
Definition: HDF5IO.cpp:1146
void setChunkSize(const size_t &size)
Definition: HDF5IO.cpp:83


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06