PlanarProjectionFactor.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <gtsam/base/Testable.h>
18 #include <gtsam/base/Lie.h>
19 
20 #include <gtsam/geometry/Cal3DS2.h>
22 #include <gtsam/geometry/Point3.h>
23 #include <gtsam/geometry/Pose2.h>
24 #include <gtsam/geometry/Pose3.h>
25 #include <gtsam/geometry/Rot3.h>
28 
29 
30 namespace gtsam {
31 
37  protected:
39 
44 
58  const Point3& landmark,
59  const Pose2& wTb,
60  const Pose3& bTc,
61  const Cal3DS2& calib,
62  OptionalJacobian<2, 3> Hlandmark = {}, // (x, y, z)
63  OptionalJacobian<2, 3> HwTb = {}, // (x, y, theta)
64  OptionalJacobian<2, 6> HbTc = {}, // (rx, ry, rz, x, y, theta)
65  OptionalJacobian<2, 9> Hcalib = {}
66  ) const {
67 #ifndef GTSAM_THROW_CHEIRALITY_EXCEPTION
68  try {
69 #endif
70  Matrix63 Hp; // 6x3
71  Matrix66 H0; // 6x6
72  Pose3 wTc = Pose3::FromPose2(wTb, HwTb ? &Hp : nullptr).compose(bTc, HwTb ? &H0 : nullptr);
73  PinholeCamera<Cal3DS2> camera = PinholeCamera<Cal3DS2>(wTc, calib);
74  if (HwTb || HbTc) {
75  // Dpose is for pose3 (R,t)
76  Matrix26 Dpose;
77  Point2 result = camera.project(landmark, Dpose, Hlandmark, Hcalib);
78  if (HbTc)
79  *HbTc = Dpose;
80  if (HwTb)
81  *HwTb = Dpose * H0 * Hp;
82  return result;
83  } else {
84  return camera.project(landmark, {}, {}, {});
85  }
86 #ifndef GTSAM_THROW_CHEIRALITY_EXCEPTION
87  } catch (CheiralityException& e) {
88  std::cout << "****** CHIRALITY EXCEPTION ******\n";
89  if (Hlandmark) Hlandmark->setZero();
90  if (HwTb) HwTb->setZero();
91  if (HbTc) HbTc->setZero();
92  if (Hcalib) Hcalib->setZero();
93  // return a large error
94  return Matrix::Constant(2, 1, 2.0 * calib.fx());
95  }
96 #endif
97  }
98 
99  Point2 measured_; // pixel measurement
100  };
101 
102 
110  : public PlanarProjectionFactorBase, public NoiseModelFactorN<Pose2> {
111  public:
113  using Base::evaluateError;
115 
117 
120  return std::static_pointer_cast<NonlinearFactor>(
122  }
123 
124 
135  Key poseKey,
136  const Point3& landmark,
137  const Point2& measured,
138  const Pose3& bTc,
139  const Cal3DS2& calib,
140  const SharedNoiseModel& model = {})
144  bTc_(bTc),
145  calib_(calib) {}
146 
151  Vector evaluateError(const Pose2& wTb, OptionalMatrixType HwTb) const override {
152  return predict(landmark_, wTb, bTc_, calib_, {}, HwTb, {}, {}) - measured_;
153  }
154 
155  private:
156  Point3 landmark_; // landmark
157  Pose3 bTc_; // "body to camera": camera offset to robot pose
158  Cal3DS2 calib_; // camera calibration
159  };
160 
161  template<>
163  public Testable<PlanarProjectionFactor1> {};
164 
172  : public PlanarProjectionFactorBase, public NoiseModelFactorN<Pose2, Point3> {
173  public:
175  using Base::evaluateError;
176 
178 
180 
183  return std::static_pointer_cast<NonlinearFactor>(
185  }
186 
197  Key poseKey,
198  Key landmarkKey,
199  const Point2& measured,
200  const Pose3& bTc,
201  const Cal3DS2& calib,
202  const SharedNoiseModel& model = {})
204  NoiseModelFactorN(model, landmarkKey, poseKey),
205  bTc_(bTc),
206  calib_(calib) {}
207 
215  const Pose2& wTb,
216  const Point3& landmark,
217  OptionalMatrixType HwTb,
218  OptionalMatrixType Hlandmark) const override {
219  return predict(landmark, wTb, bTc_, calib_, Hlandmark, HwTb, {}, {}) - measured_;
220  }
221 
222  private:
223  Pose3 bTc_; // "body to camera": camera offset to robot pose
224  Cal3DS2 calib_; // camera calibration
225  };
226 
227  template<>
229  public Testable<PlanarProjectionFactor2> {};
230 
237  class PlanarProjectionFactor3 : public PlanarProjectionFactorBase, public NoiseModelFactorN<Pose2, Pose3, Cal3DS2> {
238  public:
240  using Base::evaluateError;
241 
243 
245 
248  return std::static_pointer_cast<NonlinearFactor>(
250  }
251 
262  Key poseKey,
263  Key offsetKey,
264  Key calibKey,
265  const Point3& landmark,
266  const Point2& measured,
267  const SharedNoiseModel& model = {})
269  NoiseModelFactorN(model, poseKey, offsetKey, calibKey),
270  landmark_(landmark) {}
271 
281  const Pose2& wTb,
282  const Pose3& bTc,
283  const Cal3DS2& calib,
284  OptionalMatrixType HwTb,
285  OptionalMatrixType HbTc,
286  OptionalMatrixType Hcalib) const override {
287  return predict(landmark_, wTb, bTc, calib, {}, HwTb, HbTc, Hcalib) - measured_;
288  }
289 
290  private:
291  Point3 landmark_; // landmark
292  };
293 
294  template<>
296  public Testable<PlanarProjectionFactor3> {};
297 
298 } // namespace gtsam
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::PlanarProjectionFactor2::bTc_
Pose3 bTc_
Definition: PlanarProjectionFactor.h:223
Pose2.h
2D Pose
gtsam::PlanarProjectionFactor1::PlanarProjectionFactor1
PlanarProjectionFactor1()
Definition: PlanarProjectionFactor.h:114
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Testable.h
Concept check for values that can be used in unit tests.
gtsam::Cal3DS2
Calibration of a camera with radial distortion that also supports Lie-group behaviors for optimizatio...
Definition: Cal3DS2.h:35
gtsam::Pose3::FromPose2
static Pose3 FromPose2(const Pose2 &p, OptionalJacobian< 6, 3 > H={})
Definition: Pose3.cpp:55
gtsam::NoiseModelFactorN< Pose2 >::evaluateError
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
gtsam::LieGroup::compose
Class compose(const Class &g) const
Definition: Lie.h:48
gtsam::PlanarProjectionFactor2
Two unknowns: the pose and the landmark. Camera offset and calibration are constant....
Definition: PlanarProjectionFactor.h:171
gtsam::PlanarProjectionFactor3::PlanarProjectionFactor3
PlanarProjectionFactor3()
Definition: PlanarProjectionFactor.h:242
gtsam::PlanarProjectionFactor1::calib_
Cal3DS2 calib_
Definition: PlanarProjectionFactor.h:158
measured
Point2 measured(-17, 30)
gtsam::PlanarProjectionFactorBase::predict
Point2 predict(const Point3 &landmark, const Pose2 &wTb, const Pose3 &bTc, const Cal3DS2 &calib, OptionalJacobian< 2, 3 > Hlandmark={}, OptionalJacobian< 2, 3 > HwTb={}, OptionalJacobian< 2, 6 > HbTc={}, OptionalJacobian< 2, 9 > Hcalib={}) const
Definition: PlanarProjectionFactor.h:57
Point3.h
3D Point
gtsam::PlanarProjectionFactorBase
Camera projection for robot on the floor. Measurement is camera pixels.
Definition: PlanarProjectionFactor.h:36
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::PlanarProjectionFactor3::PlanarProjectionFactor3
PlanarProjectionFactor3(Key poseKey, Key offsetKey, Key calibKey, const Point3 &landmark, const Point2 &measured, const SharedNoiseModel &model={})
constructor for variable pose, offset, and calibration, known landmark.
Definition: PlanarProjectionFactor.h:261
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::PlanarProjectionFactor3::~PlanarProjectionFactor3
~PlanarProjectionFactor3() override
Definition: PlanarProjectionFactor.h:244
gtsam::PlanarProjectionFactor2::clone
NonlinearFactor::shared_ptr clone() const override
Definition: PlanarProjectionFactor.h:182
poseKey
const gtsam::Key poseKey
Definition: testPoseRotationPrior.cpp:29
Rot3.h
3D rotation represented as a rotation matrix or quaternion
gtsam::PlanarProjectionFactor3::clone
NonlinearFactor::shared_ptr clone() const override
Definition: PlanarProjectionFactor.h:247
gtsam::PlanarProjectionFactor1::landmark_
Point3 landmark_
Definition: PlanarProjectionFactor.h:156
gtsam::PlanarProjectionFactor1
One variable: the pose. Landmark, camera offset, camera calibration are constant. This is intended fo...
Definition: PlanarProjectionFactor.h:109
numericalDerivative.h
Some functions to compute numerical derivatives.
gtsam::PlanarProjectionFactorBase::PlanarProjectionFactorBase
PlanarProjectionFactorBase(const Point2 &measured)
Definition: PlanarProjectionFactor.h:43
gtsam::Pose3
Definition: Pose3.h:37
gtsam::PlanarProjectionFactor1::PlanarProjectionFactor1
PlanarProjectionFactor1(Key poseKey, const Point3 &landmark, const Point2 &measured, const Pose3 &bTc, const Cal3DS2 &calib, const SharedNoiseModel &model={})
constructor for known landmark, offset, and calibration
Definition: PlanarProjectionFactor.h:134
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:432
gtsam::PlanarProjectionFactor2::PlanarProjectionFactor2
PlanarProjectionFactor2()
Definition: PlanarProjectionFactor.h:177
landmark
static Point3 landmark(0, 0, 5)
PinholeCamera.h
Base class for all pinhole cameras.
gtsam::PlanarProjectionFactor2::Base
NoiseModelFactorN< Pose2, Point3 > Base
Definition: PlanarProjectionFactor.h:174
gtsam::PlanarProjectionFactor2::PlanarProjectionFactor2
PlanarProjectionFactor2(Key poseKey, Key landmarkKey, const Point2 &measured, const Pose3 &bTc, const Cal3DS2 &calib, const SharedNoiseModel &model={})
constructor for variable landmark, known offset and calibration
Definition: PlanarProjectionFactor.h:196
gtsam::Point2
Vector2 Point2
Definition: Point2.h:32
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
NonlinearFactor.h
Non-linear factor base classes.
gtsam::Cal3::fx
double fx() const
focal length x
Definition: Cal3.h:139
gtsam::PlanarProjectionFactorBase::PlanarProjectionFactorBase
PlanarProjectionFactorBase()
Definition: PlanarProjectionFactor.h:38
gtsam::PlanarProjectionFactor3
Three unknowns: the pose, the camera offset, and the camera calibration. Landmark is constant....
Definition: PlanarProjectionFactor.h:237
Lie.h
Base class and basic functions for Lie types.
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::PlanarProjectionFactor1::evaluateError
Vector evaluateError(const Pose2 &wTb, OptionalMatrixType HwTb) const override
Definition: PlanarProjectionFactor.h:151
gtsam::traits
Definition: Group.h:36
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
gtsam::PlanarProjectionFactor2::evaluateError
Vector evaluateError(const Pose2 &wTb, const Point3 &landmark, OptionalMatrixType HwTb, OptionalMatrixType Hlandmark) const override
Definition: PlanarProjectionFactor.h:214
Cal3DS2.h
Calibration of a camera with radial distortion, calculations in base class Cal3DS2_Base.
gtsam::PlanarProjectionFactorBase::measured_
Point2 measured_
Definition: PlanarProjectionFactor.h:99
gtsam::NoiseModelFactorN< Pose2 >::NoiseModelFactorN
NoiseModelFactorN()
Default Constructor for I/O.
Definition: NonlinearFactor.h:534
gtsam::Point3
Vector3 Point3
Definition: Point3.h:38
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:56
camera
static const CalibratedCamera camera(kDefaultPose)
gtsam::PlanarProjectionFactor1::clone
NonlinearFactor::shared_ptr clone() const override
Definition: PlanarProjectionFactor.h:119
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
Pose3
Definition: testDependencies.h:3
gtsam::PlanarProjectionFactor2::~PlanarProjectionFactor2
~PlanarProjectionFactor2() override
Definition: PlanarProjectionFactor.h:179
gtsam::PlanarProjectionFactor3::evaluateError
Vector evaluateError(const Pose2 &wTb, const Pose3 &bTc, const Cal3DS2 &calib, OptionalMatrixType HwTb, OptionalMatrixType HbTc, OptionalMatrixType Hcalib) const override
Definition: PlanarProjectionFactor.h:280
gtsam::PlanarProjectionFactor1::Base
NoiseModelFactorN< Pose2 > Base
Definition: PlanarProjectionFactor.h:112
Pose3.h
3D Pose manifold SO(3) x R^3 and group SE(3)
gtsam::PlanarProjectionFactor2::calib_
Cal3DS2 calib_
Definition: PlanarProjectionFactor.h:224
gtsam::PlanarProjectionFactor3::landmark_
Point3 landmark_
Definition: PlanarProjectionFactor.h:291
gtsam::Pose2
Definition: Pose2.h:39
gtsam::PlanarProjectionFactor1::~PlanarProjectionFactor1
~PlanarProjectionFactor1() override
Definition: PlanarProjectionFactor.h:116
gtsam::PlanarProjectionFactor1::bTc_
Pose3 bTc_
Definition: PlanarProjectionFactor.h:157
gtsam::PlanarProjectionFactor3::Base
NoiseModelFactorN< Pose2, Pose3, Cal3DS2 > Base
Definition: PlanarProjectionFactor.h:239


gtsam
Author(s):
autogenerated on Wed Jan 1 2025 04:02:43