9 #ifndef GRAPH_SLAM_LEVMARQ_IMPL_H
10 #define GRAPH_SLAM_LEVMARQ_IMPL_H
28 template <
class EDGE,
class gst>
35 template <
class POSE,
class VEC,
class EDGE_ITERATOR>
37 const POSE& P1DP2inv, VEC& err,
const EDGE_ITERATOR& edge)
40 gst::SE_TYPE::pseudo_ln(P1DP2inv, err);
43 template <
class MAT,
class EDGE_ITERATOR>
45 const MAT& J1, MAT& JtJ,
const EDGE_ITERATOR& edge)
51 template <
class MAT,
class EDGE_ITERATOR>
53 const MAT& J1,
const MAT& J2, MAT& JtJ,
const EDGE_ITERATOR& edge)
56 JtJ.multiply_AtB(J1, J2);
59 template <
class JAC,
class EDGE_ITERATOR,
class VEC1,
class VEC2>
61 const JAC& J,
const EDGE_ITERATOR& edge,
const VEC1& ERR, VEC2& OUT)
64 J.multiply_Atb(ERR, OUT,
true );
72 template <
class POSE,
class VEC,
class EDGE_ITERATOR>
74 const POSE& P1DP2inv, VEC& err,
const EDGE_ITERATOR& edge)
77 gst::SE_TYPE::pseudo_ln(P1DP2inv, err);
80 template <
class MAT,
class EDGE_ITERATOR>
82 const MAT& J1, MAT& JtJ,
const EDGE_ITERATOR& edge)
88 template <
class MAT,
class EDGE_ITERATOR>
90 const MAT& J1,
const MAT& J2, MAT& JtJ,
const EDGE_ITERATOR& edge)
93 JtJ.multiply_AtB(J1, J2);
96 template <
class JAC,
class EDGE_ITERATOR,
class VEC1,
class VEC2>
98 const JAC& J,
const EDGE_ITERATOR& edge,
const VEC1& ERR, VEC2& OUT)
101 J.multiply_Atb(ERR, OUT,
true );
109 template <
class POSE,
class VEC,
class EDGE_ITERATOR>
111 const POSE& P1DP2inv, VEC& err,
const EDGE_ITERATOR& edge)
113 gst::SE_TYPE::pseudo_ln(P1DP2inv, err);
116 template <
class MAT,
class EDGE_ITERATOR>
118 const MAT& J1, MAT& JtJ,
const EDGE_ITERATOR& edge)
120 JtJ.multiply_AtBC(J1, edge->second.cov_inv, J1);
122 template <
class MAT,
class EDGE_ITERATOR>
124 const MAT& J1,
const MAT& J2, MAT& JtJ,
const EDGE_ITERATOR& edge)
126 JtJ.multiply_AtBC(J1, edge->second.cov_inv, J2);
129 template <
class JAC,
class EDGE_ITERATOR,
class VEC1,
class VEC2>
131 const JAC& J,
const EDGE_ITERATOR& edge,
const VEC1& ERR, VEC2& OUT)
134 JtInf.multiply_AtB(J, edge->second.cov_inv);
135 JtInf.multiply_Ab(ERR, OUT,
true );
143 template <
class POSE,
class VEC,
class EDGE_ITERATOR>
145 const POSE& P1DP2inv, VEC& err,
const EDGE_ITERATOR& edge)
148 gst::SE_TYPE::pseudo_ln(P1DP2inv, err);
151 template <
class MAT,
class EDGE_ITERATOR>
153 const MAT& J1, MAT& JtJ,
const EDGE_ITERATOR& edge)
155 JtJ.multiply_AtBC(J1, edge->second.cov_inv, J1);
158 template <
class MAT,
class EDGE_ITERATOR>
160 const MAT& J1,
const MAT& J2, MAT& JtJ,
const EDGE_ITERATOR& edge)
162 JtJ.multiply_AtBC(J1, edge->second.cov_inv, J2);
165 template <
class JAC,
class EDGE_ITERATOR,
class VEC1,
class VEC2>
167 const JAC& J,
const EDGE_ITERATOR& edge,
const VEC1& ERR, VEC2& OUT)
170 JtInf.multiply_AtB(J, edge->second.cov_inv);
171 JtInf.multiply_Ab(ERR, OUT,
true );
179 template <
class GRAPH_T>
181 const GRAPH_T& graph,
190 lstJacobians.clear();
193 const size_t nObservations = lstObservationData.size();
195 for (
size_t i = 0; i < nObservations; i++)
197 const typename gst::observation_info_t& obs = lstObservationData[i];
198 typename gst::edge_const_iterator it = obs.edge;
199 const typename gst::graph_t::constraint_t::type_value* EDGE_POSE =
201 typename gst::graph_t::constraint_t::type_value* P1 = obs.P1;
202 typename gst::graph_t::constraint_t::type_value* P2 = obs.P2;
204 const auto&
ids = it->first;
205 const auto& edge = it->second;
210 typename gst::graph_t::constraint_t::type_value P1DP2inv(
213 typename gst::graph_t::constraint_t::type_value P1D(
215 P1D.composeFrom(*P1, *EDGE_POSE);
216 const typename gst::graph_t::constraint_t::type_value P2inv =
218 P1DP2inv.composeFrom(P1D, P2inv);
222 errs.resize(errs.size() + 1);
224 P1DP2inv, errs.back(), edge);
228 std::pair<mrpt::graphs::TPairNodeIDs, typename gst::TPairJacobs>
230 newMapEntry.first =
ids;
231 gst::SE_TYPE::jacobian_dP1DP2inv_depsilon(
232 P1DP2inv, &newMapEntry.second.first, &newMapEntry.second.second);
235 lstJacobians.insert(lstJacobians.end(), newMapEntry);
241 double ret_err = 0.0;
242 for (
size_t i = 0; i < errs.size(); i++) ret_err += errs[i].squaredNorm();