gtsam  4.0.0
gtsam
BearingRange.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 
21 #include <gtsam/base/Manifold.h>
22 #include <gtsam/base/Testable.h>
24 #include <boost/concept/assert.hpp>
25 
26 namespace gtsam {
27 
28 // Forward declaration of Bearing functor which should be of A1*A2 -> return_type
29 // For example Bearing<Pose3,Point3>(pose,point), defined in Pose3.h will return Unit3
30 // At time of writing only Pose2 and Pose3 specialize this functor.
31 template <typename A1, typename A2>
32 struct Bearing;
33 
34 // Forward declaration of Range functor which should be of A1*A2 -> return_type
35 // For example Range<Pose2,Pose2>(T1,T2), defined in Pose2.h will return double
36 // At time of writing Pose2, Pose3, and several Camera variants specialize this for several types
37 template <typename A1, typename A2>
38 struct Range;
39 
46 template <typename A1, typename A2>
48  : public ProductManifold<typename Bearing<A1, A2>::result_type,
49  typename Range<A1, A2>::result_type> {
50  typedef typename Bearing<A1, A2>::result_type B;
51  typedef typename Range<A1, A2>::result_type R;
53 
54  BearingRange() {}
55  BearingRange(const ProductManifold<B, R>& br) : Base(br) {}
56  BearingRange(const B& b, const R& r) : Base(b, r) {}
57 
60  const A1& a1, const A2& a2,
61  OptionalJacobian<Base::dimension, traits<A1>::dimension> H1 = boost::none,
62  OptionalJacobian<Base::dimension, traits<A2>::dimension> H2 =
63  boost::none) {
64  typename MakeJacobian<B, A1>::type HB1;
65  typename MakeJacobian<B, A2>::type HB2;
66  typename MakeJacobian<R, A1>::type HR1;
67  typename MakeJacobian<R, A2>::type HR2;
68 
69  B b = Bearing<A1, A2>()(a1, a2, H1 ? &HB1 : 0, H2 ? &HB2 : 0);
70  R r = Range<A1, A2>()(a1, a2, H1 ? &HR1 : 0, H2 ? &HR2 : 0);
71 
72  if (H1) *H1 << HB1, HR1;
73  if (H2) *H2 << HB2, HR2;
74  return BearingRange(b, r);
75  }
76 
77  void print(const std::string& str = "") const {
78  std::cout << str;
79  traits<B>::Print(this->first, "bearing ");
80  traits<R>::Print(this->second, "range ");
81  }
82  bool equals(const BearingRange<A1, A2>& m2, double tol = 1e-8) const {
83  return traits<B>::Equals(this->first, m2.first, tol) &&
84  traits<R>::Equals(this->second, m2.second, tol);
85  }
86 
87  private:
89  template <class ARCHIVE>
90  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
91  ar& boost::serialization::make_nvp("bearing", this->first);
92  ar& boost::serialization::make_nvp("range", this->second);
93  }
94 
95  friend class boost::serialization::access;
96 };
97 
98 // Declare this to be both Testable and a Manifold
99 template <typename A1, typename A2>
100 struct traits<BearingRange<A1, A2> >
101  : Testable<BearingRange<A1, A2> >,
102  internal::ManifoldTraits<BearingRange<A1, A2> > {};
103 
104 // Helper class for to implement Range traits for classes with a bearing method
105 // For example, to specialize Bearing to Pose3 and Point3, using Pose3::bearing, it suffices to say
106 // template <> struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
107 // where the third argument is used to indicate the return type
108 template <class A1, typename A2, class RT>
109 struct HasBearing {
110  typedef RT result_type;
111  RT operator()(
112  const A1& a1, const A2& a2,
115  return a1.bearing(a2, H1, H2);
116  }
117 };
118 
119 // Similar helper class for to implement Range traits for classes with a range method
120 // For classes with overloaded range methods, such as SimpleCamera, this can even be templated:
121 // template <typename T> struct Range<SimpleCamera, T> : HasRange<SimpleCamera, T, double> {};
122 template <class A1, typename A2, class RT>
123 struct HasRange {
124  typedef RT result_type;
125  RT operator()(
126  const A1& a1, const A2& a2,
129  return a1.range(a2, H1, H2);
130  }
131 };
132 
133 } // namespace gtsam
Bearing-Range product for a particular A1,A2 combination will use the functors above to create a simi...
Definition: BearingRange.h:47
Definition: BearingRange.h:38
static BearingRange Measure(const A1 &a1, const A2 &a2, OptionalJacobian< Base::dimension, traits< A1 >::dimension > H1=boost::none, OptionalJacobian< Base::dimension, traits< A2 >::dimension > H2=boost::none)
Prediction function that stacks measurements.
Definition: BearingRange.h:59
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition: OptionalJacobian.h:39
Definition: BearingRange.h:32
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Base class and basic functions for Manifold types.
Template to create a binary predicate.
Definition: Testable.h:110
A helper that implements the traits interface for GTSAM manifolds.
Definition: Manifold.h:95
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Definition: BearingRange.h:123
Definition: BearingRange.h:109
Special class for optional Jacobian arguments.
Helper class to construct the product manifold of two other manifolds, M1 and M2 Assumes nothing exce...
Definition: Manifold.h:175
Definition: HessianFactor.cpp:53
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Concept check for values that can be used in unit tests.