Program Listing for File Hdf5Util.hpp

Return to documentation for file (include/lvr2/util/Hdf5Util.hpp)

#ifndef HDF5UTIL_HPP
#define HDF5UTIL_HPP

#pragma once

// HDF5-related includes
#include <H5Tpublic.h>
#include <hdf5_hl.h>
#include <highfive/H5DataSet.hpp>
#include <highfive/H5DataSpace.hpp>
#include <highfive/H5File.hpp>

// Boost libraries
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>

// C++ standard library
#include <chrono>
#include <memory>
#include <string>
#include <vector>

// LVR internal includes
#include "lvr2/io/baseio/yaml/Matrix.hpp"
#include "lvr2/geometry/Matrix4.hpp"
#include "lvr2/util/Timestamp.hpp"
#include "lvr2/util/Tuple.hpp"

namespace lvr2
{

namespace hdf5util
{

using H5AllowedTypes = Tuple<
        char,
        signed char,
        unsigned char,
        short,
        unsigned short,
        int,
        unsigned,
        long,
        unsigned long,
        long long,
        unsigned long long,
        float,
        double,
        bool,
        std::string
    >;

template<typename T>
void addAtomic(HighFive::Group& g,
    const std::string datasetName,
    const T data);

template<typename T>
void addArray(
    HighFive::Group& g,
    const std::string datasetName,
    std::vector<size_t>& dim,
    boost::shared_array<T>& data);

template<typename T>
void addArray(
    HighFive::Group& g,
    const std::string datasetName,
    const size_t& length,
    boost::shared_array<T>& data);

template<typename T>
void addVector(HighFive::Group& g,
    const std::string datasetName,
    const std::vector<T>& data);

template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
void addMatrix(HighFive::Group& group,
    std::string datasetName,
    const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& mat);

template<typename T>
boost::optional<T> getAtomic(
    const HighFive::Group& g,
    const std::string datasetName);

template<typename T>
boost::shared_array<T> getArray(
    const HighFive::Group& g,
    const std::string& datasetName,
    std::vector<size_t>& dim);

template<typename T>
boost::shared_array<T> getArray(
    const HighFive::Group& g,
    const std::string& datasetName,
    size_t& dim);

template<typename T>
boost::optional<std::vector<T> > getVector(
    const HighFive::Group& g,
    const std::string& datasetName);

template<typename T>
std::vector<size_t> getDimensions(
    const HighFive::Group& g,
    const std::string& datasetName);


template<typename MatrixT>
boost::optional<MatrixT> getMatrix(const HighFive::Group& g, const std::string& datasetName);

std::vector<std::string> splitGroupNames(const std::string& groupName);

std::pair<std::string, std::string> validateGroupDataset(
    const std::string& groupName,
    const std::string& datasetName);

void writeBaseStructure(std::shared_ptr<HighFive::File> hdf5_file);

HighFive::Group getGroup(std::shared_ptr<HighFive::File> hdf5_file,
                                const std::string& groupName,
                                bool create = true);

HighFive::Group getGroup(HighFive::Group& g, const std::string& groupName, bool create = true);


struct HighFiveSplit
{
    std::vector<std::string> groups;
    std::vector<std::string> datasets;
};

HighFiveSplit split(HighFive::Group g);

bool exist(const std::shared_ptr<HighFive::File>& hdf5_file,
            const std::string& groupName);

bool exist(const HighFive::Group& group, const std::string& groupName);

std::shared_ptr<HighFive::File> open(const boost::filesystem::path& filename,
    unsigned int flag = HighFive::File::ReadWrite);

template <typename T>
std::unique_ptr<HighFive::DataSet> createDataset(HighFive::Group& g,
                                                 std::string datasetName,
                                                 const HighFive::DataSpace& dataSpace,
                                                 const HighFive::DataSetCreateProps& properties);

template <typename T, typename HT>
void setAttribute(
    HT& g,
    const std::string& attr_name,
    const T& data);

template<typename T, typename HT>
void setAttributeVector(
    HT& g,
    const std::string& attr_name,
    const std::vector<T>& vec
);

template<typename T, typename HT>
void setAttributeArray(
    HT& g,
    const std::string& attr_name,
    boost::shared_array<T> data,
    size_t size
);

template<typename HT>
void setAttributeMatrix(
    HT& g,
    const std::string& attr_name,
    const Eigen::MatrixXd& mat);



template <typename HT, typename T>
bool checkAttribute(HT& g, const std::string& attr_name, T& data);

template <typename T, typename HT>
boost::optional<T> getAttribute(
    const HT& g,
    const std::string& attr_name);

template<typename T, typename HT>
boost::optional<std::vector<T> > getAttributeVector(
    const HT& g,
    const std::string& attr_name);

template<typename HT>
boost::optional<Eigen::MatrixXd> getAttributeMatrix(
    const HT& g,
    const std::string& attr_name);

boost::optional<std::string> highFiveTypeToLvr(std::string h5type);


template<typename HT>
void setAttributeMeta(
    HT& g,
    YAML::Node node,
    std::string prefix=""
);


template<typename HT>
YAML::Node getAttributeMeta(
    const HT& g
);



} // namespace hdf5util

} // namespace lvr2

#include "Hdf5Util.tcc"

#endif