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:
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 
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 
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>
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
gtsam::BearingRange::dimension
@ dimension
Definition: BearingRange.h:60
gtsam::BearingRange::print
void print(const std::string &str="") const
Definition: BearingRange.h:110
gtsam::BearingRange::MeasureRange
static R MeasureRange(const A1 &a1, const A2 &a2)
Predict range.
Definition: BearingRange.h:102
gtsam::BearingRange::BearingRange
BearingRange()
Definition: BearingRange.h:65
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
screwPose2::xi
Vector xi
Definition: testPose2.cpp:148
Testable.h
Concept check for values that can be used in unit tests.
gtsam::BearingRange::Measure
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
gtsam::BearingRange::BearingRange
BearingRange(const B &b, const R &r)
Definition: BearingRange.h:66
gtsam::HasBearing::result_type
RT result_type
Definition: BearingRange.h:184
B
Definition: test_numpy_dtypes.cpp:299
m1
Matrix3d m1
Definition: IOFormat.cpp:2
gtsam::BearingRange::MeasureBearing
static B MeasureBearing(const A1 &a1, const A2 &a2)
Predict bearing.
Definition: BearingRange.h:97
gtsam::BearingRange::dimB
@ dimB
Definition: BearingRange.h:58
gtsam::internal::ManifoldTraits
Definition: Manifold.h:92
align_3::a1
Point2 a1
Definition: testPose2.cpp:769
m2
MatrixType m2(n_dims)
gtsam::HasBearing
Definition: BearingRange.h:183
gtsam::BearingRange::range
const R & range() const
Return range measurement.
Definition: BearingRange.h:76
A2
static const double A2[]
Definition: expn.h:7
gtsam::BearingRange::equals
bool equals(const BearingRange< A1, A2 > &m2, double tol=1e-8) const
Definition: BearingRange.h:115
Manifold.h
Base class and basic functions for Manifold types.
OptionalJacobian.h
Special class for optional Jacobian arguments.
gtsam::BearingRange::Dim
static size_t Dim()
Definition: BearingRange.h:124
gtsam::Range
Definition: BearingRange.h:41
gtsam::BearingRange::TangentVector
Eigen::Matrix< double, dimension, 1 > TangentVector
Definition: BearingRange.h:127
gtsam::MakeJacobian::type
Eigen::Matrix< double, traits< T >::dimension, traits< A >::dimension > type
Definition: OptionalJacobian.h:248
Range
pair< size_t, size_t > Range
Definition: testBTree.cpp:27
str
Definition: pytypes.h:1558
gtsam::BearingRange::localCoordinates
TangentVector localCoordinates(const BearingRange &other) const
Compute the coordinates in the tangent space.
Definition: BearingRange.h:138
gtsam::BearingRange::dim
size_t dim() const
Definition: BearingRange.h:125
gtsam::b
const G & b
Definition: Group.h:79
gtsam::BearingRange::bearing_
B bearing_
Definition: BearingRange.h:54
gtsam::BearingRange::NeedsToAlign
@ NeedsToAlign
Definition: BearingRange.h:166
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::OptionalJacobian
Definition: OptionalJacobian.h:38
gtsam::HasRange::result_type
RT result_type
Definition: BearingRange.h:198
align_3::a2
Point2 a2
Definition: testPose2.cpp:770
gtsam::HasBearing::operator()
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
gtsam::HasRange
Definition: BearingRange.h:197
gtsam::BearingRange
Definition: BearingRange.h:52
v2
Vector v2
Definition: testSerializationBase.cpp:39
A1
static const double A1[]
Definition: expn.h:6
gtsam::BearingRange::bearing
const B & bearing() const
Return bearing measurement.
Definition: BearingRange.h:73
gtsam::Print
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:65
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::BearingRange::range_
R range_
Definition: BearingRange.h:55
gtsam::BearingRange::ChartJacobian
OptionalJacobian< dimension, dimension > ChartJacobian
Definition: BearingRange.h:128
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
Definition: types.h:288
gtsam::BearingRange::retract
BearingRange retract(const TangentVector &xi) const
Retract delta to manifold.
Definition: BearingRange.h:131
gtsam::Bearing
Definition: BearingRange.h:35
gtsam::BearingRange::dimR
@ dimR
Definition: BearingRange.h:59
gtsam.examples.ShonanAveragingCLI.str
str
Definition: ShonanAveragingCLI.py:115
gtsam::HasRange::operator()
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
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
R
Rot2 R(Rot2::fromAngle(0.1))
v1
Vector v1
Definition: testSerializationBase.cpp:38


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:54