69 std::vector<mrpt::math::TPoint3D>&
71 std::vector<mrpt::math::TPoint3D>&
74 double& out_scale,
bool forceScaleToUnity)
81 TPoint3D ct_others(0, 0, 0), ct_this(0, 0, 0);
82 const size_t nMatches = points_this.size();
87 for (
size_t i = 0; i < nMatches; i++)
89 ct_others += points_other[i];
90 ct_this += points_this[i];
93 const double F = 1.0 / nMatches;
100 for (
size_t i = 0; i < nMatches; i++)
102 points_this[i] -= ct_this;
103 points_other[i] -= ct_others;
105 S.get_unsafe(0, 0) += points_other[i].x * points_this[i].x;
106 S.get_unsafe(0, 1) += points_other[i].x * points_this[i].y;
107 S.get_unsafe(0, 2) += points_other[i].x * points_this[i].z;
109 S.get_unsafe(1, 0) += points_other[i].y * points_this[i].x;
110 S.get_unsafe(1, 1) += points_other[i].y * points_this[i].y;
111 S.get_unsafe(1, 2) += points_other[i].y * points_this[i].z;
113 S.get_unsafe(2, 0) += points_other[i].z * points_this[i].x;
114 S.get_unsafe(2, 1) += points_other[i].z * points_this[i].y;
115 S.get_unsafe(2, 2) += points_other[i].z * points_this[i].z;
122 0, 0, S.get_unsafe(0, 0) + S.get_unsafe(1, 1) + S.get_unsafe(2, 2));
123 N.set_unsafe(0, 1, S.get_unsafe(1, 2) - S.get_unsafe(2, 1));
124 N.set_unsafe(0, 2, S.get_unsafe(2, 0) - S.get_unsafe(0, 2));
125 N.set_unsafe(0, 3, S.get_unsafe(0, 1) - S.get_unsafe(1, 0));
127 N.set_unsafe(1, 0, N.get_unsafe(0, 1));
129 1, 1, S.get_unsafe(0, 0) - S.get_unsafe(1, 1) - S.get_unsafe(2, 2));
130 N.set_unsafe(1, 2, S.get_unsafe(0, 1) + S.get_unsafe(1, 0));
131 N.set_unsafe(1, 3, S.get_unsafe(2, 0) + S.get_unsafe(0, 2));
133 N.set_unsafe(2, 0, N.get_unsafe(0, 2));
134 N.set_unsafe(2, 1, N.get_unsafe(1, 2));
136 2, 2, -S.get_unsafe(0, 0) + S.get_unsafe(1, 1) - S.get_unsafe(2, 2));
137 N.set_unsafe(2, 3, S.get_unsafe(1, 2) + S.get_unsafe(2, 1));
139 N.set_unsafe(3, 0, N.get_unsafe(0, 3));
140 N.set_unsafe(3, 1, N.get_unsafe(1, 3));
141 N.set_unsafe(3, 2, N.get_unsafe(2, 3));
143 3, 3, -S.get_unsafe(0, 0) - S.get_unsafe(1, 1) + S.get_unsafe(2, 2));
150 N.eigenVectors(Z, D);
151 Z.extractCol(Z.getColCount() - 1,
v);
155 sqrt(
v[0] *
v[0] +
v[1] *
v[1] +
v[2] *
v[2] +
v[3] *
v[3]) - 1.0) <
168 for (
unsigned int i = 0; i < 4; i++)
169 out_transform[i + 3] =
v[i];
173 if (forceScaleToUnity)
181 for (
size_t i = 0; i < nMatches; i++)
190 s = std::sqrt(
num / den);
195 ct_others.x, ct_others.y, ct_others.z, pp.
x, pp.
y, pp.
z);
198 out_transform[0] = ct_this.
x - pp.
x;
199 out_transform[1] = ct_this.
y - pp.
y;
200 out_transform[2] = ct_this.z - pp.
z;
209 const std::vector<mrpt::math::TPoint3D>& in_points_this,
210 const std::vector<mrpt::math::TPoint3D>& in_points_other,
212 bool forceScaleToUnity)
216 std::vector<mrpt::math::TPoint3D> points_this = in_points_this;
217 std::vector<mrpt::math::TPoint3D> points_other = in_points_other;
220 points_this, points_other, out_transform, out_scale, forceScaleToUnity);
226 bool forceScaleToUnity)
229 const size_t N = corrs.size();
230 std::vector<mrpt::math::TPoint3D> points_this(N), points_other(N);
231 for (
size_t i = 0; i < N; i++)
233 points_this[i].x = corrs[i].this_x;
234 points_this[i].y = corrs[i].this_y;
235 points_this[i].z = corrs[i].this_z;
236 points_other[i].x = corrs[i].other_x;
237 points_other[i].y = corrs[i].other_y;
238 points_other[i].z = corrs[i].other_z;
241 points_this, points_other, out_transform, out_scale, forceScaleToUnity);
#define ASSERT_EQUAL_(__A, __B)
double x() const
Common members of all points & poses classes.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
T square(const T x)
Inline function for the square of a number.
void composePoint(const double lx, const double ly, const double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 7 > *out_jacobian_df_dpose=nullptr) const
Computes the 3D point G such as .
This base provides a set of functions for maths stuff.
bool se3_l2_internal(std::vector< mrpt::math::TPoint3D > &points_this, std::vector< mrpt::math::TPoint3D > &points_other, mrpt::poses::CPose3DQuat &out_transform, double &out_scale, bool forceScaleToUnity)
bool se3_l2(const mrpt::utils::TMatchingPairList &in_correspondences, mrpt::poses::CPose3DQuat &out_transform, double &out_scale, bool forceScaleToUnity=false)
Least-squares (L2 norm) solution to finding the optimal SE(3) transform between two reference frames ...
double x
X,Y,Z coordinates.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
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.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
Functions for estimating the optimal transformation between two frames of references given measuremen...