ChunkIO.cpp
Go to the documentation of this file.
1 
35 #include <iostream>
36 #include <string>
37 
38 #include "lvr2/io/ChunkIO.hpp"
39 
40 
41 
42 namespace lvr2 {
43 
45 = default;
46 
47 ChunkIO::ChunkIO(std::string filePath)
48 :m_filePath(filePath)
49 {
51 }
52 
54 {
55  // HighFive::Group chunks = hdf5util::getGroup(m_hdf5IO.m_hdf5_file, "chunks", true); // <- maybe use this instead of string
56 
57  boost::shared_array<size_t> amountArr(new size_t[3] {amount.x, amount.y, amount.z});
58  m_hdf5IO.save(m_chunkName, m_amountName, 3, amountArr);
59 
60  boost::shared_array<float> chunkSizeArr(new float[1] {chunksize});
61  m_hdf5IO.save(m_chunkName, m_chunkSizeName, 1, chunkSizeArr);
62 
63  boost::shared_array<float> boundingBoxArr(
64  new float[6] {boundingBox.getMin()[0], boundingBox.getMin()[1], boundingBox.getMin()[2],
65  boundingBox.getMax()[0], boundingBox.getMax()[1], boundingBox.getMax()[2]});
66  std::vector<size_t> boundingBoxDim({2, 3});
67  m_hdf5IO.save(m_chunkName, m_boundingBoxName, boundingBoxDim, boundingBoxArr);
68 }
69 
70 void ChunkIO::writeChunk(lvr2::MeshBufferPtr mesh, size_t x, size_t y, size_t z)
71 {
73  std::string cellName = std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z);
74  if (!chunks.exist(cellName))
75  {
76  chunks.createGroup(cellName);
77  }
78  HighFive::Group meshGroup = chunks.getGroup(cellName);
79 
80  m_hdf5IO.save(meshGroup, mesh);
81 }
82 
84 {
85  BaseVector<size_t> amount;
86  size_t dimensionAmount;
87  boost::shared_array<size_t> amountArr
88  = m_hdf5IO.ArrayIO::load<size_t>(m_chunkName, m_amountName, dimensionAmount);
89  if(dimensionAmount != 3)
90  {
91  std::cout << "Error loading chunk data: amount has not the right dimension. Real: "
92  << dimensionAmount << "; Expected: 3" << std::endl;
93  }
94  else
95  {
96  amount = BaseVector<size_t>(amountArr[0], amountArr[1], amountArr[2]);
97  }
98  return amount;
99 }
100 
102 {
103  float chunkSize;
104  size_t dimensionChunkSize;
105  boost::shared_array<float> chunkSizeArr
106  = m_hdf5IO.ArrayIO::load<float>(m_chunkName, m_chunkSizeName, dimensionChunkSize);
107  if(dimensionChunkSize != 1)
108  {
109  std::cout << "Error loading chunk data: chunkSize has not the right dimension. Real: "
110  << dimensionChunkSize << "; Expected: 1" << std::endl;
111  chunkSize = 0;
112  }
113  else
114  {
115  chunkSize = chunkSizeArr[0];
116  }
117  return chunkSize;
118 }
119 
121 {
122  BoundingBox<BaseVector<float>> boundingBox;
123  std::vector<size_t> dimensionBox;
124  boost::shared_array<float> boundingBoxArr
125  = m_hdf5IO.ArrayIO::load<float>(m_chunkName, m_boundingBoxName, dimensionBox);
126  if(dimensionBox.at(0) != 2 && dimensionBox.at(1) != 3)
127  {
128  std::cout << "Error loading chunk data: bounding_box has not the right dimension. Real: {"
129  << dimensionBox.at(0) << ", " << dimensionBox.at(1) << "}; Expected: {2, 3}" << std::endl;
130  }
131  else
132  {
133  boundingBox = BoundingBox<BaseVector<float>>(
134  BaseVector<float>(boundingBoxArr[0], boundingBoxArr[1], boundingBoxArr[2]),
135  BaseVector<float>(boundingBoxArr[3], boundingBoxArr[4], boundingBoxArr[5]));
136  }
137  return boundingBox;
138 }
139 
141 {
142  return m_hdf5IO.loadMesh(m_chunkName + "/" + chunkName);
143 }
144 
145 void ChunkIO::writeVoxelSize(float voxelSize) {
147 
148  if (!g.exist(m_chunkName))
149  {
151  }
152 
153  boost::shared_array<float> voxelSizeArr(new float[1] {voxelSize});
154  m_hdf5IO.save(m_chunkName, "voxelsize", 1, voxelSizeArr);
155 }
157 {
158  size_t len;
159  boost::shared_array<float> voxelSize = m_hdf5IO.loadArray<float>(m_chunkName, "voxelsize", len);
160  return voxelSize.get()[0];
161 }
162 
163 void ChunkIO::writeTSDF(string chunkName,
164  size_t csize,
165  boost::shared_array<float> centers,
166  boost::shared_array<bool> extruded,
167  boost::shared_array<float> queryPoints) {
169 
170  if (!chunks.exist(chunkName))
171  {
172  chunks.createGroup(chunkName);
173  }
174 
175  boost::shared_array<size_t> numCellsArr = boost::shared_array<size_t>(new size_t[1]);
176  numCellsArr.get()[0] = csize;
177  m_hdf5IO.save(m_chunkName + "/" + chunkName, "numCells", 1, numCellsArr);
178  std::vector<size_t> centersDim({csize, 3});
179  m_hdf5IO.save(m_chunkName + "/" + chunkName, "centers", centersDim, centers);
180  m_hdf5IO.save(m_chunkName + "/" + chunkName, "extruded", csize, extruded);
181  std::vector<size_t> queryPointsDim({csize, 8});
182  m_hdf5IO.save(m_chunkName + "/" + chunkName, "queryPoints", queryPointsDim, queryPoints);
183 }
184 
185 boost::shared_array<float> ChunkIO::lsrLoadCenters(std::string chunkName)
186 {
188 
189  if (!chunks.exist(chunkName))
190  {
191  // chunk does not exist
192  return boost::shared_array<float>();
193  }
194  HighFive::Group single_chunk = chunks.getGroup(chunkName);
195 
196 
197  std::vector<size_t> dimensionCenters;
198  boost::shared_array<float> centersArr
199  = m_hdf5IO.ArrayIO::load<float>(single_chunk, "centers", dimensionCenters);
200  if (dimensionCenters.at(1) != 3)
201  {
202  std::cout << "Error loading chunk/tsdf data: centers has not the right dimension. Real: {"
203  << dimensionCenters.at(0) << ", " << dimensionCenters.at(1) << "}; Expected: {N, 3}"
204  << std::endl;
205  return boost::shared_array<float>();
206  }
207  return centersArr;
208 }
209 size_t ChunkIO::lsrLoadNumCells(std::string chunkName)
210 {
212 
213  if (!chunks.exist(chunkName))
214  {
215  // chunk does not exist
216  return 0;
217  }
218  HighFive::Group single_chunk = chunks.getGroup(chunkName);
219 
220 
221  std::vector<size_t> dimensionNumCells;
222  boost::shared_array<float> numCellsArr
223  = m_hdf5IO.ArrayIO::load<float>(single_chunk, "numCells", dimensionNumCells);
224  return numCellsArr.get()[0];
225 }
226 boost::shared_array<float> ChunkIO::lsrLoadQueryPoints(std::string chunkName)
227 {
229 
230  if (!chunks.exist(chunkName))
231  {
232  // chunk does not exist
233  return boost::shared_array<float>();
234  }
235  HighFive::Group single_chunk = chunks.getGroup(chunkName);
236 
237 
238  std::vector<size_t> dimensionQueryPoints;
239  boost::shared_array<float> qpArr
240  = m_hdf5IO.ArrayIO::load<float>(single_chunk, "queryPoints", dimensionQueryPoints);
241  if (dimensionQueryPoints.at(1) != 8)
242  {
243  std::cout << "Error loading chunk/tsdf data: queryPoints has not the right dimension. Real: {"
244  << dimensionQueryPoints.at(0) << ", " << dimensionQueryPoints.at(1) << "}; Expected: {N, 8}"
245  << std::endl;
246  return boost::shared_array<float>();
247  }
248  return qpArr;
249 }
250 boost::shared_array<bool> ChunkIO::lsrLoadExtruded(std::string chunkName)
251 {
253 
254  if (!chunks.exist(chunkName))
255  {
256  // chunk does not exist
257  return boost::shared_array<bool>();
258  }
259  HighFive::Group single_chunk = chunks.getGroup(chunkName);
260  std::vector<size_t> dimensionExtruded;
261  boost::shared_array<bool> extrudedArr
262  = m_hdf5IO.ArrayIO::load<bool>(single_chunk, "extruded", dimensionExtruded);
263  return extrudedArr;
264 }
265 
266 } // namespace lvr2
BaseVector< size_t > loadAmount()
loads and returns a BaseVector with the amount of chunks in each dimension
Definition: ChunkIO.cpp:83
void open(std::string filename)
std::shared_ptr< HighFive::File > m_hdf5_file
boost::shared_array< T > loadArray(std::string groupName, std::string datasetName, size_t &size)
ChunkHDF5IO m_hdf5IO
Definition: ChunkIO.hpp:135
HalfEdgeMesh< Vec > mesh
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
std::string m_filePath
Definition: ChunkIO.hpp:133
void writeTSDF(string cellName, size_t csize, boost::shared_array< float > centers, boost::shared_array< bool > extruded, boost::shared_array< float > queryPoints)
Writes the parameters in the HDF5 file.
Definition: ChunkIO.cpp:163
void save(std::string groupName, std::string datasetName, size_t size, boost::shared_array< T > data)
void writeBasicStructure(BaseVector< std::size_t > amount, float chunksize, BoundingBox< BaseVector< float >> boundingBox)
write amount, chunksize and the bounding box in the hdf5 file
Definition: ChunkIO.cpp:53
lvr2::MeshBufferPtr loadChunk(std::string chunkName)
load a mesh from a group with the given cellIndex
Definition: ChunkIO.cpp:140
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
const std::string m_boundingBoxName
Definition: ChunkIO.hpp:142
bool exist(const std::string &node_name) const
check a dataset or group exists in the current node / group
Group getGroup(const std::string &group_name) const
open an existing group with the name group_name
void writeVoxelSize(float voxelSize)
save reconstruction voxelsize in HDF5
Definition: ChunkIO.cpp:145
BoundingBox< BaseVector< float > > loadBoundingBox()
loads and returns the bounding box for the complete original mesh (that got chunked) ...
Definition: ChunkIO.cpp:120
float loadChunkSize()
loads and returns the chunksize
Definition: ChunkIO.cpp:101
void writeChunk(lvr2::MeshBufferPtr mesh, size_t x, size_t y, size_t z)
write a mesh in a group with the given cellIndex
Definition: ChunkIO.cpp:70
boost::shared_array< float > lsrLoadCenters(string chunkName)
loads and returns the centers for the cells/voxel in one chunk
Definition: ChunkIO.cpp:185
boost::shared_array< float > lsrLoadQueryPoints(string chunkName)
loads and returns the Querypoint-distances for the cells/voxel of one chunk
Definition: ChunkIO.cpp:226
const std::string m_chunkSizeName
Definition: ChunkIO.hpp:141
Group createGroup(const std::string &group_name)
create a new group with the name group_name
size_t lsrLoadNumCells(string chunkName)
loads and returns the number of cells/voxel in the chunk
Definition: ChunkIO.cpp:209
boost::shared_array< bool > lsrLoadExtruded(string chunkName)
load the extruded value for the cells/voxel of one chunk
Definition: ChunkIO.cpp:250
const std::string m_amountName
Definition: ChunkIO.hpp:140
HighFive::Group getGroup(std::shared_ptr< HighFive::File > hdf5_file, const std::string &groupName, bool create=true)
Definition: Hdf5Util.cpp:58
float readVoxelSize()
returns the voxelsize
Definition: ChunkIO.cpp:156
const std::string m_chunkName
Definition: ChunkIO.hpp:139


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 Mon Feb 28 2022 22:46:06