Program Listing for File PlutoMapIO.hpp

Return to documentation for file (include/lvr2/io/PlutoMapIO.hpp)

#ifndef __LVR2_PLUTOMAPIO_HPP_
#define __LVR2_PLUTOMAPIO_HPP_


#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>

#include <H5Tpublic.h>
#include <highfive/H5File.hpp>

#include "lvr2/geometry/BaseVector.hpp"

namespace hf = HighFive;

using std::string;
using std::vector;
using std::unordered_map;

namespace lvr2
{

using Vec = BaseVector<float>;

struct PlutoMapImage {
    string name;
    uint32_t width;
    uint32_t height;
    uint32_t channels;
    vector<uint8_t> data;
};

struct PlutoMapMaterial {
    int32_t textureIndex;
    uint8_t r;
    uint8_t g;
    uint8_t b;
};

class PlutoMapIO
{
public:
    PlutoMapIO(string filename);

    PlutoMapIO(
        string filename,
        const vector<float>& vertices,
        const vector<uint32_t>& face_ids
    );

    ~PlutoMapIO();

    vector<float> getVertices();

    vector<uint32_t> getFaceIds();

    vector<float> getVertexNormals();

    vector<uint8_t> getVertexColors();

    // TODO: replace PlutoMapImage with lvr2::Texture?
    vector<PlutoMapImage> getTextures();

    unordered_map<Vec, vector<float>> getFeatures();

    vector<PlutoMapMaterial> getMaterials();

    vector<uint32_t> getMaterialFaceIndices();

    vector<float> getVertexTextureCoords();

    vector<string> getLabelGroups();

    vector<string> getAllLabelsOfGroup(string groupName);

    vector<uint32_t> getFaceIdsOfLabel(string groupName, string labelName);

    vector<float> getRoughness();

    vector<float> getHeightDifference();

    PlutoMapImage getImage(hf::Group group, string name);

    hf::DataSet addVertexNormals(vector<float>& normals);

    hf::DataSet addVertexColors(vector<uint8_t>& colors);

    void addTexture(int index, uint32_t width, uint32_t height, uint8_t* data);

    void addMaterials(vector<PlutoMapMaterial>& materials, vector<uint32_t>& matFaceIndices);

    void addVertexTextureCoords(vector<float>& coords);

    void addLabel(string groupName, string labelName, vector<uint32_t>& faceIds);

    template<typename BaseVecT>
    void addTextureKeypointsMap(unordered_map<BaseVecT, std::vector<float>>& keypoints_map);

    void addRoughness(vector<float>& roughness);

    void addHeightDifference(vector<float>& diff);

    void addImage(hf::Group group,
                  string name,
                  const uint32_t width,
                  const uint32_t height,
                  const uint8_t* pixelBuffer
    );

    bool removeAllLabels();

    void flush();

private:
    std::shared_ptr<hf::File> m_file;

    // group names

    static constexpr const char* GEOMETRY_GROUP = "/geometry";
    static constexpr const char* ATTRIBUTES_GROUP = "/attributes";
    static constexpr const char* CLUSTERSETS_GROUP = "/clustersets";
    static constexpr const char* TEXTURES_GROUP = "/textures";
    static constexpr const char* LABELS_GROUP = "/labels";

    // main groups for reference
    hf::Group* m_geometryGroup;
    hf::Group* m_attributesGroup;
    hf::Group* m_clusterSetsGroup;
    hf::Group* m_texturesGroup;
    hf::Group* m_labelsGroup;
};
} // namespace lvr2


namespace HighFive {

template <>
inline AtomicType<lvr2::PlutoMapMaterial>::AtomicType()
{
    hid_t materialHid = H5Tcreate(H5T_COMPOUND, sizeof(lvr2::PlutoMapMaterial));

    H5Tinsert(materialHid, "textureIndex", offsetof(lvr2::PlutoMapMaterial, textureIndex), H5T_NATIVE_INT);
    H5Tinsert(materialHid, "r", offsetof(lvr2::PlutoMapMaterial, r), H5T_NATIVE_UCHAR);
    H5Tinsert(materialHid, "g", offsetof(lvr2::PlutoMapMaterial, g), H5T_NATIVE_UCHAR);
    H5Tinsert(materialHid, "b", offsetof(lvr2::PlutoMapMaterial, b), H5T_NATIVE_UCHAR);

    _hid = H5Tcopy(materialHid);
}

}

#include "PlutoMapIO.tcc"

#endif // __LVR2_PLUTOMAPIO_HPP_