Main MRPT website > C++ reference
MRPT logo
CMetricMap.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 #ifndef CMetricMap_H
10 #define CMetricMap_H
11 
14 #include <mrpt/utils/CObservable.h>
15 #include <mrpt/math/math_frwds.h>
19 #include <mrpt/obs/obs_frwds.h>
20 #include <mrpt/obs/link_pragmas.h>
21 #include <deque>
22 
23 namespace mrpt
24 {
25  namespace slam
26  {
27  using namespace mrpt::utils;
30 
31  /** Parameters for the determination of matchings between point clouds, etc. \sa CMetricMap::determineMatching2D, CMetricMap::determineMatching3D */
33  {
34  float maxDistForCorrespondence; //!< Maximum linear distance between two points to be paired (meters)
35  float maxAngularDistForCorrespondence; //!< Allowed "angular error" (in radians): this permits larger pairing threshold distances to more distant points.
36  bool onlyKeepTheClosest; //!< If set to true (default), only the closest correspondence will be returned. If false all are returned.
37  bool onlyUniqueRobust; //!< Additional consistency filter: "onlyKeepTheClosest" allows one correspondence for each "local map" point, but many of them may have as corresponding pair the same "global point", which this flag avoids.
38  size_t decimation_other_map_points; //!< (Default=1) Only consider 1 out of this number of points from the "other" map.
39  size_t offset_other_map_points; //!< Index of the first point in the "other" map to start checking for correspondences (Default=0)
40  mrpt::math::TPoint3D angularDistPivotPoint; //!< The point used to calculate angular distances: e.g. the coordinates of the sensor for a 2D laser scanner.
41 
42  /** Ctor: default values */
44  maxDistForCorrespondence(0.50f),
45  maxAngularDistForCorrespondence(.0f),
46  onlyKeepTheClosest(true),
47  onlyUniqueRobust(false),
48  decimation_other_map_points(1),
49  offset_other_map_points(0),
50  angularDistPivotPoint(0,0,0)
51  {}
52  };
53 
54  /** Additional results from the determination of matchings between point clouds, etc., apart from the pairings themselves \sa CMetricMap::determineMatching2D, CMetricMap::determineMatching3D */
56  {
57  float correspondencesRatio; //!< The ratio [0,1] of points in otherMap with at least one correspondence.
58  float sumSqrDist; //!< The sum of all matched points squared distances.If undesired, set to NULL, as default.
59 
60  TMatchingExtraResults() : correspondencesRatio(0),sumSqrDist(0)
61  {}
62  };
63 
65 
66  /** Declares a virtual base class for all metric maps storage classes.
67  * In this class virtual methods are provided to allow the insertion
68  * of any type of "CObservation" objects into the metric map, thus
69  * updating the map (doesn't matter if it is a 2D/3D grid, a point map, etc.).
70  *
71  * Observations don't include any information about the
72  * robot pose, just the raw observation and information about
73  * the sensor pose relative to the robot mobile base coordinates origin.
74  *
75  * Note that all metric maps implement this mrpt::utils::CObservable interface,
76  * emitting the following events:
77  * - mrpt::slam::mrptEventMetricMapClear: Upon call of the ::clear() method.
78  * - mrpt::slam::mrptEventMetricMapInsert: Upon insertion of an observation that effectively modifies the map (e.g. inserting an image into a grid map will NOT raise an event, inserting a laser scan will).
79  *
80  * \sa CObservation, CSensoryFrame, CMultiMetricMap
81  * \ingroup mrpt_obs_grp
82  */
84  public mrpt::utils::CSerializable,
85  public mrpt::utils::CObservable
86  {
87  // This must be added to any CSerializable derived class:
89 
90  private:
91  /** Internal method called by clear() */
92  virtual void internal_clear() = 0;
93 
94  /** Hook for each time a "internal_insertObservation" returns "true"
95  * This is called automatically from insertObservation() when internal_insertObservation returns true.
96  */
97  virtual void OnPostSuccesfulInsertObs(const CObservation *)
98  {
99  // Default: do nothing
100  }
101 
102  /** Internal method called by insertObservation() */
103  virtual bool internal_insertObservation(
104  const CObservation *obs,
105  const CPose3D *robotPose = NULL ) = 0;
106 
107  public:
108  /** Erase all the contents of the map */
109  void clear();
110 
111  /** Returns true if the map is empty/no observation has been inserted.
112  */
113  virtual bool isEmpty() const = 0;
114 
115  /** Load the map contents from a CSimpleMap object, erasing all previous content of the map.
116  * This is automaticed invoking "insertObservation" for each observation at the mean 3D robot pose as
117  * given by the "poses::CPosePDF" in the CSimpleMap object.
118  *
119  * \sa insertObservation, CSimpleMap
120  * \exception std::exception Some internal steps in invoked methods can raise exceptions on invalid parameters, etc...
121  */
122  void loadFromProbabilisticPosesAndObservations( const CSimpleMap &Map );
123 
124  /** Load the map contents from a CSimpleMap object, erasing all previous content of the map.
125  * This is automaticed invoking "insertObservation" for each observation at the mean 3D robot pose as
126  * given by the "poses::CPosePDF" in the CSimpleMap object.
127  *
128  * \sa insertObservation, CSimpleMap
129  * \exception std::exception Some internal steps in invoked methods can raise exceptions on invalid parameters, etc...
130  */
131  inline void loadFromSimpleMap( const CSimpleMap &Map ) { loadFromProbabilisticPosesAndObservations(Map); }
132 
133  /** Insert the observation information into this map. This method must be implemented
134  * in derived classes.
135  * \param obs The observation
136  * \param robotPose The 3D pose of the robot mobile base in the map reference system, or NULL (default) if you want to use the origin.
137  *
138  * \sa CObservation::insertObservationInto
139  */
140  bool insertObservation(const CObservation *obs, const CPose3D *robotPose = NULL );
141 
142  /** A wrapper for smart pointers, just calls the non-smart pointer version. */
143  bool insertObservationPtr(const CObservationPtr &obs, const CPose3D *robotPose = NULL );
144 
145  /** Computes the log-likelihood of a given observation given an arbitrary robot 3D pose.
146  *
147  * \param takenFrom The robot's pose the observation is supposed to be taken from.
148  * \param obs The observation.
149  * \return This method returns a log-likelihood.
150  *
151  * \sa Used in particle filter algorithms, see: CMultiMetricMapPDF::update
152  */
153  virtual double computeObservationLikelihood( const CObservation *obs, const CPose3D &takenFrom ) = 0;
154 
155  /** Computes the log-likelihood of a given observation given an arbitrary robot 2D pose.
156  *
157  * \param takenFrom The robot's pose the observation is supposed to be taken from.
158  * \param obs The observation.
159  * \return This method returns a log-likelihood.
160  *
161  * \sa Used in particle filter algorithms, see: CMultiMetricMapPDF::update
162  */
163  double computeObservationLikelihood( const CObservation *obs, const CPose2D &takenFrom );
164 
165  /** 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).
166  * \param obs The observation.
167  * \sa computeObservationLikelihood
168  */
170  {
171  MRPT_UNUSED_PARAM(obs);
172  return true; // Unless implemented otherwise, assume we can always compute the likelihood.
173  }
174 
175  /** \overload */
176  bool canComputeObservationLikelihood( const CObservationPtr &obs );
177 
178  /** Returns the sum of the log-likelihoods of each individual observation within a mrpt::slam::CSensoryFrame.
179  *
180  * \param takenFrom The robot's pose the observation is supposed to be taken from.
181  * \param sf The set of observations in a CSensoryFrame.
182  * \return This method returns a log-likelihood.
183  * \sa canComputeObservationsLikelihood
184  */
185  double computeObservationsLikelihood( const CSensoryFrame &sf, const CPose2D &takenFrom );
186 
187  /** 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).
188  * \param sf The observations.
189  * \sa canComputeObservationLikelihood
190  */
191  bool canComputeObservationsLikelihood( const CSensoryFrame &sf );
192 
193  /** Constructor */
194  CMetricMap();
195 
196  /** Destructor */
197  virtual ~CMetricMap();
198 
199  /** Computes the matching between this and another 2D point map, which includes finding:
200  * - The set of points pairs in each map
201  * - The mean squared distance between corresponding pairs.
202  *
203  * The algorithm is:
204  * - For each point in "otherMap":
205  * - Transform the point according to otherMapPose
206  * - Search with a KD-TREE the closest correspondences in "this" map.
207  * - Add to the set of candidate matchings, if it passes all the thresholds in params.
208  *
209  * This method is the most time critical one into ICP-like algorithms.
210  *
211  * \param otherMap [IN] The other map to compute the matching with.
212  * \param otherMapPose [IN] The pose of the other map as seen from "this".
213  * \param params [IN] Parameters for the determination of pairings.
214  * \param correspondences [OUT] The detected matchings pairs.
215  * \param extraResults [OUT] Other results.
216  * \sa compute3DMatchingRatio
217  */
218  virtual void determineMatching2D(
219  const CMetricMap * otherMap,
220  const CPose2D & otherMapPose,
221  TMatchingPairList & correspondences,
222  const TMatchingParams & params,
223  TMatchingExtraResults & extraResults ) const;
224 
225  /** Computes the matchings between this and another 3D points map - method used in 3D-ICP.
226  * This method finds the set of point pairs in each map.
227  *
228  * The method is the most time critical one into ICP-like algorithms.
229  *
230  * The algorithm is:
231  * - For each point in "otherMap":
232  * - Transform the point according to otherMapPose
233  * - Search with a KD-TREE the closest correspondences in "this" map.
234  * - Add to the set of candidate matchings, if it passes all the thresholds in params.
235  *
236  * \param otherMap [IN] The other map to compute the matching with.
237  * \param otherMapPose [IN] The pose of the other map as seen from "this".
238  * \param params [IN] Parameters for the determination of pairings.
239  * \param correspondences [OUT] The detected matchings pairs.
240  * \param extraResults [OUT] Other results.
241  * \sa compute3DMatchingRatio
242  */
243  virtual void determineMatching3D(
244  const CMetricMap * otherMap,
245  const CPose3D & otherMapPose,
246  TMatchingPairList & correspondences,
247  const TMatchingParams & params,
248  TMatchingExtraResults & extraResults ) const;
249 
250  /** Computes the ratio in [0,1] of correspondences between "this" and the "otherMap" map, whose 6D pose relative to "this" is "otherMapPose"
251  * In the case of a multi-metric map, this returns the average between the maps. This method always return 0 for grid maps.
252  * \param otherMap [IN] The other map to compute the matching with.
253  * \param otherMapPose [IN] The 6D pose of the other map as seen from "this".
254  * \param maxDistForCorr [IN] The minimum distance between 2 non-probabilistic map elements for counting them as a correspondence.
255  * \param maxMahaDistForCorr [IN] The minimum Mahalanobis distance between 2 probabilistic map elements for counting them as a correspondence.
256  *
257  * \return The matching ratio [0,1]
258  * \sa determineMatching2D
259  */
260  virtual float compute3DMatchingRatio(
261  const CMetricMap *otherMap,
262  const CPose3D &otherMapPose,
263  float maxDistForCorr = 0.10f,
264  float maxMahaDistForCorr = 2.0f
265  ) const;
266 
267  /** 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).
268  */
269  virtual void saveMetricMapRepresentationToFile(
270  const std::string &filNamePrefix
271  ) const = 0;
272 
273  /** Returns a 3D object representing the map.
274  */
275  virtual void getAs3DObject( mrpt::opengl::CSetOfObjectsPtr &outObj ) const = 0;
276 
277  /** When set to true (default=false), calling "getAs3DObject" will have no effects.
278  */
280 
281  /** This method is called at the end of each "prediction-update-map insertion" cycle within "mrpt::slam::CMetricMapBuilderRBPF::processActionObservation".
282  * This method should normally do nothing, but in some cases can be used to free auxiliary cached variables.
283  */
285  {
286  // Default implementation: do nothing.
287  }
288 
289  /** Returns the square distance from the 2D point (x0,y0) to the closest correspondence in the map.
290  */
291  virtual float squareDistanceToClosestCorrespondence(float x0,float y0 ) const;
292 
293 
294  /** If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points map, return it.
295  * Otherwise, return NULL
296  */
297  virtual const CSimplePointsMap * getAsSimplePointsMap() const { return NULL; }
298  virtual CSimplePointsMap * getAsSimplePointsMap() { return NULL; }
299 
300 
301  }; // End of class def.
303 
304  /** A list of metric maps (used in the mrpt::poses::CPosePDFParticles class):
305  */
306  typedef std::deque<CMetricMap*> TMetricMapList;
307 
308  } // End of namespace
309 } // End of namespace
310 
311 #endif
size_t decimation_other_map_points
(Default=1) Only consider 1 out of this number of points from the "other" map.
Definition: CMetricMap.h:38
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
void loadFromSimpleMap(const CSimpleMap &Map)
Load the map contents from a CSimpleMap object, erasing all previous content of the map...
Definition: CMetricMap.h:131
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:35
float correspondencesRatio
The ratio [0,1] of points in otherMap with at least one correspondence.
Definition: CMetricMap.h:57
bool onlyKeepTheClosest
If set to true (default), only the closest correspondence will be returned. If false all are returned...
Definition: CMetricMap.h:36
STL namespace.
float maxDistForCorrespondence
Maximum linear distance between two points to be paired (meters)
Definition: CMetricMap.h:34
std::deque< CMetricMap * > TMetricMapList
A list of metric maps (used in the mrpt::poses::CPosePDFParticles class):
Definition: CMetricMap.h:306
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
float sumSqrDist
The sum of all matched points squared distances.If undesired, set to NULL, as default.
Definition: CMetricMap.h:58
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:83
#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...
virtual bool canComputeObservationLikelihood(const CObservation *obs)
Returns true if this map is able to compute a sensible likelihood function for this observation (i...
Definition: CMetricMap.h:169
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
bool m_disableSaveAs3DObject
When set to true (default=false), calling "getAs3DObject" will have no effects.
Definition: CMetricMap.h:279
A list of TMatchingPair.
Definition: TMatchingPair.h:66
size_t offset_other_map_points
Index of the first point in the "other" map to start checking for correspondences (Default=0) ...
Definition: CMetricMap.h:39
Declares a class that represents any robot's observation.
Definition: CObservation.h:52
float maxAngularDistForCorrespondence
Allowed "angular error" (in radians): this permits larger pairing threshold distances to more distant...
Definition: CMetricMap.h:35
Parameters for the determination of matchings between point clouds, etc.
Definition: CMetricMap.h:32
This class stores a sequence of pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:34
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual const CSimplePointsMap * getAsSimplePointsMap() const
If the map is a simple points map or it's a multi-metric map that contains EXACTLY one simple points ...
Definition: CMetricMap.h:297
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:53
A class used to store a 2D pose.
Definition: CPose2D.h:36
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
Additional results from the determination of matchings between point clouds, etc., apart from the pairings themselves.
Definition: CMetricMap.h:55
mrpt::math::TPoint3D angularDistPivotPoint
The point used to calculate angular distances: e.g. the coordinates of the sensor for a 2D laser scan...
Definition: CMetricMap.h:40
bool onlyUniqueRobust
Additional consistency filter: "onlyKeepTheClosest" allows one correspondence for each "local map" po...
Definition: CMetricMap.h:37
Lightweight 3D point.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
Inherit from this class for those objects capable of being observed by a CObserver class...
Definition: CObservable.h:33
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
virtual void auxParticleFilterCleanUp()
This method is called at the end of each "prediction-update-map insertion" cycle within "mrpt::slam::...
Definition: CMetricMap.h:284
TMatchingParams()
Ctor: default values.
Definition: CMetricMap.h:43
virtual CSimplePointsMap * getAsSimplePointsMap()
Definition: CMetricMap.h:298



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