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  /** \overload */
162  const mrpt::obs::CObservation::Ptr& obs) const;
163 
164  /** Returns the sum of the log-likelihoods of each individual observation
165  * within a mrpt::obs::CSensoryFrame. See: \ref maps_observations
166  *
167  * \param takenFrom The robot's pose the observation is supposed to be taken
168  * from.
169  * \param sf The set of observations in a CSensoryFrame.
170  * \return This method returns a log-likelihood.
171  * \sa canComputeObservationsLikelihood
172  */
174  const mrpt::obs::CSensoryFrame& sf,
175  const mrpt::poses::CPose2D& takenFrom);
176 
177  /** Returns true if this map is able to compute a sensible likelihood
178  * function for this observation (i.e. an occupancy grid map cannot with an
179  * image). See: \ref maps_observations
180  * \param sf The observations.
181  * \sa canComputeObservationLikelihood
182  */
184  const mrpt::obs::CSensoryFrame& sf) const;
185 
186  /** Constructor */
187  CMetricMap();
188 
189  /** Computes the matching between this and another 2D point map, which
190  *includes finding:
191  * - The set of points pairs in each map
192  * - The mean squared distance between corresponding pairs.
193  *
194  * The algorithm is:
195  * - For each point in "otherMap":
196  * - Transform the point according to otherMapPose
197  * - Search with a KD-TREE the closest correspondences in "this"
198  *map.
199  * - Add to the set of candidate matchings, if it passes all the
200  *thresholds in params.
201  *
202  * This method is the most time critical one into ICP-like algorithms.
203  *
204  * \param otherMap [IN] The other map to compute the matching with.
205  * \param otherMapPose [IN] The pose of the other map as seen from
206  *"this".
207  * \param params [IN] Parameters for the determination of
208  *pairings.
209  * \param correspondences [OUT] The detected matchings pairs.
210  * \param extraResults [OUT] Other results.
211  * \sa compute3DMatchingRatio
212  */
213  virtual void determineMatching2D(
214  const mrpt::maps::CMetricMap* otherMap,
215  const mrpt::poses::CPose2D& otherMapPose,
216  mrpt::tfest::TMatchingPairList& correspondences,
217  const TMatchingParams& params,
218  TMatchingExtraResults& extraResults) const;
219 
220  /** Computes the matchings between this and another 3D points map - method
221  *used in 3D-ICP.
222  * This method finds the set of point pairs in each map.
223  *
224  * The method is the most time critical one into ICP-like algorithms.
225  *
226  * The algorithm is:
227  * - For each point in "otherMap":
228  * - Transform the point according to otherMapPose
229  * - Search with a KD-TREE the closest correspondences in "this"
230  *map.
231  * - Add to the set of candidate matchings, if it passes all the
232  *thresholds in params.
233  *
234  * \param otherMap [IN] The other map to compute the matching with.
235  * \param otherMapPose [IN] The pose of the other map as seen from
236  *"this".
237  * \param params [IN] Parameters for the determination of
238  *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 mrpt::maps::CMetricMap* otherMap,
245  const mrpt::poses::CPose3D& otherMapPose,
246  mrpt::tfest::TMatchingPairList& correspondences,
247  const TMatchingParams& params,
248  TMatchingExtraResults& extraResults) const;
249 
250  /** Computes the ratio in [0,1] of correspondences between "this" and the
251  * "otherMap" map, whose 6D pose relative to "this" is "otherMapPose"
252  * In the case of a multi-metric map, this returns the average between the
253  * maps. This method always return 0 for grid maps.
254  * \param otherMap [IN] The other map to compute the matching with.
255  * \param otherMapPose [IN] The 6D pose of the other map as seen from
256  * "this".
257  * \param params [IN] Matching parameters
258  * \return The matching ratio [0,1]
259  * \sa determineMatching2D
260  */
261  virtual float compute3DMatchingRatio(
262  const mrpt::maps::CMetricMap* otherMap,
263  const mrpt::poses::CPose3D& otherMapPose,
264  const TMatchingRatioParams& params) const;
265 
266  /** This virtual method saves the map to a file "filNamePrefix"+<
267  * some_file_extension >, as an image or in any other applicable way (Notice
268  * that other methods to save the map may be implemented in classes
269  * implementing this virtual interface). */
271  const std::string& filNamePrefix) const = 0;
272 
273  /** Returns a 3D object representing the map.
274  * \sa genericMapParams, TMapGenericParams::enableSaveAs3DObject */
275  virtual void getAs3DObject(
276  mrpt::opengl::CSetOfObjects::Ptr& outObj) const = 0;
277 
278  /** Common params to all maps */
280 
281  /** This method is called at the end of each "prediction-update-map
282  * insertion" cycle within
283  * "mrpt::slam::CMetricMapBuilderRBPF::processActionObservation".
284  * This method should normally do nothing, but in some cases can be used
285  * to free auxiliary cached variables.
286  */
288  { /* Default implementation: do nothing. */
289  }
290 
291  /** Returns the square distance from the 2D point (x0,y0) to the closest
292  * correspondence in the map. */
294  float x0, float y0) const;
295 
296  /** If the map is a simple points map or it's a multi-metric map that
297  * contains EXACTLY one simple points map, return it.
298  * Otherwise, return nullptr
299  */
301  {
302  return nullptr;
303  }
305  {
306  return const_cast<CSimplePointsMap*>(
307  const_cast<const CMetricMap*>(this)->getAsSimplePointsMap());
308  }
309 
310 }; // End of class def.
311 
312 /** A list of metric maps (used in the mrpt::poses::CPosePDFParticles class):
313  */
314 using TMetricMapList = std::deque<CMetricMap*>;
315 
316 } // 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.
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
bool insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=nullptr)
Insert the observation information into this map.
Definition: CMetricMap.cpp:93
virtual void auxParticleFilterCleanUp()
This method is called at the end of each "prediction-update-map insertion" cycle within "mrpt::slam::...
Definition: CMetricMap.h:287
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:187
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:279
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:178
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:168
#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:125
Additional results from the determination of matchings between point clouds, etc., apart from the pairings themselves.
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
virtual bool internal_canComputeObservationLikelihood(const mrpt::obs::CObservation *obs) const
Internal method called by canComputeObservationLikelihood()
Definition: CMetricMap.h:71
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:51
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:314
virtual double internal_computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom)=0
Internal method called by computeObservationLikelihood()
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:42
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
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
mrpt::maps::CSimplePointsMap * getAsSimplePointsMap()
Definition: CMetricMap.h:304
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:300
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:155
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:140
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
#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: 606c7e360 Mon Jun 24 22:58:07 2019 +0200 at lun jun 24 23:00:15 CEST 2019