gtsam 4.2.0
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
19#pragma once
20
21#include <gtsam/base/Manifold.h>
22#include <gtsam/base/Testable.h>
24#include <boost/concept/assert.hpp>
25#include <boost/serialization/nvp.hpp>
26#include <iostream>
27
28namespace gtsam {
29
30// Forward declaration of Bearing functor which should be of A1*A2 -> return_type
31// For example Bearing<Pose3,Point3>(pose,point), defined in Pose3.h will return Unit3
32// At time of writing only Pose2 and Pose3 specialize this functor.
33template <typename A1, typename A2>
34struct Bearing;
35
36// Forward declaration of Range functor which should be of A1*A2 -> return_type
37// For example Range<Pose2,Pose2>(T1,T2), defined in Pose2.h will return double
38// At time of writing Pose2, Pose3, and several Camera variants specialize this for several types
39template <typename A1, typename A2>
40struct Range;
41
48template <typename A1, typename A2,
49 typename B = typename Bearing<A1, A2>::result_type,
50 typename R = typename Range<A1, A2>::result_type>
52private:
53 B bearing_;
54 R range_;
55
56public:
57 enum { dimB = traits<B>::dimension };
58 enum { dimR = traits<R>::dimension };
59 enum { dimension = dimB + dimR };
60
63
64 BearingRange() {}
65 BearingRange(const B& b, const R& r) : bearing_(b), range_(r) {}
66
70
72 const B& bearing() const { return bearing_; }
73
75 const R& range() const { return range_; }
76
79 const A1& a1, const A2& a2,
80 OptionalJacobian<dimension, traits<A1>::dimension> H1 = boost::none,
81 OptionalJacobian<dimension, traits<A2>::dimension> H2 = boost::none) {
82 typename MakeJacobian<B, A1>::type HB1;
83 typename MakeJacobian<B, A2>::type HB2;
84 typename MakeJacobian<R, A1>::type HR1;
85 typename MakeJacobian<R, A2>::type HR2;
86
87 B b = Bearing<A1, A2>()(a1, a2, H1 ? &HB1 : 0, H2 ? &HB2 : 0);
88 R r = Range<A1, A2>()(a1, a2, H1 ? &HR1 : 0, H2 ? &HR2 : 0);
89
90 if (H1) *H1 << HB1, HR1;
91 if (H2) *H2 << HB2, HR2;
92 return BearingRange(b, r);
93 }
94
96 static B MeasureBearing(const A1& a1, const A2& a2) {
97 return Bearing<A1, A2>()(a1, a2);
98 }
99
101 static R MeasureRange(const A1& a1, const A2& a2) {
102 return Range<A1, A2>()(a1, a2);
103 }
104
108
109 void print(const std::string& str = "") const {
110 std::cout << str;
111 traits<B>::Print(bearing_, "bearing ");
112 traits<R>::Print(range_, "range ");
113 }
114 bool equals(const BearingRange<A1, A2>& m2, double tol = 1e-8) const {
115 return traits<B>::Equals(bearing_, m2.bearing_, tol) &&
116 traits<R>::Equals(range_, m2.range_, tol);
117 }
118
122
123 inline static size_t Dim() { return dimension; }
124 inline size_t dim() const { return dimension; }
125
126 typedef Eigen::Matrix<double, dimension, 1> TangentVector;
127 typedef OptionalJacobian<dimension, dimension> ChartJacobian;
128
130 BearingRange retract(const TangentVector& xi) const {
131 B m1 = traits<B>::Retract(bearing_, xi.template head<dimB>());
132 R m2 = traits<R>::Retract(range_, xi.template tail<dimR>());
133 return BearingRange(m1, m2);
134 }
135
137 TangentVector localCoordinates(const BearingRange& other) const {
138 typename traits<B>::TangentVector v1 = traits<B>::Local(bearing_, other.bearing_);
139 typename traits<R>::TangentVector v2 = traits<R>::Local(range_, other.range_);
140 TangentVector v;
141 v << v1, v2;
142 return v;
143 }
144
148
149private:
151 template <class ARCHIVE>
152 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
153 ar& boost::serialization::make_nvp("bearing", bearing_);
154 ar& boost::serialization::make_nvp("range", range_);
155 }
156
157 friend class boost::serialization::access;
158
160
161 // Alignment, see https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
162 enum {
163 NeedsToAlign = (sizeof(B) % 16) == 0 || (sizeof(R) % 16) == 0
164 };
165public:
167};
168
169// Declare this to be both Testable and a Manifold
170template <typename A1, typename A2>
171struct traits<BearingRange<A1, A2> >
172 : Testable<BearingRange<A1, A2> >,
173 internal::ManifoldTraits<BearingRange<A1, A2> > {};
174
175// Helper class for to implement Range traits for classes with a bearing method
176// For example, to specialize Bearing to Pose3 and Point3, using Pose3::bearing, it suffices to say
177// template <> struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
178// where the third argument is used to indicate the return type
179template <class A1, typename A2, class RT>
181 typedef RT result_type;
182 RT operator()(
183 const A1& a1, const A2& a2,
186 return a1.bearing(a2, H1, H2);
187 }
188};
189
190// Similar helper class for to implement Range traits for classes with a range method
191// For classes with overloaded range methods, such as PinholeCamera, this can even be templated:
192// template <typename T> struct Range<PinholeCamera, T> : HasRange<PinholeCamera, T, double> {};
193template <class A1, typename A2, class RT>
194struct HasRange {
195 typedef RT result_type;
196 RT operator()(
197 const A1& a1, const A2& a2,
200 return a1.range(a2, H1, H2);
201 }
202};
203
204} // namespace gtsam
Concept check for values that can be used in unit tests.
Base class and basic functions for Manifold types.
Special class for optional Jacobian arguments.
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
This marks a GTSAM object to require alignment.
Definition types.h:317
Global functions in a separate testing namespace.
Definition chartTesting.h:28
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
A helper that implements the traits interface for GTSAM manifolds.
Definition Manifold.h:95
OptionalJacobian is an Eigen::Ref like class that can take be constructed using either a fixed size o...
Definition OptionalJacobian.h:41
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
Definition BearingRange.h:34
Definition BearingRange.h:40
Bearing-Range product for a particular A1,A2 combination will use the functors above to create a simi...
Definition BearingRange.h:51
static R MeasureRange(const A1 &a1, const A2 &a2)
Predict range.
Definition BearingRange.h:101
static BearingRange Measure(const A1 &a1, const A2 &a2, OptionalJacobian< dimension, traits< A1 >::dimension > H1=boost::none, OptionalJacobian< dimension, traits< A2 >::dimension > H2=boost::none)
Prediction function that stacks measurements.
Definition BearingRange.h:78
BearingRange retract(const TangentVector &xi) const
Retract delta to manifold.
Definition BearingRange.h:130
const B & bearing() const
Return bearing measurement.
Definition BearingRange.h:72
TangentVector localCoordinates(const BearingRange &other) const
Compute the coordinates in the tangent space.
Definition BearingRange.h:137
const R & range() const
Return range measurement.
Definition BearingRange.h:75
static B MeasureBearing(const A1 &a1, const A2 &a2)
Predict bearing.
Definition BearingRange.h:96
Definition BearingRange.h:180
Definition BearingRange.h:194