gtsam/gtsam/sfm/BinaryMeasurement.h

88 lines
2.8 KiB
C
Raw Normal View History

2020-07-30 15:12:13 +08:00
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010-2020, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
/**
* @file BinaryMeasurement.h
* @author Akshay Krishnan
* @date July 2020
2020-08-14 08:38:58 +08:00
* @brief Binary measurement represents a measurement between two keys in a
* graph. A binary measurement is similar to a BetweenFactor, except that it
* does not contain an error function. It is a measurement (along with a noise
* model) from one key to another. Note that the direction is important. A
* measurement from key1 to key2 is not the same as the same measurement from
* key2 to key1.
2020-07-30 15:12:13 +08:00
*/
2020-08-05 15:18:42 +08:00
#include <gtsam/base/Testable.h>
2020-08-14 08:38:58 +08:00
#include <gtsam/inference/Factor.h>
2020-07-30 15:12:13 +08:00
#include <gtsam/inference/Key.h>
#include <gtsam/linear/NoiseModel.h>
2020-08-14 08:38:58 +08:00
#include <iostream>
#include <vector>
2020-07-30 15:12:13 +08:00
2020-08-14 08:38:58 +08:00
namespace gtsam {
2020-07-30 15:12:13 +08:00
2020-08-14 08:38:58 +08:00
template <class T> class BinaryMeasurement : public Factor {
// Check that T type is testable
BOOST_CONCEPT_ASSERT((IsTestable<T>));
2020-07-30 15:12:13 +08:00
2020-08-14 08:38:58 +08:00
public:
2020-08-09 03:09:30 +08:00
// shorthand for a smart pointer to a measurement
2020-08-14 08:38:58 +08:00
using shared_ptr = typename boost::shared_ptr<BinaryMeasurement>;
2020-07-30 15:12:13 +08:00
2020-08-14 08:38:58 +08:00
private:
T measured_; ///< The measurement
SharedNoiseModel noiseModel_; ///< Noise model
2020-07-30 15:12:13 +08:00
public:
2020-08-14 08:38:58 +08:00
BinaryMeasurement(Key key1, Key key2, const T &measured,
const SharedNoiseModel &model = nullptr)
: Factor(std::vector<Key>({key1, key2})),
measured_(measured),
noiseModel_(model) {}
2020-07-30 15:12:13 +08:00
/// Destructor
virtual ~BinaryMeasurement() {}
2020-08-14 08:38:58 +08:00
/// @name Standard Interface
/// @{
2020-08-09 03:09:30 +08:00
2020-08-14 08:38:58 +08:00
Key key1() const { return keys_[0]; }
Key key2() const { return keys_[1]; }
const T &measured() const { return measured_; }
2020-08-09 03:09:30 +08:00
const SharedNoiseModel &noiseModel() const { return noiseModel_; }
2020-08-14 08:38:58 +08:00
/// @}
/// @name Testable
/// @{
2020-08-09 03:09:30 +08:00
void print(const std::string &s, const KeyFormatter &keyFormatter =
DefaultKeyFormatter) const override {
2020-08-14 08:38:58 +08:00
std::cout << s << "BinaryMeasurement(" << keyFormatter(this->key1()) << ","
2020-08-09 03:09:30 +08:00
<< keyFormatter(this->key2()) << ")\n";
traits<T>::Print(measured_, " measured: ");
this->noiseModel_->print(" noise model: ");
}
bool equals(const BinaryMeasurement &expected, double tol = 1e-9) const {
2020-08-14 08:38:58 +08:00
const BinaryMeasurement<T> *e =
dynamic_cast<const BinaryMeasurement<T> *>(&expected);
return e != nullptr && Factor::equals(*e) &&
traits<T>::Equals(this->measured_, e->measured_, tol) &&
noiseModel_->equals(*expected.noiseModel());
2020-08-09 03:09:30 +08:00
}
2020-08-14 08:38:58 +08:00
/// @}
};
} // namespace gtsam