123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656 |
- #ifndef SOPHUS_RXSO2_HPP
- #define SOPHUS_RXSO2_HPP
- #include "so2.hpp"
- namespace Sophus {
- template <class Scalar_, int Options = 0>
- class RxSO2;
- using RxSO2d = RxSO2<double>;
- using RxSO2f = RxSO2<float>;
- }
- namespace Eigen {
- namespace internal {
- template <class Scalar_, int Options_>
- struct traits<Sophus::RxSO2<Scalar_, Options_>> {
- static constexpr int Options = Options_;
- using Scalar = Scalar_;
- using ComplexType = Sophus::Vector2<Scalar, Options>;
- };
- template <class Scalar_, int Options_>
- struct traits<Map<Sophus::RxSO2<Scalar_>, Options_>>
- : traits<Sophus::RxSO2<Scalar_, Options_>> {
- static constexpr int Options = Options_;
- using Scalar = Scalar_;
- using ComplexType = Map<Sophus::Vector2<Scalar>, Options>;
- };
- template <class Scalar_, int Options_>
- struct traits<Map<Sophus::RxSO2<Scalar_> const, Options_>>
- : traits<Sophus::RxSO2<Scalar_, Options_> const> {
- static constexpr int Options = Options_;
- using Scalar = Scalar_;
- using ComplexType = Map<Sophus::Vector2<Scalar> const, Options>;
- };
- }
- }
- namespace Sophus {
- template <class Derived>
- class RxSO2Base {
- public:
- static constexpr int Options = Eigen::internal::traits<Derived>::Options;
- using Scalar = typename ;
- using ComplexType = typename Eigen::internal::traits<Derived>::ComplexType;
- using ComplexTemporaryType = Sophus::Vector2<Scalar, Options>;
-
-
- static int constexpr DoF = 2;
-
- static int constexpr num_parameters = 2;
-
- static int constexpr N = 2;
- using Transformation = Matrix<Scalar, N, N>;
- using Point = Vector2<Scalar>;
- using HomogeneousPoint = Vector3<Scalar>;
- using Line = ParametrizedLine2<Scalar>;
- using Tangent = Vector<Scalar, DoF>;
- using Adjoint = Matrix<Scalar, DoF, DoF>;
-
-
-
-
- template <typename OtherDerived>
- using ReturnScalar = typename Eigen::ScalarBinaryOpTraits<
- Scalar, typename ;
- template <typename OtherDerived>
- using RxSO2Product = RxSO2<ReturnScalar<OtherDerived>>;
- template <typename PointDerived>
- using PointProduct = Vector2<ReturnScalar<PointDerived>>;
- template <typename HPointDerived>
- using HomogeneousPointProduct = Vector3<ReturnScalar<HPointDerived>>;
-
-
-
-
-
-
-
-
- SOPHUS_FUNC Adjoint Adj() const { return Adjoint::Identity(); }
-
-
- SOPHUS_FUNC Scalar angle() ; }
-
-
- template <class NewScalarType>
- SOPHUS_FUNC RxSO2<NewScalarType> cast() const {
- return RxSO2<NewScalarType>(complex().template cast<NewScalarType>());
- }
-
-
-
-
-
-
-
-
- SOPHUS_FUNC Scalar* data() ; }
-
-
- SOPHUS_FUNC Scalar const* data() ; }
-
-
- SOPHUS_FUNC RxSO2<Scalar> inverse()
- Scalar ;
- return RxSO2<Scalar>(complex().x() / squared_scale,
- -complex().y() /;
- }
-
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC Tangent log() const {
- using std::log;
- Tangent theta_sigma;
- theta_sigma[1] = log(scale());
- theta_sigma[0] = SO2<Scalar>(complex()).log();
- return theta_sigma;
- }
-
-
-
-
-
-
- SOPHUS_FUNC Transformation matrix() const {
- Transformation sR;
-
- sR << complex()[0], -complex()[1],
- complex()[1], complex()[0];
-
- return sR;
- }
-
-
- template <class OtherDerived>
- SOPHUS_FUNC RxSO2Base<Derived>& operator=(
- RxSO2Base<OtherDerived> const& other) {
- complex_nonconst() = other.complex();
- return *this;
- }
-
-
-
-
-
-
- template <typename OtherDerived>
- SOPHUS_FUNC RxSO2Product<OtherDerived> operator*(
- RxSO2Base<OtherDerived> const& other) const {
- using ResultT = ReturnScalar<OtherDerived>;
- Scalar lhs_real ;
- Scalar lhs_imag ;
- typename OtherDerived::Scalar const& rhs_real ;
- typename OtherDerived::Scalar const& rhs_imag ;
-
- typename RxSO2Product<OtherDerived>::ComplexType result_complex(
- lhs_real * rhs_real - lhs_imag * rhs_imag,
- lhs_real * rhs_imag + lhs_imag * rhs_real);
- const ResultT squared_scale = result_complex.squaredNorm();
- if (squared_scale <
- Constants<ResultT>::epsilon() * Constants<ResultT>::epsilon()) {
-
- result_complex.normalize();
- result_complex *= Constants<ResultT>::epsilon();
- }
- return RxSO2Product<OtherDerived>(result_complex);
- }
-
-
-
-
-
-
-
- template <typename PointDerived,
- typename = typename std::enable_if<
- IsFixedSizeVector<PointDerived, 2>::value>::type>
- SOPHUS_FUNC PointProduct<PointDerived> operator*(
- Eigen::MatrixBase<PointDerived> const& p) const {
- return matrix() * p;
- }
-
-
- template <typename HPointDerived,
- typename = typename std::enable_if<
- IsFixedSizeVector<HPointDerived, 3>::value>::type>
- SOPHUS_FUNC HomogeneousPointProduct<HPointDerived> operator*(
- Eigen::MatrixBase<HPointDerived> const& p) const {
- const auto rsp = *this * p.template head<2>();
- return HomogeneousPointProduct<HPointDerived>(rsp(0), rsp(1), p(2));
- }
-
-
-
-
-
-
-
-
- SOPHUS_FUNC Line operator*(Line const& l) const {
- return Line((*this) * l.origin(), (*this) * l.direction() / scale());
- }
-
-
-
-
-
-
- template <typename OtherDerived,
- typename = typename std::enable_if<
- std::is_same<Scalar, ReturnScalar<OtherDerived>>::value>::type>
- SOPHUS_FUNC
- RxSO2Base<OtherDerived> const& other) {
- *static_cast<Derived*>(this) = *this ;
- return *this;
- }
-
-
-
-
- SOPHUS_FUNC Sophus::Vector<Scalar, num_parameters> params()
- return ;
- }
-
-
-
- SOPHUS_FUNC void setComplex(Vector2<Scalar> const& z) {
- SOPHUS_ENSURE(z.squaredNorm()
- Constants<Scalar>::epsilon(),
- "Scale factor must be greater-equal epsilon.");
- static_cast<Derived*>(this)->complex_nonconst() = z;
- }
-
-
- SOPHUS_FUNC ComplexType const& complex() const {
- return static_cast<Derived const*>(this)->complex();
- }
-
-
- SOPHUS_FUNC Transformation rotationMatrix() const {
- ComplexTemporaryType norm_quad = complex();
- norm_quad.normalize();
- return SO2<Scalar>(norm_quad).matrix();
- }
-
-
- SOPHUS_FUNC
- Scalar scale() ; }
-
-
- SOPHUS_FUNC void setAngle(Scalar const& theta) { setSO2(SO2<Scalar>(theta)); }
-
-
-
-
- SOPHUS_FUNC void setRotationMatrix(Transformation const& R) {
- setSO2(SO2<Scalar>(R));
- }
-
-
- SOPHUS_FUNC void setScale(Scalar const& scale) {
- using ;
- complex_nonconst().normalize();
- complex_nonconst() *= scale;
- }
-
-
-
-
-
- SOPHUS_FUNC void setScaledRotationMatrix(Transformation const& sR) {
- SOPHUS_ENSURE(isScaledOrthogonalAndPositive(sR),
- "sR must be scaled orthogonal:\n %", sR);
- complex_nonconst() = sR.col(0);
- }
-
-
- SOPHUS_FUNC void setSO2(SO2<Scalar> const& so2) {
- using ;
- Scalar saved_scale ;
- complex_nonconst() = so2.unit_complex();
- complex_nonconst() *= saved_scale;
- }
- SOPHUS_FUNC SO2<Scalar> so2() ; }
- private:
-
-
- SOPHUS_FUNC ComplexType& complex_nonconst() {
- return static_cast<Derived*>(this)->complex_nonconst();
- }
- };
- template <class Scalar_, int Options>
- class RxSO2 : public RxSO2Base<RxSO2<Scalar_, Options>> {
- public:
- using Base = RxSO2Base<RxSO2<Scalar_, Options>>;
- using Scalar = Scalar_;
- using Transformation = typename Base::Transformation;
- using Point = typename Base::Point;
- using HomogeneousPoint = typename Base::HomogeneousPoint;
- using Tangent = typename Base::Tangent;
- using Adjoint = typename Base::Adjoint;
- using ComplexMember = Eigen::Matrix<Scalar, 2, 1, Options>;
-
- friend class RxSO2Base<RxSO2<Scalar_, Options>>;
- using Base::operator=;
- EIGEN_MAKE_ALIGNED_OPERATOR_NEW
-
-
-
- SOPHUS_FUNC RxSO2() : complex_(Scalar(1), Scalar(0)) {}
-
-
- SOPHUS_FUNC ;
-
-
- template <class OtherDerived>
- SOPHUS_FUNC RxSO2(RxSO2Base<OtherDerived> const& other)
- : complex_(other.complex()) {}
-
-
-
-
-
- SOPHUS_FUNC explicit RxSO2(Transformation const& sR) {
- this->setScaledRotationMatrix(sR);
- }
-
-
-
-
-
- SOPHUS_FUNC RxSO2(Scalar const& scale, Transformation
- : RxSO2((scale
-
-
-
-
- SOPHUS_FUNC
- : RxSO2((scale
-
-
-
-
- SOPHUS_FUNC
- SOPHUS_ENSURE(complex_.squaredNorm()
- Constants<Scalar>::epsilon(),
- "Scale factor must be greater-equal epsilon: % vs %",
- complex_.squaredNorm(),
- Constants<Scalar>::epsilon() ;
- }
-
-
-
-
- SOPHUS_FUNC explicit RxSO2(Scalar const& real, Scalar
- : RxSO2(Vector2<Scalar>(real, imag)) {}
-
-
- SOPHUS_FUNC ; }
-
-
- SOPHUS_FUNC static Transformation Dxi_exp_x_matrix_at_0(int i) {
- return generator(i);
- }
-
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC static RxSO2<Scalar> exp(Tangent
- using ;
- Scalar const ;
- Scalar const ;
- Scalar s ;
- Vector2<Scalar> z ;
- z *= s;
- return RxSO2<Scalar>(z);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC static Transformation generator(int i) {
- SOPHUS_ENSURE(i >= 0 && i <= 1, "i should be 0 or 1.");
- Tangent e;
- e.setZero();
- e[i] = Scalar(1);
- return hat(e);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC static Transformation hat(Tangent const& a) {
- Transformation A;
-
- A << a(1), -a(0),
- a(0), a(1);
-
- return A;
- }
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC static Tangent lieBracket(Tangent const&, Tangent const&) {
- Vector2<Scalar> res;
- res.setZero();
- return res;
- }
-
-
-
-
-
- template <class UniformRandomBitGenerator>
- static RxSO2 sampleUniform(UniformRandomBitGenerator& generator) {
- std::uniform_real_distribution<Scalar> uniform(Scalar(-1), Scalar(1));
- using std::exp2;
- return RxSO2(exp2(uniform(generator)),
- SO2<Scalar>::sampleUniform(generator));
- }
-
-
-
-
-
-
-
-
-
-
-
-
- SOPHUS_FUNC static Tangent vee(Transformation const& Omega) {
- using std::abs;
- return Tangent(Omega(1, 0), Omega(0, 0));
- }
- protected:
- SOPHUS_FUNC ComplexMember& complex_nonconst() { return complex_; }
- ComplexMember complex_;
- };
- }
- namespace Eigen {
- template <class Scalar_, int Options>
- class Map<Sophus::RxSO2<Scalar_>, Options>
- : public Sophus::RxSO2Base<Map<Sophus::RxSO2<Scalar_>, Options>> {
- using Base = Sophus::RxSO2Base<Map<Sophus::RxSO2<Scalar_>, Options>>;
- public:
- using Scalar = Scalar_;
- using Transformation = typename Base::Transformation;
- using Point = typename Base::Point;
- using HomogeneousPoint = typename Base::HomogeneousPoint;
- using Tangent = typename Base::Tangent;
- using Adjoint = typename Base::Adjoint;
-
- friend class Sophus::RxSO2Base<Map<Sophus::RxSO2<Scalar_>, Options>>;
- using Base::operator=;
- using Base::operator*=;
- using Base::operator*;
- SOPHUS_FUNC Map(Scalar* coeffs) : complex_(coeffs)
-
-
- SOPHUS_FUNC
- Map<Sophus::Vector2<Scalar>, Options> const& complex()
- return ;
- }
- protected:
- SOPHUS_FUNC Map<Sophus::Vector2<Scalar>, Options>& complex_nonconst()
- return ;
- }
- Map<Sophus::Vector2<Scalar>, Options> complex_;
- };
- template <class Scalar_, int Options>
- class Map<Sophus::RxSO2<Scalar_> const, Options>
- : public Sophus::RxSO2Base<Map<Sophus::RxSO2<Scalar_> const, Options>> {
- public:
- using Base = Sophus::RxSO2Base<Map<Sophus::RxSO2<Scalar_> const, Options>>;
- using Scalar = Scalar_;
- using Transformation = typename Base::Transformation;
- using Point = typename Base::Point;
- using HomogeneousPoint = typename Base::HomogeneousPoint;
- using Tangent = typename Base::Tangent;
- using Adjoint = typename Base::Adjoint;
- using Base::operator*=;
- using Base::operator*;
- SOPHUS_FUNC
- Map(Scalar const* coeffs) : complex_(coeffs)
-
-
- SOPHUS_FUNC
- Map<Sophus::Vector2<Scalar> const, Options> const& complex()
- return ;
- }
- protected:
- Map<Sophus::Vector2<Scalar> const, Options> const ;
- };
- }
- #endif
|