gtsam
Loading...
Searching...
No Matches
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
18
19#pragma once
20
21#include <gtsam/base/Manifold.h>
23#include <gtsam/base/Testable.h>
24#include <gtsam/base/types.h>
25#if GTSAM_ENABLE_BOOST_SERIALIZATION
26#include <boost/serialization/nvp.hpp>
27#endif
28#include <iostream>
29
30namespace gtsam {
31
32// Forward declaration of Bearing functor which should be of A1*A2 -> return_type
33// For example Bearing<Pose3,Point3>(pose,point), defined in Pose3.h will return Unit3
34// At time of writing only Pose2 and Pose3 specialize this functor.
35template <typename A1, typename A2>
36struct Bearing;
37
38// Forward declaration of Range functor which should be of A1*A2 -> return_type
39// For example Range<Pose2,Pose2>(T1,T2), defined in Pose2.h will return double
40// At time of writing Pose2, Pose3, and several Camera variants specialize this for several types
41template <typename A1, typename A2>
42struct Range;
43
50template <typename A1, typename A2,
51 typename B = typename Bearing<A1, A2>::result_type,
52 typename R = typename Range<A1, A2>::result_type>
53struct BearingRange {
54private:
55 B bearing_;
56 R range_;
57
58public:
59 constexpr static const size_t dimB = traits<B>::dimension;
60 constexpr static const size_t dimR = traits<R>::dimension;
61 constexpr static const size_t dimension = dimB + dimR;
62 using OptionalJacobian1 =
64 using OptionalJacobian2 =
66
69
70 BearingRange() {}
71 BearingRange(const B& b, const R& r) : bearing_(b), range_(r) {}
72
76
78 const B& bearing() const { return bearing_; }
79
81 const R& range() const { return range_; }
82
84 static BearingRange Measure(const A1& a1, const A2& a2,
85 OptionalJacobian1 H1 = {},
86 OptionalJacobian2 H2 = {}) {
87 typename MakeJacobian<B, A1>::type HB1;
88 typename MakeJacobian<B, A2>::type HB2;
89 typename MakeJacobian<R, A1>::type HR1;
90 typename MakeJacobian<R, A2>::type HR2;
91
92 B b = Bearing<A1, A2>()(a1, a2, H1 ? &HB1 : 0, H2 ? &HB2 : 0);
93 R r = Range<A1, A2>()(a1, a2, H1 ? &HR1 : 0, H2 ? &HR2 : 0);
94
95 if (H1) *H1 << HB1, HR1;
96 if (H2) *H2 << HB2, HR2;
97 return BearingRange(b, r);
98 }
99
101 static B MeasureBearing(const A1& a1, const A2& a2) {
102 return Bearing<A1, A2>()(a1, a2);
103 }
104
106 static R MeasureRange(const A1& a1, const A2& a2) {
107 return Range<A1, A2>()(a1, a2);
108 }
109
113
114 void print(const std::string& str = "") const {
115 std::cout << str;
116 traits<B>::Print(bearing_, "bearing ");
117 traits<R>::Print(range_, "range ");
118 }
119 bool equals(const BearingRange<A1, A2>& m2, double tol = 1e-8) const {
120 return traits<B>::Equals(bearing_, m2.bearing_, tol) &&
121 traits<R>::Equals(range_, m2.range_, tol);
122 }
123
127
128 inline static size_t Dim() { return dimension; }
129 inline size_t dim() const { return dimension; }
130
131 typedef Eigen::Matrix<double, dimension, 1> TangentVector;
132 typedef OptionalJacobian<dimension, dimension> ChartJacobian;
133
135 BearingRange retract(const TangentVector& xi) const {
136 B m1 = traits<B>::Retract(bearing_, xi.template head<dimB>());
137 R m2 = traits<R>::Retract(range_, xi.template tail<dimR>());
138 return BearingRange(m1, m2);
139 }
140
142 TangentVector localCoordinates(const BearingRange& other) const {
143 typename traits<B>::TangentVector v1 = traits<B>::Local(bearing_, other.bearing_);
144 typename traits<R>::TangentVector v2 = traits<R>::Local(range_, other.range_);
145 // Set the first dimB elements to v1, and the next dimR elements to v2
146 TangentVector v;
147 v.template head<dimB>() = v1;
148 v.template tail<dimR>() = v2;
149 return v;
150 }
151
155
156private:
157#if GTSAM_ENABLE_BOOST_SERIALIZATION
159 template <class ARCHIVE>
160 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
161 ar& boost::serialization::make_nvp("bearing", bearing_);
162 ar& boost::serialization::make_nvp("range", range_);
163 }
164
165 friend class boost::serialization::access;
166#endif
167
169};
170
171// Declare this to be both Testable and a Manifold
172template <typename A1, typename A2>
173struct traits<BearingRange<A1, A2> >
174 : Testable<BearingRange<A1, A2> >,
175 internal::ManifoldTraits<BearingRange<A1, A2> > {};
176
177// Helper class for to implement Range traits for classes with a bearing method
178// For example, to specialize Bearing to Pose3 and Point3, using Pose3::bearing, it suffices to say
179// template <> struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
180// where the third argument is used to indicate the return type
181template <class A1, typename A2, class RT>
183 typedef RT result_type;
184 RT operator()(
185 const A1& a1, const A2& a2,
188 return a1.bearing(a2, H1, H2);
189 }
190};
191
192// Similar helper class for to implement Range traits for classes with a range method
193// For classes with overloaded range methods, such as PinholeCamera, this can even be templated:
194// template <typename T> struct Range<PinholeCamera, T> : HasRange<PinholeCamera, T, double> {};
195template <class A1, typename A2, class RT>
196struct HasRange {
197 typedef RT result_type;
198 RT operator()(
199 const A1& a1, const A2& a2,
202 return a1.range(a2, H1, H2);
203 }
204};
205
206} // namespace gtsam
Typedefs for easier changing of types.
Special class for optional Jacobian arguments.
Concept check for values that can be used in unit tests.
Base class and basic functions for Manifold types.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM manifolds.
Definition Manifold.h:104
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:40
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
Definition BearingRange.h:36
Definition BearingRange.h:42
Bearing-Range product for a particular A1,A2 combination will use the functors above to create a simi...
Definition BearingRange.h:53
static R MeasureRange(const A1 &a1, const A2 &a2)
Predict range.
Definition BearingRange.h:106
BearingRange retract(const TangentVector &xi) const
Retract delta to manifold.
Definition BearingRange.h:135
const B & bearing() const
Return bearing measurement.
Definition BearingRange.h:78
static BearingRange Measure(const A1 &a1, const A2 &a2, OptionalJacobian1 H1={}, OptionalJacobian2 H2={})
Prediction function that stacks measurements.
Definition BearingRange.h:84
TangentVector localCoordinates(const BearingRange &other) const
Compute the coordinates in the tangent space.
Definition BearingRange.h:142
const R & range() const
Return range measurement.
Definition BearingRange.h:81
static B MeasureBearing(const A1 &a1, const A2 &a2)
Predict bearing.
Definition BearingRange.h:101
Definition BearingRange.h:182
Definition BearingRange.h:196