so2.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /// @file
  2. /// Special orthogonal group SO(2) - rotation in 2d.
  3. #ifndef SOPHUS_SO2_HPP
  4. #define SOPHUS_SO2_HPP
  5. #include <complex>
  6. #include <type_traits>
  7. // Include only the selective set of Eigen headers that we need.
  8. // This helps when using Sophus with unusual compilers, like nvcc.
  9. #include <Eigen/LU>
  10. #include "rotation_matrix.hpp"
  11. #include "types.hpp"
  12. namespace Sophus {
  13. template <class Scalar_, int Options = 0>
  14. class SO2;
  15. using SO2d = SO2<double>;
  16. using SO2f = SO2<float>;
  17. } // namespace Sophus
  18. namespace Eigen {
  19. namespace internal {
  20. template <class Scalar_, int Options_>
  21. struct traits<Sophus::SO2<Scalar_, Options_>> {
  22. static constexpr int Options = Options_;
  23. using Scalar = Scalar_;
  24. using ComplexType = Sophus::Vector2<Scalar, Options>;
  25. };
  26. template <class Scalar_, int Options_>
  27. struct traits<Map<Sophus::SO2<Scalar_>, Options_>>
  28. : traits<Sophus::SO2<Scalar_, Options_>> {
  29. static constexpr int Options = Options_;
  30. using Scalar = Scalar_;
  31. using ComplexType = Map<Sophus::Vector2<Scalar>, Options>;
  32. };
  33. template <class Scalar_, int Options_>
  34. struct traits<Map<Sophus::SO2<Scalar_> const, Options_>>
  35. : traits<Sophus::SO2<Scalar_, Options_> const> {
  36. static constexpr int Options = Options_;
  37. using Scalar = Scalar_;
  38. using ComplexType = Map<Sophus::Vector2<Scalar> const, Options>;
  39. };
  40. } // namespace internal
  41. } // namespace Eigen
  42. namespace Sophus {
  43. /// SO2 base type - implements SO2 class but is storage agnostic.
  44. ///
  45. /// SO(2) is the group of rotations in 2d. As a matrix group, it is the set of
  46. /// matrices which are orthogonal such that ``R * R' = I`` (with ``R'`` being
  47. /// the transpose of ``R``) and have a positive determinant. In particular, the
  48. /// determinant is 1. Let ``theta`` be the rotation angle, the rotation matrix
  49. /// can be written in close form:
  50. ///
  51. /// | cos(theta) -sin(theta) |
  52. /// | sin(theta) cos(theta) |
  53. ///
  54. /// As a matter of fact, the first column of those matrices is isomorph to the
  55. /// set of unit complex numbers U(1). Thus, internally, SO2 is represented as
  56. /// complex number with length 1.
  57. ///
  58. /// SO(2) is a compact and commutative group. First it is compact since the set
  59. /// of rotation matrices is a closed and bounded set. Second it is commutative
  60. /// since ``R(alpha) * R(beta) = R(beta) * R(alpha)``, simply because ``alpha +
  61. /// beta = beta + alpha`` with ``alpha`` and ``beta`` being rotation angles
  62. /// (about the same axis).
  63. ///
  64. /// Class invariant: The 2-norm of ``unit_complex`` must be close to 1.
  65. /// Technically speaking, it must hold that:
  66. ///
  67. /// ``|unit_complex().squaredNorm() - 1| <= Constants::epsilon()``.
  68. template <class Derived>
  69. class SO2Base {
  70. public:
  71. static constexpr int Options = Eigen::internal::traits<Derived>::Options;
  72. using Scalar = typename Eigen::internal::traits<Derived>::Scalar;
  73. using ComplexT = typename Eigen::internal::traits<Derived>::ComplexType;
  74. using ComplexTemporaryType = Sophus::Vector2<Scalar, Options>;
  75. /// Degrees of freedom of manifold, number of dimensions in tangent space (one
  76. /// since we only have in-plane rotations).
  77. static int constexpr DoF = 1;
  78. /// Number of internal parameters used (complex numbers are a tuples).
  79. static int constexpr num_parameters = 2;
  80. /// Group transformations are 2x2 matrices.
  81. static int constexpr N = 2;
  82. using Transformation = Matrix<Scalar, N, N>;
  83. using Point = Vector2<Scalar>;
  84. using HomogeneousPoint = Vector3<Scalar>;
  85. using Line = ParametrizedLine2<Scalar>;
  86. using Tangent = Scalar;
  87. using Adjoint = Scalar;
  88. /// For binary operations the return type is determined with the
  89. /// ScalarBinaryOpTraits feature of Eigen. This allows mixing concrete and Map
  90. /// types, as well as other compatible scalar types such as Ceres::Jet and
  91. /// double scalars with SO2 operations.
  92. template <typename OtherDerived>
  93. using ReturnScalar = typename Eigen::ScalarBinaryOpTraits<
  94. Scalar, typename OtherDerived::Scalar>::ReturnType;
  95. template <typename OtherDerived>
  96. using SO2Product = SO2<ReturnScalar<OtherDerived>>;
  97. template <typename PointDerived>
  98. using PointProduct = Vector2<ReturnScalar<PointDerived>>;
  99. template <typename HPointDerived>
  100. using HomogeneousPointProduct = Vector3<ReturnScalar<HPointDerived>>;
  101. /// Adjoint transformation
  102. ///
  103. /// This function return the adjoint transformation ``Ad`` of the group
  104. /// element ``A`` such that for all ``x`` it holds that
  105. /// ``hat(Ad_A * x) = A * hat(x) A^{-1}``. See hat-operator below.
  106. ///
  107. /// It simply ``1``, since ``SO(2)`` is a commutative group.
  108. ///
  109. SOPHUS_FUNC Adjoint Adj() const { return Scalar(1); }
  110. /// Returns copy of instance casted to NewScalarType.
  111. ///
  112. template <class NewScalarType>
  113. SOPHUS_FUNC SO2<NewScalarType> cast() const {
  114. return SO2<NewScalarType>(unit_complex().template cast<NewScalarType>());
  115. }
  116. /// This provides unsafe read/write access to internal data. SO(2) is
  117. /// represented by a unit complex number (two parameters). When using direct
  118. /// write access, the user needs to take care of that the complex number stays
  119. /// normalized.
  120. ///
  121. SOPHUS_FUNC Scalar* data() { return unit_complex_nonconst().data(); }
  122. /// Const version of data() above.
  123. ///
  124. SOPHUS_FUNC Scalar const* data() const { return unit_complex().data(); }
  125. /// Returns group inverse.
  126. ///
  127. SOPHUS_FUNC SO2<Scalar> inverse() const {
  128. return SO2<Scalar>(unit_complex().x(), -unit_complex().y());
  129. }
  130. /// Logarithmic map
  131. ///
  132. /// Computes the logarithm, the inverse of the group exponential which maps
  133. /// element of the group (rotation matrices) to elements of the tangent space
  134. /// (rotation angles).
  135. ///
  136. /// To be specific, this function computes ``vee(logmat(.))`` with
  137. /// ``logmat(.)`` being the matrix logarithm and ``vee(.)`` the vee-operator
  138. /// of SO(2).
  139. ///
  140. SOPHUS_FUNC Scalar log() const {
  141. using std::atan2;
  142. return atan2(unit_complex().y(), unit_complex().x());
  143. }
  144. /// It re-normalizes ``unit_complex`` to unit length.
  145. ///
  146. /// Note: Because of the class invariant, there is typically no need to call
  147. /// this function directly.
  148. ///
  149. SOPHUS_FUNC void normalize() {
  150. using std::sqrt;
  151. Scalar length = sqrt(unit_complex().x() * unit_complex().x() +
  152. unit_complex().y() * unit_complex().y());
  153. SOPHUS_ENSURE(length >= Constants<Scalar>::epsilon(),
  154. "Complex number should not be close to zero!");
  155. unit_complex_nonconst().x() /= length;
  156. unit_complex_nonconst().y() /= length;
  157. }
  158. /// Returns 2x2 matrix representation of the instance.
  159. ///
  160. /// For SO(2), the matrix representation is an orthogonal matrix ``R`` with
  161. /// ``det(R)=1``, thus the so-called "rotation matrix".
  162. ///
  163. SOPHUS_FUNC Transformation matrix() const {
  164. Scalar const& real = unit_complex().x();
  165. Scalar const& imag = unit_complex().y();
  166. Transformation R;
  167. // clang-format off
  168. R <<
  169. real, -imag,
  170. imag, real;
  171. // clang-format on
  172. return R;
  173. }
  174. /// Assignment operator
  175. ///
  176. SOPHUS_FUNC SO2Base& operator=(SO2Base const& other) = default;
  177. /// Assignment-like operator from OtherDerived.
  178. ///
  179. template <class OtherDerived>
  180. SOPHUS_FUNC SO2Base<Derived>& operator=(SO2Base<OtherDerived> const& other) {
  181. unit_complex_nonconst() = other.unit_complex();
  182. return *this;
  183. }
  184. /// Group multiplication, which is rotation concatenation.
  185. ///
  186. template <typename OtherDerived>
  187. SOPHUS_FUNC SO2Product<OtherDerived> operator*(
  188. SO2Base<OtherDerived> const& other) const {
  189. using ResultT = ReturnScalar<OtherDerived>;
  190. Scalar const lhs_real = unit_complex().x();
  191. Scalar const lhs_imag = unit_complex().y();
  192. typename OtherDerived::Scalar const& rhs_real = other.unit_complex().x();
  193. typename OtherDerived::Scalar const& rhs_imag = other.unit_complex().y();
  194. // complex multiplication
  195. ResultT const result_real = lhs_real * rhs_real - lhs_imag * rhs_imag;
  196. ResultT const result_imag = lhs_real * rhs_imag + lhs_imag * rhs_real;
  197. ResultT const squared_norm =
  198. result_real * result_real + result_imag * result_imag;
  199. // We can assume that the squared-norm is close to 1 since we deal with a
  200. // unit complex number. Due to numerical precision issues, there might
  201. // be a small drift after pose concatenation. Hence, we need to renormalizes
  202. // the complex number here.
  203. // Since squared-norm is close to 1, we do not need to calculate the costly
  204. // square-root, but can use an approximation around 1 (see
  205. // http://stackoverflow.com/a/12934750 for details).
  206. if (squared_norm != ResultT(1.0)) {
  207. ResultT const scale = ResultT(2.0) / (ResultT(1.0) + squared_norm);
  208. return SO2Product<OtherDerived>(result_real * scale, result_imag * scale);
  209. }
  210. return SO2Product<OtherDerived>(result_real, result_imag);
  211. }
  212. /// Group action on 2-points.
  213. ///
  214. /// This function rotates a 2 dimensional point ``p`` by the SO2 element
  215. /// ``bar_R_foo`` (= rotation matrix): ``p_bar = bar_R_foo * p_foo``.
  216. ///
  217. template <typename PointDerived,
  218. typename = typename std::enable_if<
  219. IsFixedSizeVector<PointDerived, 2>::value>::type>
  220. SOPHUS_FUNC PointProduct<PointDerived> operator*(
  221. Eigen::MatrixBase<PointDerived> const& p) const {
  222. Scalar const& real = unit_complex().x();
  223. Scalar const& imag = unit_complex().y();
  224. return PointProduct<PointDerived>(real * p[0] - imag * p[1],
  225. imag * p[0] + real * p[1]);
  226. }
  227. /// Group action on homogeneous 2-points.
  228. ///
  229. /// This function rotates a homogeneous 2 dimensional point ``p`` by the SO2
  230. /// element ``bar_R_foo`` (= rotation matrix): ``p_bar = bar_R_foo * p_foo``.
  231. ///
  232. template <typename HPointDerived,
  233. typename = typename std::enable_if<
  234. IsFixedSizeVector<HPointDerived, 3>::value>::type>
  235. SOPHUS_FUNC HomogeneousPointProduct<HPointDerived> operator*(
  236. Eigen::MatrixBase<HPointDerived> const& p) const {
  237. Scalar const& real = unit_complex().x();
  238. Scalar const& imag = unit_complex().y();
  239. return HomogeneousPointProduct<HPointDerived>(
  240. real * p[0] - imag * p[1], imag * p[0] + real * p[1], p[2]);
  241. }
  242. /// Group action on lines.
  243. ///
  244. /// This function rotates a parametrized line ``l(t) = o + t * d`` by the SO2
  245. /// element:
  246. ///
  247. /// Both direction ``d`` and origin ``o`` are rotated as a 2 dimensional point
  248. ///
  249. SOPHUS_FUNC Line operator*(Line const& l) const {
  250. return Line((*this) * l.origin(), (*this) * l.direction());
  251. }
  252. /// In-place group multiplication. This method is only valid if the return
  253. /// type of the multiplication is compatible with this SO2's Scalar type.
  254. ///
  255. template <typename OtherDerived,
  256. typename = typename std::enable_if<
  257. std::is_same<Scalar, ReturnScalar<OtherDerived>>::value>::type>
  258. SOPHUS_FUNC SO2Base<Derived> operator*=(SO2Base<OtherDerived> const& other) {
  259. *static_cast<Derived*>(this) = *this * other;
  260. return *this;
  261. }
  262. /// Returns derivative of this * SO2::exp(x) wrt. x at x=0.
  263. ///
  264. SOPHUS_FUNC Matrix<Scalar, num_parameters, DoF> Dx_this_mul_exp_x_at_0()
  265. const {
  266. return Matrix<Scalar, num_parameters, DoF>(-unit_complex()[1],
  267. unit_complex()[0]);
  268. }
  269. /// Returns internal parameters of SO(2).
  270. ///
  271. /// It returns (c[0], c[1]), with c being the unit complex number.
  272. ///
  273. SOPHUS_FUNC Sophus::Vector<Scalar, num_parameters> params() const {
  274. return unit_complex();
  275. }
  276. /// Takes in complex number / tuple and normalizes it.
  277. ///
  278. /// Precondition: The complex number must not be close to zero.
  279. ///
  280. SOPHUS_FUNC void setComplex(Point const& complex) {
  281. unit_complex_nonconst() = complex;
  282. normalize();
  283. }
  284. /// Accessor of unit quaternion.
  285. ///
  286. SOPHUS_FUNC
  287. ComplexT const& unit_complex() const {
  288. return static_cast<Derived const*>(this)->unit_complex();
  289. }
  290. private:
  291. /// Mutator of unit_complex is private to ensure class invariant. That is
  292. /// the complex number must stay close to unit length.
  293. ///
  294. SOPHUS_FUNC
  295. ComplexT& unit_complex_nonconst() {
  296. return static_cast<Derived*>(this)->unit_complex_nonconst();
  297. }
  298. };
  299. /// SO2 using default storage; derived from SO2Base.
  300. template <class Scalar_, int Options>
  301. class SO2 : public SO2Base<SO2<Scalar_, Options>> {
  302. public:
  303. using Base = SO2Base<SO2<Scalar_, Options>>;
  304. static int constexpr DoF = Base::DoF;
  305. static int constexpr num_parameters = Base::num_parameters;
  306. using Scalar = Scalar_;
  307. using Transformation = typename Base::Transformation;
  308. using Point = typename Base::Point;
  309. using HomogeneousPoint = typename Base::HomogeneousPoint;
  310. using Tangent = typename Base::Tangent;
  311. using Adjoint = typename Base::Adjoint;
  312. using ComplexMember = Vector2<Scalar, Options>;
  313. /// ``Base`` is friend so unit_complex_nonconst can be accessed from ``Base``.
  314. friend class SO2Base<SO2<Scalar, Options>>;
  315. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  316. /// Default constructor initializes unit complex number to identity rotation.
  317. ///
  318. SOPHUS_FUNC SO2() : unit_complex_(Scalar(1), Scalar(0)) {}
  319. /// Copy constructor
  320. ///
  321. SOPHUS_FUNC SO2(SO2 const& other) = default;
  322. /// Copy-like constructor from OtherDerived.
  323. ///
  324. template <class OtherDerived>
  325. SOPHUS_FUNC SO2(SO2Base<OtherDerived> const& other)
  326. : unit_complex_(other.unit_complex()) {}
  327. /// Constructor from rotation matrix
  328. ///
  329. /// Precondition: rotation matrix need to be orthogonal with determinant of 1.
  330. ///
  331. SOPHUS_FUNC explicit SO2(Transformation const& R)
  332. : unit_complex_(Scalar(0.5) * (R(0, 0) + R(1, 1)),
  333. Scalar(0.5) * (R(1, 0) - R(0, 1))) {
  334. SOPHUS_ENSURE(isOrthogonal(R), "R is not orthogonal:\n %", R);
  335. SOPHUS_ENSURE(R.determinant() > Scalar(0), "det(R) is not positive: %",
  336. R.determinant());
  337. }
  338. /// Constructor from pair of real and imaginary number.
  339. ///
  340. /// Precondition: The pair must not be close to zero.
  341. ///
  342. SOPHUS_FUNC SO2(Scalar const& real, Scalar const& imag)
  343. : unit_complex_(real, imag) {
  344. Base::normalize();
  345. }
  346. /// Constructor from 2-vector.
  347. ///
  348. /// Precondition: The vector must not be close to zero.
  349. ///
  350. template <class D>
  351. SOPHUS_FUNC explicit SO2(Eigen::MatrixBase<D> const& complex)
  352. : unit_complex_(complex) {
  353. static_assert(std::is_same<typename D::Scalar, Scalar>::value,
  354. "must be same Scalar type");
  355. Base::normalize();
  356. }
  357. /// Constructor from an rotation angle.
  358. ///
  359. SOPHUS_FUNC explicit SO2(Scalar theta) {
  360. unit_complex_nonconst() = SO2<Scalar>::exp(theta).unit_complex();
  361. }
  362. /// Accessor of unit complex number
  363. ///
  364. SOPHUS_FUNC ComplexMember const& unit_complex() const {
  365. return unit_complex_;
  366. }
  367. /// Group exponential
  368. ///
  369. /// This functions takes in an element of tangent space (= rotation angle
  370. /// ``theta``) and returns the corresponding element of the group SO(2).
  371. ///
  372. /// To be more specific, this function computes ``expmat(hat(omega))``
  373. /// with ``expmat(.)`` being the matrix exponential and ``hat(.)`` being the
  374. /// hat()-operator of SO(2).
  375. ///
  376. SOPHUS_FUNC static SO2<Scalar> exp(Tangent const& theta) {
  377. using std::cos;
  378. using std::sin;
  379. return SO2<Scalar>(cos(theta), sin(theta));
  380. }
  381. /// Returns derivative of exp(x) wrt. x.
  382. ///
  383. SOPHUS_FUNC static Sophus::Matrix<Scalar, num_parameters, DoF> Dx_exp_x(
  384. Tangent const& theta) {
  385. using std::cos;
  386. using std::sin;
  387. return Sophus::Matrix<Scalar, num_parameters, DoF>(-sin(theta), cos(theta));
  388. }
  389. /// Returns derivative of exp(x) wrt. x_i at x=0.
  390. ///
  391. SOPHUS_FUNC static Sophus::Matrix<Scalar, num_parameters, DoF>
  392. Dx_exp_x_at_0() {
  393. return Sophus::Matrix<Scalar, num_parameters, DoF>(Scalar(0), Scalar(1));
  394. }
  395. /// Returns derivative of exp(x).matrix() wrt. ``x_i at x=0``.
  396. ///
  397. SOPHUS_FUNC static Transformation Dxi_exp_x_matrix_at_0(int) {
  398. return generator();
  399. }
  400. /// Returns the infinitesimal generators of SO(2).
  401. ///
  402. /// The infinitesimal generators of SO(2) is:
  403. ///
  404. /// | 0 1 |
  405. /// | -1 0 |
  406. ///
  407. SOPHUS_FUNC static Transformation generator() { return hat(Scalar(1)); }
  408. /// hat-operator
  409. ///
  410. /// It takes in the scalar representation ``theta`` (= rotation angle) and
  411. /// returns the corresponding matrix representation of Lie algebra element.
  412. ///
  413. /// Formally, the hat()-operator of SO(2) is defined as
  414. ///
  415. /// ``hat(.): R^2 -> R^{2x2}, hat(theta) = theta * G``
  416. ///
  417. /// with ``G`` being the infinitesimal generator of SO(2).
  418. ///
  419. /// The corresponding inverse is the vee()-operator, see below.
  420. ///
  421. SOPHUS_FUNC static Transformation hat(Tangent const& theta) {
  422. Transformation Omega;
  423. // clang-format off
  424. Omega <<
  425. Scalar(0), -theta,
  426. theta, Scalar(0);
  427. // clang-format on
  428. return Omega;
  429. }
  430. /// Returns closed SO2 given arbitrary 2x2 matrix.
  431. ///
  432. template <class S = Scalar>
  433. static SOPHUS_FUNC enable_if_t<std::is_floating_point<S>::value, SO2>
  434. fitToSO2(Transformation const& R) {
  435. return SO2(makeRotationMatrix(R));
  436. }
  437. /// Lie bracket
  438. ///
  439. /// It returns the Lie bracket of SO(2). Since SO(2) is a commutative group,
  440. /// the Lie bracket is simple ``0``.
  441. ///
  442. SOPHUS_FUNC static Tangent lieBracket(Tangent const&, Tangent const&) {
  443. return Scalar(0);
  444. }
  445. /// Draw uniform sample from SO(2) manifold.
  446. ///
  447. template <class UniformRandomBitGenerator>
  448. static SO2 sampleUniform(UniformRandomBitGenerator& generator) {
  449. static_assert(IsUniformRandomBitGenerator<UniformRandomBitGenerator>::value,
  450. "generator must meet the UniformRandomBitGenerator concept");
  451. std::uniform_real_distribution<Scalar> uniform(-Constants<Scalar>::pi(),
  452. Constants<Scalar>::pi());
  453. return SO2(uniform(generator));
  454. }
  455. /// vee-operator
  456. ///
  457. /// It takes the 2x2-matrix representation ``Omega`` and maps it to the
  458. /// corresponding scalar representation of Lie algebra.
  459. ///
  460. /// This is the inverse of the hat()-operator, see above.
  461. ///
  462. /// Precondition: ``Omega`` must have the following structure:
  463. ///
  464. /// | 0 -a |
  465. /// | a 0 |
  466. ///
  467. SOPHUS_FUNC static Tangent vee(Transformation const& Omega) {
  468. using std::abs;
  469. return Omega(1, 0);
  470. }
  471. protected:
  472. /// Mutator of complex number is protected to ensure class invariant.
  473. ///
  474. SOPHUS_FUNC ComplexMember& unit_complex_nonconst() { return unit_complex_; }
  475. ComplexMember unit_complex_;
  476. };
  477. } // namespace Sophus
  478. namespace Eigen {
  479. /// Specialization of Eigen::Map for ``SO2``; derived from SO2Base.
  480. ///
  481. /// Allows us to wrap SO2 objects around POD array (e.g. external c style
  482. /// complex number / tuple).
  483. template <class Scalar_, int Options>
  484. class Map<Sophus::SO2<Scalar_>, Options>
  485. : public Sophus::SO2Base<Map<Sophus::SO2<Scalar_>, Options>> {
  486. public:
  487. using Base = Sophus::SO2Base<Map<Sophus::SO2<Scalar_>, Options>>;
  488. using Scalar = Scalar_;
  489. using Transformation = typename Base::Transformation;
  490. using Point = typename Base::Point;
  491. using HomogeneousPoint = typename Base::HomogeneousPoint;
  492. using Tangent = typename Base::Tangent;
  493. using Adjoint = typename Base::Adjoint;
  494. /// ``Base`` is friend so unit_complex_nonconst can be accessed from ``Base``.
  495. friend class Sophus::SO2Base<Map<Sophus::SO2<Scalar_>, Options>>;
  496. // LCOV_EXCL_START
  497. EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Map);
  498. // LCOV_EXCL_STOP
  499. using Base::operator*=;
  500. using Base::operator*;
  501. SOPHUS_FUNC
  502. Map(Scalar* coeffs) : unit_complex_(coeffs) {}
  503. /// Accessor of unit complex number.
  504. ///
  505. SOPHUS_FUNC
  506. Map<Sophus::Vector2<Scalar>, Options> const& unit_complex() const {
  507. return unit_complex_;
  508. }
  509. protected:
  510. /// Mutator of unit_complex is protected to ensure class invariant.
  511. ///
  512. SOPHUS_FUNC
  513. Map<Sophus::Vector2<Scalar>, Options>& unit_complex_nonconst() {
  514. return unit_complex_;
  515. }
  516. Map<Matrix<Scalar, 2, 1>, Options> unit_complex_;
  517. };
  518. /// Specialization of Eigen::Map for ``SO2 const``; derived from SO2Base.
  519. ///
  520. /// Allows us to wrap SO2 objects around POD array (e.g. external c style
  521. /// complex number / tuple).
  522. template <class Scalar_, int Options>
  523. class Map<Sophus::SO2<Scalar_> const, Options>
  524. : public Sophus::SO2Base<Map<Sophus::SO2<Scalar_> const, Options>> {
  525. public:
  526. using Base = Sophus::SO2Base<Map<Sophus::SO2<Scalar_> const, Options>>;
  527. using Scalar = Scalar_;
  528. using Transformation = typename Base::Transformation;
  529. using Point = typename Base::Point;
  530. using HomogeneousPoint = typename Base::HomogeneousPoint;
  531. using Tangent = typename Base::Tangent;
  532. using Adjoint = typename Base::Adjoint;
  533. using Base::operator*=;
  534. using Base::operator*;
  535. SOPHUS_FUNC Map(Scalar const* coeffs) : unit_complex_(coeffs) {}
  536. /// Accessor of unit complex number.
  537. ///
  538. SOPHUS_FUNC Map<Sophus::Vector2<Scalar> const, Options> const& unit_complex()
  539. const {
  540. return unit_complex_;
  541. }
  542. protected:
  543. /// Mutator of unit_complex is protected to ensure class invariant.
  544. ///
  545. Map<Matrix<Scalar, 2, 1> const, Options> const unit_complex_;
  546. };
  547. } // namespace Eigen
  548. #endif // SOPHUS_SO2_HPP