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 = {}) :
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 }
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:78
gtsam::PoseBetweenFactor::PoseBetweenFactor
PoseBetweenFactor()
Definition: PoseBetweenFactor.h:54
GTSAM_CONCEPT_POSE_TYPE
#define GTSAM_CONCEPT_POSE_TYPE(T)
Definition: geometry/concepts.h:74
gtsam::PoseBetweenFactor::Base
NoiseModelFactorN< POSE, POSE > Base
Definition: PoseBetweenFactor.h:37
concepts.h
Concept-checking macros for geometric objects Each macro instantiates a concept check structure,...
s
RealScalar s
Definition: level1_cplx_impl.h:126
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::NoiseModelFactorN< POSE, POSE >::evaluateError
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
gtsam::Matrix
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
gtsam::PoseBetweenFactor::~PoseBetweenFactor
~PoseBetweenFactor() override
Definition: PoseBetweenFactor.h:62
gtsam::Factor
Definition: Factor.h:70
gtsam::NoiseModelFactor::noiseModel_
SharedNoiseModel noiseModel_
Definition: NonlinearFactor.h:205
body_P_sensor
static Pose3 body_P_sensor(Rot3::RzRyRx(-M_PI_2, 0.0, -M_PI_2), Point3(0.25, -0.10, 1.0))
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
simple::p2
static Point3 p2
Definition: testInitializePose3.cpp:51
gtsam::PoseBetweenFactor::measured
const POSE & measured() const
Definition: PoseBetweenFactor.h:116
gtsam::PoseBetweenFactor::equals
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Definition: PoseBetweenFactor.h:83
gtsam::PoseBetweenFactor
Definition: PoseBetweenFactor.h:32
gtsam::KeyFormatter
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
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:431
gtsam::PoseBetweenFactor::This
PoseBetweenFactor< POSE > This
Definition: PoseBetweenFactor.h:36
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::NoiseModelFactor::equals
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Definition: NonlinearFactor.cpp:80
gtsam::PoseBetweenFactor::body_P_sensor_
std::optional< POSE > body_P_sensor_
The pose of the sensor in the body frame.
Definition: PoseBetweenFactor.h:40
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::NoiseModelFactorN< POSE, POSE >::key1
Key key1() const
Definition: NonlinearFactor.h:731
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
p1
Vector3f p1
Definition: MatrixBase_all.cpp:2
NonlinearFactor.h
Non-linear factor base classes.
gtsam::NoiseModelFactorN< POSE, POSE >::key2
Key key2() const
Definition: NonlinearFactor.h:735
gtsam
traits
Definition: SFMdata.h:40
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:68
GTSAM_CONCEPT_TESTABLE_TYPE
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
Definition: Testable.h:177
gtsam::PoseBetweenFactor::measured_
POSE measured_
Definition: PoseBetweenFactor.h:39
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
gtsam::PoseBetweenFactor::print
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: PoseBetweenFactor.h:72
gtsam::PoseBetweenFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: PoseBetweenFactor.h:65
Base
Definition: test_virtual_functions.cpp:156
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::PoseBetweenFactor::PoseBetweenFactor
PoseBetweenFactor(Key key1, Key key2, const POSE &measured, const SharedNoiseModel &model, std::optional< POSE > body_P_sensor={})
Definition: PoseBetweenFactor.h:57
gtsam::PoseBetweenFactor::evaluateError
Vector evaluateError(const POSE &p1, const POSE &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
Definition: PoseBetweenFactor.h:94
gtsam::PoseBetweenFactor::shared_ptr
std::shared_ptr< PoseBetweenFactor > shared_ptr
Definition: PoseBetweenFactor.h:51


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:36