19 #ifndef FACTOR_ADDERS_MEASUREMENT_BASED_FACTOR_ADDER_H_
20 #define FACTOR_ADDERS_MEASUREMENT_BASED_FACTOR_ADDER_H_
26 template <
typename MeasurementType>
51 const std::function<
bool(
const MeasurementType&, gtsam::NonlinearFactorGraph&)>& process_measurement_function,
52 gtsam::NonlinearFactorGraph& factors);
57 const std::function<
bool(
const MeasurementType&)>& process_measurement_function);
66 gtsam::NonlinearFactorGraph& factors) = 0;
69 friend class boost::serialization::access;
70 template <
class Archive>
71 void serialize(Archive& ar,
const unsigned int file_version) {
72 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(
FactorAdder);
78 template <
typename MeasurementType>
82 template <
typename MeasurementType>
85 gtsam::NonlinearFactorGraph& factors) {
86 const int num_added_factors = AddMeasurementBasedFactors(oldest_allowed_time, newest_allowed_time, factors);
87 RemoveOldMeasurements(oldest_allowed_time);
88 return num_added_factors;
91 template <
typename MeasurementType>
93 measurements_.Add(measurement.timestamp, measurement);
96 template <
typename MeasurementType>
99 measurements_.RemoveOldValues(oldest_allowed_timestamp);
102 template <
typename MeasurementType>
105 const std::function<
bool(
const MeasurementType&, gtsam::NonlinearFactorGraph&)>& process_measurement_function,
106 gtsam::NonlinearFactorGraph& factors) {
107 auto& measurements = measurements_.set();
108 for (
auto it = measurements.begin(); it != measurements.end();) {
109 const auto& measurement = it->second;
110 const auto timestamp = it->first;
111 if (timestamp >= oldest_allowed_time && timestamp <= newest_allowed_time &&
112 process_measurement_function(measurement, factors)) {
114 it = measurements.erase(it);
121 template <
typename MeasurementType>
124 const std::function<
bool(
const MeasurementType&)>& process_measurement_function) {
125 gtsam::NonlinearFactorGraph dummy_factors;
127 oldest_allowed_time, newest_allowed_time,
128 [&process_measurement_function](
const MeasurementType& measurement, gtsam::NonlinearFactorGraph& factors) {
129 return process_measurement_function(measurement);
135 #endif // FACTOR_ADDERS_MEASUREMENT_BASED_FACTOR_ADDER_H_