15 #include <mrpt/poses/Lie/SE.h> 17 #include <Eigen/Dense> 34 "This method requires a linearization point");
44 const auto nErrorTerms =
45 (nPt2Pt + nPl2Pl + nPt2Ln + nPt2Pl) * 3 + nLn2Ln * 4;
47 Eigen::VectorXd err(nErrorTerms);
48 Eigen::Matrix<double, Eigen::Dynamic, 6> J(nErrorTerms, 6);
54 std::size_t cur_point_block_start = 0;
56 MRPT_TODO(
"Implement robust Kernel in this solver");
61 const auto dDexpe_de =
62 mrpt::poses::Lie::SE<3>::jacob_dDexpe_de(result.
optimalPose);
65 for (
size_t idx_pt = 0; idx_pt < nPt2Pt; idx_pt++)
69 mrpt::math::CMatrixFixed<double, 3, 12> J1;
70 mrpt::math::CVectorFixedDouble<3> ret =
72 err.block<3, 1>(idx_pt * 3, 0) = ret.asEigen();
75 if (has_per_pt_weight)
78 cur_point_block_start + cur_point_block_weights->first)
81 ++cur_point_block_weights;
82 cur_point_block_start = idx_pt;
84 w.pt2pt = cur_point_block_weights->second;
88 J.block<3, 6>(idx_pt * 3, 0) =
89 w.pt2pt * J1.asEigen() * dDexpe_de.asEigen();
91 auto base_idx = nPt2Pt * 3;
94 for (
size_t idx_pt = 0; idx_pt < nPt2Ln; idx_pt++)
98 mrpt::math::CMatrixFixed<double, 3, 12> J1;
99 mrpt::math::CVectorFixedDouble<3> ret =
101 err.block<3, 1>(base_idx + idx_pt * 3, 0) = ret.asEigen();
107 J.block<3, 6>(base_idx + idx_pt * 3, 0) =
108 w.pt2ln * J1.asEigen() * dDexpe_de.asEigen();
110 base_idx += nPt2Ln * 3;
114 for (
size_t idx_ln = 0; idx_ln < nLn2Ln; idx_ln++)
117 mrpt::math::CMatrixFixed<double, 4, 12> J1;
118 mrpt::math::CVectorFixedDouble<4> ret =
120 err.block<4, 1>(base_idx + idx_ln * 4, 0) = ret.asEigen();
123 J.block<4, 6>(base_idx + idx_ln, 0) =
124 J1.asEigen() * dDexpe_de.asEigen();
129 for (
size_t idx_pl = 0; idx_pl < nPt2Pl; idx_pl++)
133 mrpt::math::CMatrixFixed<double, 3, 12> J1;
134 mrpt::math::CVectorFixedDouble<3> ret =
136 err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
138 J.block<3, 6>(idx_pl * 3 + base_idx, 0) =
139 w.pt2pl * J1.asEigen() * dDexpe_de.asEigen();
141 base_idx += nPt2Pl * 3;
144 for (
size_t idx_pl = 0; idx_pl < nPl2Pl; idx_pl++)
148 mrpt::math::CMatrixFixed<double, 3, 12> J1;
149 mrpt::math::CVectorFixedDouble<3> ret =
151 err.block<3, 1>(idx_pl * 3 + base_idx, 0) = ret.asEigen();
153 J.block<3, 6>(3 * idx_pl + base_idx, 0) =
154 w.pl2pl * J1.asEigen() * dDexpe_de.asEigen();
158 if (err.norm() <= gnParams.
maxCost)
break;
161 const Eigen::VectorXd g = J.transpose() * err;
162 const Eigen::Matrix<double, 6, 6> H = J.transpose() * J;
163 const Eigen::Matrix<double, 6, 1> delta =
164 -H.colPivHouseholderQr().solve(g);
167 const auto dE = mrpt::poses::Lie::SE<3>::exp(
168 mrpt::math::CVectorFixed<double, 6>(delta));
174 std::cout <<
"[P2P GN] iter:" << iter <<
" err:" << err.norm()
175 <<
" delta:" << delta.transpose() <<
"\n";
179 if (delta.norm() < gnParams.
minDelta)
break;
mrpt::math::CVectorFixedDouble< 4 > error_line2line(const mp2p_icp::matched_line_t &pairing, const mrpt::poses::CPose3D &relativePose, mrpt::optional_ref< mrpt::math::CMatrixFixed< double, 4, 12 >> jacobian=std::nullopt)
MatchedLineList paired_ln2ln
std::optional< mrpt::poses::CPose3D > linearizationPoint
Simple non-linear optimizer to find the SE(3) optimal transformation.
mrpt::math::CVectorFixedDouble< 3 > error_point2point(const mrpt::tfest::TMatchingPair &pairing, const mrpt::poses::CPose3D &relativePose, mrpt::optional_ref< mrpt::math::CMatrixFixed< double, 3, 12 >> jacobian=std::nullopt)
mrpt::math::CVectorFixedDouble< 3 > error_plane2plane(const mp2p_icp::matched_plane_t &pairing, const mrpt::poses::CPose3D &relativePose, mrpt::optional_ref< mrpt::math::CMatrixFixed< double, 3, 12 >> jacobian=std::nullopt)
std::vector< std::pair< std::size_t, double > > point_weights
mrpt::math::CVectorFixedDouble< 3 > error_point2plane(const mp2p_icp::point_plane_pair_t &pairing, const mrpt::poses::CPose3D &relativePose, mrpt::optional_ref< mrpt::math::CMatrixFixed< double, 3, 12 >> jacobian=std::nullopt)
MatchedPointLineList paired_pt2ln
mrpt::poses::CPose3D optimalPose
MatchedPlaneList paired_pl2pl
mrpt::math::CVectorFixedDouble< 3 > error_point2line(const mp2p_icp::point_line_pair_t &pairing, const mrpt::poses::CPose3D &relativePose, mrpt::optional_ref< mrpt::math::CMatrixFixed< double, 3, 12 >> jacobian=std::nullopt)
mrpt::tfest::TMatchingPairList paired_pt2pt
MatchedPointPlaneList paired_pt2pl
bool optimal_tf_gauss_newton(const Pairings &in, OptimalTF_Result &result, const OptimalTF_GN_Parameters &gnParams=OptimalTF_GN_Parameters())
uint32_t maxInnerLoopIterations