10 #ifndef COccupancyGridMap2D_H
11 #define COccupancyGridMap2D_H
25 #include <mrpt/config.h>
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.
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.
43 class CObservation2DRangeScan;
44 class CObservationRange;
75 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
86 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
110 std::vector<cellType>
map;
140 virtual void OnPostSuccesfulInsertObs(
const CObservation *);
152 static double H(
double p);
158 map[x+y*size_x]=p2l(value);
165 return l2p(map[x+y*size_x]);
172 if (cellIndex<size_x*size_y)
185 double computeObservationLikelihood_Consensus(
192 double computeObservationLikelihood_ConsensusOWA(
198 double computeObservationLikelihood_CellsDifference(
204 double computeObservationLikelihood_MI(
210 double computeObservationLikelihood_rayTracing(
216 double computeObservationLikelihood_likelihoodField_Thrun(
222 double computeObservationLikelihood_likelihoodField_II(
228 virtual void internal_clear( );
239 virtual bool internal_insertObservation(
const CObservation *obs,
const CPose3D *robotPose = NULL );
243 const std::vector<cellType> &
getRawMap()
const {
return this->map; }
248 void updateCell(
int x,
int y,
float v);
256 int cellsUpdated=0) : enabled(enabled),
258 cellsUpdated(cellsUpdated),
278 } updateInfoChangeOnly;
284 float min_y = -20.0f,
286 float resolution = 0.05f
291 void fill(
float default_value = 0.5f );
306 void setSize(
float x_min,
float x_max,
float y_min,
float y_max,
float resolution,
float default_value = 0.5f);
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;
320 inline
double getArea()
const {
return size_x*size_y*
square(resolution); }
324 inline unsigned int getSizeX()
const {
return size_x; }
328 inline unsigned int getSizeY()
const {
return size_y; }
332 inline float getXMin()
const {
return x_min; }
336 inline float getXMax()
const {
return x_max; }
340 inline float getYMin()
const {
return y_min; }
344 inline float getYMax()
const {
return y_max; }
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 ); }
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 ); }
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; }
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 ); }
370 static inline float l2p(
const cellType l)
372 return m_logodd_lut.
l2p(l);
377 static inline uint8_t
l2p_255(
const cellType l)
379 return m_logodd_lut.
l2p_255(l);
384 static inline cellType
p2l(
const float p)
386 return m_logodd_lut.
p2l(p);
394 if (static_cast<unsigned int>(x)>=size_x || static_cast<unsigned int>(y)>=size_y)
396 else map[x+y*size_x]=p2l(value);
404 if (static_cast<unsigned int>(x)>=size_x || static_cast<unsigned int>(y)>=size_y)
406 else return l2p(map[x+y*size_x]);
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]; }
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]; }
419 inline void setPos(
float x,
float y,
float value) { setCell(x2idx(x),y2idx(y),value); }
423 inline float getPos(
float x,
float y)
const {
return getCell(x2idx(x),y2idx(y)); }
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); }
463 TEntropyInfo() : H(0),I(0),mean_H(0),mean_I(0),effectiveMappedArea(0),effectiveMappedCells(0)
513 void loadFromConfigFile(
515 const std::string §ion);
519 void dumpToTextStream(
CStream &out)
const;
568 lmMeanInformation = 0,
597 void loadFromConfigFile(
599 const std::string §ion);
603 void dumpToTextStream(
CStream &out)
const;
699 void subSample(
int downRatio );
719 void buildVoronoiDiagram(
float threshold,
float robot_size,
int x1=0,
int x2=0,
int y1=0,
int y2=0);
730 const uint16_t *cell=m_voronoi_diagram.
cellByIndex(cx,cy);
738 uint16_t *cell=m_voronoi_diagram.
cellByIndex(cx,cy);
761 void findCriticalPoints(
float filter_distance );
777 int computeClearance(
int cx,
int cy,
int *basis_x,
int *basis_y,
int *nBasis,
bool GetContourPoint =
false )
const;
782 float computeClearance(
float x,
float y,
float maxSearchDistance )
const;
787 float computePathCost(
float x1,
float y1,
float x2,
float y2 )
const;
808 void laserScanSimulator(
811 float threshold = 0.5f,
814 unsigned int decimation = 1,
815 float angleNoiseStd =
DEG2RAD(0) )
const;
831 float threshold = 0.5f,
832 float rangeNoiseStd = 0,
833 float angleNoiseStd =
DEG2RAD(0) )
const;
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;
854 bool canComputeObservationLikelihood(
const CObservation *obs );
861 double computeLikelihoodField_Thrun(
const CPointsMap *pm,
const CPose2D *relativePose = NULL);
868 double computeLikelihoodField_II(
const CPointsMap *pm,
const CPose2D *relativePose = NULL);
874 bool saveAsBitmapFile(
const std::string &file)
const;
880 static bool saveAsBitmapTwoMapsWithCorrespondences(
881 const std::string &fileName,
890 static bool saveAsEMFTwoMapsWithCorrespondences(
891 const std::string &fileName,
900 template <
class CLANDMARKSMAP>
902 const std::string &file,
903 const CLANDMARKSMAP *landmarks,
904 bool addTextLabels =
false,
909 getAsImageFiltered( img,
false,
true );
910 const bool topleft = img.isOriginTopLeft();
911 for (
unsigned int i=0;i<landmarks->landmarks.size();i++)
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 );
921 return img.saveToFile(file.c_str() );
930 void getAsImage(
utils::CImage &img,
bool verticalFlip =
false,
bool forceRGB=
false,
bool tricolor =
false)
const;
936 void getAsImageFiltered(
utils::CImage &img,
bool verticalFlip =
false,
bool forceRGB=
false)
const;
940 void getAs3DObject ( mrpt::opengl::CSetOfObjectsPtr &outObj )
const;
945 bool isEmpty()
const;
955 bool loadFromBitmapFile(
const std::string &file,
float resolution,
float xCentralPixel = -1,
float yCentralPixel =-1 );
965 bool loadFromBitmap(
const mrpt::utils::CImage &img,
float resolution,
float xCentralPixel = -1,
float yCentralPixel =-1 );
972 virtual void determineMatching2D(
973 const CMetricMap * otherMap,
981 float compute3DMatchingRatio(
982 const CMetricMap *otherMap,
984 float maxDistForCorr = 0.10f,
985 float maxMahaDistForCorr = 2.0f
990 void saveMetricMapRepresentationToFile(
991 const std::string &filNamePrefix
1005 std::vector<int> x,
y;
1012 } CriticalPointsList;
1021 inline unsigned char GetNeighborhood(
int cx,
int cy )
const;
1027 int direccion_vecino_x[8],direccion_vecino_y[8];
1033 int direction2idx(
int dx,
int dy);
size_t getSizeY() const
Returns the vertical size of grid map in cells count.
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.
bool precomputedLikelihoodToBeRecomputed
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)
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.
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...
int x2idx(double x) const
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...
uint16_t cellTypeUnsigned
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.
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.
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.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
#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.
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.
Declares a class that represents any robot's observation.
int x2idx(float x, float x_min) const
Transform a coordinate value into a cell index, using a diferent "x_min" value.
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.
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...
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...
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...
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.
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.
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).
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 LF_maxCorrsDistance
[LikelihoodField] The max.
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 LF_maxRange
[LikelihoodField] The max.
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.
std::vector< int > y_basis2
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...
int y2idx(double y) const
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.
float resolution
Cell size, i.e.
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.
With this struct options are provided to the observation likelihood computation process.