gtsam  4.0.0
gtsam
AttitudeFactor.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 
18 #pragma once
19 
21 #include <gtsam/geometry/Pose3.h>
22 #include <gtsam/geometry/Unit3.h>
23 
24 namespace gtsam {
25 
35 
36 protected:
37 
38  const Unit3 nZ_, bRef_;
39 
40 public:
41 
44  }
45 
51  AttitudeFactor(const Unit3& nZ, const Unit3& bRef = Unit3(0, 0, 1)) :
52  nZ_(nZ), bRef_(bRef) {
53  }
54 
56  Vector attitudeError(const Rot3& p,
57  OptionalJacobian<2,3> H = boost::none) const;
58 };
59 
64 class GTSAM_EXPORT Rot3AttitudeFactor: public NoiseModelFactor1<Rot3>, public AttitudeFactor {
65 
67 
68 public:
69 
71  typedef boost::shared_ptr<Rot3AttitudeFactor> shared_ptr;
72 
75 
78  }
79 
80  virtual ~Rot3AttitudeFactor() {
81  }
82 
90  Rot3AttitudeFactor(Key key, const Unit3& nZ, const SharedNoiseModel& model,
91  const Unit3& bRef = Unit3(0, 0, 1)) :
92  Base(model, key), AttitudeFactor(nZ, bRef) {
93  }
94 
96  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
97  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
98  gtsam::NonlinearFactor::shared_ptr(new This(*this)));
99  }
100 
102  virtual void print(const std::string& s, const KeyFormatter& keyFormatter =
103  DefaultKeyFormatter) const;
104 
106  virtual bool equals(const NonlinearFactor& expected, double tol = 1e-9) const;
107 
109  virtual Vector evaluateError(const Rot3& nRb, //
110  boost::optional<Matrix&> H = boost::none) const {
111  return attitudeError(nRb, H);
112  }
113  Unit3 nZ() const {
114  return nZ_;
115  }
116  Unit3 bRef() const {
117  return bRef_;
118  }
119 
120 private:
121 
123  friend class boost::serialization::access;
124  template<class ARCHIVE>
125  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
126  ar
127  & boost::serialization::make_nvp("NoiseModelFactor1",
128  boost::serialization::base_object<Base>(*this));
129  ar & BOOST_SERIALIZATION_NVP(nZ_);
130  ar & BOOST_SERIALIZATION_NVP(bRef_);
131  }
132 };
133 
135 template<> struct traits<Rot3AttitudeFactor> : public Testable<Rot3AttitudeFactor> {};
136 
141 class GTSAM_EXPORT Pose3AttitudeFactor: public NoiseModelFactor1<Pose3>,
142  public AttitudeFactor {
143 
144  typedef NoiseModelFactor1<Pose3> Base;
145 
146 public:
147 
149  typedef boost::shared_ptr<Pose3AttitudeFactor> shared_ptr;
150 
153 
156  }
157 
158  virtual ~Pose3AttitudeFactor() {
159  }
160 
168  Pose3AttitudeFactor(Key key, const Unit3& nZ, const SharedNoiseModel& model,
169  const Unit3& bRef = Unit3(0, 0, 1)) :
170  Base(model, key), AttitudeFactor(nZ, bRef) {
171  }
172 
174  virtual gtsam::NonlinearFactor::shared_ptr clone() const {
175  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
176  gtsam::NonlinearFactor::shared_ptr(new This(*this)));
177  }
178 
180  virtual void print(const std::string& s, const KeyFormatter& keyFormatter =
181  DefaultKeyFormatter) const;
182 
184  virtual bool equals(const NonlinearFactor& expected, double tol = 1e-9) const;
185 
187  virtual Vector evaluateError(const Pose3& nTb, //
188  boost::optional<Matrix&> H = boost::none) const {
189  Vector e = attitudeError(nTb.rotation(), H);
190  if (H) {
191  Matrix H23 = *H;
192  *H = Matrix::Zero(2,6);
193  H->block<2,3>(0,0) = H23;
194  }
195  return e;
196  }
197  Unit3 nZ() const {
198  return nZ_;
199  }
200  Unit3 bRef() const {
201  return bRef_;
202  }
203 
204 private:
205 
207  friend class boost::serialization::access;
208  template<class ARCHIVE>
209  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
210  ar
211  & boost::serialization::make_nvp("NoiseModelFactor1",
212  boost::serialization::base_object<Base>(*this));
213  ar & BOOST_SERIALIZATION_NVP(nZ_);
214  ar & BOOST_SERIALIZATION_NVP(bRef_);
215  }
216 };
217 
219 template<> struct traits<Pose3AttitudeFactor> : public Testable<Pose3AttitudeFactor> {};
220 
221 }
222 
boost::shared_ptr< Pose3AttitudeFactor > shared_ptr
shorthand for a smart pointer to a factor
Definition: AttitudeFactor.h:149
AttitudeFactor(const Unit3 &nZ, const Unit3 &bRef=Unit3(0, 0, 1))
Constructor.
Definition: AttitudeFactor.h:51
const Rot3 & rotation(OptionalJacobian< 3, 6 > H=boost::none) const
get rotation
Definition: Pose3.cpp:272
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: AttitudeFactor.h:96
Nonlinear factor base class.
Definition: NonlinearFactor.h:52
3D Pose
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
Rot3AttitudeFactor()
default constructor - only use for serialization
Definition: AttitudeFactor.h:77
virtual Vector evaluateError(const Rot3 &nRb, boost::optional< Matrix & > H=boost::none) const
vector of errors
Definition: AttitudeFactor.h:109
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:140
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: AttitudeFactor.h:174
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
Definition: Pose3.h:37
virtual Vector evaluateError(const Pose3 &nTb, boost::optional< Matrix & > H=boost::none) const
vector of errors
Definition: AttitudeFactor.h:187
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
boost::shared_ptr< Rot3AttitudeFactor > shared_ptr
shorthand for a smart pointer to a factor
Definition: AttitudeFactor.h:71
Definition: AttitudeFactor.h:64
Template to create a binary predicate.
Definition: Testable.h:110
Rot3AttitudeFactor(Key key, const Unit3 &nZ, const SharedNoiseModel &model, const Unit3 &bRef=Unit3(0, 0, 1))
Constructor.
Definition: AttitudeFactor.h:90
AttitudeFactor()
default constructor - only use for serialization
Definition: AttitudeFactor.h:43
Rot3AttitudeFactor This
Typedef to this class.
Definition: AttitudeFactor.h:74
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Pose3AttitudeFactor This
Typedef to this class.
Definition: AttitudeFactor.h:152
Definition: Rot3.h:56
Definition: AttitudeFactor.h:34
const Unit3 bRef_
Position measurement in.
Definition: AttitudeFactor.h:38
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:276
Vector attitudeError(const Rot3 &p, OptionalJacobian< 2, 3 > H=boost::none) const
vector of errors
Definition: AttitudeFactor.cpp:26
Non-linear factor base classes.
Pose3AttitudeFactor(Key key, const Unit3 &nZ, const SharedNoiseModel &model, const Unit3 &bRef=Unit3(0, 0, 1))
Constructor.
Definition: AttitudeFactor.h:168
Definition: AttitudeFactor.h:141
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Pose3AttitudeFactor()
default constructor - only use for serialization
Definition: AttitudeFactor.h:155
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33