InvDepthFactor3.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <gtsam/geometry/Cal3_S2.h>
20 
21 namespace gtsam {
22 
26 template<class POSE, class LANDMARK, class INVDEPTH>
27 class InvDepthFactor3: public NoiseModelFactor3<POSE, LANDMARK, INVDEPTH> {
28 protected:
29 
30  // Keep a copy of measurement and calibration for I/O
32  boost::shared_ptr<Cal3_S2> K_;
33 
34 public:
35 
38 
41 
43  typedef boost::shared_ptr<This> shared_ptr;
44 
47  measured_(0.0, 0.0), K_(new Cal3_S2(444, 555, 666, 777, 888)) {
48  }
49 
61  const Key poseKey, Key pointKey, Key invDepthKey, const Cal3_S2::shared_ptr& K) :
62  Base(model, poseKey, pointKey, invDepthKey), measured_(measured), K_(K) {}
63 
65  ~InvDepthFactor3() override {}
66 
72  void print(const std::string& s = "InvDepthFactor3",
73  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
74  Base::print(s, keyFormatter);
75  traits<Point2>::Print(measured_, s + ".z");
76  }
77 
79  bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
80  const This *e = dynamic_cast<const This*>(&p);
81  return e && Base::equals(p, tol) && traits<Point2>::Equals(this->measured_, e->measured_, tol) && this->K_->equals(*e->K_, tol);
82  }
83 
85  Vector evaluateError(const POSE& pose, const Vector5& point, const INVDEPTH& invDepth,
86  boost::optional<Matrix&> H1=boost::none,
87  boost::optional<Matrix&> H2=boost::none,
88  boost::optional<Matrix&> H3=boost::none) const override {
89  try {
91  return camera.project(point, invDepth, H1, H2, H3) - measured_;
92  } catch( CheiralityException& e) {
93  if (H1) *H1 = Matrix::Zero(2,6);
94  if (H2) *H2 = Matrix::Zero(2,5);
95  if (H3) *H2 = Matrix::Zero(2,1);
96  std::cout << e.what() << ": Landmark "<< DefaultKeyFormatter(this->key2()) <<
97  " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
98  return Vector::Ones(2) * 2.0 * K_->fx();
99  }
100  return (Vector(1) << 0.0).finished();
101  }
102 
104  const Point2& imagePoint() const {
105  return measured_;
106  }
107 
109  inline const Cal3_S2::shared_ptr calibration() const {
110  return K_;
111  }
112 
113 private:
114 
117  template<class ARCHIVE>
118  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
119  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
120  ar & BOOST_SERIALIZATION_NVP(measured_);
121  ar & BOOST_SERIALIZATION_NVP(K_);
122  }
123 };
124 } // \ namespace gtsam
NoiseModelFactor3< POSE, LANDMARK, INVDEPTH > Base
shorthand for base class type
const gtsam::Key poseKey
boost::shared_ptr< Cal3_S2 > K_
shared pointer to calibration object
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Vector evaluateError(const POSE &pose, const Vector5 &point, const INVDEPTH &invDepth, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const override
Evaluate error h(x)-z and optionally derivatives.
noiseModel::Diagonal::shared_ptr model
Vector2 Point2
Definition: Point2.h:27
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
void serialize(ARCHIVE &ar, const unsigned int)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const gtsam::Key pointKey
const Cal3_S2::shared_ptr calibration() const
Point3 point(10, 0,-5)
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::Point2 project(const Vector5 &pw, double rho, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none, boost::optional< gtsam::Matrix & > H3=boost::none) const
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
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
Inverse Depth Camera based on Civera09tro, Montiel06rss. Landmarks are initialized from the first cam...
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Point2 measured_
2D measurement
friend class boost::serialization::access
Serialization function.
traits
Definition: chartTesting.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Non-linear factor base classes.
const Point2 & imagePoint() const
float * p
void print(const std::string &s="InvDepthFactor3", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
const G double tol
Definition: Group.h:83
InvDepthFactor3< POSE, LANDMARK, INVDEPTH > This
shorthand for this class
Point3 measured
static const CalibratedCamera camera(kDefaultPose)
boost::shared_ptr< Cal3_S2 > shared_ptr
Definition: Cal3_S2.h:39
InvDepthFactor3(const Point2 &measured, const SharedNoiseModel &model, const Key poseKey, Key pointKey, Key invDepthKey, const Cal3_S2::shared_ptr &K)
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:59
InvDepthFactor3()
Default constructor.
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
The most common 5DOF 3D->2D calibration.
const char * what() const noexceptoverride


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:14