15 #include <mrpt/math/CVectorDynamic.h>
16 #include <mrpt/math/num_jacobian.h>
18 #include <Eigen/Dense>
23 const Pairings& in,
const mrpt::poses::CPose3D& finalAlignSolution,
29 mrpt::math::CMatrixDouble66 cov;
34 mrpt::math::CMatrixDouble61 xInitial;
35 xInitial[0] = finalAlignSolution.x();
36 xInitial[1] = finalAlignSolution.y();
37 xInitial[0] = finalAlignSolution.x();
38 xInitial[3] = finalAlignSolution.yaw();
39 xInitial[4] = finalAlignSolution.pitch();
40 xInitial[5] = finalAlignSolution.roll();
42 mrpt::math::CMatrixDouble61 xIncrs;
43 for (
int i = 0; i < 3; i++) xIncrs[i] =
param.finDif_xyz;
44 for (
int i = 0; i < 3; i++) xIncrs[3 + i] =
param.finDif_angles;
50 LambdaParams lmbParams;
52 auto errorLambda = [&](
const mrpt::math::CMatrixDouble61&
x,
54 mrpt::math::CVectorDouble& err) {
55 mrpt::poses::CPose3D pose;
56 pose.setFromValues(
x[0],
x[1],
x[2],
x[3],
x[4],
x[5]);
58 const auto nPt2Pt = in.paired_pt2pt.size();
59 const auto nPt2Ln = in.paired_pt2ln.size();
60 const auto nPt2Pl = in.paired_pt2pl.size();
61 const auto nPl2Pl = in.paired_pl2pl.size();
62 const auto nLn2Ln = in.paired_ln2ln.size();
64 const auto nErrorTerms =
65 (nPt2Pt + nPl2Pl + nPt2Ln + nPt2Pl) * 3 + nLn2Ln * 4;
66 ASSERT_(nErrorTerms > 0);
67 err.resize(nErrorTerms);
70 for (
size_t idx_pt = 0; idx_pt < nPt2Pt; idx_pt++)
73 const auto& p = in.paired_pt2pt[idx_pt];
74 mrpt::math::CVectorFixedDouble<3> ret =
76 err.block<3, 1>(idx_pt * 3, 0) = ret.asEigen();
78 auto base_idx = nPt2Pt * 3;
81 for (
size_t idx_pt = 0; idx_pt < nPt2Ln; idx_pt++)
84 const auto& p = in.paired_pt2ln[idx_pt];
85 mrpt::math::CVectorFixedDouble<3> ret =
87 err.block<3, 1>(base_idx + idx_pt * 3, 0) = ret.asEigen();
89 base_idx += nPt2Ln * 3;
93 for (
size_t idx_ln = 0; idx_ln < nLn2Ln; idx_ln++)
95 const auto& p = in.paired_ln2ln[idx_ln];
96 mrpt::math::CVectorFixedDouble<4> ret =
98 err.block<4, 1>(base_idx + idx_ln * 4, 0) = ret.asEigen();
103 for (
size_t idx_pl = 0; idx_pl < nPt2Pl; idx_pl++)
106 const auto& p = in.paired_pt2pl[idx_pl];
107 mrpt::math::CVectorFixedDouble<3> ret =
109 err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
111 base_idx += nPt2Pl * 3;
114 for (
size_t idx_pl = 0; idx_pl < nPl2Pl; idx_pl++)
117 const auto& p = in.paired_pl2pl[idx_pl];
118 mrpt::math::CVectorFixedDouble<3> ret =
120 err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
126 mrpt::math::CMatrixDouble jacob;
127 mrpt::math::estimateJacobian(
130 const mrpt::math::CMatrixDouble61&,
const LambdaParams&,
131 mrpt::math::CVectorDouble&)>(errorLambda),
132 xIncrs, lmbParams, jacob);
134 const mrpt::math::CMatrixDouble66 hessian(
135 jacob.asEigen().transpose() * jacob.asEigen());
137 const mrpt::math::CMatrixDouble66 cov = hessian.inverse_LLt();