gtsam
Loading...
Searching...
No Matches
UnaryMeasurement.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
22
23#include <gtsam/base/Testable.h>
25#include <gtsam/inference/Key.h>
27
28#include <iostream>
29#include <memory>
30#include <vector>
31
32namespace gtsam {
33
37template <class T>
38class UnaryMeasurement : public Factor {
39 // Check that T type is testable
40 GTSAM_CONCEPT_ASSERT(IsTestable<T>);
41
42 public:
43 // shorthand for a smart pointer to a measurement
44 using shared_ptr = std::shared_ptr<UnaryMeasurement>;
45
46 private:
47 T measured_;
48 SharedNoiseModel noiseModel_;
49
50 public:
57 UnaryMeasurement(Key key, const T &measured,
58 const SharedNoiseModel &model = nullptr)
59 : Factor(std::vector<Key>({key})),
60 measured_(measured),
61 noiseModel_(noiseModel::validOrDefault(measured, model)) {}
62
65
66 // Returns the key of the measurement.
67 Key key() const { return keys_[0]; }
68 // Returns the measurement value.
69 const T &measured() const { return measured_; }
70 // Returns the noise model.
71 const SharedNoiseModel &noiseModel() const { return noiseModel_; }
72
76
77 // Prints the measurement.
78 void print(const std::string &s, const KeyFormatter &keyFormatter =
79 DefaultKeyFormatter) const override {
80 std::cout << s << "UnaryMeasurement(" << keyFormatter(this->key()) << ")\n";
81 traits<T>::Print(measured_, " measured: ");
82 if (noiseModel_)
83 noiseModel_->print(" noise model: ");
84 else
85 std::cout << " noise model: (null)\n";
86 }
87
88 // Checks if the measurement is equal to another measurement.
89 bool equals(const UnaryMeasurement &expected, double tol = 1e-9) const {
90 const UnaryMeasurement<T> *e =
91 dynamic_cast<const UnaryMeasurement<T> *>(&expected);
92 return e != nullptr && Factor::equals(*e) &&
93 traits<T>::Equals(this->measured_, e->measured_, tol) &&
94 ((!noiseModel_ && !expected.noiseModel_) ||
95 (noiseModel_ && noiseModel_->equals(*expected.noiseModel())));
96 }
98};
99} // namespace gtsam
Concept check for values that can be used in unit tests.
The base class for all factors.
STL namespace.
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
Unary measurement represents a measurement on a single key in a graph.
Definition UnaryMeasurement.h:38
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition UnaryMeasurement.h:78
UnaryMeasurement(Key key, const T &measured, const SharedNoiseModel &model=nullptr)
Constructs a unary measurement with a key, value, and noise model.
Definition UnaryMeasurement.h:57