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, 
const LambdaParams&,
 
   53                            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 = (nPt2Pt + nPl2Pl + nPt2Ln + nPt2Pl) * 3 + nLn2Ln * 4;
 
   65         ASSERT_(nErrorTerms > 0);
 
   66         err.resize(nErrorTerms);
 
   69         for (
size_t idx_pt = 0; idx_pt < nPt2Pt; idx_pt++)
 
   72             const auto&                       p   = in.paired_pt2pt[idx_pt];
 
   74             err.block<3, 1>(idx_pt * 3, 0)        = ret.asEigen();
 
   76         auto base_idx = nPt2Pt * 3;
 
   79         for (
size_t idx_pt = 0; idx_pt < nPt2Ln; idx_pt++)
 
   82             const auto&                       p       = in.paired_pt2ln[idx_pt];
 
   84             err.block<3, 1>(base_idx + idx_pt * 3, 0) = ret.asEigen();
 
   86         base_idx += nPt2Ln * 3;
 
   90         for (
size_t idx_ln = 0; idx_ln < nLn2Ln; idx_ln++)
 
   92             const auto&                       p       = in.paired_ln2ln[idx_ln];
 
   94             err.block<4, 1>(base_idx + idx_ln * 4, 0) = ret.asEigen();
 
   99         for (
size_t idx_pl = 0; idx_pl < nPt2Pl; idx_pl++)
 
  102             const auto&                       p       = in.paired_pt2pl[idx_pl];
 
  104             err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
 
  106         base_idx += nPt2Pl * 3;
 
  109         for (
size_t idx_pl = 0; idx_pl < nPl2Pl; idx_pl++)
 
  112             const auto&                       p       = in.paired_pl2pl[idx_pl];
 
  114             err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
 
  120     mrpt::math::CMatrixDouble jacob;
 
  121     mrpt::math::estimateJacobian(
 
  124             const mrpt::math::CMatrixDouble61&, 
const LambdaParams&, mrpt::math::CVectorDouble&)>(
 
  126         xIncrs, lmbParams, jacob);
 
  128     const mrpt::math::CMatrixDouble66 hessian(jacob.asEigen().transpose() * jacob.asEigen());
 
  130     const mrpt::math::CMatrixDouble66 cov = hessian.inverse_LLt();