52 const size_t N = in_correspondences.size();
54 if (N < 2)
return false;
56 const float N_inv = 1.0f / N;
81 __m128 sum_a_xyz = _mm_setzero_ps();
82 __m128 sum_b_xyz = _mm_setzero_ps();
86 __m128 sum_ab_xyz = _mm_setzero_ps();
89 corrIt != in_correspondences.end(); corrIt++)
98 const __m128 a_xyz = _mm_loadu_ps(&corrIt->this_x);
100 _mm_loadu_ps(&corrIt->other_x);
102 const __m128 a_xyxy =
103 _mm_shuffle_ps(a_xyz, a_xyz, _MM_SHUFFLE(1, 0, 1, 0));
104 const __m128 b_xyyx =
105 _mm_shuffle_ps(b_xyz, b_xyz, _MM_SHUFFLE(0, 1, 1, 0));
108 sum_a_xyz = _mm_add_ps(sum_a_xyz, a_xyz);
109 sum_b_xyz = _mm_add_ps(sum_b_xyz, b_xyz);
113 sum_ab_xyz = _mm_add_ps(sum_ab_xyz, _mm_mul_ps(a_xyxy, b_xyyx));
116 alignas(16)
float sums_a[4], sums_b[4];
117 _mm_store_ps(sums_a, sum_a_xyz);
118 _mm_store_ps(sums_b, sum_b_xyz);
120 const float& SumXa = sums_a[0];
121 const float& SumYa = sums_a[1];
122 const float& SumXb = sums_b[0];
123 const float& SumYb = sums_b[1];
126 const __m128 Ninv_4val =
128 sum_a_xyz = _mm_mul_ps(sum_a_xyz, Ninv_4val);
129 sum_b_xyz = _mm_mul_ps(sum_b_xyz, Ninv_4val);
135 alignas(16)
float means_a[4], means_b[4];
136 _mm_store_ps(means_a, sum_a_xyz);
137 _mm_store_ps(means_b, sum_b_xyz);
139 const float& mean_x_a = means_a[0];
140 const float& mean_y_a = means_a[1];
141 const float& mean_x_b = means_b[0];
142 const float& mean_y_b = means_b[1];
146 alignas(16)
float cross_sums[4];
147 _mm_store_ps(cross_sums, sum_ab_xyz);
149 const float& Sxx = cross_sums[0];
150 const float& Syy = cross_sums[1];
151 const float& Sxy = cross_sums[2];
152 const float& Syx = cross_sums[3];
155 const float Ax = N * (Sxx + Syy) - SumXa * SumXb - SumYa * SumYb;
156 const float Ay = SumXa * SumYb + N * (Syx - Sxy) - SumXb * SumYa;
160 float SumXa = 0, SumXb = 0, SumYa = 0, SumYb = 0;
161 float Sxx = 0, Sxy = 0, Syx = 0, Syy = 0;
164 corrIt != in_correspondences.end(); corrIt++)
167 const float xa = corrIt->this_x;
168 const float ya = corrIt->this_y;
169 const float xb = corrIt->other_x;
170 const float yb = corrIt->other_y;
185 const float mean_x_a = SumXa * N_inv;
186 const float mean_y_a = SumYa * N_inv;
187 const float mean_x_b = SumXb * N_inv;
188 const float mean_y_b = SumYb * N_inv;
191 const float Ax = N * (Sxx + Syy) - SumXa * SumXb - SumYa * SumYb;
192 const float Ay = SumXa * SumYb + N * (Syx - Sxy) - SumXb * SumYa;
196 out_transformation.
phi =
198 ? atan2(static_cast<double>(Ay),
static_cast<double>(Ax))
201 const double ccos = cos(out_transformation.
phi);
202 const double csin = sin(out_transformation.
phi);
204 out_transformation.
x = mean_x_a - mean_x_b * ccos + mean_y_b * csin;
205 out_transformation.
y = mean_y_a - mean_x_b * csin - mean_y_b * ccos;
207 if (out_estimateCovariance)
213 double var_x_a = 0, var_y_a = 0, var_x_b = 0, var_y_b = 0;
214 const double N_1_inv = 1.0 / (N - 1);
219 in_correspondences.begin();
220 corrIt != in_correspondences.end(); corrIt++)
222 var_x_a +=
square(corrIt->this_x - mean_x_a);
223 var_y_a +=
square(corrIt->this_y - mean_y_a);
224 var_x_b +=
square(corrIt->other_x - mean_x_b);
225 var_y_b +=
square(corrIt->other_y - mean_y_b);
234 const double BETA = (var_x_a + var_y_a + var_x_b + var_y_b) *
235 pow(static_cast<double>(N), 2.0) *
236 static_cast<double>(N - 1);
244 C->get_unsafe(0, 0) =
245 2.0 * N_inv + BETA *
square((mean_x_b * Ay + mean_y_b * Ax) / D);
246 C->get_unsafe(1, 1) =
247 2.0 * N_inv + BETA *
square((mean_x_b * Ax - mean_y_b * Ay) / D);
248 C->get_unsafe(2, 2) = BETA / D;
250 C->get_unsafe(0, 1) = C->get_unsafe(1, 0) =
251 -BETA * (mean_x_b * Ay + mean_y_b * Ax) *
252 (mean_x_b * Ax - mean_y_b * Ay) /
square(D);
254 C->get_unsafe(0, 2) = C->get_unsafe(2, 0) =
255 BETA * (mean_x_b * Ay + mean_y_b * Ax) / pow(D, 1.5);
257 C->get_unsafe(1, 2) = C->get_unsafe(2, 1) =
258 BETA * (mean_y_b * Ay - mean_x_b * Ax) / pow(D, 1.5);
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
CPose2D mean
The mean value.
bool se2_l2(const mrpt::utils::TMatchingPairList &in_correspondences, mrpt::math::TPose2D &out_transformation, mrpt::math::CMatrixDouble33 *out_estimateCovariance=nullptr)
Least-squares (L2 norm) solution to finding the optimal SE(2) (x,y,yaw) between two reference frames...
const Scalar * const_iterator
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Functions for estimating the optimal transformation between two frames of references given measuremen...
double phi
Orientation (rads)