gtsam  4.0.0
gtsam
BearingFactor.h
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 
21 #include <gtsam/nonlinear/ExpressionFactor.h>
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 ExpressionFactor2<T, A1, A2> {
39 
42 
44  BearingFactor(Key key1, Key key2, const T& measured,
45  const SharedNoiseModel& model)
46  : Base(key1, key2, model, measured) {
47  this->initialize(expression(key1, key2));
48  }
49 
50  // Return measurement expression
51  virtual Expression<T> expression(Key key1, Key key2) const {
52  Expression<A1> a1_(key1);
53  Expression<A2> a2_(key2);
54  return Expression<T>(Bearing<A1, A2>(), a1_, a2_);
55  }
56 
58  void print(const std::string& s = "",
59  const KeyFormatter& kf = DefaultKeyFormatter) const {
60  std::cout << s << "BearingFactor" << std::endl;
61  Base::print(s, kf);
62  }
63 
64  private:
65  friend class boost::serialization::access;
66  template <class ARCHIVE>
67  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
68  ar& boost::serialization::make_nvp(
69  "Base", boost::serialization::base_object<Base>(*this));
70  }
71 }; // BearingFactor
72 
74 template <typename A1, typename A2, typename T>
75 struct traits<BearingFactor<A1, A2, T> >
76  : public Testable<BearingFactor<A1, A2, T> > {};
77 
78 } // namespace gtsam
This is the base class for all factor types.
Definition: Factor.h:54
BearingFactor(Key key1, Key key2, const T &measured, const SharedNoiseModel &model)
primary constructor
Definition: BearingFactor.h:44
const T & measured() const
return the measurement
Definition: ExpressionFactor.h:67
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Binary specialization of ExpressionFactor meant as a base class for binary factors.
Definition: ExpressionFactor.h:226
Definition: BearingRange.h:33
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
void initialize(const Expression< T > &expression)
Initialize with constructor arguments.
Definition: ExpressionFactor.h:157
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Expression class that supports automatic differentiation.
Definition: Expression.h:49
BearingFactor()
default constructor
Definition: BearingFactor.h:41
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print relies on Testable traits being defined for T
Definition: ExpressionFactor.h:70
void print(const std::string &s="", const KeyFormatter &kf=DefaultKeyFormatter) const
print
Definition: BearingFactor.h:58
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
virtual Expression< T > expression(Key key1, Key key2) const
Recreate expression from given keys_ and measured_, used in load Needed to deserialize a derived fact...
Definition: BearingFactor.h:51
Definition: BearingFactor.h:37