gtsam
Loading...
Searching...
No Matches
ProjectionFactorPPPC.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#include <gtsam_unstable/dllexport.h>
26
27
28namespace gtsam {
29
35template <class POSE, class LANDMARK, class CALIBRATION = Cal3_S2>
37 : public NoiseModelFactorN<POSE, POSE, LANDMARK, CALIBRATION> {
38 protected:
40
41 // verbosity handling for Cheirality Exceptions
44
45 public:
47 typedef NoiseModelFactor4<POSE, POSE, LANDMARK, CALIBRATION> Base;
48
49 // Provide access to the Matrix& version of evaluateError:
50 using Base::evaluateError;
51
54
56 typedef std::shared_ptr<This> shared_ptr;
57
60 measured_(0.0, 0.0), throwCheirality_(false), verboseCheirality_(false) {
61 }
62
63
80 Key poseKey, Key transformKey, Key pointKey, Key calibKey,
81 bool throwCheirality = false, bool verboseCheirality = false) :
82 Base(model, poseKey, transformKey, pointKey, calibKey), measured_(measured),
84
87
89 NonlinearFactor::shared_ptr clone() const override {
90 return std::static_pointer_cast<NonlinearFactor>(
91 NonlinearFactor::shared_ptr(new This(*this))); }
92
98 void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
99 std::cout << s << "ProjectionFactorPPPC, z = ";
101 Base::print("", keyFormatter);
102 }
103
105 bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
106 const This *e = dynamic_cast<const This*>(&p);
107 return e
108 && Base::equals(p, tol)
109 && traits<Point2>::Equals(this->measured_, e->measured_, tol);
110 }
111
113 Vector evaluateError(const Pose3& pose, const Pose3& transform, const Point3& point, const CALIBRATION& K,
115 OptionalMatrixType H4) const override {
116 try {
117 if(H1 || H2 || H3 || H4) {
118 Matrix H0, H02;
119 const PinholeCamera<CALIBRATION> camera(pose.compose(transform, H0, H02), K);
120 const Point2 reprojectionError(camera.project(point, H1, H3, H4) - measured_);
121 *H2 = *H1 * H02;
122 *H1 = *H1 * H0;
123 return reprojectionError;
124 } else {
125 PinholeCamera<CALIBRATION> camera(pose.compose(transform), K);
126 return camera.project(point, H1, H3, H4) - measured_;
127 }
128 } catch( CheiralityException& e) {
129 if (H1) *H1 = Matrix::Zero(2,6);
130 if (H2) *H2 = Matrix::Zero(2,6);
131 if (H3) *H3 = Matrix::Zero(2,3);
132 if (H4) *H4 = Matrix::Zero(2,CALIBRATION::dimension);
134 std::cout << e.what() << ": Landmark "<< DefaultKeyFormatter(this->key3()) <<
135 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
137 throw e;
138 }
139 return Vector::Ones(2) * 2.0 * K.fx();
140 }
141
143 const Point2& measured() const {
144 return measured_;
145 }
146
148 inline bool verboseCheirality() const { return verboseCheirality_; }
149
151 inline bool throwCheirality() const { return throwCheirality_; }
152
153 private:
154
155#if GTSAM_ENABLE_BOOST_SERIALIZATION
157 friend class boost::serialization::access;
158 template<class ARCHIVE>
159 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
160 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
161 ar & BOOST_SERIALIZATION_NVP(measured_);
162 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
163 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
164 }
165#endif
166};
167
169 template<class POSE, class LANDMARK, class CALIBRATION>
170 struct traits<ProjectionFactorPPPC<POSE, LANDMARK, CALIBRATION> > :
171 public Testable<ProjectionFactorPPPC<POSE, LANDMARK, CALIBRATION> > {
172 };
173
174} // \ 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
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
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
Nonlinear factor base class.
Definition NonlinearFactor.h:70
Non-linear factor for a constraint derived from a 2D measurement.
Definition ProjectionFactorPPPC.h:37
ProjectionFactorPPPC< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition ProjectionFactorPPPC.h:53
Vector evaluateError(const Pose3 &pose, const Pose3 &transform, const Point3 &point, const CALIBRATION &K, OptionalMatrixType H1, OptionalMatrixType H2, OptionalMatrixType H3, OptionalMatrixType H4) const override
Evaluate error h(x)-z and optionally derivatives.
Definition ProjectionFactorPPPC.h:113
const Point2 & measured() const
Definition ProjectionFactorPPPC.h:143
NonlinearFactor::shared_ptr clone() const override
Definition ProjectionFactorPPPC.h:89
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition ProjectionFactorPPPC.h:105
bool verboseCheirality_
Definition ProjectionFactorPPPC.h:43
ProjectionFactorPPPC()
Default constructor.
Definition ProjectionFactorPPPC.h:59
std::shared_ptr< This > shared_ptr
Definition ProjectionFactorPPPC.h:56
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition ProjectionFactorPPPC.h:98
bool throwCheirality_
Definition ProjectionFactorPPPC.h:42
NoiseModelFactor4< POSE, POSE, LANDMARK, CALIBRATION > Base
shorthand for base class type
Definition ProjectionFactorPPPC.h:47
Point2 measured_
Definition ProjectionFactorPPPC.h:39
bool verboseCheirality() const
Definition ProjectionFactorPPPC.h:148
bool throwCheirality() const
Definition ProjectionFactorPPPC.h:151
ProjectionFactorPPPC(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key transformKey, Key pointKey, Key calibKey, bool throwCheirality=false, bool verboseCheirality=false)
Constructor with exception-handling flags TODO: Mark argument order standard (keys,...
Definition ProjectionFactorPPPC.h:79
~ProjectionFactorPPPC() override
Virtual destructor.
Definition ProjectionFactorPPPC.h:86