GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
PoseRotationPrior.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <gtsam/geometry/concepts.h>
14 
15 
16 namespace gtsam {
17 
18 template<class POSE>
19 class PoseRotationPrior : public NoiseModelFactorN<POSE> {
20 public:
21 
24  typedef POSE Pose;
25  typedef typename POSE::Translation Translation;
26  typedef typename POSE::Rotation Rotation;
27 
28  // Provide access to the Matrix& version of evaluateError:
29  using Base::evaluateError;
30 
31  GTSAM_CONCEPT_POSE_TYPE(Pose)
32  GTSAM_CONCEPT_GROUP_TYPE(Pose)
33  GTSAM_CONCEPT_LIE_TYPE(Rotation)
34 
35  // Get dimensions of pose and rotation type at compile time
36  static const int xDim = FixedDimension<POSE>::value;
37  static const int rDim = FixedDimension<typename POSE::Rotation>::value;
38 
39 protected:
40 
41  Rotation measured_;
42 
43 public:
44 
47 
49  PoseRotationPrior(Key key, const Rotation& rot_z, const SharedNoiseModel& model)
50  : Base(model, key), measured_(rot_z) {}
51 
53  PoseRotationPrior(Key key, const POSE& pose_z, const SharedNoiseModel& model)
54  : Base(model, key), measured_(pose_z.rotation()) {}
55 
56  ~PoseRotationPrior() override {}
57 
59  gtsam::NonlinearFactor::shared_ptr clone() const override {
60  return std::static_pointer_cast<gtsam::NonlinearFactor>(
61  gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
62 
63  // access
64  const Rotation& measured() const { return measured_; }
65 
66  // testable
67 
69  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
70  const This *e = dynamic_cast<const This*> (&expected);
71  return e != nullptr && Base::equals(*e, tol) && measured_.equals(e->measured_, tol);
72  }
73 
75  void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
76  Base::print(s + "PoseRotationPrior", keyFormatter);
77  measured_.print("Measured Rotation");
78  }
79 
81  Vector evaluateError(const Pose& pose, OptionalMatrixType H) const override {
82  const Rotation& newR = pose.rotation();
83  if (H) {
84  *H = Matrix::Zero(rDim, xDim);
85  std::pair<size_t, size_t> rotInterval = POSE::rotationInterval();
86  (*H).middleCols(rotInterval.first, rDim).setIdentity(rDim, rDim);
87  }
88 
89  return measured_.localCoordinates(newR);
90  }
91 
92 private:
93 
94 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
95 
96  friend class boost::serialization::access;
97  template<class ARCHIVE>
98  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
99  // NoiseModelFactor1 instead of NoiseModelFactorN for backward compatibility
100  ar & boost::serialization::make_nvp("NoiseModelFactor1",
101  boost::serialization::base_object<Base>(*this));
102  ar & BOOST_SERIALIZATION_NVP(measured_);
103  }
104 #endif
105 };
106 
107 } // \namespace gtsam
108 
109 
110 
111 
Definition: NonlinearFactor.h:431
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: PoseRotationPrior.h:75
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: PoseRotationPrior.h:59
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Definition: Factor.h:69
PoseRotationPrior(Key key, const Rotation &rot_z, const SharedNoiseModel &model)
Definition: PoseRotationPrior.h:49
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Give fixed size dimension of a type, fails at compile time if dynamic.
Definition: Manifold.h:161
Key key() const
Definition: NonlinearFactor.h:582
Definition: NonlinearFactor.h:68
PoseRotationPrior(Key key, const POSE &pose_z, const SharedNoiseModel &model)
Definition: PoseRotationPrior.h:53
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Definition: PoseRotationPrior.h:69
PoseRotationPrior()
Definition: PoseRotationPrior.h:46
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
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
Vector evaluateError(const Pose &pose, OptionalMatrixType H) const override
Definition: PoseRotationPrior.h:81
Definition: chartTesting.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Non-linear factor base classes.
Definition: PoseRotationPrior.h:19
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741