40 #ifndef PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
41 #define PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
43 #include <pcl/console/print.h>
47 namespace registration {
49 template <
typename Scalar>
53 if (convergence_state_ != CONVERGENCE_CRITERIA_NOT_CONVERGED) {
55 iterations_similar_transforms_ = 0;
56 convergence_state_ = CONVERGENCE_CRITERIA_NOT_CONVERGED;
59 bool is_similar =
false;
61 PCL_DEBUG(
"[pcl::DefaultConvergenceCriteria::hasConverged] Iteration %d out of %d.\n",
65 if (iterations_ >= max_iterations_) {
66 if (!failure_after_max_iter_) {
67 convergence_state_ = CONVERGENCE_CRITERIA_ITERATIONS;
70 convergence_state_ = CONVERGENCE_CRITERIA_FAILURE_AFTER_MAX_ITERATIONS;
75 double cos_angle = 0.5 * (transformation_.coeff(0, 0) + transformation_.coeff(1, 1) +
76 transformation_.coeff(2, 2) - 1);
77 double translation_sqr = transformation_.coeff(0, 3) * transformation_.coeff(0, 3) +
78 transformation_.coeff(1, 3) * transformation_.coeff(1, 3) +
79 transformation_.coeff(2, 3) * transformation_.coeff(2, 3);
80 PCL_DEBUG(
"[pcl::DefaultConvergenceCriteria::hasConverged] Current transformation "
81 "gave %f rotation (cosine) and %f translation.\n",
85 if (cos_angle >= rotation_threshold_ && translation_sqr <= translation_threshold_) {
86 if (iterations_similar_transforms_ >= max_iterations_similar_transforms_) {
87 convergence_state_ = CONVERGENCE_CRITERIA_TRANSFORM;
93 correspondences_cur_mse_ = calculateMSE(correspondences_);
94 PCL_DEBUG(
"[pcl::DefaultConvergenceCriteria::hasConverged] Previous / Current MSE "
95 "for correspondences distances is: %f / %f.\n",
96 correspondences_prev_mse_,
97 correspondences_cur_mse_);
101 if (std::abs(correspondences_cur_mse_ - correspondences_prev_mse_) <
102 mse_threshold_absolute_) {
103 if (iterations_similar_transforms_ >= max_iterations_similar_transforms_) {
104 convergence_state_ = CONVERGENCE_CRITERIA_ABS_MSE;
111 if (std::abs(correspondences_cur_mse_ - correspondences_prev_mse_) /
112 correspondences_prev_mse_ <
113 mse_threshold_relative_) {
114 if (iterations_similar_transforms_ >= max_iterations_similar_transforms_) {
115 convergence_state_ = CONVERGENCE_CRITERIA_REL_MSE;
123 ++iterations_similar_transforms_;
127 iterations_similar_transforms_ = 0;
130 correspondences_prev_mse_ = correspondences_cur_mse_;
bool hasConverged() override
Check if convergence has been reached.