25 #include <boost/optional.hpp> 34 template<
class POSE,
class LANDMARK,
class CALIBRATION = Cal3_S2>
40 boost::shared_ptr<CALIBRATION>
K_;
60 measured_(0, 0), throwCheirality_(false), verboseCheirality_(false) {
74 Key poseKey,
Key pointKey,
const boost::shared_ptr<CALIBRATION>& K,
75 boost::optional<POSE> body_P_sensor = boost::none) :
76 Base(model, poseKey, pointKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
77 throwCheirality_(false), verboseCheirality_(false) {}
92 Key poseKey,
Key pointKey,
const boost::shared_ptr<CALIBRATION>& K,
94 boost::optional<POSE> body_P_sensor = boost::none) :
95 Base(model, poseKey, pointKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
96 throwCheirality_(throwCheirality), verboseCheirality_(verboseCheirality) {}
102 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
104 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
111 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
112 std::cout << s <<
"GenericProjectionFactor, z = ";
114 if(this->body_P_sensor_)
115 this->body_P_sensor_->print(
" sensor pose in body frame: ");
121 const This *e =
dynamic_cast<const This*
>(&p);
125 && this->K_->equals(*e->K_, tol)
126 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->
equals(*e->body_P_sensor_)));
131 boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
137 Point2 reprojectionError(camera.project(point, H1, H2, boost::none) -
measured_);
139 return reprojectionError;
149 if (H1) *H1 = Matrix::Zero(2,6);
150 if (H2) *H2 = Matrix::Zero(2,3);
151 if (verboseCheirality_)
152 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->key2()) <<
153 " moved behind camera " << DefaultKeyFormatter(this->
key1()) << std::endl;
154 if (throwCheirality_)
157 return Vector2::Constant(2.0 * K_->fx());
180 template<
class ARCHIVE>
181 void serialize(ARCHIVE & ar,
const unsigned int ) {
182 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
183 ar & BOOST_SERIALIZATION_NVP(measured_);
184 ar & BOOST_SERIALIZATION_NVP(K_);
185 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
186 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
187 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
192 template<
class POSE,
class LANDMARK,
class CALIBRATION>
194 public Testable<GenericProjectionFactor<POSE, LANDMARK, CALIBRATION> > {
Point2 project(const Point3 &pw) const
project a point from world coordinate to the image
Definition: PinholePose.h:91
virtual ~GenericProjectionFactor()
Virtual destructor.
Definition: ProjectionFactor.h:99
bool verboseCheirality() const
return verbosity
Definition: ProjectionFactor.h:171
Nonlinear factor base class.
Definition: NonlinearFactor.h:52
boost::optional< POSE > body_P_sensor_
The pose of the sensor in the body frame.
Definition: ProjectionFactor.h:41
GenericProjectionFactor()
Default constructor.
Definition: ProjectionFactor.h:59
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition: ProjectionFactor.h:56
Definition: CalibratedCamera.h:32
virtual bool equals(const NonlinearFactor &p, double tol=1e-9) const
equals
Definition: ProjectionFactor.h:120
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: ProjectionFactor.h:102
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearFactor.cpp:63
boost::shared_ptr< CALIBRATION > K_
shared pointer to calibration object
Definition: ProjectionFactor.h:40
GenericProjectionFactor(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key pointKey, const boost::shared_ptr< CALIBRATION > &K, bool throwCheirality, bool verboseCheirality, boost::optional< POSE > body_P_sensor=boost::none)
Constructor with exception-handling flags TODO: Mark argument order standard (keys, measurement, parameters)
Definition: ProjectionFactor.h:91
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
GenericProjectionFactor(const Point2 &measured, const SharedNoiseModel &model, Key poseKey, Key pointKey, const boost::shared_ptr< CALIBRATION > &K, boost::optional< POSE > body_P_sensor=boost::none)
Constructor TODO: Mark argument order standard (keys, measurement, parameters)
Definition: ProjectionFactor.h:73
Point2 measured_
2D measurement
Definition: ProjectionFactor.h:39
bool throwCheirality() const
return flag for throwing cheirality exceptions
Definition: ProjectionFactor.h:174
friend class boost::serialization::access
Serialization function.
Definition: ProjectionFactor.h:179
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: ProjectionFactor.h:111
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: Factor.cpp:42
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:345
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:377
Vector evaluateError(const Pose3 &pose, const Point3 &point, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Evaluate error h(x)-z and optionally derivatives.
Definition: ProjectionFactor.h:130
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: PinholeCamera.h:33
bool verboseCheirality_
If true, prints text for Cheirality exceptions (default: false)
Definition: ProjectionFactor.h:45
GenericProjectionFactor< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition: ProjectionFactor.h:53
NoiseModelFactor2< POSE, LANDMARK > Base
shorthand for base class type
Definition: ProjectionFactor.h:50
Definition: ProjectionFactor.h:35
Non-linear factor base classes.
const boost::shared_ptr< CALIBRATION > calibration() const
return the calibration object
Definition: ProjectionFactor.h:166
bool throwCheirality_
If true, rethrows Cheirality exceptions (default: false)
Definition: ProjectionFactor.h:44
A simple camera class with a Cal3_S2 calibration.
const Point2 & measured() const
return the measurement
Definition: ProjectionFactor.h:161
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33