Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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>
17 #include <mrpt/obs/CObservation.h>
22 #include <mrpt/obs/obs_frwds.h>
23 #include <deque>
24 
25 namespace mrpt
26 {
27 namespace maps
28 {
29 /** Declares a virtual base class for all metric maps storage classes.
30  * In this class virtual methods are provided to allow the insertion
31  * of any type of "CObservation" objects into the metric map, thus
32  * updating the map (doesn't matter if it is a 2D/3D grid, a point map, etc.).
33  *
34  * Observations don't include any information about the
35  * robot pose, just the raw observation and information about
36  * the sensor pose relative to the robot mobile base coordinates origin.
37  *
38  * Note that all metric maps implement this mrpt::utils::CObservable interface,
39  * emitting the following events:
40  * - mrpt::obs::mrptEventMetricMapClear: Upon call of the ::clear() method.
41  * - mrpt::obs::mrptEventMetricMapInsert: Upon insertion of an observation
42  *that effectively modifies the map (e.g. inserting an image into a grid map
43  *will NOT raise an event, inserting a laser scan will).
44  *
45  * To check what observations are supported by each metric map, see: \ref
46  *maps_observations
47  *
48  * \note All derived class must implement a static class factory
49  *`<metric_map_class>::MapDefinition()` that builds a default
50  *TMetricMapInitializer [New in MRPT 1.3.0]
51  *
52  * \sa CObservation, CSensoryFrame, CMultiMetricMap
53  * \ingroup mrpt_obs_grp
54  */
57 {
59 
60  private:
61  /** Internal method called by clear() */
62  virtual void internal_clear() = 0;
63 
64  /** Internal method called by insertObservation() */
66  const mrpt::obs::CObservation* obs,
67  const mrpt::poses::CPose3D* robotPose = NULL) = 0;
68 
69  /** Internal method called by computeObservationLikelihood() */
71  const mrpt::obs::CObservation* obs,
72  const mrpt::poses::CPose3D& takenFrom) = 0;
73  /** Internal method called by canComputeObservationLikelihood() */
75  const mrpt::obs::CObservation* obs) const
76  {
77  MRPT_UNUSED_PARAM(obs);
78  return true; // Unless implemented otherwise, assume we can always
79  // compute the likelihood.
80  }
81 
82  /** Hook for each time a "internal_insertObservation" returns "true"
83  * This is called automatically from insertObservation() when
84  * internal_insertObservation returns true. */
86  { /* Default: do nothing */}
87 
88  public:
89  /** Erase all the contents of the map */
90  void clear();
91 
92  /** Returns true if the map is empty/no observation has been inserted.
93  */
94  virtual bool isEmpty() const = 0;
95 
96  /** Load the map contents from a CSimpleMap object, erasing all previous
97  * content of the map. This is done invoking `insertObservation()` for each
98  * observation at the mean 3D robot pose of each pose-observations pair in
99  * the CSimpleMap object.
100  *
101  * \sa insertObservation, CSimpleMap
102  * \exception std::exception Some internal steps in invoked methods can
103  * raise exceptions on invalid parameters, etc...
104  */
106  const mrpt::maps::CSimpleMap& Map);
107 
108  ///! \overload
110  {
112  }
113 
114  /** Insert the observation information into this map. This method must be
115  * implemented
116  * in derived classes. See: \ref maps_observations
117  * \param obs The observation
118  * \param robotPose The 3D pose of the robot mobile base in the map
119  * reference system, or NULL (default) if you want to use the origin.
120  *
121  * \sa CObservation::insertObservationInto
122  */
123  bool insertObservation(
124  const mrpt::obs::CObservation* obs,
125  const mrpt::poses::CPose3D* robotPose = NULL);
126 
127  /** A wrapper for smart pointers, just calls the non-smart pointer version.
128  * See: \ref maps_observations */
130  const mrpt::obs::CObservation::Ptr& obs,
131  const mrpt::poses::CPose3D* robotPose = NULL);
132 
133  /** Computes the log-likelihood of a given observation given an arbitrary
134  * robot 3D pose. See: \ref maps_observations
135  *
136  * \param takenFrom The robot's pose the observation is supposed to be taken
137  * from.
138  * \param obs The observation.
139  * \return This method returns a log-likelihood.
140  *
141  * \sa Used in particle filter algorithms, see: CMultiMetricMapPDF::update
142  */
144  const mrpt::obs::CObservation* obs,
145  const mrpt::poses::CPose3D& takenFrom);
146 
147  /** \overload */
149  const mrpt::obs::CObservation* obs,
150  const mrpt::poses::CPose2D& takenFrom);
151 
152  /** Returns true if this map is able to compute a sensible likelihood
153  * function for this observation (i.e. an occupancy grid map cannot with an
154  * image). See: \ref maps_observations
155  * \param obs The observation.
156  * \sa computeObservationLikelihood,
157  * genericMapParams.enableObservationLikelihood
158  */
159  virtual bool canComputeObservationLikelihood(
160  const mrpt::obs::CObservation* obs) const;
161 
162  /** \overload */
164  const mrpt::obs::CObservation::Ptr& obs) const;
165 
166  /** Returns the sum of the log-likelihoods of each individual observation
167  * within a mrpt::obs::CSensoryFrame. See: \ref maps_observations
168  *
169  * \param takenFrom The robot's pose the observation is supposed to be taken
170  * from.
171  * \param sf The set of observations in a CSensoryFrame.
172  * \return This method returns a log-likelihood.
173  * \sa canComputeObservationsLikelihood
174  */
176  const mrpt::obs::CSensoryFrame& sf,
177  const mrpt::poses::CPose2D& takenFrom);
178 
179  /** Returns true if this map is able to compute a sensible likelihood
180  * function for this observation (i.e. an occupancy grid map cannot with an
181  * image). See: \ref maps_observations
182  * \param sf The observations.
183  * \sa canComputeObservationLikelihood
184  */
186  const mrpt::obs::CSensoryFrame& sf) const;
187 
188  /** Constructor */
189  CMetricMap();
190 
191  /** Computes the matching between this and another 2D point map, which
192  *includes finding:
193  * - The set of points pairs in each map
194  * - The mean squared distance between corresponding pairs.
195  *
196  * The algorithm is:
197  * - For each point in "otherMap":
198  * - Transform the point according to otherMapPose
199  * - Search with a KD-TREE the closest correspondences in "this"
200  *map.
201  * - Add to the set of candidate matchings, if it passes all the
202  *thresholds in params.
203  *
204  * This method is the most time critical one into ICP-like algorithms.
205  *
206  * \param otherMap [IN] The other map to compute the matching with.
207  * \param otherMapPose [IN] The pose of the other map as seen from
208  *"this".
209  * \param params [IN] Parameters for the determination of
210  *pairings.
211  * \param correspondences [OUT] The detected matchings pairs.
212  * \param extraResults [OUT] Other results.
213  * \sa compute3DMatchingRatio
214  */
215  virtual void determineMatching2D(
216  const mrpt::maps::CMetricMap* otherMap,
217  const mrpt::poses::CPose2D& otherMapPose,
218  mrpt::utils::TMatchingPairList& correspondences,
219  const TMatchingParams& params,
220  TMatchingExtraResults& extraResults) const;
221 
222  /** Computes the matchings between this and another 3D points map - method
223  *used in 3D-ICP.
224  * This method finds the set of point pairs in each map.
225  *
226  * The method is the most time critical one into ICP-like algorithms.
227  *
228  * The algorithm is:
229  * - For each point in "otherMap":
230  * - Transform the point according to otherMapPose
231  * - Search with a KD-TREE the closest correspondences in "this"
232  *map.
233  * - Add to the set of candidate matchings, if it passes all the
234  *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
238  *"this".
239  * \param params [IN] Parameters for the determination of
240  *pairings.
241  * \param correspondences [OUT] The detected matchings pairs.
242  * \param extraResults [OUT] Other results.
243  * \sa compute3DMatchingRatio
244  */
245  virtual void determineMatching3D(
246  const mrpt::maps::CMetricMap* otherMap,
247  const mrpt::poses::CPose3D& otherMapPose,
248  mrpt::utils::TMatchingPairList& correspondences,
249  const TMatchingParams& params,
250  TMatchingExtraResults& extraResults) const;
251 
252  /** Computes the ratio in [0,1] of correspondences between "this" and the
253  * "otherMap" map, whose 6D pose relative to "this" is "otherMapPose"
254  * In the case of a multi-metric map, this returns the average between the
255  * maps. This method always return 0 for grid maps.
256  * \param otherMap [IN] The other map to compute the matching with.
257  * \param otherMapPose [IN] The 6D pose of the other map as seen from
258  * "this".
259  * \param params [IN] Matching parameters
260  * \return The matching ratio [0,1]
261  * \sa determineMatching2D
262  */
263  virtual float compute3DMatchingRatio(
264  const mrpt::maps::CMetricMap* otherMap,
265  const mrpt::poses::CPose3D& otherMapPose,
266  const TMatchingRatioParams& params) const;
267 
268  /** This virtual method saves the map to a file "filNamePrefix"+<
269  * some_file_extension >, as an image or in any other applicable way (Notice
270  * that other methods to save the map may be implemented in classes
271  * implementing this virtual interface). */
273  const std::string& filNamePrefix) const = 0;
274 
275  /** Returns a 3D object representing the map.
276  * \sa genericMapParams, TMapGenericParams::enableSaveAs3DObject */
277  virtual void getAs3DObject(
278  mrpt::opengl::CSetOfObjects::Ptr& outObj) const = 0;
279 
280  /** Common params to all maps */
282 
283  /** This method is called at the end of each "prediction-update-map
284  * insertion" cycle within
285  * "mrpt::slam::CMetricMapBuilderRBPF::processActionObservation".
286  * This method should normally do nothing, but in some cases can be used
287  * to free auxiliary cached variables.
288  */
290  { /* Default implementation: do nothing. */}
291 
292  /** Returns the square distance from the 2D point (x0,y0) to the closest
293  * correspondence in the map. */
295  float x0, float y0) const;
296 
297  /** If the map is a simple points map or it's a multi-metric map that
298  * contains EXACTLY one simple points map, return it.
299  * Otherwise, return NULL
300  */
302  {
303  return NULL;
304  }
306  {
307  return NULL;
308  }
309 
310 }; // End of class def.
311 
312 /** A list of metric maps (used in the mrpt::poses::CPosePDFParticles class):
313  */
314 typedef std::deque<CMetricMap*> TMetricMapList;
315 
316 } // End of namespace
317 } // End of namespace
318 
319 #endif
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
This declaration must be inserted in virtual CSerializable classes definition:
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:57
bool insertObservationPtr(const mrpt::obs::CObservation::Ptr &obs, const mrpt::poses::CPose3D *robotPose=NULL)
A wrapper for smart pointers, just calls the non-smart pointer version.
Definition: CMetricMap.cpp:109
double computeObservationsLikelihood(const mrpt::obs::CSensoryFrame &sf, const mrpt::poses::CPose2D &takenFrom)
Returns the sum of the log-likelihoods of each individual observation within a mrpt::obs::CSensoryFra...
Definition: CMetricMap.cpp:67
TMapGenericParams genericMapParams
Common params to all maps.
Definition: CMetricMap.h:281
virtual float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams &params) const
Computes the ratio in [0,1] of correspondences between "this" and the "otherMap" map,...
Definition: CMetricMap.cpp:157
virtual void internal_clear()=0
Internal method called by clear()
virtual void determineMatching3D(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, mrpt::utils::TMatchingPairList &correspondences, const TMatchingParams &params, TMatchingExtraResults &extraResults) const
Computes the matchings between this and another 3D points map - method used in 3D-ICP.
Definition: CMetricMap.cpp:142
virtual void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const =0
Returns a 3D object representing the map.
virtual float squareDistanceToClosestCorrespondence(float x0, float y0) const
Returns the square distance from the 2D point (x0,y0) to the closest correspondence in the map.
Definition: CMetricMap.cpp:170
virtual void auxParticleFilterCleanUp()
This method is called at the end of each "prediction-update-map insertion" cycle within "mrpt::slam::...
Definition: CMetricMap.h:289
void loadFromSimpleMap(const mrpt::maps::CSimpleMap &Map)
!This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: CMetricMap.h:109
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)
Insert the observation information into this map.
Definition: CMetricMap.cpp:95
virtual void determineMatching2D(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose2D &otherMapPose, mrpt::utils::TMatchingPairList &correspondences, const TMatchingParams &params, TMatchingExtraResults &extraResults) const
Computes the matching between this and another 2D point map, which includes finding:
Definition: CMetricMap.cpp:127
CMetricMap()
Constructor.
Definition: CMetricMap.cpp:29
virtual double internal_computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom)=0
Internal method called by computeObservationLikelihood()
virtual void OnPostSuccesfulInsertObs(const mrpt::obs::CObservation *)
Hook for each time a "internal_insertObservation" returns "true" This is called automatically from in...
Definition: CMetricMap.h:85
virtual bool internal_insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=NULL)=0
Internal method called by insertObservation()
void loadFromProbabilisticPosesAndObservations(const mrpt::maps::CSimpleMap &Map)
Load the map contents from a CSimpleMap object, erasing all previous content of the map.
Definition: CMetricMap.cpp:37
virtual bool internal_canComputeObservationLikelihood(const mrpt::obs::CObservation *obs) const
Internal method called by canComputeObservationLikelihood()
Definition: CMetricMap.h:74
virtual const mrpt::maps::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:301
virtual bool canComputeObservationLikelihood(const mrpt::obs::CObservation *obs) const
Returns true if this map is able to compute a sensible likelihood function for this observation (i....
Definition: CMetricMap.cpp:180
virtual bool isEmpty() const =0
Returns true if the map is empty/no observation has been inserted.
double computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom)
Computes the log-likelihood of a given observation given an arbitrary robot 3D pose.
Definition: CMetricMap.cpp:189
void clear()
Erase all the contents of the map.
Definition: CMetricMap.cpp:31
bool canComputeObservationsLikelihood(const mrpt::obs::CSensoryFrame &sf) const
Returns true if this map is able to compute a sensible likelihood function for this observation (i....
Definition: CMetricMap.cpp:86
virtual void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const =0
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >,...
virtual mrpt::maps::CSimplePointsMap * getAsSimplePointsMap()
Definition: CMetricMap.h:305
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:36
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Common params to all maps derived from mrpt::maps::CMetricMap
Declares a class that represents any robot's observation.
Definition: CObservation.h:42
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:43
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:55
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:41
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
Inherit from this class for those objects capable of being observed by a CObserver class.
Definition: CObservable.h:36
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:45
A list of TMatchingPair.
Definition: TMatchingPair.h:94
GLenum const GLfloat * params
Definition: glext.h:3534
GLsizei const GLchar ** string
Definition: glext.h:4101
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:365
std::deque< CMetricMap * > TMetricMapList
A list of metric maps (used in the mrpt::poses::CPosePDFParticles class):
Definition: CMetricMap.h:314
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Additional results from the determination of matchings between point clouds, etc.,...
Parameters for the determination of matchings between point clouds, etc.
Parameters for CMetricMap::compute3DMatchingRatio()



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST