gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PoseRotationPrior.h
Go to the documentation of this file.
1 
10 #pragma once
11 
14 
15 
16 namespace gtsam {
17 
18 template<class POSE>
19 class PoseRotationPrior : public NoiseModelFactor1<POSE> {
20 public:
21 
24  typedef POSE Pose;
25  typedef typename POSE::Translation Translation;
26  typedef typename POSE::Rotation Rotation;
27 
28  GTSAM_CONCEPT_POSE_TYPE(Pose)
29  GTSAM_CONCEPT_GROUP_TYPE(Pose)
30  GTSAM_CONCEPT_LIE_TYPE(Rotation)
31 
32 protected:
33 
34  Rotation measured_;
35 
36 public:
37 
39  PoseRotationPrior(Key key, const Rotation& rot_z, const SharedNoiseModel& model)
40  : Base(model, key), measured_(rot_z) {}
41 
43  PoseRotationPrior(Key key, const POSE& pose_z, const SharedNoiseModel& model)
44  : Base(model, key), measured_(pose_z.rotation()) {}
45 
46  virtual ~PoseRotationPrior() {}
47 
49  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
50  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
51  gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
52 
53  // access
54  const Rotation& measured() const { return measured_; }
55 
56  // testable
57 
59  virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const {
60  const This *e = dynamic_cast<const This*> (&expected);
61  return e != NULL && Base::equals(*e, tol) && measured_.equals(e->measured_, tol);
62  }
63 
65  void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
66  Base::print(s + "PoseRotationPrior", keyFormatter);
67  measured_.print("Measured Rotation");
68  }
69 
71  Vector evaluateError(const Pose& pose, boost::optional<Matrix&> H = boost::none) const {
72  const Rotation& newR = pose.rotation();
73  const size_t rDim = newR.dim(), xDim = pose.dim();
74  if (H) {
75  *H = gtsam::zeros(rDim, xDim);
76  std::pair<size_t, size_t> rotInterval = POSE::rotationInterval();
77  (*H).middleCols(rotInterval.first, rDim).setIdentity(rDim, rDim);
78  }
79 
80  return measured_.localCoordinates(newR);
81  }
82 
83 private:
84 
87  template<class ARCHIVE>
88  void serialize(ARCHIVE & ar, const unsigned int version) {
89  ar & boost::serialization::make_nvp("NoiseModelFactor1",
90  boost::serialization::base_object<Base>(*this));
91  ar & BOOST_SERIALIZATION_NVP(measured_);
92  }
93 };
94 
95 } // \namespace gtsam
96 
97 
98 
99 
Non-linear factor base classes.
PoseRotationPrior(Key key, const Rotation &rot_z, const SharedNoiseModel &model)
standard constructor
Definition: PoseRotationPrior.h:39
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.h:239
Vector evaluateError(const Pose &pose, boost::optional< Matrix & > H=boost::none) const
h(x)-z
Definition: PoseRotationPrior.h:71
friend class boost::serialization::access
Serialization function.
Definition: PoseRotationPrior.h:86
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: PoseRotationPrior.h:49
Definition: PoseRotationPrior.h:19
virtual bool equals(const NonlinearFactor &expected, double tol=1e-9) const
equals specialized to this factor
Definition: PoseRotationPrior.h:59
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print contents
Definition: PoseRotationPrior.h:65
This is the base class for all factor types.
Definition: Factor.h:51
Concept-checking macros for geometric objects Each macro instantiates a concept check structure...
size_t Key
Integer nonlinear key type.
Definition: types.h:59
PoseRotationPrior(Key key, const POSE &pose_z, const SharedNoiseModel &model)
Constructor that pulls the translation from an incoming POSE.
Definition: PoseRotationPrior.h:43
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:354
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearFactor.h:231
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:884
Nonlinear factor base class.
Definition: NonlinearFactor.h:54
Matrix zeros(size_t m, size_t n)
Creates an zeros matrix, with matlab-like syntax.
Definition: Matrix.cpp:40
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62