gtsam
Loading...
Searching...
No Matches
TranslationFactor.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
20
21#include <gtsam/base/Vector.h>
23#include <gtsam/geometry/Unit3.h>
27
28namespace gtsam {
29
42class TranslationFactor : public NoiseModelFactorT<Vector3, Point3, Point3> {
43 private:
45 Point3 measured_w_aZb_;
46
47 public:
48 // Provide access to the Matrix& version of evaluateError:
50
53
54 TranslationFactor(Key a, Key b, const Unit3& w_aZb,
56 : Base(noiseModel, a, b), measured_w_aZb_(w_aZb.point3()) {}
57
69 Vector3 evaluateError(const Point3& Ta, const Point3& Tb,
71 OptionalMatrixType H2) const override {
72 const Point3 dir = Tb - Ta;
73 Matrix33 H_predicted_dir;
74 const Point3 predicted =
75 normalize(dir, H1 || H2 ? &H_predicted_dir : nullptr);
76 if (H1) *H1 = -H_predicted_dir;
77 if (H2) *H2 = H_predicted_dir;
78 return predicted - measured_w_aZb_;
79 }
80
81 private:
82#if GTSAM_ENABLE_BOOST_SERIALIZATION
83 friend class boost::serialization::access;
84 template <class ARCHIVE>
85 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
86 ar& boost::serialization::make_nvp(
87 "Base", boost::serialization::base_object<Base>(*this));
88 }
89#endif
90}; // \ TranslationFactor
91
106 : public NoiseModelFactorT<Vector3, Point3, Point3, Vector1> {
107 private:
109 Point3 measured_w_aZb_;
110
111 public:
114
116 const Unit3& w_aZb,
118 : Base(noiseModel, a, b, scale_key), measured_w_aZb_(w_aZb.point3()) {}
119
120 // Provide access to the Matrix& version of evaluateError:
122
134 Vector3 evaluateError(const Point3& Ta, const Point3& Tb,
135 const Vector1& scale, OptionalMatrixType H1,
137 OptionalMatrixType H3) const override {
138 // Ideally we should use a positive real valued scalar datatype for scale.
139 const double abs_scale = std::abs(scale[0]);
140 const Point3 predicted = (Tb - Ta) * abs_scale;
141 if (H1) {
142 *H1 = -Matrix3::Identity() * abs_scale;
143 }
144 if (H2) {
145 *H2 = Matrix3::Identity() * abs_scale;
146 }
147 if (H3) {
148 *H3 = scale[0] >= 0 ? (Tb - Ta) : (Ta - Tb);
149 }
150 return predicted - measured_w_aZb_;
151 }
152
153 private:
154#if GTSAM_ENABLE_BOOST_SERIALIZATION
155 friend class boost::serialization::access;
156 template <class ARCHIVE>
157 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
158 ar& boost::serialization::make_nvp(
159 "Base", boost::serialization::base_object<Base>(*this));
160 }
161#endif
162}; // \ BilinearAngleTranslationFactor
163} // namespace gtsam
typedef and functions to augment Eigen's VectorXd
3D Point
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
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
Represents a 3D point on a unit sphere.
Definition Unit3.h:44
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
virtual Vector3 evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Vector3 evaluateError(const Point3 &Ta, const Point3 &Tb, OptionalMatrixType H1, OptionalMatrixType H2) const override
Calculate error: (norm(Tb - Ta) - measurement) where Tb and Ta are Point3 translations and measuremen...
Definition TranslationFactor.h:69
TranslationFactor()
default constructor
Definition TranslationFactor.h:52
BilinearAngleTranslationFactor()
default constructor
Definition TranslationFactor.h:113
Vector3 evaluateError(const Point3 &Ta, const Point3 &Tb, const Vector1 &scale, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Calculate error: (scale * (Tb - Ta) - measurement) where Tb and Ta are Point3 translations and measur...
Definition TranslationFactor.h:134