gtsam
Loading...
Searching...
No Matches
BinaryMeasurement.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010-2020, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
12#pragma once
13
25
26#include <gtsam/base/Testable.h>
28#include <gtsam/inference/Key.h>
30
31#include <iostream>
32#include <vector>
33
34namespace gtsam {
35
36template <class T>
37class BinaryMeasurement : public Factor {
38 // Check that T type is testable
39 GTSAM_CONCEPT_ASSERT(IsTestable<T>);
40
41 public:
42 // shorthand for a smart pointer to a measurement
43 using shared_ptr = typename std::shared_ptr<BinaryMeasurement>;
44
45 private:
46 T measured_;
47 SharedNoiseModel noiseModel_;
48
49 public:
50 BinaryMeasurement(Key key1, Key key2, const T &measured,
51 const SharedNoiseModel &model = nullptr)
52 : Factor(std::vector<Key>({key1, key2})),
53 measured_(measured),
54 noiseModel_(noiseModel::validOrDefault(measured, model)) {}
55
58
59 Key key1() const { return keys_[0]; }
60 Key key2() const { return keys_[1]; }
61 const T &measured() const { return measured_; }
62 const SharedNoiseModel &noiseModel() const { return noiseModel_; }
63
67
68 void print(const std::string &s, const KeyFormatter &keyFormatter =
69 DefaultKeyFormatter) const override {
70 std::cout << s << "BinaryMeasurement(" << keyFormatter(this->key1()) << ","
71 << keyFormatter(this->key2()) << ")\n";
72 traits<T>::Print(measured_, " measured: ");
73 this->noiseModel_->print(" noise model: ");
74 }
75
76 bool equals(const BinaryMeasurement &expected, double tol = 1e-9) const {
77 const BinaryMeasurement<T> *e =
78 dynamic_cast<const BinaryMeasurement<T> *>(&expected);
79 return e != nullptr && Factor::equals(*e) &&
80 traits<T>::Equals(this->measured_, e->measured_, tol) &&
81 noiseModel_->equals(*expected.noiseModel());
82 }
84};
85} // namespace gtsam
Concept check for values that can be used in unit tests.
The base class for all factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
Base::shared_ptr validOrDefault(const T &value, const Base::shared_ptr &model)
Create.
Definition NoiseModel.h:833
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A testable concept check that should be placed in applicable unit tests and in generic algorithms.
Definition Testable.h:59
Template to create a binary predicate.
Definition Testable.h:112
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
Factor()
Default constructor for I/O.
Definition Factor.h:94
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
Definition BinaryMeasurement.h:37
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition BinaryMeasurement.h:68