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 NoiseModelFactorN<POSE, LANDMARK, INVDEPTH> {
28 protected:
29 
30  // Keep a copy of measurement and calibration for I/O
32  std::shared_ptr<Cal3_S2> K_;
33 
34 public:
35 
37  typedef NoiseModelFactor3<POSE, LANDMARK, INVDEPTH> Base;
38 
39  // Provide access to the Matrix& version of evaluateError:
40  using Base::evaluateError;
41 
44 
46  typedef std::shared_ptr<This> shared_ptr;
47 
50  measured_(0.0, 0.0), K_(new Cal3_S2(444, 555, 666, 777, 888)) {
51  }
52 
64  const Key poseKey, Key pointKey, Key invDepthKey, const Cal3_S2::shared_ptr& K) :
65  Base(model, poseKey, pointKey, invDepthKey), measured_(measured), K_(K) {}
66 
68  ~InvDepthFactor3() override {}
69 
75  void print(const std::string& s = "InvDepthFactor3",
76  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
77  Base::print(s, keyFormatter);
78  traits<Point2>::Print(measured_, s + ".z");
79  }
80 
82  bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
83  const This *e = dynamic_cast<const This*>(&p);
84  return e && Base::equals(p, tol) && traits<Point2>::Equals(this->measured_, e->measured_, tol) && this->K_->equals(*e->K_, tol);
85  }
86 
88  Vector evaluateError(const POSE& pose, const Vector5& point, const INVDEPTH& invDepth,
89  OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override {
90  try {
92  return camera.project(point, invDepth, H1, H2, H3) - measured_;
93  } catch( CheiralityException& e) {
94  if (H1) *H1 = Matrix::Zero(2,6);
95  if (H2) *H2 = Matrix::Zero(2,5);
96  if (H3) *H3 = Matrix::Zero(2,1);
97  std::cout << e.what() << ": Landmark "<< DefaultKeyFormatter(this->key2()) <<
98  " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
99  return Vector::Ones(2) * 2.0 * K_->fx();
100  }
101  return (Vector(1) << 0.0).finished();
102  }
103 
105  const Point2& imagePoint() const {
106  return measured_;
107  }
108 
110  inline const Cal3_S2::shared_ptr calibration() const {
111  return K_;
112  }
113 
114 private:
115 
116 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
117  friend class boost::serialization::access;
119  template<class ARCHIVE>
120  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
121  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
122  ar & BOOST_SERIALIZATION_NVP(measured_);
123  ar & BOOST_SERIALIZATION_NVP(K_);
124  }
125 #endif
126 };
127 } // \ namespace gtsam
Point2 measured(-17, 30)
NoiseModelFactor3< POSE, LANDMARK, INVDEPTH > Base
shorthand for base class type
const gtsam::Key poseKey
const Point2 & imagePoint() const
std::string serialize(const T &input)
serializes to a string
noiseModel::Diagonal::shared_ptr model
Vector2 Point2
Definition: Point2.h:32
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const gtsam::Key pointKey
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Matrix * OptionalMatrixType
std::shared_ptr< Cal3_S2 > shared_ptr
Definition: Cal3_S2.h:39
Eigen::VectorXd Vector
Definition: Vector.h:38
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
The most common 5DOF 3D->2D calibration.
Definition: Cal3_S2.h:34
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
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
traits
Definition: chartTesting.h:28
gtsam::Point2 project(const Vector5 &pw, double rho, OptionalJacobian< 2, 6 > H1={}, OptionalJacobian< 2, 5 > H2={}, OptionalJacobian< 2, 1 > H3={}) const
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
Non-linear factor base classes.
std::shared_ptr< Cal3_S2 > K_
shared pointer to calibration object
float * p
void print(const std::string &s="InvDepthFactor3", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
const G double tol
Definition: Group.h:86
InvDepthFactor3< POSE, LANDMARK, INVDEPTH > This
shorthand for this class
const Cal3_S2::shared_ptr calibration() const
static const CalibratedCamera camera(kDefaultPose)
Vector evaluateError(const POSE &pose, const Vector5 &point, const INVDEPTH &invDepth, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Evaluate error h(x)-z and optionally derivatives.
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:102
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:62
InvDepthFactor3()
Default constructor.
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
The most common 5DOF 3D->2D calibration.
const char * what() const noexcept override


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:23