Main MRPT website > C++ reference
MRPT logo
COccupancyGridMap2D.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef COccupancyGridMap2D_H
11 #define COccupancyGridMap2D_H
12 
15 #include <mrpt/utils/CImage.h>
17 #include <mrpt/slam/CMetricMap.h>
21 #include <mrpt/poses/poses_frwds.h>
22 
23 #include <mrpt/maps/link_pragmas.h>
24 
25 #include <mrpt/config.h>
26 
27 #if !defined(OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS) && !defined(OCCUPANCY_GRIDMAP_CELL_SIZE_16BITS)
28  #error One of OCCUPANCY_GRIDMAP_CELL_SIZE_16BITS or OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS must be defined.
29 #endif
30 
31 #if defined(OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS) && defined(OCCUPANCY_GRIDMAP_CELL_SIZE_16BITS)
32  #error Only one of OCCUPANCY_GRIDMAP_CELL_SIZE_16BITS or OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS must be defined at a time.
33 #endif
34 
35 
36 namespace mrpt
37 {
38 namespace slam
39 {
40  using namespace mrpt::poses;
41  using namespace mrpt::utils;
42 
43  class CObservation2DRangeScan;
44  class CObservationRange;
45  class CObservation;
46  class CPointsMap;
47 
48  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( COccupancyGridMap2D, CMetricMap, MAPS_IMPEXP )
49 
50  /** A class for storing an occupancy grid map.
51  * COccupancyGridMap2D is a class for storing a metric map
52  * representation in the form of a probabilistic occupancy
53  * grid map: value of 0 means certainly occupied, 1 means
54  * a certainly empty cell. Initially 0.5 means uncertainty.
55  *
56  * The cells keep the log-odd representation of probabilities instead of the probabilities themselves.
57  * More details can be found at http://www.mrpt.org/Occupancy_Grids
58  *
59  * The algorithm for updating the grid from a laser scanner can optionally take into account the progressive widening of the beams, as
60  * described in the <a href="http://www.mrpt.org/Occupancy_Grids" > wiki </a> (this feature was introduced in MRPT 0.6.4).
61  *
62  * Some implemented methods are:
63  * - Update of individual cells
64  * - Insertion of observations
65  * - Voronoi diagram and critical points (\a buildVoronoiDiagram)
66  * - Saving and loading from/to a bitmap
67  * - Laser scans simulation for the map contents
68  * - Entropy and information methods (See computeEntropy)
69  *
70  * \ingroup mrpt_maps_grp
71  **/
73  public CMetricMap,
74  // Inherit from the corresponding specialization of CLogOddsGridMap2D<>:
75 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
77 #else
79 #endif
80  {
81  // This must be added to any CSerializable derived class:
83 
84  public:
85  /** The type of the map cells: */
86 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
87  typedef int8_t cellType;
88  typedef uint8_t cellTypeUnsigned;
89 #else
90  typedef int16_t cellType;
91  typedef uint16_t cellTypeUnsigned;
92 #endif
93 
94  /** Discrete to float conversion factors: The min/max values of the integer cell type, eg.[0,255] or [0,65535] */
95  static const cellType OCCGRID_CELLTYPE_MIN = CLogOddsGridMap2D<cellType>::CELLTYPE_MIN;
96  static const cellType OCCGRID_CELLTYPE_MAX = CLogOddsGridMap2D<cellType>::CELLTYPE_MAX;
97  static const cellType OCCGRID_P2LTABLE_SIZE = CLogOddsGridMap2D<cellType>::P2LTABLE_SIZE;
98 
99  protected:
100 
101  friend class CMultiMetricMap;
102  friend class CMultiMetricMapPDF;
103 
104  static CLogOddsGridMapLUT<cellType> m_logodd_lut; //!< Lookup tables for log-odds
105 
106  /** This is the buffer for storing the cells.In this dynamic
107  * size buffer are stored the cell values as
108  * "bytes", stored row by row, from left to right cells.
109  */
110  std::vector<cellType> map;
111 
112  /** The size of the grid in cells.
113  */
114  uint32_t size_x,size_y;
115 
116  /** The limits of the grid in "units" (meters).
117  */
118  float x_min,x_max,y_min,y_max;
119 
120  /** Cell size, i.e. resolution of the grid map.
121  */
122  float resolution;
123 
124  /** These are auxiliary variables to speed up the computation of observation likelihood values for LF method among others, at a high cost in memory (see TLikelihoodOptions::enableLikelihoodCache).
125  */
126  std::vector<double> precomputedLikelihood;
128 
129  /** Used for Voronoi calculation.Same struct as "map", but contains a "0" if not a basis point. */
131 
132  /** Used to store the Voronoi diagram.
133  * Contains the distance of each cell to its closer obstacles
134  * in 1/100th distance units (i.e. in centimeters), or 0 if not into the Voronoi diagram.
135  */
137 
138  bool m_is_empty; //!< True upon construction; used by isEmpty()
139 
140  virtual void OnPostSuccesfulInsertObs(const CObservation *); //!< See base class
141 
142  /** The free-cells threshold used to compute the Voronoi diagram.
143  */
145 
146  /** Frees the dynamic memory buffers of map.
147  */
148  void freeMap();
149 
150  /** Entropy computation internal function:
151  */
152  static double H(double p);
153 
154  /** Change the contents [0,1] of a cell, given its index.
155  */
156  inline void setCell_nocheck(int x,int y,float value)
157  {
158  map[x+y*size_x]=p2l(value);
159  }
160 
161  /** Read the real valued [0,1] contents of a cell, given its index.
162  */
163  inline float getCell_nocheck(int x,int y) const
164  {
165  return l2p(map[x+y*size_x]);
166  }
167 
168  /** Changes a cell by its absolute index (Do not use it normally)
169  */
170  inline void setRawCell(unsigned int cellIndex, cellType b)
171  {
172  if (cellIndex<size_x*size_y)
173  {
174  map[cellIndex] = b;
175  }
176  }
177 
178  /** Internally used to speed-up entropy calculation
179  */
180  static std::vector<float> entropyTable;
181 
182 
183  /** One of the methods that can be selected for implementing "computeObservationLikelihood" (This method is the Range-Scan Likelihood Consensus for gridmaps, see the ICRA2007 paper by Blanco et al.)
184  */
185  double computeObservationLikelihood_Consensus(
186  const CObservation *obs,
187  const CPose2D &takenFrom );
188 
189  /** One of the methods that can be selected for implementing "computeObservationLikelihood"
190  * TODO: This method is described in....
191  */
192  double computeObservationLikelihood_ConsensusOWA(
193  const CObservation *obs,
194  const CPose2D &takenFrom );
195 
196  /** One of the methods that can be selected for implementing "computeObservationLikelihood".
197  */
198  double computeObservationLikelihood_CellsDifference(
199  const CObservation *obs,
200  const CPose2D &takenFrom );
201 
202  /** One of the methods that can be selected for implementing "computeObservationLikelihood".
203  */
204  double computeObservationLikelihood_MI(
205  const CObservation *obs,
206  const CPose2D &takenFrom );
207 
208  /** One of the methods that can be selected for implementing "computeObservationLikelihood".
209  */
210  double computeObservationLikelihood_rayTracing(
211  const CObservation *obs,
212  const CPose2D &takenFrom );
213 
214  /** One of the methods that can be selected for implementing "computeObservationLikelihood".
215  */
216  double computeObservationLikelihood_likelihoodField_Thrun(
217  const CObservation *obs,
218  const CPose2D &takenFrom );
219 
220  /** One of the methods that can be selected for implementing "computeObservationLikelihood".
221  */
222  double computeObservationLikelihood_likelihoodField_II(
223  const CObservation *obs,
224  const CPose2D &takenFrom );
225 
226  /** Clear the map: It set all cells to their default occupancy value (0.5), without changing the resolution (the grid extension is reset to the default values).
227  */
228  virtual void internal_clear( );
229 
230  /** Insert the observation information into this map.
231  *
232  * \param obs The observation
233  * \param robotPose The 3D pose of the robot mobile base in the map reference system, or NULL (default) if you want to use CPose2D(0,0,deg)
234  *
235  * After successfull execution, "lastObservationInsertionInfo" is updated.
236  *
237  * \sa insertionOptions, CObservation::insertObservationInto
238  */
239  virtual bool internal_insertObservation( const CObservation *obs, const CPose3D *robotPose = NULL );
240 
241  public:
242  /** Read-only access to the raw cell contents (cells are in log-odd units) */
243  const std::vector<cellType> & getRawMap() const { return this->map; }
244 
245  /** Performs the Bayesian fusion of a new observation of a cell.
246  * \sa updateInfoChangeOnly, updateCell_fast_occupied, updateCell_fast_free
247  */
248  void updateCell(int x,int y, float v);
249 
250  /** An internal structure for storing data related to counting the new information apported by some observation.
251  */
253  {
254  TUpdateCellsInfoChangeOnly( bool enabled = false,
255  double I_change = 0,
256  int cellsUpdated=0) : enabled(enabled),
257  I_change(I_change),
258  cellsUpdated(cellsUpdated),
259  laserRaysSkip(1)
260  {
261  }
262 
263  /** If set to false (default), this struct is not used. Set to true only when measuring the info of an observation.
264  */
265  bool enabled;
266 
267  /** The cummulative change in Information: This is updated only from the "updateCell" method.
268  */
269  double I_change;
270 
271  /** The cummulative updated cells count: This is updated only from the "updateCell" method.
272  */
274 
275  /** In this mode, some laser rays can be skips to speep-up
276  */
278  } updateInfoChangeOnly;
279 
280  /** Constructor.
281  */
282  COccupancyGridMap2D( float min_x = -20.0f,
283  float max_x = 20.0f,
284  float min_y = -20.0f,
285  float max_y = 20.0f,
286  float resolution = 0.05f
287  );
288 
289  /** Fills all the cells with a default value.
290  */
291  void fill(float default_value = 0.5f );
292 
293  /** Destructor.
294  */
295  virtual ~COccupancyGridMap2D();
296 
297  /** Change the size of gridmap, erasing all its previous contents.
298  * \param x_min The "x" coordinates of left most side of grid.
299  * \param x_max The "x" coordinates of right most side of grid.
300  * \param y_min The "y" coordinates of top most side of grid.
301  * \param y_max The "y" coordinates of bottom most side of grid.
302  * \param resolution The new size of cells.
303  * \param default_value The value of cells, tipically 0.5.
304  * \sa ResizeGrid
305  */
306  void setSize(float x_min,float x_max,float y_min,float y_max,float resolution,float default_value = 0.5f);
307 
308  /** Change the size of gridmap, maintaining previous contents.
309  * \param new_x_min The "x" coordinates of new left most side of grid.
310  * \param new_x_max The "x" coordinates of new right most side of grid.
311  * \param new_y_min The "y" coordinates of new top most side of grid.
312  * \param new_y_max The "y" coordinates of new bottom most side of grid.
313  * \param new_cells_default_value The value of the new cells, tipically 0.5.
314  * \param additionalMargin If set to true (default), an additional margin of a few meters will be added to the grid, ONLY if the new coordinates are larger than current ones.
315  * \sa setSize
316  */
317  void resizeGrid(float new_x_min,float new_x_max,float new_y_min,float new_y_max,float new_cells_default_value = 0.5f, bool additionalMargin = true) MRPT_NO_THROWS;
318 
319  /** Returns the area of the gridmap, in square meters */
320  inline double getArea() const { return size_x*size_y*square(resolution); }
321 
322  /** Returns the horizontal size of grid map in cells count.
323  */
324  inline unsigned int getSizeX() const { return size_x; }
325 
326  /** Returns the vertical size of grid map in cells count.
327  */
328  inline unsigned int getSizeY() const { return size_y; }
329 
330  /** Returns the "x" coordinate of left side of grid map.
331  */
332  inline float getXMin() const { return x_min; }
333 
334  /** Returns the "x" coordinate of right side of grid map.
335  */
336  inline float getXMax() const { return x_max; }
337 
338  /** Returns the "y" coordinate of top side of grid map.
339  */
340  inline float getYMin() const { return y_min; }
341 
342  /** Returns the "y" coordinate of bottom side of grid map.
343  */
344  inline float getYMax() const { return y_max; }
345 
346  /** Returns the resolution of the grid map.
347  */
348  inline float getResolution() const { return resolution; }
349 
350  /** Transform a coordinate value into a cell index.
351  */
352  inline int x2idx(float x) const { return static_cast<int>((x-x_min)/resolution ); }
353  inline int y2idx(float y) const { return static_cast<int>((y-y_min)/resolution ); }
354 
355  inline int x2idx(double x) const { return static_cast<int>((x-x_min)/resolution ); }
356  inline int y2idx(double y) const { return static_cast<int>((y-y_min)/resolution ); }
357 
358  /** Transform a cell index into a coordinate value.
359  */
360  inline float idx2x(const size_t cx) const { return x_min+(cx+0.5f)*resolution; }
361  inline float idx2y(const size_t cy) const { return y_min+(cy+0.5f)*resolution; }
362 
363  /** Transform a coordinate value into a cell index, using a diferent "x_min" value
364  */
365  inline int x2idx(float x,float x_min) const { return static_cast<int>((x-x_min)/resolution ); }
366  inline int y2idx(float y, float y_min) const { return static_cast<int>((y-y_min)/resolution ); }
367 
368  /** Scales an integer representation of the log-odd into a real valued probability in [0,1], using p=exp(l)/(1+exp(l))
369  */
370  static inline float l2p(const cellType l)
371  {
372  return m_logodd_lut.l2p(l);
373  }
374 
375  /** Scales an integer representation of the log-odd into a linear scale [0,255], using p=exp(l)/(1+exp(l))
376  */
377  static inline uint8_t l2p_255(const cellType l)
378  {
379  return m_logodd_lut.l2p_255(l);
380  }
381 
382  /** Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the valid range of cellType.
383  */
384  static inline cellType p2l(const float p)
385  {
386  return m_logodd_lut.p2l(p);
387  }
388 
389  /** Change the contents [0,1] of a cell, given its index.
390  */
391  inline void setCell(int x,int y,float value)
392  {
393  // The x> comparison implicitly holds if x<0
394  if (static_cast<unsigned int>(x)>=size_x || static_cast<unsigned int>(y)>=size_y)
395  return;
396  else map[x+y*size_x]=p2l(value);
397  }
398 
399  /** Read the real valued [0,1] contents of a cell, given its index.
400  */
401  inline float getCell(int x,int y) const
402  {
403  // The x> comparison implicitly holds if x<0
404  if (static_cast<unsigned int>(x)>=size_x || static_cast<unsigned int>(y)>=size_y)
405  return 0.5f;
406  else return l2p(map[x+y*size_x]);
407  }
408 
409  /** Access to a "row": mainly used for drawing grid as a bitmap efficiently, do not use it normally.
410  */
411  inline cellType *getRow( int cy ) { if (cy<0 || static_cast<unsigned int>(cy)>=size_y) return NULL; else return &map[0+cy*size_x]; }
412 
413  /** Access to a "row": mainly used for drawing grid as a bitmap efficiently, do not use it normally.
414  */
415  inline const cellType *getRow( int cy ) const { if (cy<0 || static_cast<unsigned int>(cy)>=size_y) return NULL; else return &map[0+cy*size_x]; }
416 
417  /** Change the contents [0,1] of a cell, given its coordinates.
418  */
419  inline void setPos(float x,float y,float value) { setCell(x2idx(x),y2idx(y),value); }
420 
421  /** Read the real valued [0,1] contents of a cell, given its coordinates.
422  */
423  inline float getPos(float x,float y) const { return getCell(x2idx(x),y2idx(y)); }
424 
425  /** Returns "true" if cell is "static", i.e.if its occupancy is below a given threshold.
426  */
427  inline bool isStaticPos(float x,float y,float threshold = 0.7f) const { return isStaticCell(x2idx(x),y2idx(y),threshold); }
428  inline bool isStaticCell(int cx,int cy,float threshold = 0.7f) const { return (getCell(cx,cy)<=threshold); }
429 
430  /** Change a cell in the "basis" maps.Used for Voronoi calculation.
431  */
432  inline void setBasisCell(int x,int y,uint8_t value)
433  {
434  uint8_t *cell=m_basis_map.cellByIndex(x,y);
435 #ifdef _DEBUG
436  ASSERT_ABOVEEQ_(x,0)
437  ASSERT_ABOVEEQ_(y,0)
438  ASSERT_BELOWEQ_(x,int(m_basis_map.getSizeX()))
439  ASSERT_BELOWEQ_(y,int(m_basis_map.getSizeY()))
440 #endif
441  *cell = value;
442  }
443 
444  /** Reads a cell in the "basis" maps.Used for Voronoi calculation.
445  */
446  inline unsigned char getBasisCell(int x,int y) const
447  {
448  const uint8_t *cell=m_basis_map.cellByIndex(x,y);
449 #ifdef _DEBUG
450  ASSERT_ABOVEEQ_(x,0)
451  ASSERT_ABOVEEQ_(y,0)
452  ASSERT_BELOWEQ_(x,int(m_basis_map.getSizeX()))
453  ASSERT_BELOWEQ_(y,int(m_basis_map.getSizeY()))
454 #endif
455  return *cell;
456  }
457 
458  /** Used for returning entropy related information
459  * \sa computeEntropy
460  */
462  {
463  TEntropyInfo() : H(0),I(0),mean_H(0),mean_I(0),effectiveMappedArea(0),effectiveMappedCells(0)
464  {
465  }
466 
467  /** The target variable for absolute entropy, computed as:<br><center>H(map)=Sum<sub>x,y</sub>{ -p(x,y)·ln(p(x,y)) -(1-p(x,y))·ln(1-p(x,y)) }</center><br><br>
468  */
469  double H;
470 
471  /** The target variable for absolute "information", defining I(x) = 1 - H(x)
472  */
473  double I;
474 
475  /** The target variable for mean entropy, defined as entropy per cell: mean_H(map) = H(map) / (cells)
476  */
477  double mean_H;
478 
479  /** The target variable for mean information, defined as information per cell: mean_I(map) = I(map) / (cells)
480  */
481  double mean_I;
482 
483  /** The target variable for the area of cells with information, i.e. p(x)!=0.5
484  */
486 
487  /** The mapped area in cells.
488  */
489  unsigned long effectiveMappedCells;
490  };
491 
492  /** With this struct options are provided to the observation insertion process.
493  * \sa CObservation::insertIntoGridMap
494  */
496  {
497  public:
498  /** Initilization of default parameters
499  */
501 
502  /** This method load the options from a ".ini" file.
503  * Only those parameters found in the given "section" and having
504  * the same name that the variable are loaded. Those not found in
505  * the file will stay with their previous values (usually the default
506  * values loaded at initialization). An example of an ".ini" file:
507  * \code
508  * [section]
509  * resolution=0.10 ; blah blah...
510  * modeSelection=1 ; 0=blah, 1=blah,...
511  * \endcode
512  */
513  void loadFromConfigFile(
514  const mrpt::utils::CConfigFileBase &source,
515  const std::string &section);
516 
517  /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream.
518  */
519  void dumpToTextStream(CStream &out) const;
520 
521 
522  /** The altitude (z-axis) of 2D scans (within a 0.01m tolerance) for they to be inserted in this map!
523  */
524  float mapAltitude;
525 
526  /** The parameter "mapAltitude" has effect while inserting observations in the grid only if this is true.
527  */
529 
530  /** The largest distance at which cells will be updated (Default 15 meters)
531  */
533 
534  /** A value in the range [0.5,1] used for updating cell with a bayesian approach (default 0.8)
535  */
537 
538  /** If set to true (default), invalid range values (no echo rays) as consider as free space until "maxOccupancyUpdateCertainty", but ONLY when the previous and next rays are also an invalid ray.
539  */
541 
542  /** Specify the decimation of the range scan (default=1 : take all the range values!)
543  */
544  uint16_t decimation;
545 
546  /** The tolerance in rads in pitch & roll for a laser scan to be considered horizontal, then processed by calls to this class (default=0). */
548 
549  /** Gaussian sigma of the filter used in getAsImageFiltered (for features detection) (Default=1) (0:Disabled) */
551 
552  /** Size of the Median filter used in getAsImageFiltered (for features detection) (Default=3) (0:Disabled) */
554 
555  bool wideningBeamsWithDistance; //!< Enabled: Rays widen with distance to approximate the real behavior of lasers, disabled: insert rays as simple lines (Default=false)
556 
557  };
558 
559  /** With this struct options are provided to the observation insertion process.
560  * \sa CObservation::insertIntoGridMap
561  */
563 
564  /** The type for selecting a likelihood computation method
565  */
567  {
568  lmMeanInformation = 0,
574  lmConsensusOWA
575  };
576 
577  /** With this struct options are provided to the observation likelihood computation process.
578  */
580  {
581  public:
582  /** Initilization of default parameters
583  */
585 
586  /** This method load the options from a ".ini" file.
587  * Only those parameters found in the given "section" and having
588  * the same name that the variable are loaded. Those not found in
589  * the file will stay with their previous values (usually the default
590  * values loaded at initialization). An example of an ".ini" file:
591  * \code
592  * [section]
593  * resolution=0.10 ; blah blah...
594  * modeSelection=1 ; 0=blah, 1=blah,...
595  * \endcode
596  */
597  void loadFromConfigFile(
598  const mrpt::utils::CConfigFileBase &source,
599  const std::string &section);
600 
601  /** This method must display clearly all the contents of the structure in textual form, sending it to a CStream.
602  */
603  void dumpToTextStream(CStream &out) const;
604 
605  /** The selected method to compute an observation likelihood.
606  */
608 
609  /** [LikelihoodField] The laser range "sigma" used in computations; Default value = 0.35
610  */
611  float LF_stdHit;
612 
613  /** [LikelihoodField] Ratios of the hit/random components of the likelihood; Default values=0.95/0.5
614  */
615  float LF_zHit, LF_zRandom;
616 
617  /** [LikelihoodField] The max. range of the sensor (def=81meters)
618  */
619  float LF_maxRange;
620 
621  /** [LikelihoodField] The decimation of the points in a scan, default=1 == no decimation.
622  */
623  uint32_t LF_decimation;
624 
625  /** [LikelihoodField] The max. distance for searching correspondences around each sensed point
626  */
628 
629  /** [LikelihoodField] Set this to "true" ot use an alternative method, where the likelihood of the whole range scan is computed by "averaging" of individual ranges, instead of by the "product".
630  */
632 
633  /** [MI] The exponent in the MI likelihood computation. Default value = 5
634  */
635  float MI_exponent;
636 
637  /** [MI] The scan rays decimation: at every N rays, one will be used to compute the MI:
638  */
639  uint32_t MI_skip_rays;
640 
641  /** [MI] The ratio for the max. distance used in the MI computation and in the insertion of scans, e.g. if set to 2.0 the MI will use twice the distance that the update distance.
642  */
644 
645  /** [rayTracing] If true (default), the rayTracing method will ignore measured ranges shorter than the simulated ones.
646  */
648 
649  /** [rayTracing] One out of "rayTracing_decimation" rays will be simulated and compared only: set to 1 to use all the sensed ranges.
650  */
652 
653  /** [rayTracing] The laser range sigma.
654  */
656 
657  /** [Consensus] The down-sample ratio of ranges (default=1, consider all the ranges)
658  */
660 
661  /** [Consensus] The power factor for the likelihood (default=5)
662  */
664 
665  /** [OWA] The sequence of weights to be multiplied to of the ordered list of likelihood values (first one is the largest); the size of this vector determines the number of highest likelihood values to fuse.
666  */
667  std::vector<float> OWA_weights;
668 
669  /** Enables the usage of a cache of likelihood values (for LF methods), if set to true (default=false).
670  */
672 
673  } likelihoodOptions;
674 
675  /** Auxiliary private class.
676  */
677  typedef std::pair<double,mrpt::math::TPoint2D> TPairLikelihoodIndex;
678 
679  /** Some members of this struct will contain intermediate or output data after calling "computeObservationLikelihood" for some likelihood functions.
680  */
682  {
683  public:
684  TLikelihoodOutput() : OWA_pairList(), OWA_individualLikValues()
685  {}
686 
687  /** [OWA method] This will contain the ascending-ordered list of pairs:(likelihood values, 2D point in map coordinates).
688  */
689  std::vector<TPairLikelihoodIndex> OWA_pairList;
690 
691  /** [OWA method] This will contain the ascending-ordered list of likelihood values for individual range measurements in the scan.
692  */
693  std::vector<double> OWA_individualLikValues;
694 
695  } likelihoodOutputs;
696 
697  /** Performs a downsampling of the gridmap, by a given factor: resolution/=ratio
698  */
699  void subSample( int downRatio );
700 
701  /** Computes the entropy and related values of this grid map.
702  * The entropy is computed as the summed entropy of each cell, taking them as discrete random variables following a Bernoulli distribution:
703  * \param info The output information is returned here.
704  */
705  void computeEntropy( TEntropyInfo &info ) const;
706 
707  /** @name Voronoi methods
708  @{ */
709 
710  /** Build the Voronoi diagram of the grid map.
711  * \param threshold The threshold for binarizing the map.
712  * \param robot_size Size in "units" (meters) of robot, approx.
713  * \param x1 Left coordinate of area to be computed. Default, entire map.
714  * \param x2 Right coordinate of area to be computed. Default, entire map.
715  * \param y1 Top coordinate of area to be computed. Default, entire map.
716  * \param y2 Bottom coordinate of area to be computed. Default, entire map.
717  * \sa findCriticalPoints
718  */
719  void buildVoronoiDiagram(float threshold, float robot_size,int x1=0,int x2=0, int y1=0,int y2=0);
720 
721  /** Reads a the clearance of a cell (in centimeters), after building the Voronoi diagram with \a buildVoronoiDiagram */
722  inline uint16_t getVoroniClearance(int cx,int cy) const
723  {
724 #ifdef _DEBUG
725  ASSERT_ABOVEEQ_(cx,0)
726  ASSERT_ABOVEEQ_(cy,0)
727  ASSERT_BELOWEQ_(cx,int(m_voronoi_diagram.getSizeX()))
728  ASSERT_BELOWEQ_(cy,int(m_voronoi_diagram.getSizeY()))
729 #endif
730  const uint16_t *cell=m_voronoi_diagram.cellByIndex(cx,cy);
731  return *cell;
732  }
733 
734  protected:
735  /** Used to set the clearance of a cell, while building the Voronoi diagram. */
736  inline void setVoroniClearance(int cx,int cy,uint16_t dist)
737  {
738  uint16_t *cell=m_voronoi_diagram.cellByIndex(cx,cy);
739 #ifdef _DEBUG
740  ASSERT_ABOVEEQ_(cx,0)
741  ASSERT_ABOVEEQ_(cy,0)
742  ASSERT_BELOWEQ_(cx,int(m_voronoi_diagram.getSizeX()))
743  ASSERT_BELOWEQ_(cy,int(m_voronoi_diagram.getSizeY()))
744 #endif
745  *cell = dist;
746  }
747 
748  public:
749 
750  /** Return the auxiliary "basis" map built while building the Voronoi diagram \sa buildVoronoiDiagram */
751  inline const CDynamicGrid<uint8_t> & getBasisMap() const { return m_basis_map; }
752 
753  /** Return the Voronoi diagram; each cell contains the distance to its closer obstacle, or 0 if not part of the Voronoi diagram \sa buildVoronoiDiagram */
754  inline const CDynamicGrid<uint16_t> & getVoronoiDiagram() const { return m_voronoi_diagram; }
755 
756  /** Builds a list with the critical points from Voronoi diagram, which must
757  * must be built before calling this method.
758  * \param filter_distance The minimum distance between two critical points.
759  * \sa buildVoronoiDiagram
760  */
761  void findCriticalPoints( float filter_distance );
762 
763  /** @} */ // End of Voronoi methods
764 
765 
766  /** Compute the clearance of a given cell, and returns its two first
767  * basis (closest obstacle) points.Used to build Voronoi and critical points.
768  * \return The clearance of the cell, in 1/100 of "cell".
769  * \param cx The cell index
770  * \param cy The cell index
771  * \param basis_x Target buffer for coordinates of basis, having a size of two "ints".
772  * \param basis_y Target buffer for coordinates of basis, having a size of two "ints".
773  * \param nBasis The number of found basis: Can be 0,1 or 2.
774  * \param GetContourPoint If "true" the basis are not returned, but the closest free cells.Default at false.
775  * \sa Build_VoronoiDiagram
776  */
777  int computeClearance( int cx, int cy, int *basis_x, int *basis_y, int *nBasis, bool GetContourPoint = false ) const;
778 
779  /** An alternative method for computing the clearance of a given location (in meters).
780  * \return The clearance (distance to closest OCCUPIED cell), in meters.
781  */
782  float computeClearance( float x, float y, float maxSearchDistance ) const;
783 
784  /** Compute the 'cost' of traversing a segment of the map according to the occupancy of traversed cells.
785  * \return This returns '1-mean(traversed cells occupancy)', i.e. 0.5 for unknown cells, 1 for a free path.
786  */
787  float computePathCost( float x1, float y1, float x2, float y2 ) const;
788 
789 
790  /** \name Sensor simulators
791  @{
792  */
793 
794  /** Simulates a laser range scan into the current grid map.
795  * The simulated scan is stored in a CObservation2DRangeScan object, which is also used
796  * to pass some parameters: all previously stored characteristics (as aperture,...) are
797  * taken into account for simulation. Only a few more parameters are needed. Additive gaussian noise can be optionally added to the simulated scan.
798  * \param inout_Scan [IN/OUT] This must be filled with desired parameters before calling, and will contain the scan samples on return.
799  * \param robotPose [IN] The robot pose in this map coordinates. Recall that sensor pose relative to this robot pose must be specified in the observation object.
800  * \param threshold [IN] The minimum occupancy threshold to consider a cell to be occupied, for example 0.5.
801  * \param N [IN] The count of range scan "rays", by default to 361.
802  * \param noiseStd [IN] The standard deviation of measurement noise. If not desired, set to 0.
803  * \param decimation [IN] The rays that will be simulated are at indexes: 0, D, 2D, 3D, ... Default is D=1
804  * \param angleNoiseStd [IN] The sigma of an optional Gaussian noise added to the angles at which ranges are measured (in radians).
805  *
806  * \sa sonarSimulator
807  */
808  void laserScanSimulator(
809  CObservation2DRangeScan &inout_Scan,
810  const CPose2D &robotPose,
811  float threshold = 0.5f,
812  size_t N = 361,
813  float noiseStd = 0,
814  unsigned int decimation = 1,
815  float angleNoiseStd = DEG2RAD(0) ) const;
816 
817  /** Simulates the observations of a sonar rig into the current grid map.
818  * The simulated ranges are stored in a CObservationRange object, which is also used
819  * to pass in some needed parameters, as the poses of the sonar sensors onto the mobile robot.
820  * \param inout_observation [IN/OUT] This must be filled with desired parameters before calling, and will contain the simulated ranges on return.
821  * \param robotPose [IN] The robot pose in this map coordinates. Recall that sensor pose relative to this robot pose must be specified in the observation object.
822  * \param threshold [IN] The minimum occupancy threshold to consider a cell to be occupied, for example 0.5.
823  * \param rangeNoiseStd [IN] The standard deviation of measurement noise. If not desired, set to 0.
824  * \param angleNoiseStd [IN] The sigma of an optional Gaussian noise added to the angles at which ranges are measured (in radians).
825  *
826  * \sa laserScanSimulator
827  */
828  void sonarSimulator(
829  CObservationRange &inout_observation,
830  const CPose2D &robotPose,
831  float threshold = 0.5f,
832  float rangeNoiseStd = 0,
833  float angleNoiseStd = DEG2RAD(0) ) const;
834 
835  /** Simulate just one "ray" in the grid map. This method is used internally to sonarSimulator and laserScanSimulator.
836  */
837  inline void simulateScanRay(
838  const double x,const double y,const double angle_direction,
839  float &out_range,bool &out_valid,
840  const unsigned int max_ray_len,
841  const float threshold_free=0.5f,
842  const double noiseStd=0, const double angleNoiseStd=0 ) const;
843 
844 
845  /** @} */
846 
847  // See docs in base class
848  double computeObservationLikelihood( const CObservation *obs, const CPose3D &takenFrom );
849 
850  /** Returns true if this map is able to compute a sensible likelihood function for this observation (i.e. an occupancy grid map cannot with an image).
851  * \param obs The observation.
852  * \sa computeObservationLikelihood
853  */
854  bool canComputeObservationLikelihood( const CObservation *obs );
855 
856  /** Computes the likelihood [0,1] of a set of points, given the current grid map as reference.
857  * \param pm The points map
858  * \param relativePose The relative pose of the points map in this map's coordinates, or NULL for (0,0,0).
859  * See "likelihoodOptions" for configuration parameters.
860  */
861  double computeLikelihoodField_Thrun( const CPointsMap *pm, const CPose2D *relativePose = NULL);
862 
863  /** Computes the likelihood [0,1] of a set of points, given the current grid map as reference.
864  * \param pm The points map
865  * \param relativePose The relative pose of the points map in this map's coordinates, or NULL for (0,0,0).
866  * See "likelihoodOptions" for configuration parameters.
867  */
868  double computeLikelihoodField_II( const CPointsMap *pm, const CPose2D *relativePose = NULL);
869 
870  /** Saves the gridmap as a graphical file (BMP,PNG,...).
871  * The format will be derived from the file extension (see CImage::saveToFile )
872  * \return False on any error.
873  */
874  bool saveAsBitmapFile(const std::string &file) const;
875 
876  /** Saves a composite image with two gridmaps and lines representing a set of correspondences between them.
877  * \sa saveAsEMFTwoMapsWithCorrespondences
878  * \return False on any error.
879  */
880  static bool saveAsBitmapTwoMapsWithCorrespondences(
881  const std::string &fileName,
882  const COccupancyGridMap2D *m1,
883  const COccupancyGridMap2D *m2,
884  const TMatchingPairList &corrs);
885 
886  /** Saves a composite image with two gridmaps and numbers for the correspondences between them.
887  * \sa saveAsBitmapTwoMapsWithCorrespondences
888  * \return False on any error.
889  */
890  static bool saveAsEMFTwoMapsWithCorrespondences(
891  const std::string &fileName,
892  const COccupancyGridMap2D *m1,
893  const COccupancyGridMap2D *m2,
894  const TMatchingPairList &corrs);
895 
896  /** Saves the gridmap as a graphical bitmap file, 8 bit gray scale, 1 pixel is 1 cell, and with an overlay of landmarks.
897  * \note The template parameter CLANDMARKSMAP is assumed to be mrpt::slam::CLandmarksMap normally.
898  * \return False on any error.
899  */
900  template <class CLANDMARKSMAP>
902  const std::string &file,
903  const CLANDMARKSMAP *landmarks,
904  bool addTextLabels = false,
905  const mrpt::utils::TColor &marks_color = mrpt::utils::TColor(0,0,255) ) const
906  {
907  MRPT_START
908  CImage img(1,1,3);
909  getAsImageFiltered( img, false, true ); // in RGB
910  const bool topleft = img.isOriginTopLeft();
911  for (unsigned int i=0;i<landmarks->landmarks.size();i++)
912  {
913  const typename CLANDMARKSMAP::landmark_type *lm = landmarks->landmarks.get( i );
914  int px = x2idx( lm->pose_mean.x );
915  int py = topleft ? size_y-1- y2idx( lm->pose_mean.y ) : y2idx( lm->pose_mean.y );
916  img.rectangle( px - 7, (py + 7), px +7, (py -7), marks_color );
917  img.rectangle( px - 6, (py + 6), px +6, (py -6), marks_color );
918  if (addTextLabels)
919  img.textOut(px,py-8,format("%u",i), TColor::black);
920  }
921  return img.saveToFile(file.c_str() );
922  MRPT_END
923  }
924 
925 
926  /** Returns the grid as a 8-bit graylevel image, where each pixel is a cell (output image is RGB only if forceRGB is true)
927  * If "tricolor" is true, only three gray levels will appear in the image: gray for unobserved cells, and black/white for occupied/empty cells respectively.
928  * \sa getAsImageFiltered
929  */
930  void getAsImage( utils::CImage &img, bool verticalFlip = false, bool forceRGB=false, bool tricolor = false) const;
931 
932  /** Returns the grid as a 8-bit graylevel image, where each pixel is a cell (output image is RGB only if forceRGB is true) - This method filters the image for easy feature detection
933  * If "tricolor" is true, only three gray levels will appear in the image: gray for unobserved cells, and black/white for occupied/empty cells respectively.
934  * \sa getAsImage
935  */
936  void getAsImageFiltered( utils::CImage &img, bool verticalFlip = false, bool forceRGB=false) const;
937 
938  /** Returns a 3D plane with its texture being the occupancy grid and transparency proportional to "uncertainty" (i.e. a value of 0.5 is fully transparent)
939  */
940  void getAs3DObject ( mrpt::opengl::CSetOfObjectsPtr &outObj ) const;
941 
942  /** Returns true upon map construction or after calling clear(), the return
943  * changes to false upon successful insertObservation() or any other method to load data in the map.
944  */
945  bool isEmpty() const;
946 
947  /** Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
948  * \param file The file to be loaded.
949  * \param resolution The size of a pixel (cell), in meters. Recall cells are always squared, so just a dimension is needed.
950  * \param xCentralPixel The "x" coordinate (0=first) for the pixel which will be taken at coordinates origin (0,0). If not supplied, it will be used the middle of the map.
951  * \param yCentralPixel The "y" coordinate (0=first) for the pixel which will be taken at coordinates origin (0,0). If not supplied, it will be used the middle of the map.
952  * \return False on any error.
953  * \sa loadFromBitmap
954  */
955  bool loadFromBitmapFile(const std::string &file, float resolution, float xCentralPixel = -1, float yCentralPixel =-1 );
956 
957  /** Load the gridmap from a image in a file (the format can be any supported by CImage::loadFromFile).
958  * \param img The image. Only a grayscale image will be used, so RGB components will be mixed if a color image is passed.
959  * \param resolution The size of a pixel (cell), in meters. Recall cells are always squared, so just a dimension is needed.
960  * \param xCentralPixel The "x" coordinate (0=first) for the pixel which will be taken at coordinates origin (0,0). If not supplied, it will be used the middle of the map.
961  * \param yCentralPixel The "y" coordinate (0=first) for the pixel which will be taken at coordinates origin (0,0). If not supplied, it will be used the middle of the map.
962  * \return False on any error.
963  * \sa loadFromBitmapFile
964  */
965  bool loadFromBitmap(const mrpt::utils::CImage &img, float resolution, float xCentralPixel = -1, float yCentralPixel =-1 );
966 
967  /** See the base class for more details: In this class it is implemented as correspondences of the passed points map to occupied cells.
968  * NOTICE: That the "z" dimension is ignored in the points. Clip the points as appropiated if needed before calling this method.
969  *
970  * \sa computeMatching3DWith
971  */
972  virtual void determineMatching2D(
973  const CMetricMap * otherMap,
974  const CPose2D & otherMapPose,
975  TMatchingPairList & correspondences,
976  const TMatchingParams & params,
977  TMatchingExtraResults & extraResults ) const ;
978 
979 
980  /** See docs in base class: in this class this always returns 0 */
981  float compute3DMatchingRatio(
982  const CMetricMap *otherMap,
983  const CPose3D &otherMapPose,
984  float maxDistForCorr = 0.10f,
985  float maxMahaDistForCorr = 2.0f
986  ) const;
987 
988  /** This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >, as an image or in any other applicable way (Notice that other methods to save the map may be implemented in classes implementing this virtual interface).
989  */
990  void saveMetricMapRepresentationToFile(
991  const std::string &filNamePrefix
992  ) const;
993 
994  /** The structure used to store the set of Voronoi diagram
995  * critical points.
996  * \sa findCriticalPoints
997  */
999  {
1000  TCriticalPointsList() : x(),y(),clearance(),x_basis1(),y_basis1(),x_basis2(),y_basis2()
1001  {}
1002 
1003  /** The coordinates of critical point.
1004  */
1005  std::vector<int> x,y;
1006  /** The clearance of critical points, in 1/100 of cells.
1007  */
1008  std::vector<int> clearance;
1009  /** Their two first basis points coordinates.
1010  */
1011  std::vector<int> x_basis1,y_basis1, x_basis2,y_basis2;
1012  } CriticalPointsList;
1013 
1014 
1015  private:
1016  /** Returns a byte with the occupancy of the 8 sorrounding cells.
1017  * \param cx The cell index
1018  * \param cy The cell index
1019  * \sa direction2idx
1020  */
1021  inline unsigned char GetNeighborhood( int cx, int cy ) const;
1022 
1023  /** Used to store the 8 possible movements from a cell to the
1024  * sorrounding ones.Filled in the constructor.
1025  * \sa direction2idx
1026  */
1027  int direccion_vecino_x[8],direccion_vecino_y[8];
1028 
1029  /** Returns the index [0,7] of the given movement, or
1030  * -1 if invalid one.
1031  * \sa direccion_vecino_x,direccion_vecino_y,GetNeighborhood
1032  */
1033  int direction2idx(int dx, int dy);
1034  };
1036 
1037 
1038  bool operator <(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2);
1039 
1040  } // End of namespace
1041 } // End of namespace
1042 
1043 #endif
size_t getSizeY() const
Returns the vertical size of grid map in cells count.
Definition: CDynamicGrid.h:237
float maxOccupancyUpdateCertainty
A value in the range [0.5,1] used for updating cell with a bayesian approach (default 0...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
uint16_t decimation
Specify the decimation of the range scan (default=1 : take all the range values!) ...
float rayTracing_stdHit
[rayTracing] The laser range sigma.
TLikelihoodMethod
The type for selecting a likelihood computation method.
#define ASSERT_BELOWEQ_(__A, __B)
bool enabled
If set to false (default), this struct is not used.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
std::vector< TPairLikelihoodIndex > OWA_pairList
[OWA method] This will contain the ascending-ordered list of pairs:(likelihood values, 2D point in map coordinates).
const CDynamicGrid< uint16_t > & getVoronoiDiagram() const
Return the Voronoi diagram; each cell contains the distance to its closer obstacle, or 0 if not part of the Voronoi diagram.
Declares a class derived from "CObservation" that encapsules a single range measurement, and associated parameters.
float mapAltitude
The altitude (z-axis) of 2D scans (within a 0.01m tolerance) for they to be inserted in this map! ...
EIGEN_STRONG_INLINE void fill(const Scalar v)
Definition: eigen_plugins.h:38
unsigned int getSizeX() const
Returns the horizontal size of grid map in cells count.
float getYMax() const
Returns the "y" coordinate of bottom side of grid map.
uint8_t l2p_255(const cell_t l)
Scales an integer representation of the log-odd into a linear scale [0,255], using p=exp(l)/(1+exp(l)...
This class stores any customizable set of metric maps.
bool considerInvalidRangesAsFreeSpace
If set to true (default), invalid range values (no echo rays) as consider as free space until "maxOcc...
float l2p(const cell_t l)
Scales an integer representation of the log-odd into a real valued probability in [0...
bool enableLikelihoodCache
Enables the usage of a cache of likelihood values (for LF methods), if set to true (default=false)...
With this struct options are provided to the observation insertion process.
float LF_stdHit
[LikelihoodField] The laser range "sigma" used in computations; Default value = 0.35
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:97
CDynamicGrid< uint16_t > m_voronoi_diagram
Used to store the Voronoi diagram.
bool wideningBeamsWithDistance
Enabled: Rays widen with distance to approximate the real behavior of lasers, disabled: insert rays a...
std::vector< double > precomputedLikelihood
These are auxiliary variables to speed up the computation of observation likelihood values for LF met...
std::pair< double, mrpt::math::TPoint2D > TPairLikelihoodIndex
Auxiliary private class.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void setRawCell(unsigned int cellIndex, cellType b)
Changes a cell by its absolute index (Do not use it normally)
static uint8_t l2p_255(const cellType l)
Scales an integer representation of the log-odd into a linear scale [0,255], using p=exp(l)/(1+exp(l)...
bool isStaticCell(int cx, int cy, float threshold=0.7f) const
std::vector< cellType > map
This is the buffer for storing the cells.In this dynamic size buffer are stored the cell values as "b...
uint32_t MI_skip_rays
[MI] The scan rays decimation: at every N rays, one will be used to compute the MI: ...
#define MRPT_NO_THROWS
Used after member declarations.
float CFD_features_gaussian_size
Gaussian sigma of the filter used in getAsImageFiltered (for features detection) (Default=1) (0:Disab...
double I_change
The cummulative change in Information: This is updated only from the "updateCell" method...
void setCell(int x, int y, float value)
Change the contents [0,1] of a cell, given its index.
float idx2x(const size_t cx) const
Transform a cell index into a coordinate value.
const cellType * getRow(int cy) const
Access to a "row": mainly used for drawing grid as a bitmap efficiently, do not use it normally...
static float l2p(const cellType l)
Scales an integer representation of the log-odd into a real valued probability in [0...
double mean_H
The target variable for mean entropy, defined as entropy per cell: mean_H(map) = H(map) / (cells) ...
The structure used to store the set of Voronoi diagram critical points.
bool rayTracing_useDistanceFilter
[rayTracing] If true (default), the rayTracing method will ignore measured ranges shorter than the si...
void setCell_nocheck(int x, int y, float value)
Change the contents [0,1] of a cell, given its index.
size_t getSizeX() const
Returns the horizontal size of grid map in cells count.
Definition: CDynamicGrid.h:233
float maxDistanceInsertion
The largest distance at which cells will be updated (Default 15 meters)
void setVoroniClearance(int cx, int cy, uint16_t dist)
Used to set the clearance of a cell, while building the Voronoi diagram.
This class allows loading and storing values and vectors of different types from a configuration text...
An internal structure for storing data related to counting the new information apported by some obser...
void setBasisCell(int x, int y, uint8_t value)
Change a cell in the "basis" maps.Used for Voronoi calculation.
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:83
bool LF_alternateAverageMethod
[LikelihoodField] Set this to "true" ot use an alternative method, where the likelihood of the whole ...
float getPos(float x, float y) const
Read the real valued [0,1] contents of a cell, given its coordinates.
uint32_t LF_decimation
[LikelihoodField] The decimation of the points in a scan, default=1 == no decimation.
const std::vector< cellType > & getRawMap() const
Read-only access to the raw cell contents (cells are in log-odd units)
Used for returning entropy related information.
#define DEG2RAD(x)
Definition: Utils.h:61
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
int laserRaysSkip
In this mode, some laser rays can be skips to speep-up.
#define MRPT_END
float getXMin() const
Returns the "x" coordinate of left side of grid map.
float MI_exponent
[MI] The exponent in the MI likelihood computation.
unsigned int getSizeY() const
Returns the vertical size of grid map in cells count.
float MI_ratio_max_distance
[MI] The ratio for the max.
static cellType p2l(const float p)
Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the val...
int cellsUpdated
The cummulative updated cells count: This is updated only from the "updateCell" method.
A list of TMatchingPair.
Definition: TMatchingPair.h:66
Declares a class that represents any robot's observation.
Definition: CObservation.h:52
int x2idx(float x, float x_min) const
Transform a coordinate value into a cell index, using a diferent "x_min" value.
A RGB color - 8bit.
Definition: TColor.h:25
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
float getCell_nocheck(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
Parameters for the determination of matchings between point clouds, etc.
Definition: CMetricMap.h:32
void setPos(float x, float y, float value)
Change the contents [0,1] of a cell, given its coordinates.
static std::vector< float > entropyTable
Internally used to speed-up entropy calculation.
double H
The target variable for absolute entropy, computed as: H(map)=Sumx,y{ -p(x,y)·ln(p(x,y)) -(1-p(x,y))·ln(1-p(x,y)) }
bool useMapAltitude
The parameter "mapAltitude" has effect while inserting observations in the grid only if this is true...
cellType * getRow(int cy)
Access to a "row": mainly used for drawing grid as a bitmap efficiently, do not use it normally...
T * cellByIndex(unsigned int cx, unsigned int cy)
Returns a pointer to the contents of a cell given by its cell indexes, or NULL if it is out of the ma...
Definition: CDynamicGrid.h:215
double I
The target variable for absolute "information", defining I(x) = 1 - H(x)
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
std::vector< double > OWA_individualLikValues
[OWA method] This will contain the ascending-ordered list of likelihood values for individual range m...
const CDynamicGrid< uint8_t > & getBasisMap() const
Return the auxiliary "basis" map built while building the Voronoi diagram.
bool isStaticPos(float x, float y, float threshold=0.7f) const
Returns "true" if cell is "static", i.e.if its occupancy is below a given threshold.
int x2idx(float x) const
Transform a coordinate value into a cell index.
uint16_t getVoroniClearance(int cx, int cy) const
Reads a the clearance of a cell (in centimeters), after building the Voronoi diagram with buildVorono...
#define MRPT_START
int32_t rayTracing_decimation
[rayTracing] One out of "rayTracing_decimation" rays will be simulated and compared only: set to 1 to...
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:110
TUpdateCellsInfoChangeOnly(bool enabled=false, double I_change=0, int cellsUpdated=0)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int y2idx(float y, float y_min) const
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
TInsertionOptions insertionOptions
With this struct options are provided to the observation insertion process.
static CLogOddsGridMapLUT< cellType > m_logodd_lut
Lookup tables for log-odds.
float getXMax() const
Returns the "x" coordinate of right side of grid map.
#define ASSERT_ABOVEEQ_(__A, __B)
bool m_is_empty
True upon construction; used by isEmpty()
double effectiveMappedArea
The target variable for the area of cells with information, i.e.
A class for storing an occupancy grid map.
Some members of this struct will contain intermediate or output data after calling "computeObservatio...
A class used to store a 2D pose.
Definition: CPose2D.h:36
unsigned char getBasisCell(int x, int y) const
Reads a cell in the "basis" maps.Used for Voronoi calculation.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
float CFD_features_median_size
Size of the Median filter used in getAsImageFiltered (for features detection) (Default=3) (0:Disabled...
CDynamicGrid< uint8_t > m_basis_map
Used for Voronoi calculation.Same struct as "map", but contains a "0" if not a basis point...
cell_t p2l(const float p)
Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the val...
float horizontalTolerance
The tolerance in rads in pitch & roll for a laser scan to be considered horizontal, then processed by calls to this class (default=0).
float getResolution() const
Returns the resolution of the grid map.
std::vector< float > OWA_weights
[OWA] The sequence of weights to be multiplied to of the ordered list of likelihood values (first one...
float idx2y(const size_t cy) const
float voroni_free_threshold
The free-cells threshold used to compute the Voronoi diagram.
Additional results from the determination of matchings between point clouds, etc., apart from the pairings themselves.
Definition: CMetricMap.h:55
bool saveAsBitmapFileWithLandmarks(const std::string &file, const CLANDMARKSMAP *landmarks, bool addTextLabels=false, const mrpt::utils::TColor &marks_color=mrpt::utils::TColor(0, 0, 255)) const
Saves the gridmap as a graphical bitmap file, 8 bit gray scale, 1 pixel is 1 cell, and with an overlay of landmarks.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
Definition: CPointsMap.h:59
float getCell(int x, int y) const
Read the real valued [0,1] contents of a cell, given its index.
int16_t cellType
The type of the map cells:
double mean_I
The target variable for mean information, defined as information per cell: mean_I(map) = I(map) / (ce...
Declares a class that represents a Rao-Blackwellized set of particles for solving the SLAM problem (T...
int32_t consensus_takeEachRange
[Consensus] The down-sample ratio of ranges (default=1, consider all the ranges)
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
unsigned long effectiveMappedCells
The mapped area in cells.
TLikelihoodMethod likelihoodMethod
The selected method to compute an observation likelihood.
std::vector< int > clearance
The clearance of critical points, in 1/100 of cells.
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
float consensus_pow
[Consensus] The power factor for the likelihood (default=5)
float getYMin() const
Returns the "y" coordinate of top side of grid map.
static TColor black
Predefined colors.
Definition: TColor.h:40
With this struct options are provided to the observation likelihood computation process.



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014