gtsam 4.2
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
24#include <gtsam_unstable/dllexport.h>
25
26#include <boost/optional.hpp>
27
28namespace gtsam {
29
35template <class POSE, class LANDMARK, class CALIBRATION = Cal3_S2>
36class GTSAM_UNSTABLE_EXPORT ProjectionFactorPPPC
37 : public NoiseModelFactorN<POSE, POSE, LANDMARK, CALIBRATION> {
38 protected:
40
41 // verbosity handling for Cheirality Exceptions
44
45 public:
48
51
53 typedef boost::shared_ptr<This> shared_ptr;
54
57 measured_(0.0, 0.0), throwCheirality_(false), verboseCheirality_(false) {
58 }
59
60
77 Key poseKey, Key transformKey, Key pointKey, Key calibKey,
78 bool throwCheirality = false, bool verboseCheirality = false) :
79 Base(model, poseKey, transformKey, pointKey, calibKey), measured_(measured),
81
84
86 NonlinearFactor::shared_ptr clone() const override {
87 return boost::static_pointer_cast<NonlinearFactor>(
88 NonlinearFactor::shared_ptr(new This(*this))); }
89
95 void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
96 std::cout << s << "ProjectionFactorPPPC, z = ";
98 Base::print("", keyFormatter);
99 }
100
102 bool equals(const NonlinearFactor& p, double tol = 1e-9) const override {
103 const This *e = dynamic_cast<const This*>(&p);
104 return e
105 && Base::equals(p, tol)
106 && traits<Point2>::Equals(this->measured_, e->measured_, tol);
107 }
108
110 Vector evaluateError(const Pose3& pose, const Pose3& transform, const Point3& point, const CALIBRATION& K,
111 boost::optional<Matrix&> H1 = boost::none,
112 boost::optional<Matrix&> H2 = boost::none,
113 boost::optional<Matrix&> H3 = boost::none,
114 boost::optional<Matrix&> H4 = boost::none) const override {
115 try {
116 if(H1 || H2 || H3 || H4) {
117 Matrix H0, H02;
118 const PinholeCamera<CALIBRATION> camera(pose.compose(transform, H0, H02), K);
119 const Point2 reprojectionError(camera.project(point, H1, H3, H4) - measured_);
120 *H2 = *H1 * H02;
121 *H1 = *H1 * H0;
122 return reprojectionError;
123 } else {
124 PinholeCamera<CALIBRATION> camera(pose.compose(transform), K);
125 return camera.project(point, H1, H3, H4) - measured_;
126 }
127 } catch( CheiralityException& e) {
128 if (H1) *H1 = Matrix::Zero(2,6);
129 if (H2) *H2 = Matrix::Zero(2,6);
130 if (H3) *H3 = Matrix::Zero(2,3);
131 if (H4) *H4 = Matrix::Zero(2,CALIBRATION::Dim());
133 std::cout << e.what() << ": Landmark "<< DefaultKeyFormatter(this->key2()) <<
134 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
136 throw e;
137 }
138 return Vector::Ones(2) * 2.0 * K.fx();
139 }
140
142 const Point2& measured() const {
143 return measured_;
144 }
145
147 inline bool verboseCheirality() const { return verboseCheirality_; }
148
150 inline bool throwCheirality() const { return throwCheirality_; }
151
152 private:
153
155 friend class boost::serialization::access;
156 template<class ARCHIVE>
157 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
158 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
159 ar & BOOST_SERIALIZATION_NVP(measured_);
160 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
161 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
162 }
163};
164
166 template<class POSE, class LANDMARK, class CALIBRATION>
167 struct traits<ProjectionFactorPPPC<POSE, LANDMARK, CALIBRATION> > :
168 public Testable<ProjectionFactorPPPC<POSE, LANDMARK, CALIBRATION> > {
169 };
170
171} // \ namespace gtsam
The most common 5DOF 3D->2D calibration.
Base class for all pinhole cameras.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
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:27
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
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:36
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:724
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
Definition CalibratedCamera.h:32
A pinhole camera class that has a Pose3 and a Calibration.
Definition PinholeCamera.h:33
Point2 project(const Point3 &pw, OptionalJacobian< 2, 6 > Dpose=boost::none, OptionalJacobian< 2, 3 > Dpoint=boost::none, OptionalJacobian< 2, DimK > Dcal=boost::none) const
project a 3D point from world coordinates into the image
Definition PinholePose.h:118
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:37
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
Nonlinear factor base class.
Definition NonlinearFactor.h:42
NoiseModelFactorN()
Definition NonlinearFactor.h:469
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:50
const Point2 & measured() const
Definition ProjectionFactorPPPC.h:142
NonlinearFactor::shared_ptr clone() const override
Definition ProjectionFactorPPPC.h:86
boost::shared_ptr< This > shared_ptr
Definition ProjectionFactorPPPC.h:53
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition ProjectionFactorPPPC.h:102
bool verboseCheirality_
Definition ProjectionFactorPPPC.h:43
ProjectionFactorPPPC()
Default constructor.
Definition ProjectionFactorPPPC.h:56
NoiseModelFactorN< POSE, POSE, LANDMARK, CALIBRATION > Base
shorthand for base class type
Definition ProjectionFactorPPPC.h:47
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition ProjectionFactorPPPC.h:95
bool throwCheirality_
Definition ProjectionFactorPPPC.h:42
Point2 measured_
Definition ProjectionFactorPPPC.h:39
bool verboseCheirality() const
Definition ProjectionFactorPPPC.h:147
bool throwCheirality() const
Definition ProjectionFactorPPPC.h:150
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:76
~ProjectionFactorPPPC() override
Virtual destructor.
Definition ProjectionFactorPPPC.h:83
Vector evaluateError(const Pose3 &pose, const Pose3 &transform, const Point3 &point, const CALIBRATION &K, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none, boost::optional< Matrix & > H4=boost::none) const override
Evaluate error h(x)-z and optionally derivatives.
Definition ProjectionFactorPPPC.h:110