gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BearingFactor.h
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, 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 
17 #pragma once
18 
21 #include <gtsam/base/Testable.h>
22 
23 namespace gtsam {
24 
29  template<class POSE, class POINT, class ROTATION = typename POSE::Rotation>
30  class BearingFactor: public NoiseModelFactor2<POSE, POINT> {
31  private:
32 
33  typedef POSE Pose;
34  typedef ROTATION Rot;
35  typedef POINT Point;
36 
39 
40  Rot measured_;
43  GTSAM_CONCEPT_TESTABLE_TYPE(Rot)
44  GTSAM_CONCEPT_POSE_TYPE(Pose)
45 
46  public:
47 
50 
52  BearingFactor(Key poseKey, Key pointKey, const Rot& measured,
53  const SharedNoiseModel& model) :
54  Base(model, poseKey, pointKey), measured_(measured) {
55  }
56 
57  virtual ~BearingFactor() {}
58 
60  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
61  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
62  gtsam::NonlinearFactor::shared_ptr(new This(*this))); }
63 
65  Vector evaluateError(const Pose& pose, const Point& point,
66  boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) const {
67  Rot hx = pose.bearing(point, H1, H2);
68  return Rot::Logmap(measured_.between(hx));
69  }
70 
72  const Rot& measured() const {
73  return measured_;
74  }
75 
77  virtual bool equals(const NonlinearFactor& expected, double tol=1e-9) const {
78  const This *e = dynamic_cast<const This*> (&expected);
79  return e != NULL && Base::equals(*e, tol) && this->measured_.equals(e->measured_, tol);
80  }
81 
83  void print(const std::string& s="", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
84  std::cout << s << "BearingFactor, bearing = ";
85  measured_.print();
86  Base::print("", keyFormatter);
87  }
88 
89  private:
90 
93  template<class ARCHIVE>
94  void serialize(ARCHIVE & ar, const unsigned int version) {
95  ar & boost::serialization::make_nvp("NoiseModelFactor2",
96  boost::serialization::base_object<Base>(*this));
97  ar & BOOST_SERIALIZATION_NVP(measured_);
98  }
99 
100  }; // BearingFactor
101 
102 } // namespace gtsam
Non-linear factor base classes.
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.h:239
BearingFactor()
measurement
Definition: BearingFactor.h:49
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print contents
Definition: BearingFactor.h:83
Definition: BearingFactor.h:30
const Rot & measured() const
return the measured
Definition: BearingFactor.h:72
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:423
This is the base class for all factor types.
Definition: Factor.h:51
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: BearingFactor.h:60
friend class boost::serialization::access
Serialization function.
Definition: BearingFactor.h:92
Concept-checking macros for geometric objects Each macro instantiates a concept check structure...
virtual bool equals(const NonlinearFactor &expected, double tol=1e-9) const
equals
Definition: BearingFactor.h:77
Concept check for values that can be used in unit tests.
size_t Key
Integer nonlinear key type.
Definition: types.h:59
BearingFactor(Key poseKey, Key pointKey, const Rot &measured, const SharedNoiseModel &model)
primary constructor
Definition: BearingFactor.h:52
Vector evaluateError(const Pose &pose, const Point &point, boost::optional< Matrix & > H1, boost::optional< Matrix & > H2) const
h(x)-z -> between(z,h(x)) for Rot2 manifold
Definition: BearingFactor.h:65
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
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