gtsam
Loading...
Searching...
No Matches
PoseRotationPrior.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <gtsam/base/Manifold.h>
16
17
18namespace gtsam {
19
20template<class POSE>
22public:
23
24 typedef PoseRotationPrior<POSE> This;
25 typedef NoiseModelFactorN<POSE> Base;
26 typedef POSE Pose;
27 typedef typename POSE::Translation Translation;
28 typedef typename POSE::Rotation Rotation;
29
30 // Provide access to the Matrix& version of evaluateError:
32
33 GTSAM_CONCEPT_POSE_TYPE(Pose)
34 GTSAM_CONCEPT_GROUP_TYPE(Pose)
35 GTSAM_CONCEPT_LIE_TYPE(Rotation)
36
37 // Get dimensions of pose and rotation type at compile time
38 static const int xDim = FixedDimension<POSE>::value;
39 static const int rDim = FixedDimension<typename POSE::Rotation>::value;
40
41protected:
42
43 Rotation measured_;
44
45public:
46
49
51 PoseRotationPrior(Key key, const Rotation& rot_z, const SharedNoiseModel& model)
52 : Base(model, key), measured_(rot_z) {}
53
55 PoseRotationPrior(Key key, const POSE& pose_z, const SharedNoiseModel& model)
56 : Base(model, key), measured_(pose_z.rotation()) {}
57
58 ~PoseRotationPrior() override {}
59
61 gtsam::NonlinearFactor::shared_ptr clone() const override {
62 return std::static_pointer_cast<gtsam::NonlinearFactor>(
63 gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
64
65 // access
66 const Rotation& measured() const { return measured_; }
67
68 // testable
69
71 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
72 const This *e = dynamic_cast<const This*> (&expected);
73 return e != nullptr && Base::equals(*e, tol) && measured_.equals(e->measured_, tol);
74 }
75
77 void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
78 Base::print(s + "PoseRotationPrior", keyFormatter);
79 measured_.print("Measured Rotation");
80 }
81
83 Vector evaluateError(const Pose& pose, OptionalMatrixType H) const override {
84 Eigen::Matrix<double, rDim, xDim> Hrotation;
85 const Rotation& newR = pose.rotation(H ? &Hrotation : nullptr);
86#ifdef GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR
88 if (H) {
90 const Vector error =
91 traits<Rotation>::Local(measured_, newR, OptionalNone, &Hlocal);
92 *H = Hlocal * Hrotation;
93 return error;
94 }
95 }
96#endif
97 if (H) *H = Hrotation;
98
99 return traits<Rotation>::Local(measured_, newR);
100 }
101
102private:
103
104#if GTSAM_ENABLE_BOOST_SERIALIZATION
106 friend class boost::serialization::access;
107 template<class ARCHIVE>
108 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
109 // NoiseModelFactor1 instead of NoiseModelFactorN for backward compatibility
110 ar & boost::serialization::make_nvp("NoiseModelFactor1",
111 boost::serialization::base_object<Base>(*this));
112 ar & BOOST_SERIALIZATION_NVP(measured_);
113 }
114#endif
115};
116
117} // \namespace gtsam
118
119
120
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
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
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
Definition PoseRotationPrior.h:21
PoseRotationPrior(Key key, const Rotation &rot_z, const SharedNoiseModel &model)
standard constructor
Definition PoseRotationPrior.h:51
PoseRotationPrior(Key key, const POSE &pose_z, const SharedNoiseModel &model)
Constructor that pulls the translation from an incoming POSE.
Definition PoseRotationPrior.h:55
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition PoseRotationPrior.h:61
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals specialized to this factor
Definition PoseRotationPrior.h:71
PoseRotationPrior()
default constructor - only use for serialization
Definition PoseRotationPrior.h:48
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print contents
Definition PoseRotationPrior.h:77
Vector evaluateError(const Pose &pose, OptionalMatrixType H) const override
h(x)-z
Definition PoseRotationPrior.h:83
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...