gtsam/gtsam/sfm/BinaryMeasurement.h

92 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-10 13:03:01 +08:00
* @brief Binary measurement represents a measurement between two keys in a graph.
2020-08-09 03:09:30 +08:00
* 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 <ostream>
#include <gtsam/base/Testable.h>
#include <gtsam/base/Lie.h>
#include <gtsam/nonlinear/NonlinearFactor.h>
2020-07-30 15:12:13 +08:00
#include <gtsam/inference/Key.h>
#include <gtsam/linear/NoiseModel.h>
namespace gtsam {
2020-08-09 03:09:30 +08:00
template<class VALUE>
2020-07-30 15:12:13 +08:00
class BinaryMeasurement {
2020-08-09 03:09:30 +08:00
// Check that VALUE type is testable
BOOST_CONCEPT_ASSERT((IsTestable<VALUE>));
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
public:
typedef VALUE T;
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
// shorthand for a smart pointer to a measurement
typedef typename boost::shared_ptr<BinaryMeasurement> shared_ptr;
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
private:
Key key1_, key2_; /** Keys */
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
VALUE measured_; /** The measurement */
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
SharedNoiseModel noiseModel_; /** Noise model */
2020-07-30 15:12:13 +08:00
2020-08-09 03:09:30 +08:00
public:
/** Constructor */
BinaryMeasurement(Key key1, Key key2, const VALUE &measured,
const SharedNoiseModel &model = nullptr) :
2020-07-30 15:12:13 +08:00
key1_(key1), key2_(key2), measured_(measured), noiseModel_(model) {
2020-08-09 03:09:30 +08:00
}
Key key1() const { return key1_; }
Key key2() const { return key2_; }
const SharedNoiseModel &noiseModel() const { return noiseModel_; }
/** implement functions needed for Testable */
/** print */
void print(const std::string &s, const KeyFormatter &keyFormatter = DefaultKeyFormatter) const {
std::cout << s << "BinaryMeasurement("
<< keyFormatter(this->key1()) << ","
<< keyFormatter(this->key2()) << ")\n";
traits<T>::Print(measured_, " measured: ");
this->noiseModel_->print(" noise model: ");
}
/** equals */
bool equals(const BinaryMeasurement &expected, double tol = 1e-9) const {
const BinaryMeasurement<VALUE> *e = dynamic_cast<const BinaryMeasurement<VALUE> *> (&expected);
return e != nullptr && key1_ == e->key1_ &&
key2_ == e->key2_
&& traits<VALUE>::Equals(this->measured_, e->measured_, tol) &&
noiseModel_->equals(*expected.noiseModel());
}
/** return the measured value */
VALUE measured() const {
return measured_;
}
}; // \class BetweenMeasurement
2020-07-30 15:12:13 +08:00
}