Main MRPT website > C++ reference
MRPT logo
CICP.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CICP_H
29 #define CICP_H
30 
33 
34 namespace mrpt
35 {
36  namespace slam
37  {
38  using namespace poses;
39 
40  /** The ICP algorithm selection, used in mrpt::slam::CICP::options.
41  * For details on the algorithms refer to http://www.mrpt.org/Scan_Matching_Algorithms
42  * \ingroup mrpt_slam_grp
43  */
45  {
49  };
50 
51  /** Several implementations of ICP (Iterative closest point) algorithms for aligning two point maps or a point map wrt a grid map.
52  *
53  * CICP::AlignPDF() or CICP::Align() are the two main entry points of the algorithm.
54  *
55  * To choose among existing ICP algorithms or customizing their parameters, see CICP::TConfigParams and the member \a options.
56  *
57  * There exists an extension of the original ICP algorithm that provides multihypotheses-support for the correspondences, and which generates a Sum-of-Gaussians (SOG)
58  * PDF as output. See scanmatching::robustRigidTransformation.
59  *
60  * For further details on the implemented methods, check the web:
61  * http://www.mrpt.org/Iterative_Closest_Point_(ICP)_and_other_matching_algorithms
62  *
63  * For a paper explaining some of the basic equations, see for example:
64  * J. Martinez, J. Gonzalez, J. Morales, A. Mandow, A. Garcia-Cerezo,
65  * "Genetic and ICP Laser Point Matching for 2D Mobile Robot Motion Estimation",
66  * Journal of Field Robotics, vol. 23, no. 1, 2006. ( http://babel.isa.uma.es/~jlblanco/papers/martinez2006gil.pdf )
67  *
68  * \sa CMetricMapsAlignmentAlgorithm
69  * \ingroup mrpt_slam_grp
70  */
72  {
73  public:
74  /** The ICP algorithm configuration data
75  */
77  {
78  public:
79  TConfigParams(); //!< Initializer for default values:
80 
81  void loadFromConfigFile(
82  const mrpt::utils::CConfigFileBase &source,
83  const std::string &section); //!< See utils::CLoadableOptions
84 
85  void dumpToTextStream(CStream &out) const; //!<See utils::CLoadableOptions
86 
87 
88  /** The algorithm to use (default: icpClassic)
89  * See http://www.mrpt.org/Scan_Matching_Algorithms for details.
90  */
92 
93  bool onlyClosestCorrespondences; //!< The usual approach: to consider only the closest correspondence for each local point (Default to true)
94  bool onlyUniqueRobust; //! Apart of "onlyClosestCorrespondences=true", if this option is enabled only the closest correspondence for each reference point will be kept (default=false).
95 
96  /** @name Termination criteria
97  @{ */
98  unsigned int maxIterations; //!< Maximum number of iterations to run.
99  float minAbsStep_trans; //!< If the correction in all translation coordinates (X,Y,Z) is below this threshold (in meters), iterations are terminated (Default:1e-6)
100  float minAbsStep_rot; //!< If the correction in all rotation coordinates (yaw,pitch,roll) is below this threshold (in radians), iterations are terminated (Default:1e-6)
101  /** @} */
102 
103  float thresholdDist,thresholdAng; //!< Initial threshold distance for two points to become a correspondence.
104  float ALFA; //!< The scale factor for threshold everytime convergence is achieved.
105  float smallestThresholdDist; //!< The size for threshold such that iterations will stop, since it is considered precise enough.
106 
107  /** This is the normalization constant \f$ \sigma^2_p \f$ that is used to scale the whole 3x3 covariance.
108  * This has a default value of \f$ (0.02)^2 \f$, that is, a 2cm sigma.
109  * See the paper: ....
110  */
112 
113  bool doRANSAC; //!< Perform a RANSAC step after the ICP convergence, to obtain a better estimation of the pose PDF.
114 
115  /** RANSAC-step options:
116  * \sa CICP::robustRigidTransformation
117  */
118  unsigned int ransac_minSetSize,ransac_maxSetSize,ransac_nSimulations;
119 
120  /** RANSAC-step options:
121  * \sa CICP::robustRigidTransformation
122  */
124 
125  /** RANSAC-step option: The standard deviation in X,Y of landmarks/points which are being matched (used to compute covariances in the SoG)
126  * \sa CICP::robustRigidTransformation
127  */
129 
130  /** RANSAC-step options:
131  * \sa CICP::robustRigidTransformation
132  */
134 
135  /** RANSAC-step options:
136  * \sa CICP::robustRigidTransformation
137  */
138  float ransac_fuseMaxDiffXY, ransac_fuseMaxDiffPhi;
139 
140  /** Cauchy kernel rho, for estimating the optimal transformation covariance, in meters (default = 0.07m). */
141  float kernel_rho;
142 
143  /** Whether to use kernel_rho to smooth distances, or use distances directly (default=true) */
145 
146  /** The size of the perturbance in x & y used to estimate the Jacobians of the square error (in LM & IKF methods, default=0.05).*/
148 
149  /** The initial value of the lambda parameter in the LM method (default=1e-4). */
151 
152  /** Skip the computation of the covariance (saves some time) (default=false) */
154 
155  /** Decimation of the point cloud being registered against the reference one (default=5) - set to 1 to have the older (MRPT <0.9.5) behavior
156  * of not approximating ICP by ignoring the correspondence of some points. The speed-up comes from a decimation of the number of KD-tree queries,
157  * the most expensive step in ICP.
158  */
160 
161  };
162 
163  TConfigParams options; //!< The options employed by the ICP align.
164 
165 
166  /** Constructor with the default options */
167  CICP() : options() { }
168  /** Constructor that directly set the ICP params from a given struct \sa options */
169  CICP(const TConfigParams &icpParams) : options(icpParams) { }
170 
171  virtual ~CICP() { } //!< Destructor
172 
173 
174  /** The ICP algorithm return information.
175  */
177  {
179  cbSize(sizeof(TReturnInfo)),
180  nIterations(0),
181  goodness(0),
182  quality(0)
183  {
184  }
185 
186  /** Size in bytes of this struct: Must be set correctly before using it */
187  unsigned int cbSize;
188 
189  /** The number of executed iterations until convergence.
190  */
191  unsigned short nIterations;
192 
193  /** A goodness measure for the alignment, it is a [0,1] range indicator of percentage of correspondences.
194  */
195  float goodness;
196 
197  /** A measure of the 'quality' of the local minimum of the sqr. error found by the method.
198  * Higher values are better. Low values will be found in ill-conditioned situations (e.g. a corridor).
199  */
200  float quality;
201  };
202 
203  /** An implementation of CMetricMapsAlignmentAlgorithm for the case of a point maps and a occupancy grid/point map.
204  *
205  * This method computes the PDF of the displacement (relative pose) between
206  * two maps: <b>the relative pose of m2 with respect to m1</b>. This pose
207  * is returned as a PDF rather than a single value.
208  *
209  * \note This method can be configurated with "CICP::options"
210  * \note The output PDF is a CPosePDFGaussian if "doRANSAC=false", or a CPosePDFSOG otherwise.
211  *
212  * \param m1 [IN] The first map (CAN BE A mrpt::poses::CPointsMap derived class or a mrpt::slam::COccupancyGrid2D class)
213  * \param m2 [IN] The second map. (MUST BE A mrpt::poses::CPointsMap derived class)The pose of this map respect to m1 is to be estimated.
214  * \param initialEstimationPDF [IN] An initial gross estimation for the displacement.
215  * \param runningTime [OUT] A pointer to a container for obtaining the algorithm running time in seconds, or NULL if you don't need it.
216  * \param info [OUT] A pointer to a CICP::TReturnInfo, or NULL if it isn't needed.
217  *
218  * \return A smart pointer to the output estimated pose PDF.
219  *
220  * \sa CMetricMapsAlignmentAlgorithm, CICP::options, CICP::TReturnInfo
221  */
222  CPosePDFPtr AlignPDF(
223  const CMetricMap *m1,
224  const CMetricMap *m2,
225  const CPosePDFGaussian &initialEstimationPDF,
226  float *runningTime = NULL,
227  void *info = NULL );
228 
229  /** Align a pair of metric maps, aligning the full 6D pose.
230  * The meaning of some parameters are implementation dependant,
231  * so look at the derived classes for more details.
232  * The goal is to find a PDF for the pose displacement between
233  * maps, that is, <b>the pose of m2 relative to m1</b>. This pose
234  * is returned as a PDF rather than a single value.
235  *
236  * \note This method can be configurated with a "options" structure in the implementation classes.
237  *
238  * \param m1 [IN] The first map (MUST BE A COccupancyGridMap2D derived class)
239  * \param m2 [IN] The second map. (MUST BE A CPointsMap derived class) The pose of this map respect to m1 is to be estimated.
240  * \param initialEstimationPDF [IN] An initial gross estimation for the displacement.
241  * \param runningTime [OUT] A pointer to a container for obtaining the algorithm running time in seconds, or NULL if you don't need it.
242  * \param info [OUT] See derived classes for details, or NULL if it isn't needed.
243  *
244  * \return A smart pointer to the output estimated pose PDF.
245  * \sa CICP
246  */
247  CPose3DPDFPtr Align3DPDF(
248  const CMetricMap *m1,
249  const CMetricMap *m2,
250  const CPose3DPDFGaussian &initialEstimationPDF,
251  float *runningTime = NULL,
252  void *info = NULL );
253 
254 
255  protected:
256  /** Computes:
257  * \f[ K(x^2) = \frac{x^2}{x^2+\rho^2} \f]
258  * or just return the input if options.useKernel = false.
259  */
260  float kernel(const float &x2, const float &rho2);
261 
262  /** The internal method implementing CICP::AlignPDF when options.ICP_algorithm is icpClassic.
263  */
264  CPosePDFPtr ICP_Method_Classic(
265  const CMetricMap *m1,
266  const CMetricMap *m2,
267  const CPosePDFGaussian &initialEstimationPDF,
268  TReturnInfo &outInfo );
269 
270  /** The internal method implementing CICP::AlignPDF when options.ICP_algorithm is icpLevenbergMarquardt.
271  */
272  CPosePDFPtr ICP_Method_LM(
273  const CMetricMap *m1,
274  const CMetricMap *m2,
275  const CPosePDFGaussian &initialEstimationPDF,
276  TReturnInfo &outInfo );
277 
278  /** The internal method implementing CICP::AlignPDF when options.ICP_algorithm is icpIKF.
279  */
280  CPosePDFPtr ICP_Method_IKF(
281  const CMetricMap *m1,
282  const CMetricMap *m2,
283  const CPosePDFGaussian &initialEstimationPDF,
284  TReturnInfo &outInfo );
285 
286  /** The internal method implementing CICP::Align3DPDF when options.ICP_algorithm is icpClassic.
287  */
288  CPose3DPDFPtr ICP3D_Method_Classic(
289  const CMetricMap *m1,
290  const CMetricMap *m2,
291  const CPose3DPDFGaussian &initialEstimationPDF,
292  TReturnInfo &outInfo );
293 
294 
295  };
296 
297  } // End of namespace
298 } // End of namespace
299 
300 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013