sam/BearingFactor.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 
19 #pragma once
20 
22 
23 namespace gtsam {
24 
25 // forward declaration of Bearing functor, assumed partially specified
26 template <typename A1, typename A2>
27 struct Bearing;
28 
35 template <typename A1, typename A2,
36  typename T = typename Bearing<A1, A2>::result_type>
37 struct BearingFactor : public ExpressionFactorN<T, A1, A2> {
39 
42 
45  const SharedNoiseModel& model)
46  : Base({key1, key2}, model, measured) {
47  this->initialize(expression({key1, key2}));
48  }
49 
50  // Return measurement expression
51  Expression<T> expression(const typename Base::ArrayNKeys &keys) const override {
52  Expression<A1> a1_(keys[0]);
53  Expression<A2> a2_(keys[1]);
54  return Expression<T>(Bearing<A1, A2>(), a1_, a2_);
55  }
56 
58  void print(const std::string& s = "",
59  const KeyFormatter& kf = DefaultKeyFormatter) const override {
60  std::cout << s << "BearingFactor" << std::endl;
61  Base::print(s, kf);
62  }
63 
64  Vector evaluateError(const A1& a1, const A2& a2,
66  std::vector<Matrix> Hs(2);
67  const auto &keys = Factor::keys();
69  {{keys[0], genericValue(a1)}, {keys[1], genericValue(a2)}},
70  Hs);
71  if (H1) *H1 = Hs[0];
72  if (H2) *H2 = Hs[1];
73  return error;
74  }
75 
76 
77  private:
78 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
79  friend class boost::serialization::access;
80  template <class ARCHIVE>
81  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
82  ar& boost::serialization::make_nvp(
83  "Base", boost::serialization::base_object<Base>(*this));
84  }
85 #endif
86 }; // BearingFactor
87 
89 template <typename A1, typename A2, typename T>
90 struct traits<BearingFactor<A1, A2, T> >
91  : public Testable<BearingFactor<A1, A2, T> > {};
92 
93 } // namespace gtsam
key1
const Symbol key1('v', 1)
s
RealScalar s
Definition: level1_cplx_impl.h:126
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::BearingFactor
Definition: sam/BearingFactor.h:37
gtsam::genericValue
GenericValue< T > genericValue(const T &v)
Definition: GenericValue.h:211
gtsam::ExpressionFactor< typename Bearing< A1, A2 >::result_type >::unwhitenedError
virtual Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const =0
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::Expression
Definition: Expression.h:47
gtsam::BearingFactor::BearingFactor
BearingFactor()
default constructor
Definition: sam/BearingFactor.h:41
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
key2
const Symbol key2('v', 2)
gtsam::BearingFactor::expression
Expression< T > expression(const typename Base::ArrayNKeys &keys) const override
Definition: sam/BearingFactor.h:51
OptionalNone
#define OptionalNone
Definition: NonlinearFactor.h:49
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::ExpressionFactor< typename Bearing< A1, A2 >::result_type >::initialize
void initialize(const Expression< typename Bearing< A1, A2 >::result_type > &expression)
Initialize with constructor arguments.
Definition: ExpressionFactor.h:172
A2
static const double A2[]
Definition: expn.h:7
gtsam::ExpressionFactorN< typename Bearing< A1, A2 >::result_type, A1, A2 >::expression
Expression< typename Bearing< A1, A2 >::result_type > expression() const override
Return an expression that predicts the measurement given Values.
Definition: ExpressionFactor.h:282
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
Eigen::Triplet
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:162
gtsam::ExpressionFactorN::ArrayNKeys
std::array< Key, NARY_EXPRESSION_SIZE > ArrayNKeys
Definition: ExpressionFactor.h:252
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
gtsam::ExpressionFactor< typename Bearing< A1, A2 >::result_type >::measured
const typename Bearing< A1, A2 >::result_type & measured() const
Definition: ExpressionFactor.h:82
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
error
static double error
Definition: testRot3.cpp:37
gtsam::traits
Definition: Group.h:36
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:143
align_3::a2
Point2 a2
Definition: testPose2.cpp:770
A1
static const double A1[]
Definition: expn.h:6
gtsam::ExpressionFactorN
Definition: ExpressionFactor.h:249
gtsam::BearingFactor::print
void print(const std::string &s="", const KeyFormatter &kf=DefaultKeyFormatter) const override
print
Definition: sam/BearingFactor.h:58
ExpressionFactor.h
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
gtsam::Bearing
Definition: BearingRange.h:35
gtsam::ExpressionFactor::print
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print relies on Testable traits being defined for T
Definition: ExpressionFactor.h:85
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::BearingFactor::evaluateError
Vector evaluateError(const A1 &a1, const A2 &a2, OptionalMatrixType H1=OptionalNone, OptionalMatrixType H2=OptionalNone) const
Definition: sam/BearingFactor.h:64
gtsam::BearingFactor::Base
ExpressionFactorN< T, A1, A2 > Base
Definition: sam/BearingFactor.h:38
gtsam::BearingFactor::BearingFactor
BearingFactor(Key key1, Key key2, const T &measured, const SharedNoiseModel &model)
primary constructor
Definition: sam/BearingFactor.h:44


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:54