34 template<
class POSE,
class LANDMARK,
class CALIBRATION = Cal3_S2>
40 std::shared_ptr<CALIBRATION>
K_;
73 KeySet poseKeys,
Key pointKey,
const std::shared_ptr<CALIBRATION>& K,
74 std::optional<POSE> body_P_sensor = {}) :
77 keys_.assign(poseKeys.begin(), poseKeys.end());
78 keys_.push_back(pointKey);
94 KeySet poseKeys,
Key pointKey,
const std::shared_ptr<CALIBRATION>& K,
96 std::optional<POSE> body_P_sensor = {}) :
104 NonlinearFactor::shared_ptr
clone()
const override {
106 NonlinearFactor::shared_ptr(
new This(*
this))); }
113 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const override {
114 std::cout << s <<
"MultiProjectionFactor, z = ";
115 std::cout << measured_ <<
"measurements, z = ";
116 if(this->body_P_sensor_)
117 this->body_P_sensor_->print(
" sensor pose in body frame: ");
123 const This *e =
dynamic_cast<const This*
>(&p);
127 && this->K_->equals(*e->K_, tol)
128 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->
equals(*e->body_P_sensor_)));
166 Vector evaluateError(
const Pose3& pose,
const Point3& point,
175 return reprojectionError;
179 return reprojectionError;
184 return reprojectionError;
187 if (H1) *H1 = Matrix::Zero(2,6);
188 if (H2) *H2 = Matrix::Zero(2,3);
189 if (verboseCheirality_)
190 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->
keys_.at(1)) <<
191 " moved behind camera " << DefaultKeyFormatter(this->
keys_.at(0)) << std::endl;
192 if (throwCheirality_)
195 return Vector::Ones(2) * 2.0 * K_->fx();
216 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 217 friend class boost::serialization::access; 219 template<
class ARCHIVE>
220 void serialize(ARCHIVE & ar,
const unsigned int ) {
221 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
222 ar & BOOST_SERIALIZATION_NVP(measured_);
223 ar & BOOST_SERIALIZATION_NVP(K_);
224 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
225 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
226 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
std::vector< Matrix > * OptionalMatrixVecType
Definition: NonlinearFactor.h:61
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
Vector2 Point2
Definition: Point2.h:32
const Vector & measured() const
Definition: MultiProjectionFactor.h:199
Definition: NonlinearFactor.h:68
NonlinearFactor::shared_ptr clone() const override
Definition: MultiProjectionFactor.h:104
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:87
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition: MultiProjectionFactor.h:57
MultiProjectionFactor(const Vector &measured, const SharedNoiseModel &model, KeySet poseKeys, Key pointKey, const std::shared_ptr< CALIBRATION > &K, bool throwCheirality, bool verboseCheirality, std::optional< POSE > body_P_sensor={})
Definition: MultiProjectionFactor.h:93
~MultiProjectionFactor() override
Definition: MultiProjectionFactor.h:101
const std::shared_ptr< CALIBRATION > calibration() const
Definition: MultiProjectionFactor.h:204
MultiProjectionFactor< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition: MultiProjectionFactor.h:54
Definition: NonlinearFactor.h:197
bool throwCheirality() const
Definition: MultiProjectionFactor.h:212
bool verboseCheirality() const
Definition: MultiProjectionFactor.h:209
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
std::optional< POSE > body_P_sensor_
The pose of the sensor in the body frame.
Definition: MultiProjectionFactor.h:41
bool throwCheirality_
If true, rethrows Cheirality exceptions (default: false)
Definition: MultiProjectionFactor.h:45
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
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
Evaluate error h(x)-z and optionally derivatives.
Definition: MultiProjectionFactor.h:132
Definition: PinholeCamera.h:33
Definition: chartTesting.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: OptionalJacobian.h:38
Non-linear factor base classes.
bool verboseCheirality_
If true, prints text for Cheirality exceptions (default: false)
Definition: MultiProjectionFactor.h:46
Definition: CalibratedCamera.h:34
NoiseModelFactor Base
shorthand for base class type
Definition: MultiProjectionFactor.h:51
Vector3 Point3
Definition: Point3.h:38
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition: MultiProjectionFactor.h:122
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: MultiProjectionFactor.h:113
Vector measured_
2D measurement for each of the n views
Definition: MultiProjectionFactor.h:39
MultiProjectionFactor(const Vector &measured, const SharedNoiseModel &model, KeySet poseKeys, Key pointKey, const std::shared_ptr< CALIBRATION > &K, std::optional< POSE > body_P_sensor={})
Definition: MultiProjectionFactor.h:72
Definition: MultiProjectionFactor.h:35
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::shared_ptr< CALIBRATION > K_
shared pointer to calibration object
Definition: MultiProjectionFactor.h:40
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
The most common 5DOF 3D->2D calibration.
MultiProjectionFactor()
Default constructor.
Definition: MultiProjectionFactor.h:60
bool equals(const This &other, double tol=1e-9) const
check equality