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 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/nvp.hpp>
26 #endif
27 #include <iostream>
28 
29 namespace gtsam {
30 
31 // Forward declaration of Bearing functor which should be of A1*A2 -> return_type
32 // For example Bearing<Pose3,Point3>(pose,point), defined in Pose3.h will return Unit3
33 // At time of writing only Pose2 and Pose3 specialize this functor.
34 template <typename A1, typename A2>
35 struct Bearing;
36 
37 // Forward declaration of Range functor which should be of A1*A2 -> return_type
38 // For example Range<Pose2,Pose2>(T1,T2), defined in Pose2.h will return double
39 // At time of writing Pose2, Pose3, and several Camera variants specialize this for several types
40 template <typename A1, typename A2>
41 struct Range;
42 
49 template <typename A1, typename A2,
50  typename B = typename Bearing<A1, A2>::result_type,
51  typename R = typename Range<A1, A2>::result_type>
52 struct BearingRange {
53 private:
55  R range_;
56 
57 public:
60  enum { dimension = dimB + dimR };
61 
64 
66  BearingRange(const B& b, const R& r) : bearing_(b), range_(r) {}
67 
71 
73  const B& bearing() const { return bearing_; }
74 
76  const R& range() const { return range_; }
77 
80  const A1& a1, const A2& a2,
83  typename MakeJacobian<B, A1>::type HB1;
84  typename MakeJacobian<B, A2>::type HB2;
85  typename MakeJacobian<R, A1>::type HR1;
86  typename MakeJacobian<R, A2>::type HR2;
87 
88  B b = Bearing<A1, A2>()(a1, a2, H1 ? &HB1 : 0, H2 ? &HB2 : 0);
89  R r = Range<A1, A2>()(a1, a2, H1 ? &HR1 : 0, H2 ? &HR2 : 0);
90 
91  if (H1) *H1 << HB1, HR1;
92  if (H2) *H2 << HB2, HR2;
93  return BearingRange(b, r);
94  }
95 
97  static B MeasureBearing(const A1& a1, const A2& a2) {
98  return Bearing<A1, A2>()(a1, a2);
99  }
100 
102  static R MeasureRange(const A1& a1, const A2& a2) {
103  return Range<A1, A2>()(a1, a2);
104  }
105 
109 
110  void print(const std::string& str = "") const {
111  std::cout << str;
112  traits<B>::Print(bearing_, "bearing ");
113  traits<R>::Print(range_, "range ");
114  }
115  bool equals(const BearingRange<A1, A2>& m2, double tol = 1e-8) const {
116  return traits<B>::Equals(bearing_, m2.bearing_, tol) &&
117  traits<R>::Equals(range_, m2.range_, tol);
118  }
119 
123 
124  inline static size_t Dim() { return dimension; }
125  inline size_t dim() const { return dimension; }
126 
129 
131  BearingRange retract(const TangentVector& xi) const {
132  B m1 = traits<B>::Retract(bearing_, xi.template head<dimB>());
133  R m2 = traits<R>::Retract(range_, xi.template tail<dimR>());
134  return BearingRange(m1, m2);
135  }
136 
138  TangentVector localCoordinates(const BearingRange& other) const {
139  typename traits<B>::TangentVector v1 = traits<B>::Local(bearing_, other.bearing_);
140  typename traits<R>::TangentVector v2 = traits<R>::Local(range_, other.range_);
141  TangentVector v;
142  v << v1, v2;
143  return v;
144  }
145 
149 
150 private:
151 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
152  template <class ARCHIVE>
154  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
155  ar& boost::serialization::make_nvp("bearing", bearing_);
156  ar& boost::serialization::make_nvp("range", range_);
157  }
158 
159  friend class boost::serialization::access;
160 #endif
161 
163 
164  // Alignment, see https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
165  enum {
166  NeedsToAlign = (sizeof(B) % 16) == 0 || (sizeof(R) % 16) == 0
167  };
168 public:
170 };
171 
172 // Declare this to be both Testable and a Manifold
173 template <typename A1, typename A2>
174 struct traits<BearingRange<A1, A2> >
175  : Testable<BearingRange<A1, A2> >,
176  internal::ManifoldTraits<BearingRange<A1, A2> > {};
177 
178 // Helper class for to implement Range traits for classes with a bearing method
179 // For example, to specialize Bearing to Pose3 and Point3, using Pose3::bearing, it suffices to say
180 // template <> struct Bearing<Pose3, Point3> : HasBearing<Pose3, Point3, Unit3> {};
181 // where the third argument is used to indicate the return type
182 template <class A1, typename A2, class RT>
183 struct HasBearing {
184  typedef RT result_type;
186  const A1& a1, const A2& a2,
189  return a1.bearing(a2, H1, H2);
190  }
191 };
192 
193 // Similar helper class for to implement Range traits for classes with a range method
194 // For classes with overloaded range methods, such as PinholeCamera, this can even be templated:
195 // template <typename T> struct Range<PinholeCamera, T> : HasRange<PinholeCamera, T, double> {};
196 template <class A1, typename A2, class RT>
197 struct HasRange {
198  typedef RT result_type;
200  const A1& a1, const A2& a2,
203  return a1.range(a2, H1, H2);
204  }
205 };
206 
207 } // namespace gtsam
Point2 a1
Definition: testPose2.cpp:769
static Matrix A1
Vector v2
static B MeasureBearing(const A1 &a1, const A2 &a2)
Predict bearing.
Definition: BearingRange.h:97
Concept check for values that can be used in unit tests.
RT operator()(const A1 &a1, const A2 &a2, OptionalJacobian< traits< RT >::dimension, traits< A1 >::dimension > H1={}, OptionalJacobian< traits< RT >::dimension, traits< A2 >::dimension > H2={})
Definition: BearingRange.h:185
Vector v1
std::string serialize(const T &input)
serializes to a string
MatrixType m2(n_dims)
Rot2 R(Rot2::fromAngle(0.1))
void print(const std::string &str="") const
Definition: BearingRange.h:110
OptionalJacobian< dimension, dimension > ChartJacobian
Definition: BearingRange.h:128
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
static size_t Dim()
Definition: BearingRange.h:124
Eigen::Matrix< double, dimension, 1 > TangentVector
Definition: BearingRange.h:127
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Definition: types.h:293
TangentVector localCoordinates(const BearingRange &other) const
Compute the coordinates in the tangent space.
Definition: BearingRange.h:138
size_t dim() const
Definition: BearingRange.h:125
Matrix3d m1
Definition: IOFormat.cpp:2
Definition: pytypes.h:1403
Base class and basic functions for Manifold types.
Array< int, Dynamic, 1 > v
RT operator()(const A1 &a1, const A2 &a2, OptionalJacobian< traits< RT >::dimension, traits< A1 >::dimension > H1={}, OptionalJacobian< traits< RT >::dimension, traits< A2 >::dimension > H2={})
Definition: BearingRange.h:199
Array< double, 1, 3 > e(1./3., 0.5, 2.)
BearingRange retract(const TangentVector &xi) const
Retract delta to manifold.
Definition: BearingRange.h:131
const G & b
Definition: Group.h:86
Vector xi
Definition: testPose2.cpp:148
traits
Definition: chartTesting.h:28
Point2 a2
Definition: testPose2.cpp:770
bool equals(const BearingRange< A1, A2 > &m2, double tol=1e-8) const
Definition: BearingRange.h:115
BearingRange(const B &b, const R &r)
Definition: BearingRange.h:66
const R & range() const
Return range measurement.
Definition: BearingRange.h:76
Special class for optional Jacobian arguments.
const G double tol
Definition: Group.h:86
The matrix class, also used for vectors and row-vectors.
static R MeasureRange(const A1 &a1, const A2 &a2)
Predict range.
Definition: BearingRange.h:102
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:62
const B & bearing() const
Return bearing measurement.
Definition: BearingRange.h:73


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:57