From a556b45abf18f1bd509daaf63b66b7d55e9fd291 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 22 Apr 2024 21:56:26 -0400 Subject: add engine version --- engine-ocean/Eigen/src/Geometry/RotationBase.h | 206 +++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 engine-ocean/Eigen/src/Geometry/RotationBase.h (limited to 'engine-ocean/Eigen/src/Geometry/RotationBase.h') diff --git a/engine-ocean/Eigen/src/Geometry/RotationBase.h b/engine-ocean/Eigen/src/Geometry/RotationBase.h new file mode 100644 index 0000000..f0ee0bd --- /dev/null +++ b/engine-ocean/Eigen/src/Geometry/RotationBase.h @@ -0,0 +1,206 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008 Gael Guennebaud +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_ROTATIONBASE_H +#define EIGEN_ROTATIONBASE_H + +namespace Eigen { + +// forward declaration +namespace internal { +template +struct rotation_base_generic_product_selector; +} + +/** \class RotationBase + * + * \brief Common base class for compact rotation representations + * + * \tparam Derived is the derived type, i.e., a rotation type + * \tparam _Dim the dimension of the space + */ +template +class RotationBase +{ + public: + enum { Dim = _Dim }; + /** the scalar type of the coefficients */ + typedef typename internal::traits::Scalar Scalar; + + /** corresponding linear transformation matrix type */ + typedef Matrix RotationMatrixType; + typedef Matrix VectorType; + + public: + EIGEN_DEVICE_FUNC inline const Derived& derived() const { return *static_cast(this); } + EIGEN_DEVICE_FUNC inline Derived& derived() { return *static_cast(this); } + + /** \returns an equivalent rotation matrix */ + EIGEN_DEVICE_FUNC inline RotationMatrixType toRotationMatrix() const { return derived().toRotationMatrix(); } + + /** \returns an equivalent rotation matrix + * This function is added to be conform with the Transform class' naming scheme. + */ + EIGEN_DEVICE_FUNC inline RotationMatrixType matrix() const { return derived().toRotationMatrix(); } + + /** \returns the inverse rotation */ + EIGEN_DEVICE_FUNC inline Derived inverse() const { return derived().inverse(); } + + /** \returns the concatenation of the rotation \c *this with a translation \a t */ + EIGEN_DEVICE_FUNC inline Transform operator*(const Translation& t) const + { return Transform(*this) * t; } + + /** \returns the concatenation of the rotation \c *this with a uniform scaling \a s */ + EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const UniformScaling& s) const + { return toRotationMatrix() * s.factor(); } + + /** \returns the concatenation of the rotation \c *this with a generic expression \a e + * \a e can be: + * - a DimxDim linear transformation matrix + * - a DimxDim diagonal matrix (axis aligned scaling) + * - a vector of size Dim + */ + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::rotation_base_generic_product_selector::ReturnType + operator*(const EigenBase& e) const + { return internal::rotation_base_generic_product_selector::run(derived(), e.derived()); } + + /** \returns the concatenation of a linear transformation \a l with the rotation \a r */ + template friend + EIGEN_DEVICE_FUNC inline RotationMatrixType operator*(const EigenBase& l, const Derived& r) + { return l.derived() * r.toRotationMatrix(); } + + /** \returns the concatenation of a scaling \a l with the rotation \a r */ + EIGEN_DEVICE_FUNC friend inline Transform operator*(const DiagonalMatrix& l, const Derived& r) + { + Transform res(r); + res.linear().applyOnTheLeft(l); + return res; + } + + /** \returns the concatenation of the rotation \c *this with a transformation \a t */ + template + EIGEN_DEVICE_FUNC inline Transform operator*(const Transform& t) const + { return toRotationMatrix() * t; } + + template + EIGEN_DEVICE_FUNC inline VectorType _transformVector(const OtherVectorType& v) const + { return toRotationMatrix() * v; } +}; + +namespace internal { + +// implementation of the generic product rotation * matrix +template +struct rotation_base_generic_product_selector +{ + enum { Dim = RotationDerived::Dim }; + typedef Matrix ReturnType; + EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const MatrixType& m) + { return r.toRotationMatrix() * m; } +}; + +template +struct rotation_base_generic_product_selector< RotationDerived, DiagonalMatrix, false > +{ + typedef Transform ReturnType; + EIGEN_DEVICE_FUNC static inline ReturnType run(const RotationDerived& r, const DiagonalMatrix& m) + { + ReturnType res(r); + res.linear() *= m; + return res; + } +}; + +template +struct rotation_base_generic_product_selector +{ + enum { Dim = RotationDerived::Dim }; + typedef Matrix ReturnType; + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE ReturnType run(const RotationDerived& r, const OtherVectorType& v) + { + return r._transformVector(v); + } +}; + +} // end namespace internal + +/** \geometry_module + * + * \brief Constructs a Dim x Dim rotation matrix from the rotation \a r + */ +template +template +EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> +::Matrix(const RotationBase& r) +{ + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)) + *this = r.toRotationMatrix(); +} + +/** \geometry_module + * + * \brief Set a Dim x Dim rotation matrix from the rotation \a r + */ +template +template +EIGEN_DEVICE_FUNC Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>& +Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> +::operator=(const RotationBase& r) +{ + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)) + return *this = r.toRotationMatrix(); +} + +namespace internal { + +/** \internal + * + * Helper function to return an arbitrary rotation object to a rotation matrix. + * + * \tparam Scalar the numeric type of the matrix coefficients + * \tparam Dim the dimension of the current space + * + * It returns a Dim x Dim fixed size matrix. + * + * Default specializations are provided for: + * - any scalar type (2D), + * - any matrix expression, + * - any type based on RotationBase (e.g., Quaternion, AngleAxis, Rotation2D) + * + * Currently toRotationMatrix is only used by Transform. + * + * \sa class Transform, class Rotation2D, class Quaternion, class AngleAxis + */ +template +EIGEN_DEVICE_FUNC static inline Matrix toRotationMatrix(const Scalar& s) +{ + EIGEN_STATIC_ASSERT(Dim==2,YOU_MADE_A_PROGRAMMING_MISTAKE) + return Rotation2D(s).toRotationMatrix(); +} + +template +EIGEN_DEVICE_FUNC static inline Matrix toRotationMatrix(const RotationBase& r) +{ + return r.toRotationMatrix(); +} + +template +EIGEN_DEVICE_FUNC static inline const MatrixBase& toRotationMatrix(const MatrixBase& mat) +{ + EIGEN_STATIC_ASSERT(OtherDerived::RowsAtCompileTime==Dim && OtherDerived::ColsAtCompileTime==Dim, + YOU_MADE_A_PROGRAMMING_MISTAKE) + return mat; +} + +} // end namespace internal + +} // end namespace Eigen + +#endif // EIGEN_ROTATIONBASE_H -- cgit v1.2.3-70-g09d2