sam/BearingRangeFactor.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 
20 #pragma once
21 
24 
25 namespace gtsam {
26 
31 template <typename A1, typename A2,
32  typename B = typename Bearing<A1, A2>::result_type,
33  typename R = typename Range<A1, A2>::result_type>
35  : public ExpressionFactorN<BearingRange<A1, A2>, A1, A2> {
36  private:
40 
41  public:
42  typedef std::shared_ptr<This> shared_ptr;
43 
46 
48  BearingRangeFactor(Key key1, Key key2, const T &bearingRange,
49  const SharedNoiseModel &model)
50  : Base({{key1, key2}}, model, T(bearingRange)) {
51  this->initialize(expression({{key1, key2}}));
52  }
53 
55  BearingRangeFactor(Key key1, Key key2, const B &measuredBearing,
56  const R &measuredRange, const SharedNoiseModel &model)
57  : Base({{key1, key2}}, model, T(measuredBearing, measuredRange)) {
58  this->initialize(expression({{key1, key2}}));
59  }
60 
61  ~BearingRangeFactor() override {}
62 
65  return std::static_pointer_cast<gtsam::NonlinearFactor>(
67  }
68 
69  // Return measurement expression
70  Expression<T> expression(const typename Base::ArrayNKeys& keys) const override {
72  Expression<A2>(keys[1]));
73  }
74 
75  Vector evaluateError(const A1& a1, const A2& a2,
77  std::vector<Matrix> Hs(2);
78  const auto &keys = Factor::keys();
79  const Vector error = this->unwhitenedError(
80  {{keys[0], genericValue(a1)}, {keys[1], genericValue(a2)}}, Hs);
81  if (H1) *H1 = Hs[0];
82  if (H2) *H2 = Hs[1];
83  return error;
84  }
85 
87  void print(const std::string& s = "",
88  const KeyFormatter& kf = DefaultKeyFormatter) const override {
89  std::cout << s << "BearingRangeFactor" << std::endl;
90  Base::print(s, kf);
91  }
92 
93 
94  private:
95 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
96  friend class boost::serialization::access;
97  template <class ARCHIVE>
98  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
99  ar& boost::serialization::make_nvp(
100  "Base", boost::serialization::base_object<Base>(*this));
101  }
102 #endif
103 }; // BearingRangeFactor
104 
106 template <typename A1, typename A2, typename B, typename R>
108  : public Testable<BearingRangeFactor<A1, A2, B, R> > {};
109 
110 } // namespace gtsam
key1
const Symbol key1('v', 1)
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:78
gtsam::BearingRangeFactor::~BearingRangeFactor
~BearingRangeFactor() override
Definition: sam/BearingRangeFactor.h:61
s
RealScalar s
Definition: level1_cplx_impl.h:126
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::BearingRange::Measure
static BearingRange Measure(const A1 &a1, const A2 &a2, OptionalJacobian< dimension, traits< A1 >::dimension > H1={}, OptionalJacobian< dimension, traits< A2 >::dimension > H2={})
Prediction function that stacks measurements.
Definition: BearingRange.h:79
B
Definition: test_numpy_dtypes.cpp:299
gtsam::genericValue
GenericValue< T > genericValue(const T &v)
Definition: GenericValue.h:211
gtsam::ExpressionFactor< BearingRange< A1, A2 > >::unwhitenedError
virtual Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const =0
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::BearingRangeFactor::This
BearingRangeFactor< A1, A2 > This
Definition: sam/BearingRangeFactor.h:39
gtsam::BearingRangeFactor::print
void print(const std::string &s="", const KeyFormatter &kf=DefaultKeyFormatter) const override
print
Definition: sam/BearingRangeFactor.h:87
gtsam::BearingRangeFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: sam/BearingRangeFactor.h:42
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::Expression
Definition: Expression.h:47
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
gtsam::BearingRangeFactor::evaluateError
Vector evaluateError(const A1 &a1, const A2 &a2, OptionalMatrixType H1=OptionalNone, OptionalMatrixType H2=OptionalNone) const
Definition: sam/BearingRangeFactor.h:75
key2
const Symbol key2('v', 2)
OptionalNone
#define OptionalNone
Definition: NonlinearFactor.h:49
gtsam::BearingRangeFactor::BearingRangeFactor
BearingRangeFactor(Key key1, Key key2, const B &measuredBearing, const R &measuredRange, const SharedNoiseModel &model)
Construct from separate bearing and range.
Definition: sam/BearingRangeFactor.h:55
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::BearingRangeFactor
Definition: sam/BearingRangeFactor.h:34
gtsam::ExpressionFactor< BearingRange< A1, A2 > >::initialize
void initialize(const Expression< BearingRange< A1, A2 > > &expression)
Initialize with constructor arguments.
Definition: ExpressionFactor.h:172
gtsam::BearingRangeFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: sam/BearingRangeFactor.h:64
A2
static const double A2[]
Definition: expn.h:7
gtsam::ExpressionFactorN< BearingRange< A1, A2 >, A1, A2 >::expression
Expression< BearingRange< A1, A2 > > 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
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
Range
pair< size_t, size_t > Range
Definition: testBTree.cpp:27
gtsam::BearingRangeFactor::BearingRangeFactor
BearingRangeFactor(Key key1, Key key2, const T &bearingRange, const SharedNoiseModel &model)
Construct from BearingRange instance.
Definition: sam/BearingRangeFactor.h:48
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
gtsam::BearingRange
Definition: BearingRange.h:52
A1
static const double A1[]
Definition: expn.h:6
gtsam::ExpressionFactorN
Definition: ExpressionFactor.h:249
ExpressionFactor.h
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
gtsam::BearingRangeFactor::Base
ExpressionFactorN< T, A1, A2 > Base
Definition: sam/BearingRangeFactor.h:38
BearingRange.h
Bearing-Range product.
gtsam::BearingRangeFactor::BearingRangeFactor
BearingRangeFactor()
Default constructor.
Definition: sam/BearingRangeFactor.h:45
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::BearingRangeFactor::expression
Expression< T > expression(const typename Base::ArrayNKeys &keys) const override
Definition: sam/BearingRangeFactor.h:70
R
Rot2 R(Rot2::fromAngle(0.1))
gtsam::BearingRangeFactor::T
BearingRange< A1, A2 > T
Definition: sam/BearingRangeFactor.h:37


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