30 template<
class POSE,
class LANDMARK>
37 boost::optional<POSE> body_P_sensor_;
40 bool throwCheirality_;
41 bool verboseCheirality_;
48 typedef boost::shared_ptr<GenericStereoFactor>
shared_ptr;
55 throwCheirality_(false), verboseCheirality_(false) {}
68 boost::optional<POSE> body_P_sensor = boost::none) :
69 Base(model, poseKey, landmarkKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
70 throwCheirality_(false), verboseCheirality_(false) {}
86 boost::optional<POSE> body_P_sensor = boost::none) :
87 Base(model, poseKey, landmarkKey), measured_(measured), K_(K), body_P_sensor_(body_P_sensor),
88 throwCheirality_(throwCheirality), verboseCheirality_(verboseCheirality) {}
94 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
96 gtsam::NonlinearFactor::shared_ptr(
new This(*
this))); }
103 void print(
const std::string& s =
"",
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
105 measured_.
print(s +
".z");
106 if(this->body_P_sensor_)
107 this->body_P_sensor_->print(
" sensor pose in body frame: ");
117 && measured_.
equals(e->measured_, tol)
118 && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
123 boost::optional<Matrix&> H1 = boost::none, boost::optional<Matrix&> H2 = boost::none)
const {
129 StereoPoint2 reprojectionError(stereoCam.project(point, H1, H2) - measured_);
131 return reprojectionError.
vector();
134 return (stereoCam.project(point, H1, H2) - measured_).vector();
138 return (stereoCam.project(point, H1, H2) - measured_).vector();
141 if (H1) *H1 =
zeros(3,6);
142 if (H2) *H2 =
zeros(3,3);
143 if (verboseCheirality_)
144 std::cout << e.what() <<
": Landmark "<< DefaultKeyFormatter(this->key2()) <<
145 " moved behind camera " << DefaultKeyFormatter(this->
key1()) << std::endl;
146 if (throwCheirality_)
149 return ones(3) * 2.0 * K_->fx();
171 template<
class Archive>
172 void serialize(Archive & ar,
const unsigned int version) {
173 ar & boost::serialization::make_nvp(
"NoiseModelFactor2",
174 boost::serialization::base_object<Base>(*
this));
175 ar & BOOST_SERIALIZATION_NVP(measured_);
176 ar & BOOST_SERIALIZATION_NVP(K_);
177 ar & BOOST_SERIALIZATION_NVP(body_P_sensor_);
178 ar & BOOST_SERIALIZATION_NVP(throwCheirality_);
179 ar & BOOST_SERIALIZATION_NVP(verboseCheirality_);
Definition: Cal3_S2Stereo.h:29
Non-linear factor base classes.
Pose3 compose(const Pose3 &p2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
compose this transformation onto another (first *this and then p2)
Definition: Pose3.cpp:272
bool verboseCheirality() const
return verbosity
Definition: StereoFactor.h:163
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.h:239
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
equals
Definition: StereoFactor.h:113
NoiseModelFactor2< POSE, LANDMARK > Base
typedef for base class
Definition: StereoFactor.h:46
boost::shared_ptr< Cal3_S2Stereo > shared_ptr
shared pointer to stereo calibration object
Definition: Cal3_S2Stereo.h:37
Definition: StereoPoint2.h:31
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: StereoFactor.h:94
A Stereo Camera based on two Simple Cameras.
GenericStereoFactor(const StereoPoint2 &measured, const SharedNoiseModel &model, Key poseKey, Key landmarkKey, const Cal3_S2Stereo::shared_ptr &K, bool throwCheirality, bool verboseCheirality, boost::optional< POSE > body_P_sensor=boost::none)
Constructor with exception-handling flags.
Definition: StereoFactor.h:83
GenericStereoFactor()
Default constructor.
Definition: StereoFactor.h:54
Definition: StereoFactor.h:31
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:423
POSE CamPose
typedef for Pose Lie Value type
Definition: StereoFactor.h:49
boost::shared_ptr< GenericStereoFactor > shared_ptr
typedef for shared pointer to this object
Definition: StereoFactor.h:48
This is the base class for all factor types.
Definition: Factor.h:51
GenericStereoFactor(const StereoPoint2 &measured, const SharedNoiseModel &model, Key poseKey, Key landmarkKey, const Cal3_S2Stereo::shared_ptr &K, boost::optional< POSE > body_P_sensor=boost::none)
Constructor.
Definition: StereoFactor.h:66
bool equals(const StereoPoint2 &q, double tol=1e-9) const
equals
Definition: StereoPoint2.h:60
GenericStereoFactor< POSE, LANDMARK > This
typedef for this class (with templates)
Definition: StereoFactor.h:47
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:455
Definition: StereoCamera.h:29
Vector evaluateError(const Pose3 &pose, const Point3 &point, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
h(x)-z
Definition: StereoFactor.h:122
size_t Key
Integer nonlinear key type.
Definition: types.h:59
Matrix ones(size_t m, size_t n)
Creates an ones matrix, with matlab-like syntax.
Definition: Matrix.cpp:45
const StereoPoint2 & measured() const
return the measured
Definition: StereoFactor.h:153
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: StereoFactor.h:103
void print(const std::string &s="") const
print
Definition: StereoPoint2.cpp:25
virtual ~GenericStereoFactor()
Virtual destructor.
Definition: StereoFactor.h:91
Definition: StereoCamera.h:39
const Cal3_S2Stereo::shared_ptr calibration() const
return the calibration object
Definition: StereoFactor.h:158
Vector3 vector() const
convert to vector
Definition: StereoPoint2.h:141
bool throwCheirality() const
return flag for throwing cheirality exceptions
Definition: StereoFactor.h:166
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearFactor.h:231
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:884
Nonlinear factor base class.
Definition: NonlinearFactor.h:54
Matrix zeros(size_t m, size_t n)
Creates an zeros matrix, with matlab-like syntax.
Definition: Matrix.cpp:40
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
friend class boost::serialization::access
Serialization function.
Definition: StereoFactor.h:170