24 #include <gtsam_unstable/dllexport.h> 34 template <
class POSE,
class LANDMARK,
class CALIBRATION = Cal3_S2>
46 typedef NoiseModelFactor4<POSE, POSE, LANDMARK, CALIBRATION>
Base;
49 using Base::evaluateError;
59 measured_(0.0, 0.0), throwCheirality_(false), verboseCheirality_(false) {
79 Key poseKey,
Key transformKey,
Key pointKey,
Key calibKey,
80 bool throwCheirality =
false,
bool verboseCheirality =
false) :
81 Base(model, poseKey, transformKey, pointKey, calibKey), measured_(measured),
82 throwCheirality_(throwCheirality), verboseCheirality_(verboseCheirality) {}
88 NonlinearFactor::shared_ptr
clone()
const override {
90 NonlinearFactor::shared_ptr(
new This(*
this))); }
97 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
98 std::cout << s <<
"ProjectionFactorPPPC, z = ";
105 const This *e =
dynamic_cast<const This*
>(&p);
107 && Base::equals(p, tol)
116 if(H1 || H2 || H3 || H4) {
119 const Point2 reprojectionError(camera.project(point, H1, H3, H4) - measured_);
122 return reprojectionError;
125 return camera.
project(point, H1, H3, H4) - measured_;
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());
132 if (verboseCheirality_)
133 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->key2()) <<
134 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
135 if (throwCheirality_)
138 return Vector::Ones(2) * 2.0 * K.fx();
154 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 155 friend class boost::serialization::access; 157 template<
class ARCHIVE>
158 void serialize(ARCHIVE & ar,
const unsigned int ) {
159 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
160 ar & BOOST_SERIALIZATION_NVP(measured_);
161 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
162 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
168 template<
class POSE,
class LANDMARK,
class CALIBRATION>
170 public Testable<ProjectionFactorPPPC<POSE, LANDMARK, CALIBRATION> > {
Point2 measured_
2D measurement
Definition: ProjectionFactorPPPC.h:38
~ProjectionFactorPPPC() override
Definition: ProjectionFactorPPPC.h:85
bool verboseCheirality() const
Definition: ProjectionFactorPPPC.h:147
Definition: NonlinearFactor.h:431
ProjectionFactorPPPC(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key transformKey, Key pointKey, Key calibKey, bool throwCheirality=false, bool verboseCheirality=false)
Definition: ProjectionFactorPPPC.h:78
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Definition: Testable.h:152
Vector2 Point2
Definition: Point2.h:32
ProjectionFactorPPPC()
Default constructor.
Definition: ProjectionFactorPPPC.h:58
Definition: NonlinearFactor.h:68
NonlinearFactor::shared_ptr clone() const override
Definition: ProjectionFactorPPPC.h:88
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition: ProjectionFactorPPPC.h:55
Definition: ProjectionFactorPPPC.h:35
Base class for all pinhole cameras.
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
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition: ProjectionFactorPPPC.h:104
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
bool verboseCheirality_
If true, prints text for Cheirality exceptions (default: false)
Definition: ProjectionFactorPPPC.h:42
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: ProjectionFactorPPPC.h:97
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
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
Definition: PinholeCamera.h:33
Definition: chartTesting.h:28
const Point2 & measured() const
Definition: ProjectionFactorPPPC.h:142
Non-linear factor base classes.
bool throwCheirality() const
Definition: ProjectionFactorPPPC.h:150
Definition: CalibratedCamera.h:34
bool throwCheirality_
If true, rethrows Cheirality exceptions (default: false)
Definition: ProjectionFactorPPPC.h:41
Vector3 Point3
Definition: Point3.h:38
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
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:112
ProjectionFactorPPPC< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition: ProjectionFactorPPPC.h:52
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
The most common 5DOF 3D->2D calibration.
NoiseModelFactor4< POSE, POSE, LANDMARK, CALIBRATION > Base
shorthand for base class type
Definition: ProjectionFactorPPPC.h:46