iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StandardConvergenceCriteria.H
Go to the documentation of this file.
1 /*! @file
2  @author Shane Grant
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifdef NRT_HAVE_CLOUD
36 #ifndef NRT_POINTCLOUD2_REGISTRATION_CONVERGENCE_STANDARDCONVERGENCECRITERIA_H_
37 #define NRT_POINTCLOUD2_REGISTRATION_CONVERGENCE_STANDARDCONVERGENCECRITERIA_H_
38 
41 
42 namespace nrt
43 {
44  //! A standard convergence criteria
45  /*! This convergence criteria implements the following requirements for convergence (any one is enough to converge):
46  * some maximum number of iterations
47  * the transform from source to target cannot be updated (difference between current and previous is less than some threshold)
48  * the mean squared error (MSE) between the current set of correspondences and the previous is smaller than some threshold */
49  class StandardConvergenceCriteria : public ConvergenceCriteriaBase
50  {
51  public:
52  //! Represents the current state of the convergence
53  enum class ConvergenceState
54  {
55  not_converged,
56  max_iterations,
57  transform,
58  absolute_mse,
59  relative_mse
60  };
61 
62  //! Create a standard convergence criteria
63  /*! Initializes a standard convergence with several default parameters
64 
65  @param[in] maxIterations Maximum number of iterations
66  @param[in] failAfterMaxIterations Whether it is considered a failure to converge after the max
67  iterations is reached.
68  @param[in] rotationThreshold The rotation threshold (default value is equivalent to 0.256 degrees)
69  @param[in] translationThreshold The translation threshold in meters
70  @param[in] relativeMSE Relative MSE threshold, in the range[0,1]
71  @param[in] absoluteMSE Absolute MSE threshold
72  @param[in] maxSimilarTransforms Maximum number of consecutive similar transforms from either MSE or transform scores
73  required for convergence from either of these methods */
75  size_t maxIterations = 100, bool failAfterMaxIterations = false,
76  double rotationThreshold = 0.99999, double translationThreshold = 0.0003,
77  double relativeMSE = 0.00001, double absoluteMSE = 1e-12,
78  size_t maxSimilarTransforms = 0 );
79 
80  //! Check whether we have converged
81  /*! @param[in] iteration Current iteration of the optimization
82  @param[in] transform Current transform estimated by the optimization
83  @param[in] correspondences The current set of correspondences
84  @return Whether convergence has been reached */
85  bool converged( size_t const iteration, PointCloud2::AffineTransform const & transform, Correspondences const correspondences );
86 
87  //! Get our convergence state
89 
90  //! Resets any internal state associated with determining convergence
91  void reset();
92 
93  //! Gets the maximum number of iterations for convergence
94  size_t maxIterations() const;
95 
96  protected:
97  //! Computes an MSE score
98  double calculateMSE( Correspondences const & c ) const;
99 
100  private:
101  const size_t itsMaxIterations;
102  const bool itsFailOnMaxIteration;
103 
104  const double itsRotationThreshold;
105  const double itsTranslationThreshold;
106  const double itsMSEThresholdRelative;
107  const double itsMSEThresholdAbsolute;
108  const size_t itsMaxSimilarTransforms;
109 
110  size_t itsNumSimilarTransforms;
111 
112  ConvergenceState itsConvergenceState;
113 
114  double itsPreviousMSE;
115  double itsCurrentMSE;
116  };
117 } //namespace nrt
118 
119 #endif // NRT_POINTCLOUD2_REGISTRATION_CONVERGENCE_STANDARDCONVERGENCECRITERIA_H_
120 #endif // NRT_HAVE_CLOUD