16 const std::string &group,
17 const std::string &container,
24 const std::string &group,
25 const std::string &container,
30 for(
auto elem : *buffer)
32 this->
template save(g, elem.first, elem.second);
38 const std::string &groupName,
39 const std::string &datasetName,
40 const cv::Mat &img)
const 48 const char* interlace =
"INTERLACE_PIXEL";
52 if(img.type() == CV_8U)
54 if(group.
exist(datasetName))
56 H5Ldelete(group.
getId(), datasetName.data(), H5P_DEFAULT);
58 H5IMmake_image_8bit(group.
getId(), datasetName.c_str(), w, h, img.data);
60 else if(img.type() == CV_8UC3)
62 if(group.
exist(datasetName))
64 H5Ldelete(group.
getId(), datasetName.data(), H5P_DEFAULT);
67 H5IMmake_image_24bit(group.
getId(), datasetName.c_str(), w, h, interlace, img.data);
76 std::vector<size_t> dims = {
static_cast<size_t>(img.rows), static_cast<size_t>(img.cols)};
77 std::vector<hsize_t> chunkSizes = {
static_cast<hsize_t
>(img.rows), static_cast<hsize_t>(img.cols)};
79 if(img.channels() > 1)
81 dims.push_back(img.channels());
82 chunkSizes.push_back(img.channels());
105 const int SCTYPE = img.type() % 8;
110 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<unsigned char>(
111 group, datasetName, dataSpace, properties
113 const unsigned char* ptr =
reinterpret_cast<unsigned char*
>(img.data);
116 else if(SCTYPE == CV_8S)
118 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<char>(
119 group, datasetName, dataSpace, properties
121 const char* ptr =
reinterpret_cast<char*
>(img.data);
124 else if(SCTYPE == CV_16U)
126 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<unsigned short>(
127 group, datasetName, dataSpace, properties
129 const unsigned short* ptr =
reinterpret_cast<unsigned short*
>(img.data);
132 else if(SCTYPE == CV_16S)
134 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<short>(
135 group, datasetName, dataSpace, properties
137 const short* ptr =
reinterpret_cast<short*
>(img.data);
140 else if(SCTYPE == CV_32S)
142 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<int>(
143 group, datasetName, dataSpace, properties
145 const int* ptr =
reinterpret_cast<int*
>(img.data);
148 else if(SCTYPE == CV_32F)
150 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<float>(
151 group, datasetName, dataSpace, properties
153 const float* ptr =
reinterpret_cast<float*
>(img.data);
156 else if(SCTYPE == CV_64F)
158 std::unique_ptr<HighFive::DataSet> dataset = hdf5util::createDataset<double>(
159 group, datasetName, dataSpace, properties
161 const double* ptr =
reinterpret_cast<double*
>(img.data);
166 std::cout <<
timestamp <<
"HDF5Kernel:SaveImage: Warning: unknown opencv type " << img.type() << std::endl;
174 throw std::runtime_error(
"[Hdf5IO - ChannelIO]: Hdf5 file not open.");
179 const std::string &group,
180 const std::string &metaName,
181 const YAML::Node &node)
const 183 cout <<
"SaveMetaYAML: " << group <<
" / " << metaName << std::endl;
186 if(hg.
isValid() && node[
"sensor_type"] )
188 std::string sensor_type = node[
"sensor_type"].as<std::string>();
189 if(sensor_type ==
"ScanPosition")
194 else if(sensor_type ==
"Scan")
198 else if(sensor_type ==
"ScanCamera")
202 else if(sensor_type ==
"ScanProject")
206 else if(sensor_type ==
"HyperspectralCamera")
210 else if(sensor_type ==
"HyperspectralPanoramaChannel")
217 <<
"HDF5Kernel::SaveMetaYAML(): Warning: Sensor type '" 218 << sensor_type <<
"' is not defined." << std::endl;
225 const std::string &group,
226 const std::string container)
const 232 const std::string &group,
233 const std::string &container)
const 247 std::unique_ptr<HighFive::DataSet> dataset;
250 dataset = std::make_unique<HighFive::DataSet>(
260 boost::optional<PointBuffer::val_type> opt_vchannel
261 = this->
template load<PointBuffer::val_type>(group, name);
283 const std::string &groupName,
284 const std::string &datasetName)
const 286 boost::optional<cv::Mat> ret;
291 if(group.
exist(datasetName))
293 if(H5IMis_image(group.
getId(), datasetName.c_str()))
295 long long unsigned int w, h, planes;
299 int err = H5IMget_image_info(group.
getId(), datasetName.c_str(), &w, &h, &planes, interlace, &npals);
303 ret = cv::Mat(h, w, CV_8U);
304 H5IMread_image(group.
getId(), datasetName.c_str(), ret->data);
305 }
else if(planes == 3) {
307 ret = cv::Mat(h, w, CV_8UC3);
308 H5IMread_image(group.
getId(), datasetName.c_str(), ret->data);
322 ret = createMat<unsigned char>(dims);
323 dataset.
read(reinterpret_cast<unsigned char*>(ret->data));
325 ret = createMat<char>(dims);
326 dataset.
read(reinterpret_cast<char*>(ret->data));
328 ret = createMat<unsigned short>(dims);
329 dataset.
read(reinterpret_cast<unsigned short*>(ret->data));
331 ret = createMat<short>(dims);
332 dataset.
read(reinterpret_cast<short*>(ret->data));
334 ret = createMat<int>(dims);
335 dataset.
read(reinterpret_cast<int*>(ret->data));
337 ret = createMat<float>(dims);
338 dataset.
read(reinterpret_cast<float*>(ret->data));
340 ret = createMat<double>(dims);
341 dataset.
read(reinterpret_cast<double*>(ret->data));
343 std::cout <<
timestamp <<
"HDF5Kernel::loadImage(): Warning: Could'nt load blob. Datatype unkown." << std::endl;
351 throw std::runtime_error(
"[Hdf5 - ImageIO]: Hdf5 file not open.");
364 const std::string &group,
365 const std::string &container,
366 YAML::Node& node)
const 370 if(hg.
isValid() && node[
"sensor_type"] )
373 std::string sensor_type = node[
"sensor_type"].as<std::string>();
374 if(sensor_type ==
"ScanPosition")
378 else if(sensor_type ==
"Scan")
382 else if(sensor_type ==
"ScanCamera")
386 else if(sensor_type ==
"ScanProject")
390 else if(sensor_type ==
"HyperspectralCamera")
394 else if(sensor_type ==
"HyperspectralPanoramaChannel")
401 <<
"HDF5Kernel::LoadMetaYAML(): Warning: Sensor type '" 402 << sensor_type <<
"' is not defined." << std::endl;
409 <<
"HDF5Kernel::loadMetaYAML(): Warning: Sensor type field missing." 415 const std::string &group,
416 const std::string &container,
417 std::vector<size_t> &dims)
const 419 return this->
template loadArray<unsigned char>(group, container, dims);
423 const std::string &group,
424 const std::string &container,
425 std::vector<size_t> &dims)
const 427 return this->
template loadArray<float>(group, container, dims);
431 const std::string &group,
432 const std::string &container,
433 std::vector<size_t> &dims)
const 435 return this->
template loadArray<double>(group, container, dims);
439 const std::string &groupName,
440 const std::string &datasetName,
441 const std::vector<size_t> &dimensions,
442 const boost::shared_array<float> &data)
const 444 this->
template saveArray<float>(groupName, datasetName, dimensions, data);
448 const std::string &groupName,
const std::string &datasetName,
449 const std::vector<size_t> &dimensions,
450 const boost::shared_array<double> &data)
const 452 this->
template saveArray<double>(groupName, datasetName, dimensions, data);
456 const std::string &groupName,
const std::string &datasetName,
457 const std::vector<size_t> &dimensions,
458 const boost::shared_array<unsigned char> &data)
const 460 this->
template saveArray<unsigned char>(groupName, datasetName, dimensions, data);
488 return getChannel<float>(group, name, channel);
494 return getChannel<unsigned int>(group, name, channel);
500 return getChannel<unsigned char>(group, name, channel);
506 return addChannel<float>(group, name, channel);
512 return addChannel<unsigned int>(group, name, channel);
518 return addChannel<unsigned char>(group, name, channel);
DataSpace getSpace() const
getSpace
A class to handle point information with an arbitrarily large number of attribute channels...
virtual void saveMeshBuffer(const std::string &group, const std::string &container, const MeshBufferPtr &buffer) const
void read(T &array) const
Exception specific to HighFive DataSet interface.
std::shared_ptr< MeshBuffer > MeshBufferPtr
virtual doubleArr loadDoubleArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
void loadMetaData(const YAML::Node &node)
virtual void saveMetaYAML(const std::string &group, const std::string &metaName, const YAML::Node &node) const
static Timestamp timestamp
A global time stamp object for program runtime measurement.
std::shared_ptr< HighFive::File > m_hdf5File
virtual void saveDoubleArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< double > &data) const
virtual void saveImage(const std::string &group, const std::string &container, const cv::Mat &image) const
boost::shared_array< double > doubleArr
virtual void savePointBuffer(const std::string &group, const std::string &container, const PointBufferPtr &buffer) const
bool getChannel(const std::string group, const std::string name, FloatChannelOptional &channel) const
getChannel Reads a float attribute channel in the given group with the given name ...
boost::shared_array< unsigned char > ucharArr
virtual void subGroupNames(const std::string &group, std::vector< string > &subGroupNames) const
UCharChannel::Optional UCharChannelOptional
std::shared_ptr< PointBuffer > PointBufferPtr
virtual PointBufferPtr loadPointBuffer(const std::string &group, const std::string &container) const
bool isValid() const
isValid
virtual boost::optional< cv::Mat > loadImage(const std::string &group, const std::string &container) const
bool exist(const std::string &node_name) const
check a dataset or group exists in the current node / group
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
create an HDF5 DataType from a C++ type
DataType getDataType() const
getDataType
virtual void loadMetaYAML(const std::string &group, const std::string &container, YAML::Node &node) const
virtual bool exists(const std::string &group) const
boost::shared_array< float > floatArr
void filter(lvr2::PointBufferPtr &cloud, lvr2::indexArray &inlier, size_t j)
FloatChannel::Optional FloatChannelOptional
virtual floatArr loadFloatArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
virtual ucharArr loadUCharArray(const std::string &group, const std::string &container, std::vector< size_t > &dims) const
virtual void saveFloatArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< float > &data) const
virtual MeshBufferPtr loadMeshBuffer(const std::string &group, const std::string container) const
IndexChannel::Optional IndexChannelOptional
bool addChannel(const std::string group, const std::string name, const AttributeChannel< T > &channel) const
virtual void saveUCharArray(const std::string &groupName, const std::string &datasetName, const std::vector< size_t > &dimensions, const boost::shared_array< unsigned char > &data) const
HDF5MetaDescriptionBase * m_metaDescription
std::vector< std::string > listObjectNames() const
list all leaf objects name of the node / group
std::shared_ptr< HighFive::File > open(const std::string &filename)
The MeshBuffer Mesh representation for I/O modules.
std::vector< size_t > getDimensions() const
getDimensions
HighFive::Group getGroup(std::shared_ptr< HighFive::File > hdf5_file, const std::string &groupName, bool create=true)
void save(std::string groupName, std::string datasetName, const Channel< T > &channel) const
bool exist(std::shared_ptr< HighFive::File > hdf5_file, const std::string &groupName)