gtsam
Loading...
Searching...
No Matches
ProjectionFactorPPP.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
18
19#pragma once
20
25
26namespace gtsam {
27
33 template<class POSE, class LANDMARK, class CALIBRATION = Cal3_S2>
35 : public NoiseModelFactorT<Vector2, POSE, POSE, LANDMARK> {
36 protected:
37
38 // Keep a copy of measurement and calibration for I/O
40 std::shared_ptr<CALIBRATION> K_;
41
42 // verbosity handling for Cheirality Exceptions
45
46 public:
47
50
51 // Provide access to the Matrix& version of evaluateError:
53
56
58 typedef std::shared_ptr<This> shared_ptr;
59
62 measured_(0.0, 0.0), throwCheirality_(false), verboseCheirality_(false) {
63 }
64
76 Key poseKey, Key transformKey, Key pointKey,
77 const std::shared_ptr<CALIBRATION>& K) :
78 Base(model, poseKey, transformKey, pointKey), measured_(measured), K_(K),
79 throwCheirality_(false), verboseCheirality_(false) {}
80
93 Key poseKey, Key transformKey, Key pointKey,
94 const std::shared_ptr<CALIBRATION>& K,
96 Base(model, poseKey, transformKey, pointKey), measured_(measured), K_(K),
98
101
103 NonlinearFactor::shared_ptr clone() const override {
104 return std::static_pointer_cast<NonlinearFactor>(
105 NonlinearFactor::shared_ptr(new This(*this))); }
106
112 void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
113 std::cout << s << "ProjectionFactorPPP, z = ";
115 Base::print("", keyFormatter);
116 }
117
119 bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
120 const This *e = dynamic_cast<const This*>(&p);
121 return e
122 && Base::equals(p, tol)
123 && traits<Point2>::Equals(this->measured_, e->measured_, tol)
124 && this->K_->equals(*e->K_, tol);
125 }
126
128 Vector2 evaluateError(const Pose3& pose, const Pose3& transform,
129 const Point3& point, OptionalMatrixType H1,
131 OptionalMatrixType H3) const override {
132 try {
133 if(H1 || H2 || H3) {
134 Matrix H0, H02;
135 PinholeCamera<CALIBRATION> camera(pose.compose(transform, H0, H02), *K_);
136 Point2 reprojectionError(camera.project(point, H1, H3, {}) - measured_);
137 *H2 = *H1 * H02;
138 *H1 = *H1 * H0;
139 return reprojectionError;
140 } else {
141 PinholeCamera<CALIBRATION> camera(pose.compose(transform), *K_);
142 return camera.project(point, H1, H3, {}) - measured_;
143 }
144 } catch( CheiralityException& e) {
145 if (H1) *H1 = Matrix::Zero(2,6);
146 if (H2) *H2 = Matrix::Zero(2,6);
147 if (H3) *H3 = Matrix::Zero(2,3);
149 std::cout << e.what() << ": Landmark "
150 << DefaultKeyFormatter(this->key3())
151 << " moved behind camera "
152 << DefaultKeyFormatter(this->key1())
153 << std::endl;
155 throw e;
156 }
157 return Vector::Ones(2) * 2.0 * K_->fx();
158 }
159
161 const Point2& measured() const {
162 return measured_;
163 }
164
166 inline const std::shared_ptr<CALIBRATION> calibration() const {
167 return K_;
168 }
169
171 inline bool verboseCheirality() const { return verboseCheirality_; }
172
174 inline bool throwCheirality() const { return throwCheirality_; }
175
176 private:
177
178#if GTSAM_ENABLE_BOOST_SERIALIZATION
180 friend class boost::serialization::access;
181 template<class ARCHIVE>
182 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
183 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
184 ar & BOOST_SERIALIZATION_NVP(measured_);
185 ar & BOOST_SERIALIZATION_NVP(K_);
186 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
187 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
188 }
189#endif
190 };
191
193 template<class POSE, class LANDMARK, class CALIBRATION>
194 struct traits<ProjectionFactorPPP<POSE, LANDMARK, CALIBRATION> > :
195 public Testable<ProjectionFactorPPP<POSE, LANDMARK, CALIBRATION> > {
196 };
197
198} // \ namespace gtsam
The most common 5DOF 3D->2D calibration.
Base class for all pinhole cameras.
Base class for noise model factors with N variables.
Non-linear factor base classes.
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
Vector3 Point3
As of GTSAM 4, in order to make GTSAM more lean, it is now possible to just typedef Point3 to Vector3...
Definition Point3.h:38
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
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
Definition CalibratedCamera.h:35
A pinhole camera class that has a Pose3 and a Calibration.
Definition PinholeCamera.h:34
Point2 project(const Point3 &pw, OptionalJacobian< 2, 6 > Dpose={}, OptionalJacobian< 2, 3 > Dpoint={}, OptionalJacobian< 2, DimK > Dcal={}) const
project a 3D point from world coordinates into the image
Definition PinholePose.h:112
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
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
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
virtual Vector2 evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Nonlinear factor base class.
Definition NonlinearFactor.h:70
Non-linear factor for a constraint derived from a 2D measurement.
Definition ProjectionFactorPPP.h:35
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition ProjectionFactorPPP.h:119
NonlinearFactor::shared_ptr clone() const override
Definition ProjectionFactorPPP.h:103
bool verboseCheirality_
Definition ProjectionFactorPPP.h:44
ProjectionFactorPPP(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key transformKey, Key pointKey, const std::shared_ptr< CALIBRATION > &K)
Constructor TODO: Mark argument order standard (keys, measurement, parameters).
Definition ProjectionFactorPPP.h:75
bool throwCheirality() const
Definition ProjectionFactorPPP.h:174
NoiseModelFactorT< Vector2, POSE, POSE, LANDMARK > Base
shorthand for base class type
Definition ProjectionFactorPPP.h:49
std::shared_ptr< This > shared_ptr
Definition ProjectionFactorPPP.h:58
Vector2 evaluateError(const Pose3 &pose, const Pose3 &transform, const Point3 &point, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3) const override
Evaluate error h(x)-z and optionally derivatives.
Definition ProjectionFactorPPP.h:128
ProjectionFactorPPP()
Default constructor.
Definition ProjectionFactorPPP.h:61
ProjectionFactorPPP< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition ProjectionFactorPPP.h:55
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition ProjectionFactorPPP.h:112
~ProjectionFactorPPP() override
Virtual destructor.
Definition ProjectionFactorPPP.h:100
Point2 measured_
Definition ProjectionFactorPPP.h:39
std::shared_ptr< CALIBRATION > K_
Definition ProjectionFactorPPP.h:40
bool throwCheirality_
Definition ProjectionFactorPPP.h:43
ProjectionFactorPPP(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key transformKey, Key pointKey, const std::shared_ptr< CALIBRATION > &K, bool throwCheirality, bool verboseCheirality)
Constructor with exception-handling flags TODO: Mark argument order standard (keys,...
Definition ProjectionFactorPPP.h:92
const Point2 & measured() const
Definition ProjectionFactorPPP.h:161
bool verboseCheirality() const
Definition ProjectionFactorPPP.h:171
const std::shared_ptr< CALIBRATION > calibration() const
return the calibration object
Definition ProjectionFactorPPP.h:166