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_ */
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
BaseVector.hpp
lvr2::HDF5IO::getRawScans
std::vector< ScanPtr > getRawScans(bool load_points=true)
Definition: HDF5IO.cpp:414
lvr2::HDF5IO::addVertices
virtual bool addVertices(const FloatChannel &channel_ptr)
Persistence layer interface, Writes the vertices of the mesh to the persistence layer.
Definition: HDF5IO.cpp:1187
lvr2::IndexChannelOptional
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
HighFive::File::ReadOnly
static const int ReadOnly
Open flag: Read only access.
Definition: H5File.hpp:30
lvr2::HDF5IO::reduceData
boost::shared_array< T > reduceData(boost::shared_array< T > data, size_t dataCount, size_t dataWidth, unsigned int reductionFactor, size_t *reducedDataCount)
lvr2::UCharChannelOptional
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
lvr2::HDF5IO::addRawDataHeader
void addRawDataHeader(std::string description, Matrix4< BaseVector< float >> &referenceFrame)
Definition: HDF5IO.cpp:979
lvr2::HDF5IO::readPointCloud
bool readPointCloud(ModelPtr model_ptr)
Definition: HDF5IO.cpp:146
lvr2::Matrix4
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
lvr2::HDF5IO::write_base_structure
void write_base_structure()
Definition: HDF5IO.cpp:260
lvr2::BaseVector< float >
lvr2::HDF5IO::saveMesh
bool saveMesh(ModelPtr model_ptr)
Definition: HDF5IO.cpp:299
lvr2::HDF5IO::m_usePreviews
bool m_usePreviews
Definition: HDF5IO.hpp:321
lvr2::HDF5IO::m_part_name
std::string m_part_name
Definition: HDF5IO.hpp:323
HDF5IO
BaseHDF5IO::AddFeatures< lvr2::hdf5features::ScanProjectIO, lvr2::hdf5features::ArrayIO > HDF5IO
Definition: src/tools/lvr2_hdf5_builder_2/Main.cpp:18
lvr2::HDF5IO::addArray
void addArray(std::string groupName, std::string datasetName, unsigned int size, boost::shared_array< T > data)
lvr2::HDF5IO::meshes_group
static const std::string meshes_group
Definition: HDF5IO.hpp:61
lvr2::HDF5IO::m_previewReductionFactor
unsigned int m_previewReductionFactor
Definition: HDF5IO.hpp:322
lvr2::HDF5IO::deleteDataset
bool deleteDataset(const char *name)
deletes a dataset permanently from the hdf file
Definition: HDF5IO.cpp:110
H5File.hpp
lvr2::HDF5IO::isGroup
bool isGroup(HighFive::Group grp, std::string objName)
Definition: HDF5IO.cpp:1129
lvr2::HDF5IO::addIndices
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
lvr2::HDF5IO::compress
bool compress()
Definition: HDF5IO.cpp:105
lvr2::HDF5IO::splitGroupNames
std::vector< std::string > splitGroupNames(const std::string &groupName)
Definition: HDF5IO.cpp:984
lvr2::HDF5IO::m_hdf5_file
HighFive::File * m_hdf5_file
Definition: HDF5IO.hpp:317
lvr2::HDF5IO::exist
bool exist(const std::string &groupName)
Definition: HDF5IO.cpp:1092
lvr2::FloatChannelOptional
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
H5DataSet.hpp
H5DataSpace.hpp
ScanTypes.hpp
lvr2::HDF5IO::addRawCamData
void addRawCamData(int scan_id, int img_id, ScanImage &cam_data)
add recorded image referenced to a scan pose
Definition: HDF5IO.cpp:927
lvr2::HDF5IO::getFloatChannelFromRawScan
floatArr getFloatChannelFromRawScan(std::string name, int nr, unsigned int &n, unsigned &w)
Definition: HDF5IO.cpp:644
lvr2::HDF5IO::readMesh
bool readMesh(ModelPtr model_ptr)
Definition: HDF5IO.cpp:191
lvr2::HDF5IO::getMeshGroup
boost::optional< HighFive::Group > getMeshGroup(bool create=false)
Definition: HDF5IO.cpp:1146
lvr2::HDF5IO::setPreviewReductionFactor
void setPreviewReductionFactor(const unsigned int factor)
Definition: HDF5IO.cpp:88
lvr2::HDF5IO::addFloatChannelToRawScan
void addFloatChannelToRawScan(std::string name, int nr, size_t n, unsigned w, floatArr data)
Definition: HDF5IO.cpp:720
lvr2::HDF5IO::open
bool open(std::string filename, int open_flag)
Definition: HDF5IO.cpp:232
lvr2::HDF5IO::~HDF5IO
virtual ~HDF5IO()
Definition: HDF5IO.cpp:70
lvr2::HDF5IO::getChannel
bool getChannel(const std::string group, const std::string name, boost::optional< AttributeChannel< T >> &channel)
HighFive::Group
Definition: H5Group.hpp:20
lvr2::HDF5IO::getSingleRawCamData
ScanImage getSingleRawCamData(int scan_id, int img_id, bool load_image_data=true)
Definition: HDF5IO.cpp:591
scripts.normalize_multiple.filename
filename
Definition: normalize_multiple.py:60
lvr2::HDF5IO::getSingleRawScan
ScanPtr getSingleRawScan(int nr, bool load_points=true)
Definition: HDF5IO.cpp:507
DataStruct.hpp
Datastructures for holding loaded data.
MatrixTypes.hpp
lvr2::HDF5IO::getGroup
HighFive::Group getGroup(const std::string &groupName, bool create=true)
Definition: HDF5IO.cpp:1012
lvr2::ScanImage
Definition: ScanTypes.hpp:107
lvr2::HDF5IO::setChunkSize
void setChunkSize(const size_t &size)
Definition: HDF5IO.cpp:83
lvr2::HDF5IO::m_chunkSize
size_t m_chunkSize
Definition: HDF5IO.hpp:320
HighFive::File
File class.
Definition: H5File.hpp:25
lvr2::HDF5IO::m_mesh_path
std::string m_mesh_path
Definition: HDF5IO.hpp:324
lvr2::HDF5IO::getRawCamData
std::vector< std::vector< ScanImage > > getRawCamData(bool load_image_data=true)
Definition: HDF5IO.cpp:466
lvr2::HDF5IO::addRawScan
void addRawScan(int nr, ScanPtr scan)
Definition: HDF5IO.cpp:799
lvr2::HDF5IO::addChannel
bool addChannel(const std::string group, const std::string name, const AttributeChannel< T > &channel)
lvr2::Channel< float >
lvr2::HDF5IO::setCompress
void setCompress(bool compress)
Definition: HDF5IO.cpp:78
lvr2::HDF5IO::getArray
boost::shared_array< T > getArray(std::string groupName, std::string datasetName, unsigned int &size)
lvr2::HDF5IO::read
virtual ModelPtr read(std::string filename)
Parse the given file and load supported elements.
Definition: HDF5IO.cpp:121
BaseIO.hpp
Base interface for all I/O related classes.
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
AttributeMeshIOBase.hpp
lvr2::Texture
This class represents a texture.
Definition: Texture.hpp:54
lvr2::HDF5IO::HDF5IO
HDF5IO()
Construct a new HDF5IO object. Do not use this. Only used by ModelFactory.
Definition: HDF5IO.hpp:93
lvr2::HDF5IO::setUsePreviews
void setUsePreviews(bool use)
Definition: HDF5IO.cpp:100
lvr2::HDF5IO::addImage
void addImage(std::string groupName, std::string name, cv::Mat &img)
Definition: HDF5IO.cpp:674
HighFive::File::ReadWrite
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
lvr2::HDF5IO::indices_name
static const std::string indices_name
Definition: HDF5IO.hpp:60
lvr2::HDF5IO::getIndices
virtual IndexChannelOptional getIndices()
Persistence layer interface, Accesses the face indices of the mesh in the persistence layer.
Definition: HDF5IO.cpp:1172
lvr2::HDF5IO::chunkSize
size_t chunkSize()
Definition: HDF5IO.cpp:116
lvr2::HDF5IO::getImage
Texture getImage(std::string groupName, std::string datasetName)
Definition: HDF5IO.cpp:360
lvr2::HDF5IO::save
virtual void save(std::string filename)
Save the loaded elements to the given file.
Definition: HDF5IO.cpp:282
lvr2::HDF5IO::getVertices
virtual FloatChannelOptional getVertices()
Persistence layer interface, Accesses the vertices of the mesh in the persistence layer.
Definition: HDF5IO.cpp:1156
lvr2::HDF5IO::m_compress
bool m_compress
Definition: HDF5IO.hpp:319
lvr2::HDF5IO::vertices_name
static const std::string vertices_name
Definition: HDF5IO.hpp:59
lvr2::ScanPtr
std::shared_ptr< Scan > ScanPtr
Shared pointer to scans.
Definition: ScanTypes.hpp:98


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 Wed Mar 2 2022 00:37:23