hdf5_map_io.h
Go to the documentation of this file.
1 #ifndef HDF5_MAP_IO__H_
2 #define HDF5_MAP_IO__H_
3 
4 #include <string>
5 #include <vector>
6 #include <iostream>
7 #include <unordered_map>
8 
9 #include <H5Tpublic.h>
10 #include <highfive/H5File.hpp>
11 
12 namespace hf = HighFive;
13 
14 namespace hdf5_map_io
15 {
16 
20 struct MapVertex {
21  float x;
22  float y;
23  float z;
24 };
25 
26 
30 struct MapImage {
31  std::string name;
32  uint32_t width;
33  uint32_t height;
34  uint32_t channels;
35  std::vector<uint8_t> data;
36 };
37 
43 struct MapMaterial {
44  int32_t textureIndex;
45  uint8_t r;
46  uint8_t g;
47  uint8_t b;
48 };
49 
59 class HDF5MapIO
60 {
61 public:
65  HDF5MapIO(std::string filename);
66 
70  HDF5MapIO(
71  std::string filename,
72  const std::vector<float>& vertices,
73  const std::vector<uint32_t>& face_ids
74  );
75 
79  ~HDF5MapIO();
80 
84  std::vector<float> getVertices();
85 
89  std::vector<uint32_t> getFaceIds();
90 
94  std::vector<float> getVertexNormals();
95 
99  std::vector<uint8_t> getVertexColors();
100 
104  std::vector<MapImage> getTextures();
105 
110  std::unordered_map<MapVertex, std::vector<float>> getFeatures();
111 
115  std::vector<MapMaterial> getMaterials();
116 
120  std::vector<uint32_t> getMaterialFaceIndices();
121 
125  std::vector<float> getVertexTextureCoords();
126 
130  std::vector<std::string> getLabelGroups();
131 
135  std::vector<std::string> getAllLabelsOfGroup(std::string groupName);
136 
141  std::vector<uint32_t> getFaceIdsOfLabel(std::string groupName, std::string labelName);
142 
146  std::vector<float> getRoughness();
147 
151  std::vector<float> getHeightDifference();
152 
156  std::vector<float> getVertexCosts(std::string costlayer);
157 
161  std::vector<std::string> getCostLayers();
162 
166  MapImage getImage(hf::Group group, std::string name);
167 
171  hf::DataSet addVertexNormals(std::vector<float>& normals);
172 
176  hf::DataSet addVertexColors(std::vector<uint8_t>& colors);
177 
181  void addTexture(int index, uint32_t width, uint32_t height, uint8_t* data);
182 
186  void addMaterials(std::vector<MapMaterial>& materials, std::vector<uint32_t>& matFaceIndices);
187 
191  void addVertexTextureCoords(std::vector<float>& coords);
192 
197  void addLabel(std::string groupName, std::string labelName, std::vector<uint32_t>& faceIds);
198 
203  void addOrUpdateLabel(std::string groupName, std::string labelName, std::vector<uint32_t>& faceIds);
204 
209  void addTextureKeypointsMap(std::unordered_map<MapVertex, std::vector<float>>& keypoints_map);
210 
214  void addRoughness(std::vector<float>& roughness);
215 
219  void addHeightDifference(std::vector<float>& diff);
220 
224  void addImage(hf::Group group,
225  std::string name,
226  const uint32_t width,
227  const uint32_t height,
228  const uint8_t* pixelBuffer
229  );
230 
239  bool removeAllLabels();
240 
244  void flush();
245 
246 private:
248 
249  void creatOrGetGroups();
250 
251  size_t getSize(hf::DataSet& data_set);
252  // group names
253  static constexpr const char* CHANNELS_GROUP = "/mesh/channels";
254  static constexpr const char* CLUSTERSETS_GROUP = "/mesh/clustersets";
255  static constexpr const char* TEXTURES_GROUP = "/mesh/textures";
256  static constexpr const char* LABELS_GROUP = "/mesh/labels";
257 
258  // main groups for reference
263 };
264 } // namespace hdf5_map_io
265 
266 
267 namespace HighFive {
268 
272 template <>
274 {
275  hid_t materialHid = H5Tcreate(H5T_COMPOUND, sizeof(hdf5_map_io::MapMaterial));
276 
277  H5Tinsert(materialHid, "textureIndex", offsetof(hdf5_map_io::MapMaterial, textureIndex), H5T_NATIVE_INT);
278  H5Tinsert(materialHid, "r", offsetof(hdf5_map_io::MapMaterial, r), H5T_NATIVE_UCHAR);
279  H5Tinsert(materialHid, "g", offsetof(hdf5_map_io::MapMaterial, g), H5T_NATIVE_UCHAR);
280  H5Tinsert(materialHid, "b", offsetof(hdf5_map_io::MapMaterial, b), H5T_NATIVE_UCHAR);
281 
282  _hid = H5Tcopy(materialHid);
283 }
284 
285 }
286 
287 namespace std
288 {
289 template <>
290 struct hash<hdf5_map_io::MapVertex>
291 {
292  size_t operator()(const hdf5_map_io::MapVertex& k) const
293  {
294  size_t h1 = std::hash<double>()(k.x);
295  size_t h2 = std::hash<double>()(k.y);
296  size_t h3 = std::hash<double>()(k.z);
297  return (h1 ^ (h2 << 1)) ^ h3;
298  }
299 };
300 
301 template <>
302 struct equal_to<hdf5_map_io::MapVertex>
303 {
304  bool operator()( const hdf5_map_io::MapVertex& lhs, const hdf5_map_io::MapVertex& rhs ) const{
305  return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.z == rhs.z);
306  }
307 };
308 
309 }
310 
311 #endif // HDF5_MAP_IO__H_
hdf5_map_io::HDF5MapIO::getMaterials
std::vector< MapMaterial > getMaterials()
Returns materials as MapMaterial.
Definition: hdf5_map_io.cpp:177
hdf5_map_io::HDF5MapIO::getLabelGroups
std::vector< std::string > getLabelGroups()
Returns all available label groups.
Definition: hdf5_map_io.cpp:222
hdf5_map_io::HDF5MapIO::getMaterialFaceIndices
std::vector< uint32_t > getMaterialFaceIndices()
Returns material <-> face indices.
Definition: hdf5_map_io.cpp:192
hdf5_map_io::HDF5MapIO::getHeightDifference
std::vector< float > getHeightDifference()
Returns the height difference as float vector.
Definition: hdf5_map_io.cpp:263
hdf5_map_io::HDF5MapIO::m_file
hf::File m_file
Definition: hdf5_map_io.h:247
hdf5_map_io::MapMaterial::r
uint8_t r
Definition: hdf5_map_io.h:45
hdf5_map_io::HDF5MapIO::removeAllLabels
bool removeAllLabels()
Definition: hdf5_map_io.cpp:448
hdf5_map_io::HDF5MapIO::getImage
MapImage getImage(hf::Group group, std::string name)
Returns the image in the group, if it exists. If not an empty struct is returned.
Definition: hdf5_map_io.cpp:288
hdf5_map_io::HDF5MapIO::HDF5MapIO
HDF5MapIO(std::string filename)
Opens a map file for reading and writing.
Definition: hdf5_map_io.cpp:31
hdf5_map_io::MapVertex::z
float z
Definition: hdf5_map_io.h:23
hdf5_map_io::HDF5MapIO::~HDF5MapIO
~HDF5MapIO()
Closes main groups and makes sure all buffers are flushed to the file on disc.
Definition: hdf5_map_io.cpp:59
hdf5_map_io::HDF5MapIO::getFaceIds
std::vector< uint32_t > getFaceIds()
Returns face ids vector.
Definition: hdf5_map_io.cpp:91
hdf5_map_io::MapMaterial::g
uint8_t g
Definition: hdf5_map_io.h:46
hdf5_map_io::HDF5MapIO::getAllLabelsOfGroup
std::vector< std::string > getAllLabelsOfGroup(std::string groupName)
Returns all labels inside the given group.
Definition: hdf5_map_io.cpp:227
hdf5_map_io::MapVertex::x
float x
Definition: hdf5_map_io.h:21
hdf5_map_io::HDF5MapIO::addHeightDifference
void addHeightDifference(std::vector< float > &diff)
Adds the height difference to the attributes group.
Definition: hdf5_map_io.cpp:436
hdf5_map_io::MapMaterial::textureIndex
int32_t textureIndex
Definition: hdf5_map_io.h:44
hdf5_map_io::HDF5MapIO::addRoughness
void addRoughness(std::vector< float > &roughness)
Adds the roughness to the attributes group.
Definition: hdf5_map_io.cpp:430
hdf5_map_io::HDF5MapIO::getFaceIdsOfLabel
std::vector< uint32_t > getFaceIdsOfLabel(std::string groupName, std::string labelName)
Returns face ids for the given label inside the group. E.g: label=tree_1 -> groupName=tree; labelName...
Definition: hdf5_map_io.cpp:237
hdf5_map_io::MapVertex
Definition: hdf5_map_io.h:20
hdf5_map_io::HDF5MapIO::getFeatures
std::unordered_map< MapVertex, std::vector< float > > getFeatures()
Returns an map which keys are representing the features point in space and the values are an vector o...
Definition: hdf5_map_io.cpp:142
hdf5_map_io::HDF5MapIO::getCostLayers
std::vector< std::string > getCostLayers()
returns the names of all available costlayers
Definition: hdf5_map_io.cpp:283
hdf5_map_io::HDF5MapIO::m_labelsGroup
hf::Group m_labelsGroup
Definition: hdf5_map_io.h:262
hdf5_map_io::MapMaterial::b
uint8_t b
Definition: hdf5_map_io.h:47
hdf5_map_io::MapImage::name
std::string name
Definition: hdf5_map_io.h:31
hdf5_map_io::HDF5MapIO::getRoughness
std::vector< float > getRoughness()
Returns the roughness as float vector.
Definition: hdf5_map_io.cpp:258
hdf5_map_io::HDF5MapIO::addTexture
void addTexture(int index, uint32_t width, uint32_t height, uint8_t *data)
Definition: hdf5_map_io.cpp:336
hdf5_map_io::HDF5MapIO::getVertexCosts
std::vector< float > getVertexCosts(std::string costlayer)
Returns one costlayer as float vector.
Definition: hdf5_map_io.cpp:268
hdf5_map_io::HDF5MapIO::addVertexTextureCoords
void addVertexTextureCoords(std::vector< float > &coords)
Add vertex texture coordinates to the textures group.
Definition: hdf5_map_io.cpp:365
hdf5_map_io::HDF5MapIO::CHANNELS_GROUP
static constexpr const char * CHANNELS_GROUP
Definition: hdf5_map_io.h:253
hdf5_map_io::HDF5MapIO::getVertexNormals
std::vector< float > getVertexNormals()
Returns vertex normals vector.
Definition: hdf5_map_io.cpp:102
hdf5_map_io::HDF5MapIO::getVertexTextureCoords
std::vector< float > getVertexTextureCoords()
Returns vertex texture coordinates.
Definition: hdf5_map_io.cpp:207
hdf5_map_io::HDF5MapIO::addTextureKeypointsMap
void addTextureKeypointsMap(std::unordered_map< MapVertex, std::vector< float >> &keypoints_map)
Adds the keypoints with their corresponding positions to the attributes_group. The position is saved ...
Definition: hdf5_map_io.cpp:407
hdf5_map_io::HDF5MapIO::LABELS_GROUP
static constexpr const char * LABELS_GROUP
Definition: hdf5_map_io.h:256
hdf5_map_io::HDF5MapIO::getTextures
std::vector< MapImage > getTextures()
Returns textures vector.
Definition: hdf5_map_io.cpp:125
HighFive::Group
filename
filename
hdf5_map_io::HDF5MapIO::TEXTURES_GROUP
static constexpr const char * TEXTURES_GROUP
Definition: hdf5_map_io.h:255
H5File.hpp
hdf5_map_io::HDF5MapIO::addVertexNormals
hf::DataSet addVertexNormals(std::vector< float > &normals)
Add normals to the attributes group.
Definition: hdf5_map_io.cpp:319
hdf5_map_io::HDF5MapIO::addImage
void addImage(hf::Group group, std::string name, const uint32_t width, const uint32_t height, const uint8_t *pixelBuffer)
Adds an image with given data set name to the given group.
Definition: hdf5_map_io.cpp:442
hdf5_map_io::MapImage::channels
uint32_t channels
Definition: hdf5_map_io.h:34
hdf5_map_io::HDF5MapIO::addMaterials
void addMaterials(std::vector< MapMaterial > &materials, std::vector< uint32_t > &matFaceIndices)
Add materials as MapMaterial and the corresponding material <-> face indices.
Definition: hdf5_map_io.cpp:354
HighFive::File
colors
colors
hdf5_map_io::MapImage
Definition: hdf5_map_io.h:30
hdf5_map_io::HDF5MapIO::m_channelsGroup
hf::Group m_channelsGroup
Definition: hdf5_map_io.h:259
hdf5_map_io::HDF5MapIO
Definition: hdf5_map_io.h:59
std::equal_to< hdf5_map_io::MapVertex >::operator()
bool operator()(const hdf5_map_io::MapVertex &lhs, const hdf5_map_io::MapVertex &rhs) const
Definition: hdf5_map_io.h:304
hdf5_map_io::HDF5MapIO::getVertexColors
std::vector< uint8_t > getVertexColors()
Returns vertex colors vector.
Definition: hdf5_map_io.cpp:113
std
hdf5_map_io::HDF5MapIO::CLUSTERSETS_GROUP
static constexpr const char * CLUSTERSETS_GROUP
Definition: hdf5_map_io.h:254
hdf5_map_io::HDF5MapIO::flush
void flush()
Flushes the file. All opened buffers are saved to disc.
Definition: hdf5_map_io.cpp:460
hdf5_map_io::HDF5MapIO::getVertices
std::vector< float > getVertices()
Returns vertices vector.
Definition: hdf5_map_io.cpp:80
HighFive::AtomicType::AtomicType
AtomicType()
hdf5_map_io::MapImage::height
uint32_t height
Definition: hdf5_map_io.h:33
hdf5_map_io::MapImage::width
uint32_t width
Definition: hdf5_map_io.h:32
hdf5_map_io::HDF5MapIO::addLabel
void addLabel(std::string groupName, std::string labelName, std::vector< uint32_t > &faceIds)
Adds the label (labelName) to the label group with the given faces. E.g.: tree_1 -> groupName=tree; l...
Definition: hdf5_map_io.cpp:395
hdf5_map_io::HDF5MapIO::m_texturesGroup
hf::Group m_texturesGroup
Definition: hdf5_map_io.h:261
hdf5_map_io::HDF5MapIO::getSize
size_t getSize(hf::DataSet &data_set)
Definition: hdf5_map_io.cpp:74
hdf5_map_io::HDF5MapIO::creatOrGetGroups
void creatOrGetGroups()
Definition: hdf5_map_io.cpp:8
hdf5_map_io
Definition: hdf5_map_io.h:14
hdf5_map_io::HDF5MapIO::m_clusterSetsGroup
hf::Group m_clusterSetsGroup
Definition: hdf5_map_io.h:260
hdf5_map_io::MapMaterial
Definition: hdf5_map_io.h:43
HighFive::DataSet
HighFive
hdf5_map_io::HDF5MapIO::addOrUpdateLabel
void addOrUpdateLabel(std::string groupName, std::string labelName, std::vector< uint32_t > &faceIds)
Adds or updates the label (labelName) to the label group with the given faces. E.g....
Definition: hdf5_map_io.cpp:372
std::hash< hdf5_map_io::MapVertex >::operator()
size_t operator()(const hdf5_map_io::MapVertex &k) const
Definition: hdf5_map_io.h:292
hdf5_map_io::MapImage::data
std::vector< uint8_t > data
Definition: hdf5_map_io.h:35
hdf5_map_io::MapVertex::y
float y
Definition: hdf5_map_io.h:22
hdf5_map_io::HDF5MapIO::addVertexColors
hf::DataSet addVertexColors(std::vector< uint8_t > &colors)
Add vertex colors to the attributes group.
Definition: hdf5_map_io.cpp:328


hdf5_map_io
Author(s): Sebastian Pütz
autogenerated on Sun Jan 21 2024 04:06:12