PoseBetweenFactor.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
16 #pragma once
17 
18 #include <ostream>
19 
22 #include <gtsam/base/Testable.h>
23 
24 namespace gtsam {
25 
31  template<class POSE>
32  class PoseBetweenFactor: public NoiseModelFactorN<POSE, POSE> {
33 
34  private:
35 
38 
39  POSE measured_;
40  std::optional<POSE> body_P_sensor_;
41 
45  public:
46 
47  // Provide access to the Matrix& version of evaluateError:
48  using Base::evaluateError;
49 
50  // shorthand for a smart pointer to a factor
51  typedef typename std::shared_ptr<PoseBetweenFactor> shared_ptr;
52 
55 
58  const SharedNoiseModel& model, std::optional<POSE> body_P_sensor = {}) :
59  Base(model, key1, key2), measured_(measured), body_P_sensor_(body_P_sensor) {
60  }
61 
62  ~PoseBetweenFactor() override {}
63 
66  return std::static_pointer_cast<gtsam::NonlinearFactor>(
68 
72  void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
73  std::cout << s << "BetweenFactor("
74  << keyFormatter(this->key1()) << ","
75  << keyFormatter(this->key2()) << ")\n";
76  measured_.print(" measured: ");
77  if(this->body_P_sensor_)
78  this->body_P_sensor_->print(" sensor pose in body frame: ");
79  this->noiseModel_->print(" noise model: ");
80  }
81 
83  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
84  const This *e = dynamic_cast<const This*> (&expected);
85  return e != nullptr
86  && Base::equals(*e, tol)
87  && this->measured_.equals(e->measured_, tol)
88  && ((!body_P_sensor_ && !e->body_P_sensor_) || (body_P_sensor_ && e->body_P_sensor_ && body_P_sensor_->equals(*e->body_P_sensor_)));
89  }
90 
94  Vector evaluateError(const POSE& p1, const POSE& p2,
95  OptionalMatrixType H1, OptionalMatrixType H2) const override {
96  if(body_P_sensor_) {
97  POSE hx;
98  if(H1 || H2) {
99  Matrix H3;
100  hx = p1.compose(*body_P_sensor_,H3).between(p2.compose(*body_P_sensor_), H1, H2); // h(x)
101  if(H1) (*H1) *= H3;
102  if(H2) (*H2) *= H3;
103  } else {
104  hx = p1.compose(*body_P_sensor_).between(p2.compose(*body_P_sensor_)); // h(x)
105  }
106  // manifold equivalent of h(x)-z -> log(z,h(x))
107  return measured_.localCoordinates(hx);
108  } else {
109  POSE hx = p1.between(p2, H1, H2); // h(x)
110  // manifold equivalent of h(x)-z -> log(z,h(x))
111  return measured_.localCoordinates(hx);
112  }
113  }
114 
116  const POSE& measured() const {
117  return measured_;
118  }
119 
120  private:
121 
122 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
123 
124  friend class boost::serialization::access;
125  template<class ARCHIVE>
126  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
127  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
128  ar & BOOST_SERIALIZATION_NVP(measured_);
129 
130  }
131 #endif
132  }; // \class PoseBetweenFactor
133 
134 }
std::shared_ptr< PoseBetweenFactor > shared_ptr
Concept check for values that can be used in unit tests.
PoseBetweenFactor< POSE > This
Vector3f p1
std::string serialize(const T &input)
serializes to a string
noiseModel::Diagonal::shared_ptr model
Matrix expected
Definition: testMatrix.cpp:971
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
static Pose3 body_P_sensor(Rot3::RzRyRx(-M_PI_2, 0.0, -M_PI_2), Point3(0.25, -0.10, 1.0))
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
std::optional< POSE > body_P_sensor_
The pose of the sensor in the body frame.
Vector evaluateError(const POSE &p1, const POSE &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
Definition: Testable.h:177
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const POSE & measured() const
#define GTSAM_CONCEPT_POSE_TYPE(T)
Matrix * OptionalMatrixType
Eigen::VectorXd Vector
Definition: Vector.h:38
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
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
traits
Definition: chartTesting.h:28
SharedNoiseModel noiseModel_
gtsam::NonlinearFactor::shared_ptr clone() const override
Non-linear factor base classes.
std::shared_ptr< This > shared_ptr
static Point3 p2
const G double tol
Definition: Group.h:86
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
PoseBetweenFactor(Key key1, Key key2, const POSE &measured, const SharedNoiseModel &model, std::optional< POSE > body_P_sensor={})
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741
NoiseModelFactorN< POSE, POSE > Base
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: Factor.cpp:42


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:15