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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: dad381fd7 Sun Oct 20 13:36:46 2019 +0200 at dom oct 20 13:40:10 CEST 2019