gtsam
Loading...
Searching...
No Matches
ReferenceFrameFactor.h
Go to the documentation of this file.
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
15
16/*
17 * @file ReferenceFrameFactor.h
18 * @brief A constraint for combining graphs by common landmarks and a transform node
19 * @author Alex Cunningham
20 */
21
22#pragma once
23
25
26namespace gtsam {
27
33template<class T, class P>
35 const T& trans, const P& global,
36 OptionalMatrixType Dtrans,
37 OptionalMatrixType Dglobal) {
38 return trans.transformFrom(global, Dtrans, Dglobal);
39}
40
60template<class POINT, class TRANSFORM>
62 : public NoiseModelFactorT<typename traits<POINT>::TangentVector, POINT,
63 TRANSFORM, POINT> {
64protected:
67
68public:
70 TRANSFORM, POINT>
71 Base;
72 using ErrorVector = typename traits<POINT>::TangentVector;
74
75 // Provide access to the Matrix& version of evaluateError:
77
78 typedef POINT Point;
79 typedef TRANSFORM Transform;
80
84 ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, const noiseModel::Base::shared_ptr& model)
85 : Base(model,globalKey, transKey, localKey) {}
86
91 ReferenceFrameFactor(double mu, Key globalKey, Key transKey, Key localKey)
92 : Base(noiseModel::Constrained::All(Point().dim(), mu), globalKey,
93 transKey, localKey) {}
94
99 ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, double sigma = 1e-2)
100 : Base(noiseModel::Isotropic::Sigma(traits<POINT>::dimension, sigma),
101 globalKey, transKey, localKey) {}
102
103 ~ReferenceFrameFactor() override{}
104
105 NonlinearFactor::shared_ptr clone() const override {
106 return std::static_pointer_cast<NonlinearFactor>(
107 NonlinearFactor::shared_ptr(new This(*this))); }
108
110 ErrorVector evaluateError(const Point& _global, const Transform& trans,
111 const Point& local, OptionalMatrixType Dforeign,
112 OptionalMatrixType Dtrans,
113 OptionalMatrixType Dlocal) const override {
114 Point newlocal = transform_point<Transform,Point>(trans, _global, Dtrans, Dforeign);
115 if (Dlocal) {
116 *Dlocal = -1* Matrix::Identity(traits<Point>::dimension, traits<Point>::dimension);
117 }
118 return traits<Point>::Local(local,newlocal);
119 }
120
121 void print(const std::string& s="",
122 const gtsam::KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
123 std::cout << s << ": ReferenceFrameFactor("
124 << "Global: " << keyFormatter(this->key1()) << ","
125 << " Transform: " << keyFormatter(this->key2()) << ","
126 << " Local: " << keyFormatter(this->key3()) << ")\n";
127 this->noiseModel_->print(" noise model");
128 }
129
130 // access - convenience functions
131 Key global_key() const { return this->key1(); }
132 Key transform_key() const { return this->key2(); }
133 Key local_key() const { return this->key3(); }
134
135private:
136#if GTSAM_ENABLE_BOOST_SERIALIZATION
138 friend class boost::serialization::access;
139 template<class ARCHIVE>
140 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
141 ar & boost::serialization::make_nvp("NonlinearFactor3",
142 boost::serialization::base_object<Base>(*this));
143 }
144#endif
145};
146
148template<class T1, class T2>
149struct traits<ReferenceFrameFactor<T1, T2> > : public Testable<ReferenceFrameFactor<T1, T2> > {};
150
151} // \namespace gtsam
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
P transform_point(const T &trans, const P &global, OptionalMatrixType Dtrans, OptionalMatrixType Dglobal)
Transform function that must be specialized specific domains.
Definition ReferenceFrameFactor.h:34
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
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 helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
A Constrained constrained model is a specialization of Diagonal which allows some or all of the sigma...
Definition NoiseModel.h:436
A convenient base class for creating your own NoiseModelFactor with n variables.
Definition NoiseModelFactorN.h:155
virtual OutputVec evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const =0
Override evaluateError to finish implementing an n-way factor.
size_t dim() const override
get the dimension of the factor (number of rows on linearization)
Definition NonlinearFactor.h:251
A constraint between two landmarks in separate maps Templated on: Point : Type of landmark Transform ...
Definition ReferenceFrameFactor.h:63
void print(const std::string &s="", const gtsam::KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print.
Definition ReferenceFrameFactor.h:121
ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, const noiseModel::Base::shared_ptr &model)
General constructor with arbitrary noise model (constrained or otherwise).
Definition ReferenceFrameFactor.h:84
NonlinearFactor::shared_ptr clone() const override
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition ReferenceFrameFactor.h:105
ErrorVector evaluateError(const Point &_global, const Transform &trans, const Point &local, OptionalMatrixType Dforeign, OptionalMatrixType Dtrans, OptionalMatrixType Dlocal) const override
Combined cost and derivative function using boost::optional.
Definition ReferenceFrameFactor.h:110
ReferenceFrameFactor(Key globalKey, Key transKey, Key localKey, double sigma=1e-2)
Simple soft constraint constructor for frame of reference, with equal weighting for each degree of fr...
Definition ReferenceFrameFactor.h:99
ReferenceFrameFactor(double mu, Key globalKey, Key transKey, Key localKey)
Construct a hard frame of reference reference constraint with equal mu values for each degree of free...
Definition ReferenceFrameFactor.h:91
ReferenceFrameFactor()
default constructor for serialization only
Definition ReferenceFrameFactor.h:66
An isotropic noise model corresponds to a scaled diagonal covariance To construct,...
Definition NoiseModel.h:581