PoseToPointFactor.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <gtsam/geometry/Point2.h>
11 #include <gtsam/geometry/Pose2.h>
12 #include <gtsam/geometry/Point3.h>
13 #include <gtsam/geometry/Pose3.h>
15 #include <ostream>
16 
17 namespace gtsam {
18 
23 template<typename POSE = Pose3, typename POINT = Point3>
24 class PoseToPointFactor : public NoiseModelFactorN<POSE, POINT> {
25  private:
28 
29  POINT measured_;
31  public:
32 
33  // Provide access to the Matrix& version of evaluateError:
34  using Base::evaluateError;
35 
36  // shorthand for a smart pointer to a factor
37  typedef std::shared_ptr<PoseToPointFactor> shared_ptr;
38 
41 
44  const SharedNoiseModel& model)
45  : Base(model, key1, key2), measured_(measured) {}
46 
47  virtual ~PoseToPointFactor() {}
48 
52  void print(const std::string& s, const KeyFormatter& keyFormatter =
53  DefaultKeyFormatter) const override {
54  std::cout << s << "PoseToPointFactor("
55  << keyFormatter(this->key1()) << ","
56  << keyFormatter(this->key2()) << ")\n"
57  << " measured: " << measured_.transpose() << std::endl;
58  this->noiseModel_->print(" noise model: ");
59  }
60 
63  double tol = 1e-9) const override {
64  const This* e = dynamic_cast<const This*>(&expected);
65  return e != nullptr && Base::equals(*e, tol) &&
66  traits<POINT>::Equals(this->measured_, e->measured_, tol);
67  }
68 
71  return std::static_pointer_cast<gtsam::NonlinearFactor>(
73  }
74 
85  const POSE& w_T_b, const POINT& w_P,
87  OptionalMatrixType H2) const override {
88  return w_T_b.transformTo(w_P, H1, H2) - measured_;
89  }
90 
92  const POINT& measured() const { return measured_; }
93 
94  private:
95 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
96 
97  friend class boost::serialization::access;
98  template <class ARCHIVE>
99  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
100  // NoiseModelFactor2 instead of NoiseModelFactorN for backward compatibility
101  ar& boost::serialization::make_nvp(
102  "NoiseModelFactor2",
103  boost::serialization::base_object<Base>(*this));
104  ar& BOOST_SERIALIZATION_NVP(measured_);
105  }
106 #endif
107 
108 }; // \class PoseToPointFactor
109 
110 } // namespace gtsam
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Vector evaluateError(const POSE &w_T_b, const POINT &w_P, OptionalMatrixType H1, OptionalMatrixType H2) const override
Error = w_T_b.inverse()*w_P - measured_.
std::shared_ptr< PoseToPointFactor > shared_ptr
NoiseModelFactorN< POSE, POINT > Base
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
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Matrix * OptionalMatrixType
Eigen::VectorXd Vector
Definition: Vector.h:38
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
PoseToPointFactor(Key key1, Key key2, const POINT &measured, const SharedNoiseModel &model)
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_
const POINT & measured() const
Non-linear factor base classes.
std::shared_ptr< This > shared_ptr
3D Point
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
const G double tol
Definition: Group.h:86
gtsam::NonlinearFactor::shared_ptr clone() const override
2D Pose
2D Point
3D Pose
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:741


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