gtsam
Loading...
Searching...
No Matches
PoseBetweenFactor.h
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, 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
16#pragma once
17
18#include <ostream>
19
23#include <gtsam/base/Testable.h>
24
25namespace gtsam {
26
32 template<class POSE>
34 : public NoiseModelFactorT<typename traits<POSE>::TangentVector, POSE,
35 POSE> {
36
37 private:
38
39 typedef PoseBetweenFactor<POSE> This;
41 Base;
42 using ErrorVector = typename traits<POSE>::TangentVector;
43
44 POSE measured_;
45 std::optional<POSE> body_P_sensor_;
46
48 GTSAM_CONCEPT_TESTABLE_TYPE(POSE)
49 GTSAM_CONCEPT_POSE_TYPE(POSE)
50 public:
51
52 // Provide access to the Matrix& version of evaluateError:
54
55 // shorthand for a smart pointer to a factor
56 typedef typename std::shared_ptr<PoseBetweenFactor> shared_ptr;
57
60
62 PoseBetweenFactor(Key key1, Key key2, const POSE& measured,
63 const SharedNoiseModel& model, std::optional<POSE> body_P_sensor = {}) :
64 Base(model, key1, key2), measured_(measured), body_P_sensor_(body_P_sensor) {
65 }
66
67 ~PoseBetweenFactor() override {}
68
70 gtsam::NonlinearFactor::shared_ptr clone() const override {
71 return std::static_pointer_cast<gtsam::NonlinearFactor>(
72 gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
73
75
77 void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
78 std::cout << s << "BetweenFactor("
79 << keyFormatter(this->key1()) << ","
80 << keyFormatter(this->key2()) << ")\n";
81 measured_.print(" measured: ");
82 if(this->body_P_sensor_)
83 this->body_P_sensor_->print(" sensor pose in body frame: ");
84 this->noiseModel_->print(" noise model: ");
85 }
86
88 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
89 const This *e = dynamic_cast<const This*> (&expected);
90 return e != nullptr
91 && Base::equals(*e, tol)
92 && this->measured_.equals(e->measured_, tol)
93 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
94 }
95
97
99 ErrorVector evaluateError(const POSE& p1, const POSE& p2,
101 OptionalMatrixType H2) const override {
102 if(body_P_sensor_) {
103 POSE hx;
104 if(H1 || H2) {
105 Matrix H3;
106 hx = p1.compose(*body_P_sensor_,H3).between(p2.compose(*body_P_sensor_), H1, H2); // h(x)
107 if(H1) (*H1) *= H3;
108 if(H2) (*H2) *= H3;
109 } else {
110 hx = p1.compose(*body_P_sensor_).between(p2.compose(*body_P_sensor_)); // h(x)
111 }
112 // manifold equivalent of h(x)-z -> log(z,h(x))
113 return measured_.localCoordinates(hx);
114 } else {
115 POSE hx = p1.between(p2, H1, H2); // h(x)
116 // manifold equivalent of h(x)-z -> log(z,h(x))
117 return measured_.localCoordinates(hx);
118 }
119 }
120
122 const POSE& measured() const {
123 return measured_;
124 }
125
126 private:
127
128#if GTSAM_ENABLE_BOOST_SERIALIZATION
130 friend class boost::serialization::access;
131 template<class ARCHIVE>
132 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
133 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
134 ar & BOOST_SERIALIZATION_NVP(measured_);
135
136 }
137#endif
138 }; // \class PoseBetweenFactor
139
140}
Concept check for values that can be used in unit tests.
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual OutputVec evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const =0
Override evaluateError to finish implementing an n-way factor.
Nonlinear factor base class.
Definition NonlinearFactor.h:70
PoseBetweenFactor(Key key1, Key key2, const POSE &measured, const SharedNoiseModel &model, std::optional< POSE > body_P_sensor={})
Constructor.
Definition PoseBetweenFactor.h:62
PoseBetweenFactor()
default constructor - only use for serialization
Definition PoseBetweenFactor.h:59
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition PoseBetweenFactor.h:88
ErrorVector evaluateError(const POSE &p1, const POSE &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
implement functions needed to derive from Factor
Definition PoseBetweenFactor.h:99
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
implement functions needed for Testable
Definition PoseBetweenFactor.h:77
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition PoseBetweenFactor.h:70
const POSE & measured() const
return the measured
Definition PoseBetweenFactor.h:122
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...