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_HPP_
00041 #define PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
00042
00043 #include <pcl/console/print.h>
00044
00046 template <typename Scalar> bool
00047 pcl::registration::DefaultConvergenceCriteria<Scalar>::hasConverged ()
00048 {
00049 convergence_state_ = CONVERGENCE_CRITERIA_NOT_CONVERGED;
00050
00051 PCL_DEBUG ("[pcl::DefaultConvergenceCriteria::hasConverged] Iteration %d out of %d.\n", iterations_, max_iterations_);
00052
00053 if (iterations_ >= max_iterations_)
00054 {
00055 if (failure_after_max_iter_)
00056 return (false);
00057 else
00058 {
00059 convergence_state_ = CONVERGENCE_CRITERIA_ITERATIONS;
00060 return (true);
00061 }
00062 return (failure_after_max_iter_ ? false : true);
00063 }
00064
00065
00066 double cos_angle = 0.5 * (transformation_.coeff (0, 0) + transformation_.coeff (1, 1) + transformation_.coeff (2, 2) - 1);
00067 double translation_sqr = transformation_.coeff (0, 3) * transformation_.coeff (0, 3) +
00068 transformation_.coeff (1, 3) * transformation_.coeff (1, 3) +
00069 transformation_.coeff (2, 3) * transformation_.coeff (2, 3);
00070 PCL_DEBUG ("[pcl::DefaultConvergenceCriteria::hasConverged] Current transformation gave %f rotation (cosine) and %f translation.\n", cos_angle, translation_sqr);
00071
00072 if (cos_angle >= rotation_threshold_ && translation_sqr <= translation_threshold_)
00073 {
00074 if (iterations_similar_transforms_ < max_iterations_similar_transforms_)
00075 {
00076
00077 ++iterations_similar_transforms_;
00078 return (false);
00079 }
00080 else
00081 {
00082 iterations_similar_transforms_ = 0;
00083 convergence_state_ = CONVERGENCE_CRITERIA_TRANSFORM;
00084 return (true);
00085 }
00086 }
00087
00088 correspondences_cur_mse_ = calculateMSE (correspondences_);
00089 PCL_DEBUG ("[pcl::DefaultConvergenceCriteria::hasConverged] Previous / Current MSE for correspondences distances is: %f / %f.\n", correspondences_prev_mse_, correspondences_cur_mse_);
00090
00091
00092
00093 if (fabs (correspondences_cur_mse_ - correspondences_prev_mse_) < mse_threshold_absolute_)
00094 {
00095 if (iterations_similar_transforms_ < max_iterations_similar_transforms_)
00096 {
00097
00098 ++iterations_similar_transforms_;
00099 return (false);
00100 }
00101 else
00102 {
00103 iterations_similar_transforms_ = 0;
00104 convergence_state_ = CONVERGENCE_CRITERIA_ABS_MSE;
00105 return (true);
00106 }
00107 }
00108
00109
00110 if (fabs (correspondences_cur_mse_ - correspondences_prev_mse_) / correspondences_prev_mse_ < mse_threshold_relative_)
00111 {
00112 if (iterations_similar_transforms_ < max_iterations_similar_transforms_)
00113 {
00114
00115 ++iterations_similar_transforms_;
00116 return (false);
00117 }
00118 else
00119 {
00120 iterations_similar_transforms_ = 0;
00121 convergence_state_ = CONVERGENCE_CRITERIA_REL_MSE;
00122 return (true);
00123 }
00124 }
00125
00126 correspondences_prev_mse_ = correspondences_cur_mse_;
00127
00128 return (false);
00129 }
00130
00131 #endif // PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_