Class CRandomFieldGridMap2D
Defined in File CRandomFieldGridMap2D.h
Nested Relationships
Nested Types
Inheritance Relationships
Base Types
public mrpt::maps::CMetricMappublic mrpt::containers::CDynamicGrid< TRandomFieldCell >public mrpt::system::COutputLogger
Derived Types
public mrpt::maps::CGasConcentrationGridMap2D(Class CGasConcentrationGridMap2D)public mrpt::maps::CHeightGridMap2D_MRF(Class CHeightGridMap2D_MRF)public mrpt::maps::CWirelessPowerGridMap2D(Class CWirelessPowerGridMap2D)
Class Documentation
-
class CRandomFieldGridMap2D : public mrpt::maps::CMetricMap, public mrpt::containers::CDynamicGrid<TRandomFieldCell>, public mrpt::system::COutputLogger
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property which is estimated by this map, either as a simple value or as a probility distribution (for each cell).
There are a number of methods available to build the MRF grid-map, depending on the value of
TMapRepresentation maptypepassed in the constructor.The following papers describe the mapping alternatives implemented here:
mrKernelDM: A Gaussian kernel-based method. See:”Building gas concentration gridmaps with a mobile robot”, Lilienthal, A. and Duckett, T., Robotics and Autonomous Systems, v.48, 2004.
mrKernelDMV: A kernel-based method. See:”A Statistical Approach to Gas Distribution Modelling with Mobile
Robots–The Kernel DM+ V Algorithm”, Lilienthal, A.J. and Reggente, M. and Trincavelli, M. and Blanco, J.L. and Gonzalez, J., IROS 2009.
mrKalmanFilter: A “brute-force” approach to estimate the entire map with a dense (linear) Kalman filter. Will be very slow for mid or large maps. It’s provided just for comparison purposes, not useful in practice.mrKalmanApproximate: A compressed/sparse Kalman filter approach. See:”A Kalman Filter Based Approach to Probabilistic Gas Distribution
Mapping”, JL Blanco, JG Monroy, J Gonzalez-Jimenez, A Lilienthal, 28th Symposium On Applied Computing (SAC), 2013.
mrGMRF_SD: A Gaussian Markov Random Field (GMRF) estimator, with these constraints:mrGMRF_SD: Each cell only connected to its 4 immediate neighbors (Up, down, left, right).(Removed in MRPT 1.5.0:
mrGMRF_G: Each cell connected to a square area of neighbors cells)See papers:
”Time-variant gas distribution mapping with obstacle
information”, Monroy, J. G., Blanco, J. L., & Gonzalez-Jimenez, J. Autonomous Robots, 40(1), 1-16, 2016.
Note that this class is virtual, since derived classes still have to implement:
mrpt::maps::CMetricMap::internal_computeObservationLikelihood()
mrpt::maps::CMetricMap::internal_insertObservation()
Serialization methods: writeToStream() and readFromStream()
[GMRF only] A custom connectivity pattern between cells can be defined by calling setCellsConnectivity().
See also
mrpt::maps::CGasConcentrationGridMap2D, mrpt::maps::CWirelessPowerGridMap2D, mrpt::maps::CMetricMap, mrpt::containers::CDynamicGrid, The application icp-slam, mrpt::maps::CMultiMetricMap
Subclassed by mrpt::maps::CGasConcentrationGridMap2D, mrpt::maps::CHeightGridMap2D_MRF, mrpt::maps::CWirelessPowerGridMap2D
Auxiliary vars for DM & DM+V methods
-
float m_DM_lastCutOff = {0}
-
std::vector<float> m_DM_gaussWindow
-
double m_average_normreadings_mean = {0}
-
double m_average_normreadings_var = {0}
-
size_t m_average_normreadings_count = {0}
Public Types
-
enum TMapRepresentation
The type of map representation to be used, see CRandomFieldGridMap2D for a discussion.
Values:
-
enumerator mrKernelDM
Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrAchim
Another alias for “mrKernelDM”, for backwards compatibility (see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrKalmanFilter
“Brute-force” Kalman filter (see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrKalmanApproximate
(see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrKernelDMV
Double mean + variance Gaussian kernel-based estimator (see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrGMRF_SD
Gaussian Markov Random Field, squared differences prior weights between 4 neighboring cells (see discussion in mrpt::maps::CRandomFieldGridMap2D)
-
enumerator mrKernelDM
Public Functions
-
inline void clear()
Calls the base CMetricMap::clear Declared here to avoid ambiguity between the two clear() in both base classes.
-
inline float cell2float(const TRandomFieldCell &c) const override
-
inline std::string asString() const override
Returns a short description of the map.
-
CRandomFieldGridMap2D(TMapRepresentation mapType = mrKernelDM, double x_min = -2, double x_max = 2, double y_min = -2, double y_max = 2, double resolution = 0.1)
Constructor
-
~CRandomFieldGridMap2D() override
Destructor
-
bool isEmpty() const override
Returns true if the map is empty/no observation has been inserted (in this class it always return false, unless redefined otherwise in base classes)
-
virtual void saveAsBitmapFile(const std::string &filName) const
Save the current map as a graphical file (BMP,PNG,…). The file format will be derived from the file extension (see CImage::saveToFile ) It depends on the map representation model: mrAchim: Each pixel is the ratio \( \sum{\frac{wR}{w}} \) mrKalmanFilter: Each pixel is the mean value of the Gaussian that represents each cell.
See also
-
virtual void getAsBitmapFile(mrpt::img::CImage &out_img) const
Returns an image just as described in saveAsBitmapFile
-
virtual void getAsMatrix(mrpt::math::CMatrixDouble &out_mat) const
Like saveAsBitmapFile(), but returns the data in matrix form (first row in the matrix is the upper (y_max) part of the map)
-
void resize(double new_x_min, double new_x_max, double new_y_min, double new_y_max, const TRandomFieldCell &defaultValueNewCells, double additionalMarginMeters = 1.0f) override
Changes the size of the grid, maintaining previous contents.
See also
-
virtual void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const TRandomFieldCell *fill_value = nullptr)
Changes the size of the grid, erasing previous contents.
See also
- Parameters:
connectivity_descriptor – [in] Optional user-supplied object that will visit all grid cells to define their connectivity with neighbors and the strength of existing edges. If present, it overrides all options in insertionOptions
-
void setCellsConnectivity(const ConnectivityDescriptor::Ptr &new_connectivity_descriptor)
Sets a custom object to define the connectivity between cells. Must call clear() or setSize() afterwards for the changes to take place.
-
float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams ¶ms) const override
See docs in base class: in this class this always returns 0
-
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
The implementation in this class just calls all the corresponding method of the contained metric maps
-
virtual void saveAsMatlab3DGraph(const std::string &filName) const
Save a matlab “.m” file which represents as 3D surfaces the mean and a given confidence level for the concentration of each cell. This method can only be called in a KF map model.
-
void getVisualizationInto(mrpt::viz::CSetOfObjects &outObj) const override
Returns a 3D object representing the map (mean)
-
virtual void getAs3DObject(mrpt::viz::CSetOfObjects &meanObj, mrpt::viz::CSetOfObjects &varObj) const
Returns two 3D objects representing the mean and variance maps
-
TMapRepresentation getMapType()
Return the type of the random-field grid map, according to parameters passed on construction.
-
void insertIndividualReading(const double sensorReading, const mrpt::math::TPoint2D &point, const bool update_map = true, const bool time_invariant = true, const double reading_stddev = .0)
Direct update of the map with a reading in a given position of the map, using the appropriate method according to mapType passed in the constructor.
This is a direct way to update the map, an alternative to the generic insertObservation() method which works with mrpt::obs::CObservation objects.
- Parameters:
sensorReading – [in] The value observed in the (x,y) position
point – [in] The (x,y) location
update_map – [in] Run a global map update after inserting this observatin (algorithm-dependant)
time_invariant – [in] Whether the observation “vanishes” with time (false) or not (true) [Only for GMRF methods]
reading_stddev – [in] The uncertainty (standard deviation) of the reading. Default=”0.0” means use the default settings per map-wide parameters.
-
virtual void predictMeasurement(const double x, const double y, double &out_predict_response, double &out_predict_response_variance, bool do_sensor_normalization, const TGridInterpolationMethod interp_method = gimNearest)
Returns the prediction of the measurement at some (x,y) coordinates, and its certainty (in the form of the expected variance).
- Parameters:
x – [in] Query X coordinate
y – [in] Query Y coordinate
out_predict_response – [out] The output value
out_predict_response_variance – [out] The output variance
do_sensor_normalization – [in] Whether to renormalize the prediction to a predefined interval (`R` values in insertionOptions)
interp_method – [in] Interpolation method
-
void getMeanAndCov(mrpt::math::CVectorDouble &out_means, mrpt::math::CMatrixDouble &out_cov) const
Return the mean and covariance vector of the full Kalman filter estimate (works for all KF-based methods).
-
void getMeanAndSTD(mrpt::math::CVectorDouble &out_means, mrpt::math::CVectorDouble &out_STD) const
Return the mean and STD vectors of the full Kalman filter estimate (works for all KF-based methods).
-
void setMeanAndSTD(mrpt::math::CVectorDouble &out_means, mrpt::math::CVectorDouble &out_STD)
Load the mean and STD vectors of the full Kalman filter estimate (works for all KF-based methods).
-
void updateMapEstimation()
Run the method-specific procedure required to ensure that the mean & variances are up-to-date with all inserted observations.
-
inline void enableVerbose(bool enable_verbose)
-
inline bool isEnabledVerbose() const
-
inline void enableProfiler(bool enable = true)
-
inline bool isProfilerEnabled() const
Protected Functions
-
virtual CRandomFieldGridMap2D::TInsertionOptionsCommon *getCommonInsertOptions() = 0
Get the part of the options common to all CRandomFieldGridMap2D classes
-
void insertObservation_KernelDM_DMV(double normReading, const mrpt::math::TPoint2D &point, bool is_DMV)
The implementation of “insertObservation” for Achim Lilienthal’s map models DM & DM+V.
- Parameters:
normReading – Is a [0,1] normalized concentration reading.
point – Is the sensor location on the map
is_DMV – = false -> map type is Kernel DM; true -> map type is DM+V
-
void insertObservation_KF(double normReading, const mrpt::math::TPoint2D &point)
The implementation of “insertObservation” for the (whole) Kalman Filter map model.
- Parameters:
normReading – Is a [0,1] normalized concentration reading.
point – Is the sensor location on the map
-
void insertObservation_KF2(double normReading, const mrpt::math::TPoint2D &point)
The implementation of “insertObservation” for the Efficient Kalman Filter map model.
- Parameters:
normReading – Is a [0,1] normalized concentration reading.
point – Is the sensor location on the map
-
void insertObservation_GMRF(double normReading, const mrpt::math::TPoint2D &point, const bool update_map, const bool time_invariant, const double reading_information)
The implementation of “insertObservation” for the Gaussian Markov Random Field map model.
- Parameters:
normReading – Is a [0,1] normalized concentration reading.
point – Is the sensor location on the map
-
void updateMapEstimation_GMRF()
solves the minimum quadratic system to determine the new concentration of each cell
-
double computeConfidenceCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the confidence of the cell concentration (alpha)
-
double computeMeanCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the average cell concentration, or the overall average value if it has never been observed
-
double computeVarCellValue_DM_DMV(const TRandomFieldCell *cell) const
Computes the estimated variance of the cell concentration, or the overall average variance if it has never been observed
-
void recoverMeanAndCov() const
In the KF2 implementation, takes the auxiliary matrices and from them update the cells’ mean and std values.
See also
-
void internal_clear() override
Erase all the contents of the map
-
bool exist_relation_between2cells(const mrpt::maps::COccupancyGridMap2D *m_Ocgridmap, size_t cxo_min, size_t cxo_max, size_t cyo_min, size_t cyo_max, size_t seed_cxo, size_t seed_cyo, size_t objective_cxo, size_t objective_cyo)
Check if two cells of the gridmap (m_map) are connected, based on the provided occupancy gridmap
Protected Attributes
-
bool m_rfgm_run_update_upon_clear = {true}
-
TInsertionOptionsCommon *m_insertOptions_common = {nullptr}
Common options to all random-field grid maps: pointer that is set to the derived-class instance of “insertOptions” upon construction of this class.
-
TMapRepresentation m_mapType
The map representation type of this map, as passed in the constructor
-
mrpt::math::CMatrixD m_cov
The whole covariance matrix, used for the Kalman Filter map representation.
-
mrpt::math::CMatrixD m_stackedCov
The compressed band diagonal matrix for the KF2 implementation. The format is a Nx(W^2+2W+1) matrix, one row per cell in the grid map with the cross-covariances between each cell and half of the window around it in the grid.
-
mutable bool m_hasToRecoverMeanAndCov = {true}
Only for the KF2 implementation.
-
ConnectivityDescriptor::Ptr m_gmrf_connectivity
Empty: default
-
mrpt::graphs::ScalarFactorGraph m_gmrf
-
std::vector<std::list<TObservationGMRF>> m_mrf_factors_activeObs
Vector with the active observations and their respective Information
-
std::deque<TPriorFactorGMRF> m_mrf_factors_priors
Vector with the precomputed priors for each GMRF model
-
struct ConnectivityDescriptor
Base class for user-supplied objects capable of describing cells connectivity, used to build prior factors of the MRF graph.
See also
Public Types
-
using Ptr = std::shared_ptr<ConnectivityDescriptor>
Public Functions
-
ConnectivityDescriptor()
-
virtual ~ConnectivityDescriptor()
-
virtual bool getEdgeInformation(const CRandomFieldGridMap2D *parent, size_t icx, size_t icy, size_t jcx, size_t jcy, double &out_edge_information) = 0
Implement the check of whether node i=(icx,icy) is connected with node j=(jcx,jcy). This visitor method will be called only for immediate neighbors.
- Parameters:
parent – The parent map on which we are running
icx – (cx,cy) for node “i”
jcx – (cx,cy) for node “j”
out_edge_information – Must output here the inverse of the variance of the constraint edge.
- Returns:
true if connected (and the “information” value should be also updated in out_edge_information), false otherwise.
-
using Ptr = std::shared_ptr<ConnectivityDescriptor>
-
struct TInsertionOptionsCommon
Parameters common to any derived class. Derived classes should derive a new struct from this one, plus “public
CLoadableOptions”, and call the internal_* methods where appropriate to deal with the variables declared here. Derived classes instantions of their “TInsertionOptions” MUST set the pointer “m_insertOptions_common” upon construction.
Subclassed by mrpt::maps::CGasConcentrationGridMap2D::TInsertionOptions, mrpt::maps::CHeightGridMap2D_MRF::TInsertionOptions, mrpt::maps::CWirelessPowerGridMap2D::TInsertionOptions
Kernel methods (mrKernelDM, mrKernelDMV)
-
float sigma = {0.15f}
The sigma of the “Parzen”-kernel Gaussian
-
float cutoffRadius
The cutoff radius for updating cells.
-
float R_min = {0}
Limits for normalization of sensor readings.
-
float R_max = {3}
-
double dm_sigma_omega = {0.05}
[DM/DM+V methods] The scaling parameter for the confidence “alpha” values (see the IROS 2009 paper; see CRandomFieldGridMap2D)
Kalman-filter methods (mrKalmanFilter, mrKalmanApproximate)
-
float KF_covSigma = {0.35f}
The “sigma” for the initial covariance value between cells (in meters).
-
float KF_initialCellStd = {1.0}
The initial standard deviation of each cell’s concentration (will be stored both at each cell’s structure and in the covariance matrix as variances in the diagonal) (in normalized concentration units).
-
float KF_observationModelNoise = {0}
The sensor model noise (in normalized concentration units).
-
float KF_defaultCellMeanValue = {0}
The default value for the mean of cells’ concentration.
-
uint16_t KF_W_size = {4}
[mrKalmanApproximate] The size of the window of neighbor cells.
Gaussian Markov Random Fields methods (mrGMRF_SD)
-
double GMRF_lambdaPrior = {0.01f}
The information (Lambda) of fixed map constraints
-
double GMRF_lambdaObs = {10.0f}
The initial information (Lambda) of each observation (this information will decrease with time)
-
double GMRF_lambdaObsLoss = {0.0f}
The loss of information of the observations with each iteration
-
bool GMRF_use_occupancy_information = {false}
whether to use information of an occupancy_gridmap map for building the GMRF
-
std::string GMRF_simplemap_file
simplemap_file name of the occupancy_gridmap
-
std::string GMRF_gridmap_image_file
image name of the occupancy_gridmap
-
double GMRF_gridmap_image_res = {0.01f}
occupancy_gridmap resolution: size of each pixel (m)
-
size_t GMRF_gridmap_image_cx = {0}
Pixel coordinates of the origin for the occupancy_gridmap
-
size_t GMRF_gridmap_image_cy = {0}
Pixel coordinates of the origin for the occupancy_gridmap
-
double GMRF_saturate_min
(Default:-inf,+inf) Saturate the estimated mean in these limits
-
double GMRF_saturate_max
-
bool GMRF_skip_variance = {false}
(Default:false) Skip the computation of the variance, just compute the mean
Public Functions
-
TInsertionOptionsCommon()
Default values loader
-
void internal_loadFromConfigFile_common(const mrpt::config::CConfigFileBase &source, const std::string §ion)
See mrpt::config::CLoadableOptions
-
void internal_dumpToTextStream_common(std::ostream &out) const
See mrpt::config::CLoadableOptions
-
float sigma = {0.15f}
-
struct TObservationGMRF : public mrpt::graphs::ScalarFactorGraph::UnaryFactorVirtualBase
Public Functions
-
virtual double evaluateResidual() const override
-
virtual double getInformation() const override
-
virtual void evalJacobian(double &dr_dx) const override
-
inline TObservationGMRF(CRandomFieldGridMap2D &parent)
-
virtual double evaluateResidual() const override
-
struct TPriorFactorGMRF : public mrpt::graphs::ScalarFactorGraph::BinaryFactorVirtualBase
Public Functions
-
virtual double evaluateResidual() const override
-
virtual double getInformation() const override
-
virtual void evalJacobian(double &dr_dx_i, double &dr_dx_j) const override
-
inline TPriorFactorGMRF(CRandomFieldGridMap2D &parent)
Public Members
-
double Lambda
“Information” of the observation (=inverse of the variance)
-
virtual double evaluateResidual() const override