ChunkHashGrid.hpp
Go to the documentation of this file.
1 
35 #ifndef CHUNK_HASH_GRID_HPP
36 #define CHUNK_HASH_GRID_HPP
37 
38 #include "lvr2/io/MeshBuffer.hpp"
39 #include "lvr2/io/PointBuffer.hpp"
41 #include "lvr2/io/hdf5/ChunkIO.hpp"
42 
43 #include <list>
44 #include <unordered_map>
45 
46 namespace lvr2
47 {
48 
53 class ChunkGeomtryChannelVisitor : public boost::static_visitor<FloatChannelOptional>
54 {
55  public:
57  {
58  return mesh->getFloatChannel("vertices");
59  }
60 
62  {
63  return points->getFloatChannel("points");
64  }
65 };
66 
68 {
69  public:
70  using val_type = boost::variant<MeshBufferPtr, PointBufferPtr>;
71 
73 
79  explicit ChunkHashGrid(std::string hdf5Path, size_t cacheSize, float chunkSize = 10.0f);
80 
86  ChunkHashGrid(std::string hdf5Path,
87  size_t cacheSize,
88  BoundingBox<BaseVector<float>> boundingBox,
89  float chunkSize);
90 
105  template <typename T>
106  void setGeometryChunk(std::string layer, int x, int y, int z, T data);
107 
122  template <typename T>
123  void setChunk(std::string layer, int x, int y, int z, T data);
124 
140  template <typename T>
141  boost::optional<T> getChunk(std::string layer, int x, int y, int z);
142 
151  bool isChunkLoaded(std::string layer, size_t hashValue);
152 
163  bool isChunkLoaded(std::string layer, int x, int y, int z);
164 
174  inline std::size_t hashValue(int i, int j, int k) const
175  {
178  }
179 
181  {
182  return m_boundingBox;
183  }
184 
185  float getChunkSize() const
186  {
187  return m_chunkSize;
188  }
189 
191  {
192  return m_chunkAmount;
193  }
194 
199  {
201  return offset * -1;
202  }
203 
208  {
212  return maxChunkIndex;
213  }
214 
220  void setBoundingBox(const BoundingBox<BaseVector<float>> boundingBox);
221 
222  protected:
229  void rehashCache(const BaseVector<std::size_t>& oldChunkAmount,
230  const BaseVector<std::size_t>& oldChunkIndexOffset);
231 
232  void expandBoundingBox(const val_type& data);
233 
245  template <typename T>
246  bool loadChunk(std::string layer, int x, int y, int z);
247 
261  void loadChunk(std::string layer, int x, int y, int z, const val_type& data);
262 
268  void setChunkSize(float chunkSize)
269  {
270  m_chunkSize = chunkSize;
271  m_io.saveChunkSize(m_chunkSize);
272  }
273 
274  // bounding box of the entire chunked model
275  // i had to make this protected because of the getGlobalBoundingBox() function in ChunkManager
277 
278  private:
285  void setChunkAmountAndOffset(const BaseVector<std::size_t>& chunkAmount,
286  const BaseVector<std::size_t>& chunkIndexOffset);
287 
288  private:
289  // chunkIO for the HDF5 file-IO
291 
292  // number of chunks that will be cached before deleting old chunks
293  size_t m_cacheSize;
294 
295  // ordered list to save recently used hashValues for the lru cache
296  std::list<std::pair<std::string, size_t>> m_items;
297 
298  // hash map containing chunked meshes
299  std::unordered_map<std::string, std::unordered_map<size_t, val_type>> m_hashGrid;
300 
301  // size of chunks
302  float m_chunkSize;
303 
304  // amount of chunks
306 
307  // offset of chunks to make chunk index start at 0
309 };
310 
311 } /* namespace lvr2 */
312 
313 #include "ChunkHashGrid.tcc"
314 
315 #endif // CHUNK_HASH_GRID_HPP
lvr2::ChunkHashGrid::rehashCache
void rehashCache(const BaseVector< std::size_t > &oldChunkAmount, const BaseVector< std::size_t > &oldChunkIndexOffset)
regenerates cache hash grid
Definition: ChunkHashGrid.cpp:85
lvr2::BaseVector< float >
lvr2::ChunkHashGrid::expandBoundingBox
void expandBoundingBox(const val_type &data)
Definition: ChunkHashGrid.cpp:130
lvr2::ChunkHashGrid::setBoundingBox
void setBoundingBox(const BoundingBox< BaseVector< float >> boundingBox)
sets the bounding box in this container and in persistend storage
Definition: ChunkHashGrid.cpp:172
lvr2::ChunkHashGrid::getChunk
boost::optional< T > getChunk(std::string layer, int x, int y, int z)
delivers the content of a chunk
lvr2::ChunkHashGrid::getBoundingBox
const BoundingBox< BaseVector< float > > & getBoundingBox() const
Definition: ChunkHashGrid.hpp:180
lvr2::ChunkHashGrid::m_cacheSize
size_t m_cacheSize
Definition: ChunkHashGrid.hpp:293
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::ChunkHashGrid::m_hashGrid
std::unordered_map< std::string, std::unordered_map< size_t, val_type > > m_hashGrid
Definition: ChunkHashGrid.hpp:299
lvr2::ChunkHashGrid::ChunkHashGrid
ChunkHashGrid(std::string hdf5Path, size_t cacheSize, float chunkSize=10.0f)
class to load chunks from an HDF5 file
Definition: ChunkHashGrid.cpp:39
lvr2::ChunkGeomtryChannelVisitor::operator()
FloatChannelOptional operator()(const PointBufferPtr points) const
Definition: ChunkHashGrid.hpp:61
lvr2::ChunkHashGrid
Definition: ChunkHashGrid.hpp:67
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::ChunkHashGrid::hashValue
std::size_t hashValue(int i, int j, int k) const
Calculates the hash value for the given index triple.
Definition: ChunkHashGrid.hpp:174
lvr2::FloatChannelOptional
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
lvr2::ChunkHashGrid::val_type
boost::variant< MeshBufferPtr, PointBufferPtr > val_type
Definition: ChunkHashGrid.hpp:70
lvr2::ChunkHashGrid::loadChunk
bool loadChunk(std::string layer, int x, int y, int z)
loads a chunk from persistent storage into cache
lvr2::ChunkGeomtryChannelVisitor
visitor that returns the channel that holds geometic information (like vertices-channel for meshes)
Definition: ChunkHashGrid.hpp:53
lvr2::ChunkHashGrid::getChunkSize
float getChunkSize() const
Definition: ChunkHashGrid.hpp:185
lvr2::BaseVector::y
CoordT y
Definition: BaseVector.hpp:66
PointBuffer.hpp
lvr2::ChunkHashGrid::m_chunkAmount
BaseVector< std::size_t > m_chunkAmount
Definition: ChunkHashGrid.hpp:305
lvr2::ChunkHashGrid::m_io
io m_io
Definition: ChunkHashGrid.hpp:290
lvr2::ChunkHashGrid::m_boundingBox
BoundingBox< BaseVector< float > > m_boundingBox
Definition: ChunkHashGrid.hpp:276
lvr2::ChunkGeomtryChannelVisitor::operator()
FloatChannelOptional operator()(const MeshBufferPtr mesh) const
Definition: ChunkHashGrid.hpp:56
lvr2::ChunkHashGrid::getChunkAmount
const BaseVector< std::size_t > & getChunkAmount() const
Definition: ChunkHashGrid.hpp:190
lvr2::ChunkHashGrid::m_items
std::list< std::pair< std::string, size_t > > m_items
Definition: ChunkHashGrid.hpp:296
lvr2::ChunkHashGrid::getChunkMinChunkIndex
BaseVector< int > getChunkMinChunkIndex() const
returns the minimum chunk ids
Definition: ChunkHashGrid.hpp:198
lvr2::ChunkHashGrid::setGeometryChunk
void setGeometryChunk(std::string layer, int x, int y, int z, T data)
sets a chunk of a given layer in hashgrid
MeshBuffer.hpp
ChunkIO.hpp
HDF5FeatureBase.hpp
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::ChunkHashGrid::io
Hdf5Build< hdf5features::ChunkIO > io
Definition: ChunkHashGrid.hpp:72
lvr2::BaseVector::z
CoordT z
Definition: BaseVector.hpp:67
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ChunkHashGrid::setChunk
void setChunk(std::string layer, int x, int y, int z, T data)
sets a chunk of a given layer in hashgrid
lvr2::MeshBufferPtr
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
lvr2::ChunkHashGrid::isChunkLoaded
bool isChunkLoaded(std::string layer, size_t hashValue)
indicates if wether or not a chunk is currently loaded in the local cache
lvr2::Hdf5Build
typename Hdf5Construct< Feature >::type Hdf5Build
Definition: HDF5FeatureBase.hpp:169
lvr2::ChunkHashGrid::setChunkAmountAndOffset
void setChunkAmountAndOffset(const BaseVector< std::size_t > &chunkAmount, const BaseVector< std::size_t > &chunkIndexOffset)
sets the amount of chunks in x y and z direction in this container and in persistent storage
Definition: ChunkHashGrid.cpp:202
lvr2::ChunkHashGrid::setChunkSize
void setChunkSize(float chunkSize)
sets chunk size in this container and in persistent storage
Definition: ChunkHashGrid.hpp:268
lvr2::ChunkHashGrid::getChunkMaxChunkIndex
BaseVector< int > getChunkMaxChunkIndex() const
returns the maximum chunk ids
Definition: ChunkHashGrid.hpp:207
lvr2::ChunkHashGrid::m_chunkSize
float m_chunkSize
Definition: ChunkHashGrid.hpp:302
mesh
HalfEdgeMesh< Vec > mesh
Definition: src/tools/lvr2_gs_reconstruction/Main.cpp:26
lvr2::ChunkHashGrid::m_chunkIndexOffset
BaseVector< std::size_t > m_chunkIndexOffset
Definition: ChunkHashGrid.hpp:308


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 Wed Mar 2 2022 00:37:23