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  {
176  return (i + m_chunkIndexOffset.x) * m_chunkAmount.y * m_chunkAmount.z
177  + (j + m_chunkIndexOffset.y) * m_chunkAmount.z + k + m_chunkIndexOffset.z;
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  {
200  BaseVector<int> offset(m_chunkIndexOffset.x, m_chunkIndexOffset.y, m_chunkIndexOffset.z);
201  return offset * -1;
202  }
203 
208  {
209  BaseVector<int> maxChunkIndex(m_chunkAmount.x - m_chunkIndexOffset.x,
210  m_chunkAmount.y - m_chunkIndexOffset.y,
211  m_chunkAmount.z - m_chunkIndexOffset.z);
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
BaseVector< int > getChunkMaxChunkIndex() const
returns the maximum chunk ids
const BoundingBox< BaseVector< float > > & getBoundingBox() const
float getChunkSize() const
HalfEdgeMesh< Vec > mesh
std::shared_ptr< MeshBuffer > MeshBufferPtr
Definition: MeshBuffer.hpp:217
FloatChannelOptional operator()(const PointBufferPtr points) const
FloatChannelOptional operator()(const MeshBufferPtr mesh) const
std::size_t hashValue(int i, int j, int k) const
Calculates the hash value for the given index triple.
const BaseVector< std::size_t > & getChunkAmount() const
visitor that returns the channel that holds geometic information (like vertices-channel for meshes) ...
BaseVector< std::size_t > m_chunkIndexOffset
std::shared_ptr< PointBuffer > PointBufferPtr
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
typename Hdf5Construct< Feature >::type Hdf5Build
BaseVector< int > getChunkMinChunkIndex() const
returns the minimum chunk ids
boost::variant< MeshBufferPtr, PointBufferPtr > val_type
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
void setChunkSize(float chunkSize)
sets chunk size in this container and in persistent storage
Hdf5Build< hdf5features::ChunkIO > io
BoundingBox< BaseVector< float > > m_boundingBox
std::list< std::pair< std::string, size_t > > m_items
std::unordered_map< std::string, std::unordered_map< size_t, val_type > > m_hashGrid
BaseVector< std::size_t > m_chunkAmount


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