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 
216 
217  /***
218  * @return Returns an iterator to the last query point
219  */
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 
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 
288 
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_ */
lvr2::HashGrid::calcIndex
int calcIndex(float f)
Definition: HashGrid.hpp:281
lvr2::HashGrid::box_map_it
unordered_map< size_t, BoxT * >::iterator box_map_it
Typedef to alias iterators for box maps.
Definition: HashGrid.hpp:106
lvr2::HashGrid::qp_bb
BoundingBox< BaseVecT > qp_bb
Definition: HashGrid.hpp:98
lvr2::GridBase::GridBase
GridBase(bool extrude=true)
Definition: HashGrid.hpp:58
lvr2::HashGrid::m_maxIndexX
size_t m_maxIndexX
The maximal index in x direction.
Definition: HashGrid.hpp:301
lvr2::HashGrid::m_voxelsize
float m_voxelsize
The voxelsize used for reconstruction.
Definition: HashGrid.hpp:292
lvr2::HashGrid::m_coordinateScales
BaseVecT m_coordinateScales
Save scaling factors (i.e., -1 or +1) to mapp different coordinate systems.
Definition: HashGrid.hpp:322
lvr2::HashGrid::saveGrid
virtual void saveGrid(string file)
Saves a representation of the grid to the given file.
lvr2::HashGrid::hashValue
size_t hashValue(int i, int j, int k) const
Calculates the hash value for the given index triple.
Definition: HashGrid.hpp:252
lvr2::HashGrid::query_point_it
vector< QueryPoint< BaseVecT > >::iterator query_point_it
Typedef to alias iterators to query points.
Definition: HashGrid.hpp:109
lvr2::GridBase::addLatticePoint
virtual void addLatticePoint(int i, int j, int k, float distance=0.0)=0
lvr2::HashGrid::lastQueryPoint
query_point_it lastQueryPoint()
Definition: HashGrid.hpp:220
lvr2::HashGrid::getMaxIndex
size_t getMaxIndex()
Definition: HashGrid.hpp:237
lvr2::HashGrid::m_maxIndexY
size_t m_maxIndexY
The maximal index in y direction.
Definition: HashGrid.hpp:304
lvr2::GridBase::m_extrude
bool m_extrude
Definition: HashGrid.hpp:90
lvr2::HashGrid::serialize
virtual void serialize(string file)
lvr2::HashGrid::setBB
void setBB(BoundingBox< BaseVecT > &bb)
lvr2::HashGrid::getMaxIndexY
size_t getMaxIndexY()
Definition: HashGrid.hpp:241
lvr2::HashGrid::getQueryPoints
vector< QueryPoint< BaseVecT > > & getQueryPoints()
Definition: HashGrid.hpp:222
lvr2::GridBase
Definition: HashGrid.hpp:54
lvr2::HashGrid::m_boundingBox
BoundingBox< BaseVecT > m_boundingBox
Bounding box of the covered volume.
Definition: HashGrid.hpp:316
lvr2::GridBase::~GridBase
virtual ~GridBase()
Definition: HashGrid.hpp:60
lvr2::HashGrid::setCoordinateScaling
void setCoordinateScaling(float x, float y, float z)
Set x, y, z values to scale the scene or use combinations of +/-1 to mapp different coordinate system...
lvr2::HashGrid::saveCells
void saveCells(string file)
Saves a representation of the cells to the given file.
lvr2::HashGrid::firstQueryPoint
query_point_it firstQueryPoint()
Definition: HashGrid.hpp:215
lvr2::HashGrid::getMaxIndexX
size_t getMaxIndexX()
Definition: HashGrid.hpp:239
lvr2::HashGrid::calcIndices
void calcIndices()
Calculates needed lattice parameters.
lvr2::GridBase::saveGrid
virtual void saveGrid(string file)=0
Saves a representation of the grid to the given file.
lvr2::HashGrid::getMaxIndexZ
size_t getMaxIndexZ()
Definition: HashGrid.hpp:243
lvr2::HashGrid::getNumberOfCells
size_t getNumberOfCells()
Definition: HashGrid.hpp:200
lvr2::HashGrid::firstCell
box_map_it firstCell()
Definition: HashGrid.hpp:205
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::HashGrid::m_maxIndexZ
size_t m_maxIndexZ
The maximal index in z direction.
Definition: HashGrid.hpp:307
file
FILE * file
Definition: arithmeticencoder.cpp:77
QueryPoint.hpp
lvr2::HashGrid::getCells
box_map getCells()
Definition: HashGrid.hpp:224
lvr2::HashGrid::box_map
unordered_map< size_t, BoxT * > box_map
Typedef to alias box map.
Definition: HashGrid.hpp:101
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::HashGrid::m_maxIndex
size_t m_maxIndex
The absolute maximal index of the reconstruction grid.
Definition: HashGrid.hpp:295
lvr2::HashGrid::m_qpIndices
qp_map m_qpIndices
Definition: HashGrid.hpp:289
lvr2::HashGrid::m_boxType
string m_boxType
True if a local tetraeder decomposition is used for reconstruction.
Definition: HashGrid.hpp:313
lvr2::HashGrid::addLatticePoint
virtual void addLatticePoint(int i, int j, int k, float distance=0.0)
lvr2::GridBase::setExtrusion
virtual void setExtrusion(bool extrude)
Definition: HashGrid.hpp:87
lvr2::HashGrid::getBoundingBox
BoundingBox< BaseVecT > & getBoundingBox()
Definition: HashGrid.hpp:247
lvr2::HashGrid::HashGrid
HashGrid(float cellSize, BoundingBox< BaseVecT > boundingBox, bool isVoxelSize=true, bool extrude=true)
lvr2::HashGrid::lastCell
box_map_it lastCell()
Definition: HashGrid.hpp:210
lvr2::HashGrid::qp_map
unordered_map< size_t, size_t > qp_map
Definition: HashGrid.hpp:103
lvr2::HashGrid::findQueryPoint
unsigned int findQueryPoint(int position, int x, int y, int z)
Searches for a existing shared lattice point in the grid.
BoundingBox.hpp
lvr2::HashGrid::m_cells
box_map m_cells
Map to handle the boxes in the grid.
Definition: HashGrid.hpp:287
lvr2::HashGrid::~HashGrid
virtual ~HashGrid()
lvr2::HashGrid::m_globalIndex
unsigned int m_globalIndex
The maximum used cell index within the grid.
Definition: HashGrid.hpp:319
lvr2::HashGrid
Definition: HashGrid.hpp:94
lvr2::HashGrid::m_queryPoints
vector< QueryPoint< BaseVecT > > m_queryPoints
A vector containing the query points for the reconstruction.
Definition: HashGrid.hpp:310
lvr2::HashGrid::m_maxIndexSquare
size_t m_maxIndexSquare
The squared maximal index of the reconstruction grid.
Definition: HashGrid.hpp:298


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