18 #ifndef FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_
19 #define FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_
26 #include <gtsam/linear/NoiseModel.h>
27 #include <gtsam/slam/BetweenFactor.h>
32 template <
class PoseNodeAdderType>
37 const std::shared_ptr<PoseNodeAdderType> node_adder);
41 int AddFactorsForSingleMeasurement(
43 gtsam::NonlinearFactorGraph& factors)
final;
47 std::shared_ptr<PoseNodeAdderType> node_adder_;
51 template <
class PoseNodeAdderType>
53 const std::shared_ptr<PoseNodeAdderType> node_adder)
56 node_adder_(node_adder) {}
58 template <
class PoseNodeAdderType>
61 gtsam::NonlinearFactorGraph& factors) {
62 if (!node_adder_->AddNode(measurement.
timestamp_a, factors) ||
63 !node_adder_->AddNode(measurement.
timestamp_b, factors)) {
64 LogError(
"AddFactorsForSingleMeasurement: Failed to add nodes at respective times.");
68 const auto keys_a = node_adder_->Keys(measurement.
timestamp_a);
70 const auto& pose_key_a = keys_a[0];
71 const auto keys_b = node_adder_->Keys(measurement.
timestamp_b);
72 const auto& pose_key_b = keys_b[0];
73 const auto relative_pose_noise =
75 const gtsam::BetweenFactor<gtsam::Pose3>::shared_ptr pose_between_factor(
76 new gtsam::BetweenFactor<gtsam::Pose3>(pose_key_a, pose_key_b, measurement.
relative_pose, relative_pose_noise));
77 factors.push_back(pose_between_factor);
81 template <
class PoseNodeAdderType>
82 bool RelativePoseFactorAdder<PoseNodeAdderType>::CanAddFactor(
84 return node_adder_->CanAddNode(measurement.
timestamp_a) && node_adder_->CanAddNode(measurement.
timestamp_b);
88 #endif // FACTOR_ADDERS_RELATIVE_POSE_FACTOR_ADDER_H_