Point Cloud Library (PCL) 1.15.1
Loading...
Searching...
No Matches
default_convergence_criteria.hpp
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2012-, Open Perception, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * $Id$
37 *
38 */
39
40#ifndef PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
41#define PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
42
43#include <pcl/console/print.h>
44
45namespace pcl {
46
47namespace registration {
48
49template <typename Scalar>
50bool
52{
54 // If it already converged or failed before, reset.
57 }
58
59 bool is_similar = false;
60
61 PCL_DEBUG("[pcl::DefaultConvergenceCriteria::hasConverged] Iteration %d out of %d.\n",
64 // 1. Number of iterations has reached the maximum user imposed number of iterations
68 return (true);
69 }
71 }
72
73 // 2. The epsilon (difference) between the previous transformation and the current
74 // estimated transformation
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",
82 cos_angle,
83 translation_sqr);
84
85 if (cos_angle >= rotation_threshold_ && translation_sqr <= translation_threshold_) {
88 return (true);
89 }
90 is_similar = true;
91 }
92
94 if (std::numeric_limits<double>::max() == correspondences_prev_mse_) {
95 PCL_DEBUG("[pcl::DefaultConvergenceCriteria::hasConverged] Previous / Current MSE "
96 "for correspondences distances is: INIT / %f.\n",
98 }
99 else {
100 PCL_DEBUG("[pcl::DefaultConvergenceCriteria::hasConverged] Previous / Current MSE "
101 "for correspondences distances is: %f / %f.\n",
104 }
105
106 // 3. The relative sum of Euclidean squared errors is smaller than a user defined
107 // threshold Absolute
112 return (true);
113 }
114 is_similar = true;
115 }
116
117 // Relative
123 return (true);
124 }
125 is_similar = true;
126 }
127
128 if (is_similar) {
129 // Increment the number of transforms that the thresholds are allowed to be similar
131 }
132 else {
133 // When the transform becomes large, reset.
135 }
136
138
139 return (false);
140}
141
142} // namespace registration
143} // namespace pcl
144
145#endif // PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_HPP_
ConvergenceState convergence_state_
The state of the convergence (e.g., why did the registration converge).
int iterations_similar_transforms_
Internal counter for the number of iterations that the internal rotation, translation,...
double correspondences_cur_mse_
The MSE for the current set of correspondences.
const Matrix4 & transformation_
The current transformation obtained by the transformation estimation method.
const pcl::Correspondences & correspondences_
The current set of point correspondences between the source and the target.
const int & iterations_
The number of iterations done by the registration loop so far.
int max_iterations_
The maximum nuyyGmber of iterations that the registration loop is to be executed.
double translation_threshold_
The translation threshold is the relative translation between two iterations (0 if no translation).
double mse_threshold_absolute_
The absolute change from the previous MSE for the current set of correspondences.
bool hasConverged() override
Check if convergence has been reached.
double calculateMSE(const pcl::Correspondences &correspondences) const
Calculate the mean squared error (MSE) of the distance for a given set of correspondences.
bool failure_after_max_iter_
Specifys if the registration fails or converges when the maximum number of iterations is reached.
double rotation_threshold_
The rotation threshold is the relative rotation between two iterations (as angle cosine).
double mse_threshold_relative_
The relative change from the previous MSE for the current set of correspondences, e....
double correspondences_prev_mse_
The MSE for the previous set of correspondences.
int max_iterations_similar_transforms_
The maximum number of iterations that the internal rotation, translation, and MSE differences are all...