19 #ifndef LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_
20 #define LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_
25 #include <boost/optional.hpp>
26 #include <gtsam/nonlinear/Marginals.h>
29 template <
typename NodesT>
33 const boost::optional<const gtsam::Marginals&>& marginals = boost::none);
35 const Time& timestamp_b)
final;
38 boost::optional<const gtsam::Marginals&> marginals_;
39 std::shared_ptr<const NodesT> nodes_;
43 template <
typename NodesT>
45 const std::shared_ptr<const NodesT>&
nodes,
const boost::optional<const gtsam::Marginals&>& marginals)
46 : nodes_(
nodes), marginals_(marginals) {}
48 template <
typename NodesT>
51 const Time& timestamp_a,
52 const Time& timestamp_b) {
53 boost::optional<PoseCovariance> covariance_a_b;
55 if (marginals_ && nodes_) {
56 const auto closest_t_a = nodes_->ClosestTimestamp(timestamp_a);
57 const auto closest_t_b = nodes_->ClosestTimestamp(timestamp_b);
58 if (!closest_t_a || !closest_t_b) {
59 LogError(
"Interpolate: Failed to get closest timestamps.");
62 if (std::abs(*closest_t_a - timestamp_a) > 3.0 || std::abs(*closest_t_b - timestamp_b) > 3.0) {
63 LogWarning(
"Interpolate: Timestamps far from closest timestamps available.");
65 const auto keys_a = nodes_->Keys(*closest_t_a);
66 const auto keys_b = nodes_->Keys(*closest_t_b);
67 covariance_a_b = marginals_->jointMarginalCovariance({keys_a[0], keys_b[0]}).fullMatrix();
74 #endif // LOCALIZATION_COMMON_MARGINALS_POSE_COVARIANCE_INTERPOLATER_H_