gtsam
Loading...
Searching...
No Matches
InvDepthFactor3.h
Go to the documentation of this file.
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
24
25#pragma once
26
30
31namespace gtsam {
32
36template<class POSE, class LANDMARK, class INVDEPTH>
38 : public NoiseModelFactorT<Vector2, POSE, LANDMARK, INVDEPTH> {
39protected:
40
41 // Keep a copy of measurement and calibration for I/O
43 std::shared_ptr<Cal3_S2> K_;
44
45public:
46
49
50 // Provide access to the Matrix& version of evaluateError:
52
55
57 typedef std::shared_ptr<This> shared_ptr;
58
61 measured_(0.0, 0.0), K_(new Cal3_S2(444, 555, 666, 777, 888)) {
62 }
63
74 InvDepthFactor3(const Point2& measured, const SharedNoiseModel& model,
75 const Key poseKey, Key pointKey, Key invDepthKey, const Cal3_S2::shared_ptr& K) :
76 Base(model, poseKey, pointKey, invDepthKey), measured_(measured), K_(K) {}
77
79 ~InvDepthFactor3() override {}
80
86 void print(const std::string& s = "InvDepthFactor3",
87 const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
88 Base::print(s, keyFormatter);
90 }
91
93 bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
94 const This *e = dynamic_cast<const This*>(&p);
95 return e && Base::equals(p, tol) && traits<Point2>::Equals(this->measured_, e->measured_, tol) && this->K_->equals(*e->K_, tol);
96 }
97
99 Vector2 evaluateError(const POSE& pose, const Vector5& point,
100 const INVDEPTH& invDepth, OptionalMatrixType H1,
102 OptionalMatrixType H3) const override {
103 try {
104 InvDepthCamera3<Cal3_S2> camera(pose, K_);
105 return camera.project(point, invDepth, H1, H2, H3) - measured_;
106 } catch( CheiralityException& e) {
107 if (H1) *H1 = Matrix::Zero(2,6);
108 if (H2) *H2 = Matrix::Zero(2,5);
109 if (H3) *H3 = Matrix::Zero(2,1);
110 std::cout << e.what() << ": Landmark "<< DefaultKeyFormatter(this->key2()) <<
111 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
112 return Vector::Ones(2) * 2.0 * K_->fx();
113 }
114 return Vector{{0.0}};
115 }
116
118 const Point2& imagePoint() const {
119 return measured_;
120 }
121
123 inline const Cal3_S2::shared_ptr calibration() const {
124 return K_;
125 }
126
127private:
128
129#if GTSAM_ENABLE_BOOST_SERIALIZATION
131 friend class boost::serialization::access;
132 template<class ARCHIVE>
133 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
134 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
135 ar & BOOST_SERIALIZATION_NVP(measured_);
136 ar & BOOST_SERIALIZATION_NVP(K_);
137 }
138#endif
139};
140} // \ namespace gtsam
The most common 5DOF 3D->2D calibration.
Non-linear factor base classes.
Inverse Depth Camera based on Civera09tro, Montiel06rss.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
Vector2 Point2
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point2 to Vector2...
Definition Point2.h:32
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
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
The most common 5DOF 3D->2D calibration.
Definition Cal3_S2.h:35
Definition CalibratedCamera.h:35
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual Vector2 evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Nonlinear factor base class.
Definition NonlinearFactor.h:70
A pinhole camera class that has a Pose3 and a Calibration.
Definition InvDepthCamera3.h:36
gtsam::Point2 project(const Vector5 &pw, double rho, OptionalJacobian< 2, 6 > H1={}, OptionalJacobian< 2, 5 > H2={}, OptionalJacobian< 2, 1 > H3={}) const
project a point from world InvDepth parameterization to the image
Definition InvDepthCamera3.h:89
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition InvDepthFactor3.h:93
NoiseModelFactorT< Vector2, POSE, LANDMARK, INVDEPTH > Base
shorthand for base class type
Definition InvDepthFactor3.h:48
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition InvDepthFactor3.h:57
Vector2 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.
Definition InvDepthFactor3.h:99
void print(const std::string &s="InvDepthFactor3", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition InvDepthFactor3.h:86
const Point2 & imagePoint() const
return the measurement
Definition InvDepthFactor3.h:118
InvDepthFactor3< POSE, LANDMARK, INVDEPTH > This
shorthand for this class
Definition InvDepthFactor3.h:54
InvDepthFactor3(const Point2 &measured, const SharedNoiseModel &model, const Key poseKey, Key pointKey, Key invDepthKey, const Cal3_S2::shared_ptr &K)
Constructor TODO: Mark argument order standard (keys, measurement, parameters).
Definition InvDepthFactor3.h:74
Point2 measured_
2D measurement
Definition InvDepthFactor3.h:42
const Cal3_S2::shared_ptr calibration() const
return the calibration object
Definition InvDepthFactor3.h:123
InvDepthFactor3()
Default constructor.
Definition InvDepthFactor3.h:60
~InvDepthFactor3() override
Virtual destructor.
Definition InvDepthFactor3.h:79
std::shared_ptr< Cal3_S2 > K_
shared pointer to calibration object
Definition InvDepthFactor3.h:43