Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00041 #define PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00042
00043 #include <pcl/registration/eigen.h>
00044 #include <pcl/correspondence.h>
00045 #include <pcl/registration/convergence_criteria.h>
00046
00047 namespace pcl
00048 {
00049 namespace registration
00050 {
00064 template <typename Scalar = float>
00065 class DefaultConvergenceCriteria : public ConvergenceCriteria
00066 {
00067 public:
00068 typedef boost::shared_ptr<DefaultConvergenceCriteria<Scalar> > Ptr;
00069 typedef boost::shared_ptr<const DefaultConvergenceCriteria<Scalar> > ConstPtr;
00070
00071 typedef Eigen::Matrix<Scalar, 4, 4> Matrix4;
00072
00073 enum ConvergenceState
00074 {
00075 CONVERGENCE_CRITERIA_NOT_CONVERGED,
00076 CONVERGENCE_CRITERIA_ITERATIONS,
00077 CONVERGENCE_CRITERIA_TRANSFORM,
00078 CONVERGENCE_CRITERIA_ABS_MSE,
00079 CONVERGENCE_CRITERIA_REL_MSE,
00080 CONVERGENCE_CRITERIA_NO_CORRESPONDENCES
00081 };
00082
00094 DefaultConvergenceCriteria (const int &iterations, const Matrix4 &transform, const pcl::Correspondences &correspondences)
00095 : iterations_ (iterations)
00096 , transformation_ (transform)
00097 , correspondences_ (correspondences)
00098 , correspondences_prev_mse_ (std::numeric_limits<double>::max ())
00099 , correspondences_cur_mse_ (std::numeric_limits<double>::max ())
00100 , max_iterations_ (100)
00101 , failure_after_max_iter_ (false)
00102 , rotation_threshold_ (0.99999)
00103 , translation_threshold_ (3e-4 * 3e-4)
00104 , mse_threshold_relative_ (0.00001)
00105 , mse_threshold_absolute_ (1e-12)
00106 , iterations_similar_transforms_ (0)
00107 , max_iterations_similar_transforms_ (0)
00108 , convergence_state_ (CONVERGENCE_CRITERIA_NOT_CONVERGED)
00109 {
00110 }
00111
00113 virtual ~DefaultConvergenceCriteria () {}
00114
00119 inline void
00120 setMaximumIterationsSimilarTransforms (const int nr_iterations) { max_iterations_similar_transforms_ = nr_iterations; }
00121
00125 inline int
00126 getMaximumIterationsSimilarTransforms () const { return (max_iterations_similar_transforms_); }
00127
00131 inline void
00132 setMaximumIterations (const int nr_iterations) { max_iterations_ = nr_iterations; }
00133
00135 inline int
00136 getMaximumIterations () const { return (max_iterations_); }
00137
00141 inline void
00142 setFailureAfterMaximumIterations (const bool failure_after_max_iter) { failure_after_max_iter_ = failure_after_max_iter; }
00143
00145 inline bool
00146 getFailureAfterMaximumIterations () const { return (failure_after_max_iter_); }
00147
00151 inline void
00152 setRotationThreshold (const double threshold) { rotation_threshold_ = threshold; }
00153
00156 inline double
00157 getRotationThreshold () const { return (rotation_threshold_); }
00158
00162 inline void
00163 setTranslationThreshold (const double threshold) { translation_threshold_ = threshold; }
00164
00167 inline double
00168 getTranslationThreshold () const { return (translation_threshold_); }
00169
00173 inline void
00174 setRelativeMSE (const double mse_relative) { mse_threshold_relative_ = mse_relative; }
00175
00177 inline double
00178 getRelativeMSE () const { return (mse_threshold_relative_); }
00179
00183 inline void
00184 setAbsoluteMSE (const double mse_absolute) { mse_threshold_absolute_ = mse_absolute; }
00185
00187 inline double
00188 getAbsoluteMSE () const { return (mse_threshold_absolute_); }
00189
00190
00192 virtual bool
00193 hasConverged ();
00194
00196 ConvergenceState
00197 getConvergenceState ()
00198 {
00199 return (convergence_state_);
00200 }
00201
00207 inline void
00208 setConvergenceState(ConvergenceState c)
00209 {
00210 convergence_state_ = c;
00211 }
00212
00213 protected:
00214
00218 inline double
00219 calculateMSE (const pcl::Correspondences &correspondences) const
00220 {
00221 double mse = 0;
00222 for (size_t i = 0; i < correspondences.size (); ++i)
00223 mse += correspondences[i].distance;
00224 mse /= double (correspondences.size ());
00225 return (mse);
00226 }
00227
00229 const int &iterations_;
00230
00232 const Matrix4 &transformation_;
00233
00235 const pcl::Correspondences &correspondences_;
00236
00238 double correspondences_prev_mse_;
00239
00241 double correspondences_cur_mse_;
00242
00244 int max_iterations_;
00245
00247 bool failure_after_max_iter_;
00248
00250 double rotation_threshold_;
00251
00253 double translation_threshold_;
00254
00256 double mse_threshold_relative_;
00257
00259 double mse_threshold_absolute_;
00260
00263 int iterations_similar_transforms_;
00264
00267 int max_iterations_similar_transforms_;
00268
00270 ConvergenceState convergence_state_;
00271
00272 public:
00273 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00274 };
00275 }
00276 }
00277
00278 #include <pcl/registration/impl/default_convergence_criteria.hpp>
00279
00280 #endif // PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00281