25 #include <boost/optional.hpp> 34 template<
class POSE,
class LANDMARK,
class CALIBRATION = Cal3_S2>
40 boost::shared_ptr<CALIBRATION>
K_;
73 KeySet poseKeys,
Key pointKey,
const boost::shared_ptr<CALIBRATION>& K,
74 boost::optional<POSE> body_P_sensor = boost::none) :
77 keys_.assign(poseKeys.begin(), poseKeys.end());
78 keys_.push_back(pointKey);
94 KeySet poseKeys,
Key pointKey,
const boost::shared_ptr<CALIBRATION>& K,
96 boost::optional<POSE> body_P_sensor = boost::none) :
104 virtual NonlinearFactor::shared_ptr
clone()
const {
105 return boost::static_pointer_cast<NonlinearFactor>(
106 NonlinearFactor::shared_ptr(
new This(*
this))); }
113 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
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)
166 Vector evaluateError(
const Pose3& pose,
const Point3& point,
167 boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
175 return reprojectionError;
178 Point2 reprojectionError(camera.project(point, H1, H2) -
measured_);
179 return reprojectionError;
182 PinholeCamera<CALIBRATION> camera(pose, *
K_);
183 Point2 reprojectionError(camera.project(point, H1, H2) -
measured_);
184 return reprojectionError;
186 }
catch( CheiralityException& e) {
187 if (H1) *H1 = Matrix::Zero(2,6);
188 if (H2) *H2 = Matrix::Zero(2,3);
190 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->key2()) <<
191 " moved behind camera " << DefaultKeyFormatter(this->key1()) << std::endl;
195 return Vector::Ones(2) * 2.0 *
K_->fx();
218 template<
class ARCHIVE>
219 void serialize(ARCHIVE & ar,
const unsigned int ) {
220 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
222 ar & BOOST_SERIALIZATION_NVP(
K_);
This is the base class for all factor types.
Definition: Factor.h:54
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
NoiseModelFactor Base
shorthand for base class type
Definition: MultiProjectionFactor.h:51
Definition: MultiProjectionFactor.h:35
A simple camera class with a Cal3_S2 calibration.
Definition: PinholeCamera.h:33
MultiProjectionFactor< POSE, LANDMARK, CALIBRATION > This
shorthand for this class
Definition: MultiProjectionFactor.h:54
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearFactor.cpp:63
virtual bool equals(const NonlinearFactor &p, double tol=1e-9) const
equals
Definition: MultiProjectionFactor.h:122
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
boost::optional< POSE > body_P_sensor_
The pose of the sensor in the body frame.
Definition: MultiProjectionFactor.h:41
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition: MultiProjectionFactor.h:57
Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Evaluate error h(x)-z and optionally derivatives.
Definition: MultiProjectionFactor.h:132
MultiProjectionFactor()
Default constructor.
Definition: MultiProjectionFactor.h:60
friend class boost::serialization::access
Serialization function.
Definition: MultiProjectionFactor.h:217
bool throwCheirality_
If true, rethrows Cheirality exceptions (default: false)
Definition: MultiProjectionFactor.h:45
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
bool throwCheirality() const
return flag for throwing cheirality exceptions
Definition: MultiProjectionFactor.h:212
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
bool verboseCheirality() const
return verbosity
Definition: MultiProjectionFactor.h:209
boost::shared_ptr< CALIBRATION > K_
shared pointer to calibration object
Definition: MultiProjectionFactor.h:40
A nonlinear sum-of-squares factor with a zero-mean noise model implementing the density Templated on...
Definition: NonlinearFactor.h:161
Non-linear factor base classes.
bool verboseCheirality_
If true, prints text for Cheirality exceptions (default: false)
Definition: MultiProjectionFactor.h:46
const Vector & measured() const
return the measurements
Definition: MultiProjectionFactor.h:199
virtual ~MultiProjectionFactor()
Virtual destructor.
Definition: MultiProjectionFactor.h:101
MultiProjectionFactor(const Vector &measured, const SharedNoiseModel &model, KeySet poseKeys, 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: MultiProjectionFactor.h:72
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
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 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,...
Definition: MultiProjectionFactor.h:93
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: MultiProjectionFactor.h:113
virtual NonlinearFactor::shared_ptr clone() const
Definition: MultiProjectionFactor.h:104
const boost::shared_ptr< CALIBRATION > calibration() const
return the calibration object
Definition: MultiProjectionFactor.h:204