gtsam
Loading...
Searching...
No Matches
PoseTranslationPrior.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <gtsam/base/Manifold.h>
16
17namespace gtsam {
18
22template<class POSE>
24public:
25 typedef PoseTranslationPrior<POSE> This;
26 typedef NoiseModelFactorN<POSE> Base;
27 typedef POSE Pose;
28 typedef typename POSE::Translation Translation;
29 typedef typename POSE::Rotation Rotation;
30
31 // Provide access to the Matrix& version of evaluateError:
33
34 GTSAM_CONCEPT_POSE_TYPE(Pose)
35 GTSAM_CONCEPT_GROUP_TYPE(Pose)
36 GTSAM_CONCEPT_LIE_TYPE(Translation)
37
38protected:
39
40 Translation measured_;
41
42public:
43
46
48 PoseTranslationPrior(Key key, const Translation& measured, const noiseModel::Base::shared_ptr& model)
49 : Base(model, key), measured_(measured) {
50 }
51
53 PoseTranslationPrior(Key key, const POSE& pose_z, const noiseModel::Base::shared_ptr& model)
54 : Base(model, key), measured_(pose_z.translation()) {
55 }
56
57 ~PoseTranslationPrior() override {}
58
59 const Translation& measured() const { return measured_; }
60
62 gtsam::NonlinearFactor::shared_ptr clone() const override {
63 return std::static_pointer_cast<gtsam::NonlinearFactor>(
64 gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
65
67 Vector evaluateError(const Pose& pose, OptionalMatrixType H) const override {
68 Matrix Htranslation;
69 const Translation& newTrans = pose.translation(H ? &Htranslation : nullptr);
70#ifdef GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR
72 if (H) {
74 const Vector error = traits<Translation>::Local(
75 measured_, newTrans, OptionalNone, &Hlocal);
76 *H = Hlocal * Htranslation;
77 return error;
78 }
79 }
80#endif
81 if (H) *H = Htranslation;
82
83 return traits<Translation>::Local(measured_, newTrans);
84 }
85
87 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
88 const This *e = dynamic_cast<const This*> (&expected);
89 return e != nullptr && Base::equals(*e, tol) && traits<Translation>::Equals(measured_, e->measured_, tol);
90 }
91
93 void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
94 Base::print(s + "PoseTranslationPrior", keyFormatter);
95 traits<Translation>::Print(measured_, "Measured Translation");
96 }
97
98private:
99
100#if GTSAM_ENABLE_BOOST_SERIALIZATION
102 friend class boost::serialization::access;
103 template<class ARCHIVE>
104 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
105 // NoiseModelFactor1 instead of NoiseModelFactorN for backward compatibility
106 ar & boost::serialization::make_nvp("NoiseModelFactor1",
107 boost::serialization::base_object<Base>(*this));
108 ar & BOOST_SERIALIZATION_NVP(measured_);
109 }
110#endif
111
112};
113
114} // \namespace gtsam
115
116
Base class and basic functions for Manifold types.
Base class for noise model factors with N variables.
Non-linear factor base classes.
#define OptionalNone
These typedefs and aliases will help with making the evaluateError interface independent of boost TOD...
Definition NonlinearFactor.h:51
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
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
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
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
Detect whether a traits type provides Local with Jacobians.
Definition Manifold.h:145
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Key key() const
Definition NoiseModelFactorN.h:307
Nonlinear factor base class.
Definition NonlinearFactor.h:70
double error(const Values &c) const override
Calculate the error of the factor.
Definition NonlinearFactor.cpp:146
A prior on the translation part of a pose.
Definition PoseTranslationPrior.h:23
PoseTranslationPrior(Key key, const Translation &measured, const noiseModel::Base::shared_ptr &model)
standard constructor
Definition PoseTranslationPrior.h:48
PoseTranslationPrior(Key key, const POSE &pose_z, const noiseModel::Base::shared_ptr &model)
Constructor that pulls the translation from an incoming POSE.
Definition PoseTranslationPrior.h:53
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals specialized to this factor
Definition PoseTranslationPrior.h:87
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition PoseTranslationPrior.h:62
Vector evaluateError(const Pose &pose, OptionalMatrixType H) const override
h(x)-z
Definition PoseTranslationPrior.h:67
PoseTranslationPrior()
default constructor - only use for serialization
Definition PoseTranslationPrior.h:45
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print contents
Definition PoseTranslationPrior.h:93
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...