HashGrid.hpp
Go to the documentation of this file.
1 
28 /*
29  * HashGrid.hpp
30  *
31  * Created on: Nov 27, 2014
32  * Author: twiemann
33  */
34 
35 #ifndef _LVR2_RECONSTRUCTION_HASHGRID_H_
36 #define _LVR2_RECONSTRUCTION_HASHGRID_H_
37 
38 #include <unordered_map>
39 #include <vector>
40 #include <string>
41 
42 #include "QueryPoint.hpp"
43 
46 
47 using std::string;
48 using std::vector;
49 using std::unordered_map;
50 
51 namespace lvr2
52 {
53 
54 class GridBase
55 {
56 public:
57 
58  GridBase(bool extrude = true) : m_extrude(extrude) {}
59 
60  virtual ~GridBase() {}
61 
70  virtual void addLatticePoint(int i, int j, int k, float distance = 0.0) = 0;
71 
77  virtual void saveGrid(string file) = 0;
78 
79  /***
80  * @brief Is extrude is set to true, additional cells within the
81  * grid will be create to fill up holes consisting of single
82  * cells.
83  *
84  * @param extrude If set to true, additional cells will be created.
85  * Default value is true.
86  */
87  virtual void setExtrusion(bool extrude) { m_extrude = extrude; }
88 
89 protected:
90  bool m_extrude;
91 };
92 
93 template<typename BaseVecT, typename BoxT>
94 class HashGrid : public GridBase
95 {
96 public:
97 
99 
101  typedef unordered_map<size_t, BoxT*> box_map;
102 
103  typedef unordered_map<size_t, size_t> qp_map;
104 
106  typedef typename unordered_map<size_t, BoxT*>::iterator box_map_it;
107 
109  typedef typename vector<QueryPoint<BaseVecT>>::iterator query_point_it;
110 
111  /***
112  * @brief Constructor
113  *
114  * If set to true, cell size is interpreted as
115  * absolute voxel size (default). Otherwise \ref cellSize
116  * is interpreted as number of intersections along the
117  * longest size of the given bounding box to estimate a suitable
118  * resolution.
119  *
120  * @param cellSize Voxel size of the grid cells
121  * @param isVoxelSize Whether to interpret \ref cellSize as voxelsize or intersections
122  */
123  HashGrid(float cellSize, BoundingBox<BaseVecT> boundingBox, bool isVoxelSize = true, bool extrude = true);
124 
125 
126  /***
127  * @brief Constructor
128  *
129  * Construcs a HashGrid from a file
130  *
131  * @param file File representing the HashGrid (See HashGrid::serialize(string file) )
132  */
133  HashGrid(string file);
134 
135  /***
136  * @brief Construct a new Hash Grid object
137  *
138  * @param files
139  * @param boundingBox
140  * @param voxelsize
141  */
142  HashGrid(std::vector<string>& files, BoundingBox<BaseVecT>& boundingBox, float voxelsize);
143 
144 
145  /***
146  * @brief Construct a new Hash Grid object
147  *
148  * @param files vector of strings to the files which contain the voxel-grid data for the chunks
149  * @param innerBoxes vector of BoundingBoxes. Each chunk is only used for the BoundingBox.
150  * This is important because the data in the chunks may overlap.
151  * @param boundingBox bounding box of the complete grid
152  * @param voxelsize the voxelsize of the grid
153  */
154  HashGrid(std::vector<string>& files, std::vector<BoundingBox<BaseVecT>> innerBoxes, BoundingBox<BaseVecT>& boundingBox, float voxelsize);
155 
156  /***
157  * Constructs a new Hash Grid object from multiple PointBufferPtr,
158  * where the HashGrid attributes are saved in the PointBuffer-Channels.
159  *
160  * @param chunks vector with the voxel-grid data for the chunks
161  * @param innerBoxes vector of BoundingBoxes. Each chunk is only used for the BoundingBox.
162  * This is important because the data in the chunks may overlap.
163  * @param boundingBox bounding box of the complete grid
164  * @param voxelSize the voxelsize of the grid
165  */
166  HashGrid(std::vector<PointBufferPtr> chunks,
167  std::vector<BoundingBox<BaseVecT>> innerBoxes,
168  BoundingBox<BaseVecT>& boundingBox,
169  float voxelSize);
170 
179  virtual void addLatticePoint(int i, int j, int k, float distance = 0.0);
180 
186  virtual void saveGrid(string file);
187 
193  void saveCells(string file);
194 
195  virtual void serialize(string file);
196 
197  /***
198  * @brief Returns the number of generated cells.
199  */
200  size_t getNumberOfCells() { return m_cells.size(); }
201 
205  box_map_it firstCell() { return m_cells.begin(); }
206 
210  box_map_it lastCell() { return m_cells.end(); }
211 
215  query_point_it firstQueryPoint() { return m_queryPoints.begin(); }
216 
217  /***
218  * @return Returns an iterator to the last query point
219  */
220  query_point_it lastQueryPoint() { return m_queryPoints.end(); }
221 
222  vector<QueryPoint<BaseVecT>>& getQueryPoints() { return m_queryPoints; }
223 
224  box_map getCells() { return m_cells; }
225 
226  /***
227  * @brief Destructor
228  */
229  virtual ~HashGrid();
230 
235  void setCoordinateScaling(float x, float y, float z);
236 
237  size_t getMaxIndex() { return m_maxIndex; }
238 
239  size_t getMaxIndexX() { return m_maxIndexX; }
240 
241  size_t getMaxIndexY() { return m_maxIndexY; }
242 
243  size_t getMaxIndexZ() { return m_maxIndexZ; }
244 
245  void setBB(BoundingBox<BaseVecT>& bb);
246 
247  BoundingBox<BaseVecT> & getBoundingBox() { return m_boundingBox; }
248 
252  inline size_t hashValue(int i, int j, int k) const
253  {
254  return i * m_maxIndexSquare + j * m_maxIndex + k;
255  }
256 
266  unsigned int findQueryPoint(
267  int position,
268  int x,
269  int y,
270  int z
271  );
272 
276  void calcIndices();
277 
278 
279 protected:
280 
281  inline int calcIndex(float f)
282  {
283  return f < 0 ? f - .5 : f + .5;
284  }
285 
287  box_map m_cells;
288 
289  qp_map m_qpIndices;
290 
292  float m_voxelsize;
293 
295  size_t m_maxIndex;
296 
299 
301  size_t m_maxIndexX;
302 
304  size_t m_maxIndexY;
305 
307  size_t m_maxIndexZ;
308 
310  vector<QueryPoint<BaseVecT>> m_queryPoints;
311 
313  string m_boxType;
314 
317 
319  unsigned int m_globalIndex;
320 
323 };
324 
325 } /* namespace lvr */
326 
327 #include "HashGrid.tcc"
328 
329 #endif /* _LVR2_RECONSTRUCTION_HASHGRID_H_ */
size_t getMaxIndexY()
Definition: HashGrid.hpp:241
box_map_it lastCell()
Definition: HashGrid.hpp:210
virtual ~GridBase()
Definition: HashGrid.hpp:60
unordered_map< size_t, size_t > qp_map
Definition: HashGrid.hpp:103
size_t getMaxIndexZ()
Definition: HashGrid.hpp:243
size_t m_maxIndexSquare
The squared maximal index of the reconstruction grid.
Definition: HashGrid.hpp:298
box_map m_cells
Map to handle the boxes in the grid.
Definition: HashGrid.hpp:287
float m_voxelsize
The voxelsize used for reconstruction.
Definition: HashGrid.hpp:292
size_t getNumberOfCells()
Definition: HashGrid.hpp:200
unsigned int m_globalIndex
The maximum used cell index within the grid.
Definition: HashGrid.hpp:319
size_t m_maxIndexX
The maximal index in x direction.
Definition: HashGrid.hpp:301
box_map getCells()
Definition: HashGrid.hpp:224
query_point_it firstQueryPoint()
Definition: HashGrid.hpp:215
int calcIndex(float f)
Definition: HashGrid.hpp:281
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
BoundingBox< BaseVecT > & getBoundingBox()
Definition: HashGrid.hpp:247
unordered_map< size_t, BoxT * > box_map
Typedef to alias box map.
Definition: HashGrid.hpp:101
size_t m_maxIndexZ
The maximal index in z direction.
Definition: HashGrid.hpp:307
qp_map m_qpIndices
Definition: HashGrid.hpp:289
vector< QueryPoint< BaseVecT > > m_queryPoints
A vector containing the query points for the reconstruction.
Definition: HashGrid.hpp:310
virtual void setExtrusion(bool extrude)
Definition: HashGrid.hpp:87
query_point_it lastQueryPoint()
Definition: HashGrid.hpp:220
BoundingBox< BaseVecT > qp_bb
Definition: HashGrid.hpp:98
vector< QueryPoint< BaseVecT > >::iterator query_point_it
Typedef to alias iterators to query points.
Definition: HashGrid.hpp:109
vector< QueryPoint< BaseVecT > > & getQueryPoints()
Definition: HashGrid.hpp:222
FILE * file
size_t hashValue(int i, int j, int k) const
Calculates the hash value for the given index triple.
Definition: HashGrid.hpp:252
BoundingBox< BaseVecT > m_boundingBox
Bounding box of the covered volume.
Definition: HashGrid.hpp:316
GridBase(bool extrude=true)
Definition: HashGrid.hpp:58
box_map_it firstCell()
Definition: HashGrid.hpp:205
size_t getMaxIndex()
Definition: HashGrid.hpp:237
virtual void addLatticePoint(int i, int j, int k, float distance=0.0)=0
virtual void saveGrid(string file)=0
Saves a representation of the grid to the given file.
BaseVecT m_coordinateScales
Save scaling factors (i.e., -1 or +1) to mapp different coordinate systems.
Definition: HashGrid.hpp:322
size_t m_maxIndex
The absolute maximal index of the reconstruction grid.
Definition: HashGrid.hpp:295
unordered_map< size_t, BoxT * >::iterator box_map_it
Typedef to alias iterators for box maps.
Definition: HashGrid.hpp:106
string m_boxType
True if a local tetraeder decomposition is used for reconstruction.
Definition: HashGrid.hpp:313
size_t m_maxIndexY
The maximal index in y direction.
Definition: HashGrid.hpp:304
size_t getMaxIndexX()
Definition: HashGrid.hpp:239


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