13#ifndef EIGEN_TRANSFORM_H
14#define EIGEN_TRANSFORM_H
17#include "./InternalHeaderCheck.h"
23template <
typename Transform>
24struct transform_traits {
27 HDim = Transform::HDim,
28 Mode = Transform::Mode,
33template <
typename TransformType,
typename MatrixType,
34 int Case = transform_traits<TransformType>::IsProjective ? 0
35 : int(MatrixType::RowsAtCompileTime) == int(transform_traits<TransformType>::HDim) ? 1
37 int RhsCols = MatrixType::ColsAtCompileTime>
38struct transform_right_product_impl;
40template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim,
int OtherRows = Other::RowsAtCompileTime,
41 int OtherCols = Other::ColsAtCompileTime>
42struct transform_left_product_impl;
44template <
typename Lhs,
typename Rhs,
45 bool AnyProjective = transform_traits<Lhs>::IsProjective || transform_traits<Rhs>::IsProjective>
46struct transform_transform_product_impl;
48template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim,
int OtherRows = Other::RowsAtCompileTime,
49 int OtherCols = Other::ColsAtCompileTime>
50struct transform_construct_from_matrix;
52template <
typename TransformType>
53struct transform_take_affine_part;
55template <
typename LhsScalar,
typename RhsScalar,
typename BinaryOp,
typename TargetScalar,
typename =
void>
56struct has_matching_binary_op_traits : std::false_type {};
58template <
typename LhsScalar,
typename RhsScalar,
typename BinaryOp,
typename TargetScalar>
59struct has_matching_binary_op_traits<LhsScalar, RhsScalar, BinaryOp, TargetScalar,
60 void_t<typename ScalarBinaryOpTraits<LhsScalar, RhsScalar, BinaryOp>::ReturnType>>
61 : std::integral_constant<
62 bool, std::is_convertible<typename ScalarBinaryOpTraits<LhsScalar, RhsScalar, BinaryOp>::ReturnType,
63 TargetScalar>::value ||
64 std::is_assignable<TargetScalar&,
65 typename ScalarBinaryOpTraits<LhsScalar, RhsScalar, BinaryOp>::ReturnType>::value> {};
67template <
typename TargetScalar,
typename Derived,
typename LhsScalar,
typename RhsScalar,
typename BinaryOp,
69struct transform_convert_arg {
70 EIGEN_DEVICE_FUNC
static auto run(
const MatrixBase<Derived>& mat) {
return mat.template cast<TargetScalar>(); }
73template <
typename TargetScalar,
typename Derived,
typename LhsScalar,
typename RhsScalar,
typename BinaryOp>
74struct transform_convert_arg<
75 TargetScalar, Derived, LhsScalar, RhsScalar, BinaryOp,
76 std::enable_if_t<std::is_same<typename Derived::Scalar, TargetScalar>::value ||
77 has_matching_binary_op_traits<LhsScalar, RhsScalar, BinaryOp, TargetScalar>::value>> {
78 EIGEN_DEVICE_FUNC
static const Derived& run(
const MatrixBase<Derived>& mat) {
return mat.derived(); }
81template <
typename Scalar_,
int Dim_,
int Mode_,
int Options_>
82struct traits<Transform<Scalar_, Dim_, Mode_, Options_> > {
83 using Scalar = Scalar_;
84 using StorageIndex = Eigen::Index;
85 using StorageKind = Dense;
87 Dim1 = Dim_ == Dynamic ? Dim_ : Dim_ + 1,
88 RowsAtCompileTime = Mode_ ==
Projective ? Dim1 : Dim_,
89 ColsAtCompileTime = Dim1,
90 MaxRowsAtCompileTime = RowsAtCompileTime,
91 MaxColsAtCompileTime = ColsAtCompileTime,
97struct transform_make_affine;
221template <
typename Scalar_,
int Dim_,
int Mode_,
int Options_>
225 Dim_ == Dynamic ? Dynamic : (Dim_ + 1) * (Dim_ + 1))
235 using StorageIndex = Eigen::Index;
238 using MatrixType =
typename internal::make_proper_matrix_type<Scalar, Rows, HDim, Options>::type;
273 check_template_params();
284 check_template_params();
287 EIGEN_DEVICE_FUNC
inline explicit Transform(
const UniformScaling<Scalar>& s) {
288 check_template_params();
291 template <
typename Derived>
292 EIGEN_DEVICE_FUNC
inline explicit Transform(
const RotationBase<Derived, Dim>& r) {
293 check_template_params();
297 using take_affine_part = internal::transform_take_affine_part<Transform>;
301 template <
typename OtherDerived>
304 (std::is_same<Scalar, typename OtherDerived::Scalar>::value),
305 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
307 check_template_params();
308 internal::transform_construct_from_matrix<OtherDerived, Mode, Options, Dim, HDim>::run(
this, other.
derived());
313 template <
typename OtherDerived>
316 (std::is_same<Scalar, typename OtherDerived::Scalar>::value),
317 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
319 internal::transform_construct_from_matrix<OtherDerived, Mode, Options, Dim, HDim>::run(
this, other.
derived());
323 template <
int OtherOptions>
325 check_template_params();
327 m_matrix = other.
matrix();
330 template <
int OtherMode,
int OtherOptions>
332 check_template_params();
335 EIGEN_STATIC_ASSERT(internal::check_implication(OtherMode ==
int(
Projective), Mode ==
int(
Projective)),
336 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
342 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
349 if (EIGEN_CONST_CONDITIONAL(ModeIsAffineCompact == OtherModeIsAffineCompact)) {
353 m_matrix.template block<Dim, Dim + 1>(0, 0) = other.matrix().template block<Dim, Dim + 1>(0, 0);
355 }
else if (EIGEN_CONST_CONDITIONAL(OtherModeIsAffineCompact)) {
357 internal::transform_construct_from_matrix<OtherMatrixType, Mode, Options, Dim, HDim>::run(
this, other.matrix());
362 linear() = other.linear();
367 template <
typename OtherDerived>
368 EIGEN_DEVICE_FUNC
Transform(
const ReturnByValue<OtherDerived>& other) {
369 check_template_params();
373 template <
typename OtherDerived>
379#ifdef EIGEN_QT_SUPPORT
380#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
381 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.") inline
Transform(const QMatrix& other);
382 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.") inline
Transform& operator=(const QMatrix& other);
383 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.") inline QMatrix toQMatrix(
void) const;
385 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.") inline
Transform(const QTransform& other);
386 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.")
388 EIGEN_DEPRECATED_WITH_REASON(
"Copy the coefficients explicitly.") inline QTransform
toQTransform(
void) const;
391 EIGEN_DEVICE_FUNC
constexpr Index rows() const noexcept {
392 return int(Mode) == int(
Projective) ? m_matrix.cols() : (m_matrix.cols() - 1);
394 EIGEN_DEVICE_FUNC
constexpr Index cols() const noexcept {
return m_matrix.cols(); }
403#ifdef EIGEN_MULTIDIMENSIONAL_SUBSCRIPT
406 EIGEN_DEVICE_FUNC
inline Scalar operator[](Index row, Index col)
const {
return m_matrix[row, col]; }
409 EIGEN_DEVICE_FUNC
inline Scalar& operator[](Index row, Index col) {
return m_matrix[row, col]; }
458 template <
typename OtherDerived>
459 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const typename internal::transform_right_product_impl<
Transform,
460 OtherDerived>::ResultType
462 return internal::transform_right_product_impl<Transform, OtherDerived>::run(*
this, other.derived());
472 template <
typename OtherDerived>
473 friend EIGEN_DEVICE_FUNC
inline const typename internal::transform_left_product_impl<OtherDerived, Mode, Options,
474 Dim_, Dim_ + 1>::ResultType
476 return internal::transform_left_product_impl<OtherDerived, Mode, Options, Dim, HDim>::run(a.derived(), b);
485 template <
typename DiagonalDerived>
489 res.linearExt() *= b;
499 template <
typename DiagonalDerived>
509 template <
typename OtherDerived>
511 return *
this = *
this * other;
516 return internal::transform_transform_product_impl<Transform, Transform>::run(*
this, other);
520 template <
int OtherMode,
int OtherOptions>
521 EIGEN_DEVICE_FUNC
inline
522 typename internal::transform_transform_product_impl<
Transform,
525 return internal::transform_transform_product_impl<Transform, Transform<Scalar, Dim, OtherMode, OtherOptions> >::run(
538 template <
typename OtherDerived>
541 template <
typename OtherDerived>
547 template <
typename OtherDerived>
550 template <
typename OtherDerived>
553 template <
typename RotationType>
556 template <
typename RotationType>
574 res.scale(s.factor());
578 EIGEN_DEVICE_FUNC
inline Transform& operator*=(
const DiagonalMatrix<Scalar, Dim>& s) {
583 template <
typename Derived>
585 template <
typename Derived>
586 EIGEN_DEVICE_FUNC
inline Transform& operator*=(
const RotationBase<Derived, Dim>& r) {
587 return rotate(r.toRotationMatrix());
589 template <
typename Derived>
590 EIGEN_DEVICE_FUNC
inline Transform operator*(
const RotationBase<Derived, Dim>& r)
const;
593 EIGEN_DEVICE_FUNC RotationReturnType
rotation()
const;
595 template <
typename RotationMatrixType,
typename ScalingMatrixType>
597 template <
typename ScalingMatrixType,
typename RotationMatrixType>
600 template <
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
602 const OrientationType& orientation,
608 EIGEN_DEVICE_FUNC
constexpr const Scalar*
data()
const {
return m_matrix.data(); }
610 EIGEN_DEVICE_FUNC
constexpr Scalar*
data() {
return m_matrix.data(); }
617 template <
typename NewScalarType>
618 EIGEN_DEVICE_FUNC
inline
619 typename internal::cast_return_type<Transform, Transform<NewScalarType, Dim, Mode, Options> >::type
621 return typename internal::cast_return_type<Transform, Transform<NewScalarType, Dim, Mode, Options> >::type(*
this);
625 template <
typename OtherScalarType>
627 check_template_params();
635 EIGEN_DEVICE_FUNC
bool isApprox(
const Transform& other,
const typename NumTraits<Scalar>::Real& prec =
636 NumTraits<Scalar>::dummy_precision())
const {
637 return m_matrix.isApprox(other.m_matrix, prec);
642 EIGEN_DEVICE_FUNC
void makeAffine() { internal::transform_make_affine<int(Mode)>::run(m_matrix); }
648 EIGEN_DEVICE_FUNC
inline Block<MatrixType, int(Mode) == int(
Projective) ? HDim : Dim, Dim> linearExt() {
649 return m_matrix.template block < int(Mode) == int(Projective) ? HDim : Dim, Dim > (0, 0);
655 EIGEN_DEVICE_FUNC
inline const Block<MatrixType, int(Mode) == int(
Projective) ? HDim : Dim, Dim> linearExt()
const {
656 return m_matrix.template block < int(Mode) == int(Projective) ? HDim : Dim, Dim > (0, 0);
663 EIGEN_DEVICE_FUNC
inline Block<
MatrixType, int(Mode) == int(
Projective) ? HDim : Dim, 1> translationExt() {
664 return m_matrix.template block < int(Mode) == int(Projective) ? HDim : Dim, 1 > (0, Dim);
670 EIGEN_DEVICE_FUNC
inline const Block<
MatrixType, int(Mode) == int(
Projective) ? HDim : Dim, 1> translationExt()
672 return m_matrix.template block < int(Mode) == int(Projective) ? HDim : Dim, 1 > (0, Dim);
675#ifdef EIGEN_TRANSFORM_PLUGIN
676#include EIGEN_TRANSFORM_PLUGIN
680#ifndef EIGEN_PARSED_BY_DOXYGEN
681 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
void check_template_params() {
682 EIGEN_STATIC_ASSERT((Options & (
DontAlign |
RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS)
727#ifdef EIGEN_QT_SUPPORT
730EIGEN_DIAGNOSTICS(push)
731EIGEN_DIAGNOSTICS_OFF(disable : 4996, ignored
"-Wdeprecated-declarations")
733#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
740template <
typename Scalar,
int Dim,
int Mode,
int Options>
742 check_template_params();
752template <
typename Scalar,
int Dim,
int Mode,
int Options>
754 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
756 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy();
758 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy(), 0, 0, 1;
770template <
typename Scalar,
int Dim,
int Mode,
int Options>
772 check_template_params();
773 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
774 return QMatrix(m_matrix.coeff(0, 0), m_matrix.coeff(1, 0), m_matrix.coeff(0, 1), m_matrix.coeff(1, 1),
775 m_matrix.coeff(0, 2), m_matrix.coeff(1, 2));
785template <
typename Scalar,
int Dim,
int Mode,
int Options>
787 check_template_params();
797template <
typename Scalar,
int Dim,
int Mode,
int Options>
799 check_template_params();
800 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
802 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy();
804 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy(), other.m13(), other.m23(),
815template <
typename Scalar,
int Dim,
int Mode,
int Options>
817 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
819 return QTransform(m_matrix.coeff(0, 0), m_matrix.coeff(1, 0), m_matrix.coeff(0, 1), m_matrix.coeff(1, 1),
820 m_matrix.coeff(0, 2), m_matrix.coeff(1, 2));
822 return QTransform(m_matrix.coeff(0, 0), m_matrix.coeff(1, 0), m_matrix.coeff(2, 0), m_matrix.coeff(0, 1),
823 m_matrix.coeff(1, 1), m_matrix.coeff(2, 1), m_matrix.coeff(0, 2), m_matrix.coeff(1, 2),
824 m_matrix.coeff(2, 2));
827EIGEN_DIAGNOSTICS(pop)
838template <
typename Scalar,
int Dim,
int Mode,
int Options>
839template <
typename OtherDerived>
842 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
843 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
844 linearExt() = linearExt() * other.
asDiagonal();
852template <
typename Scalar,
int Dim,
int Mode,
int Options>
855 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
864template <
typename Scalar,
int Dim,
int Mode,
int Options>
865template <
typename OtherDerived>
868 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
869 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
878template <
typename Scalar,
int Dim,
int Mode,
int Options>
881 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
882 m_matrix.template topRows<Dim>() *= s;
890template <
typename Scalar,
int Dim,
int Mode,
int Options>
891template <
typename OtherDerived>
894 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
897 internal::transform_convert_arg<
Scalar, OtherDerived,
Scalar,
typename OtherDerived::Scalar,
898 internal::fast_mult_op<Scalar, typename OtherDerived::Scalar>>::run(other);
906template <
typename Scalar,
int Dim,
int Mode,
int Options>
907template <
typename OtherDerived>
910 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
911 if (EIGEN_CONST_CONDITIONAL(
int(Mode) ==
int(
Projective)))
913 internal::transform_convert_arg<
Scalar, OtherDerived,
typename OtherDerived::Scalar,
Scalar,
914 internal::fast_mult_op<typename OtherDerived::Scalar, Scalar>>::run(other) *
918 internal::transform_convert_arg<
Scalar, OtherDerived,
Scalar,
typename OtherDerived::Scalar,
919 internal::scalar_sum_op<Scalar, typename OtherDerived::Scalar>>::run(other);
925template <
typename TransformType,
typename RotationType,
typename Enable =
void>
926struct transform_rotate_impl {
927 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const RotationType& rotation) {
928 t.linearExt() *= internal::toRotationMatrix<typename TransformType::Scalar, TransformType::Dim>(rotation);
932template <
typename TransformType,
typename Derived>
933struct transform_rotate_impl<TransformType, Derived,
934 std::enable_if_t<std::is_base_of<MatrixBase<Derived>, Derived>::value>> {
935 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const Derived& rotation) {
936 using Scalar =
typename TransformType::Scalar;
937 t.linearExt() *= internal::transform_convert_arg<
938 Scalar, Derived, Scalar,
typename Derived::Scalar,
939 internal::fast_mult_op<Scalar, typename Derived::Scalar>>::run(rotation);
943template <
typename TransformType,
typename Derived>
944struct transform_rotate_impl<
945 TransformType, Derived,
946 std::enable_if_t<std::is_base_of<RotationBase<Derived, TransformType::Dim>, Derived>::value>> {
947 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const Derived& rotation) {
948 t.rotate(rotation.toRotationMatrix());
952template <
typename TransformType,
typename OtherScalar>
953struct transform_rotate_impl<TransformType, OtherScalar, std::enable_if_t<std::is_scalar<OtherScalar>::value>> {
954 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const OtherScalar& rotation) {
955 EIGEN_STATIC_ASSERT(TransformType::Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
956 t.rotate(Rotation2D<OtherScalar>(rotation).toRotationMatrix());
960template <
typename TransformType,
typename RotationType,
typename Enable =
void>
961struct transform_prerotate_impl {
962 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const RotationType& rotation) {
963 t.matrix().template block<TransformType::Dim, TransformType::HDim>(0, 0) =
964 internal::toRotationMatrix<typename TransformType::Scalar, TransformType::Dim>(rotation) *
965 t.matrix().template block<TransformType::Dim, TransformType::HDim>(0, 0);
969template <
typename TransformType,
typename Derived>
970struct transform_prerotate_impl<TransformType, Derived,
971 std::enable_if_t<std::is_base_of<MatrixBase<Derived>, Derived>::value>> {
972 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const Derived& rotation) {
973 using Scalar =
typename TransformType::Scalar;
974 t.
matrix().template block<TransformType::Dim, TransformType::HDim>(0, 0) =
975 internal::transform_convert_arg<
976 Scalar, Derived,
typename Derived::Scalar, Scalar,
977 internal::fast_mult_op<typename Derived::Scalar, Scalar>>::run(rotation) *
978 t.
matrix().template block<TransformType::Dim, TransformType::HDim>(0, 0);
982template <
typename TransformType,
typename Derived>
983struct transform_prerotate_impl<
984 TransformType, Derived,
985 std::enable_if_t<std::is_base_of<RotationBase<Derived, TransformType::Dim>, Derived>::value>> {
986 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const Derived& rotation) {
987 t.prerotate(rotation.toRotationMatrix());
991template <
typename TransformType,
typename OtherScalar>
992struct transform_prerotate_impl<TransformType, OtherScalar, std::enable_if_t<std::is_scalar<OtherScalar>::value>> {
993 EIGEN_DEVICE_FUNC
static inline void run(TransformType& t,
const OtherScalar& rotation) {
994 EIGEN_STATIC_ASSERT(TransformType::Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
995 t.prerotate(Rotation2D<OtherScalar>(rotation).toRotationMatrix());
1018template <
typename Scalar,
int Dim,
int Mode,
int Options>
1019template <
typename RotationType>
1022 internal::transform_rotate_impl<Transform, RotationType>::run(*
this,
rotation);
1033template <
typename Scalar,
int Dim,
int Mode,
int Options>
1034template <
typename RotationType>
1037 internal::transform_prerotate_impl<Transform, RotationType>::run(*
this,
rotation);
1046template <
typename Scalar,
int Dim,
int Mode,
int Options>
1049 EIGEN_STATIC_ASSERT(
int(Dim) == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
1050 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
1060template <
typename Scalar,
int Dim,
int Mode,
int Options>
1063 EIGEN_STATIC_ASSERT(
int(Dim) == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
1064 EIGEN_STATIC_ASSERT(Mode !=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
1065 m_matrix.template block<Dim, HDim>(0, 0) =
1066 LinearMatrixType({{1, sy}, {sx, 1}}) * m_matrix.template block<Dim, HDim>(0, 0);
1074template <
typename Scalar,
int Dim,
int Mode,
int Options>
1076 const TranslationType& t) {
1078 translation() = t.vector();
1083template <
typename Scalar,
int Dim,
int Mode,
int Options>
1085 const TranslationType& t)
const {
1086 Transform res = *
this;
1087 res.translate(t.vector());
1091template <
typename Scalar,
int Dim,
int Mode,
int Options>
1095 linear().diagonal().fill(s.factor());
1100template <
typename Scalar,
int Dim,
int Mode,
int Options>
1101template <
typename Derived>
1104 linear() = internal::toRotationMatrix<Scalar, Dim>(r);
1105 translation().setZero();
1110template <
typename Scalar,
int Dim,
int Mode,
int Options>
1111template <
typename Derived>
1115 res.rotate(r.derived());
1125struct transform_rotation_impl {
1126 template <
typename TransformType>
1127 EIGEN_DEVICE_FUNC
static inline const typename TransformType::LinearMatrixType run(
const TransformType& t) {
1128 using LinearMatrixType =
typename TransformType::LinearMatrixType;
1129 LinearMatrixType result;
1130 t.computeRotationScaling(&result, (LinearMatrixType*)0);
1135struct transform_rotation_impl<
Isometry> {
1136 template <
typename TransformType>
1137 EIGEN_DEVICE_FUNC
static inline typename TransformType::ConstLinearPart run(
const TransformType& t) {
1152template <
typename Scalar,
int Dim,
int Mode,
int Options>
1153EIGEN_DEVICE_FUNC
typename Transform<Scalar, Dim, Mode, Options>::RotationReturnType
1155 return internal::transform_rotation_impl<Mode>::run(*
this);
1169template <
typename Scalar,
int Dim,
int Mode,
int Options>
1170template <
typename RotationMatrixType,
typename ScalingMatrixType>
1172 ScalingMatrixType* scaling)
const {
1181 if (scaling) (*scaling).noalias() = svd.
matrixV() * sv.asDiagonal() * svd.
matrixV().adjoint();
1184 m.col(Dim - 1) *= x;
1185 (*rotation).noalias() = m * svd.
matrixV().adjoint();
1200template <
typename Scalar,
int Dim,
int Mode,
int Options>
1201template <
typename ScalingMatrixType,
typename RotationMatrixType>
1203 ScalingMatrixType* scaling, RotationMatrixType*
rotation)
const {
1212 if (scaling) *scaling = svd.
matrixU() * sv.asDiagonal() * svd.
matrixU().adjoint();
1215 m.col(Dim - 1) *= x;
1223template <
typename Scalar,
int Dim,
int Mode,
int Options>
1224template <
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
1227 const OrientationType& orientation,
1229 linear() = internal::toRotationMatrix<Scalar, Dim>(orientation);
1230 linear() *= scale.asDiagonal();
1239struct transform_make_affine {
1240 template <
typename MatrixType>
1241 EIGEN_DEVICE_FUNC
static void run(MatrixType& mat) {
1242 static const int Dim = MatrixType::ColsAtCompileTime - 1;
1243 mat.template block<1, Dim>(Dim, 0).setZero();
1244 mat.coeffRef(Dim, Dim) =
typename MatrixType::Scalar(1);
1250 template <
typename MatrixType>
1251 EIGEN_DEVICE_FUNC
static void run(MatrixType&) {}
1257template <
typename TransformType,
int Mode = TransformType::Mode>
1258struct projective_transform_inverse {
1259 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType& m, TransformType& res) { res = m.inverse(
Affine); }
1262template <
typename TransformType>
1263struct projective_transform_inverse<TransformType,
Projective> {
1264 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType& m, TransformType& res) {
1265 res.matrix() = m.matrix().inverse();
1291template <
typename Scalar,
int Dim,
int Mode,
int Options>
1296 internal::projective_transform_inverse<Transform>::run(*
this, res);
1299 res.
matrix().template topLeftCorner<Dim, Dim>() =
linear().transpose();
1300 }
else if (hint &
Affine) {
1301 res.
matrix().template topLeftCorner<Dim, Dim>() =
linear().inverse();
1303 eigen_assert(
false &&
"Invalid transform traits in Transform::Inverse");
1306 res.
matrix().template topRightCorner<Dim, 1>().noalias() =
1319template <
typename TransformType>
1320struct transform_take_affine_part {
1321 using MatrixType =
typename TransformType::MatrixType;
1322 using AffinePart =
typename TransformType::AffinePart;
1323 using ConstAffinePart =
typename TransformType::ConstAffinePart;
1324 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE AffinePart run(MatrixType& m) {
1325 return m.template block<TransformType::Dim, TransformType::HDim>(0, 0);
1327 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstAffinePart run(
const MatrixType& m) {
1328 return m.template block<TransformType::Dim, TransformType::HDim>(0, 0);
1332template <
typename Scalar,
int Dim,
int Options>
1333struct transform_take_affine_part<Transform<Scalar, Dim,
AffineCompact, Options> > {
1335 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE MatrixType& run(MatrixType& m) {
return m; }
1336 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const MatrixType& run(
const MatrixType& m) {
return m; }
1343template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1344struct transform_construct_from_matrix<Other, Mode, Options, Dim, HDim, Dim, Dim> {
1345 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
1346 Transform<typename Other::Scalar, Dim, Mode, Options>* transform,
const Other& other) {
1347 transform->linear() = other;
1348 transform->translation().setZero();
1349 transform->makeAffine();
1353template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1354struct transform_construct_from_matrix<Other, Mode, Options, Dim, HDim, Dim, HDim> {
1355 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
1356 Transform<typename Other::Scalar, Dim, Mode, Options>* transform,
const Other& other) {
1357 transform->affine() = other;
1358 transform->makeAffine();
1362template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1363struct transform_construct_from_matrix<Other, Mode, Options, Dim, HDim, HDim, HDim> {
1364 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
1365 Transform<typename Other::Scalar, Dim, Mode, Options>* transform,
const Other& other) {
1366 transform->matrix() = other;
1369 transform->matrix());
1373template <
typename Other,
int Options,
int Dim,
int HDim>
1374struct transform_construct_from_matrix<Other,
AffineCompact, Options, Dim, HDim, HDim, HDim> {
1375 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
1376 Transform<typename Other::Scalar, Dim, AffineCompact, Options>* transform,
const Other& other) {
1377 transform->matrix() = other.template block<Dim, HDim>(0, 0);
1385template <
int LhsMode,
int RhsMode>
1386struct transform_product_result {
1396template <
typename TransformType,
typename MatrixType,
int RhsCols>
1397struct transform_right_product_impl<TransformType, MatrixType, 0, RhsCols> {
1398 using ResultType =
typename MatrixType::PlainObject;
1400 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other) {
1401 return T.matrix() * other;
1405template <
typename TransformType,
typename MatrixType,
int RhsCols>
1406struct transform_right_product_impl<TransformType, MatrixType, 1, RhsCols> {
1408 Dim = TransformType::Dim,
1409 HDim = TransformType::HDim,
1410 OtherRows = MatrixType::RowsAtCompileTime,
1411 OtherCols = MatrixType::ColsAtCompileTime
1414 using ResultType =
typename MatrixType::PlainObject;
1416 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other) {
1417 EIGEN_STATIC_ASSERT(OtherRows == HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1419 using TopLeftLhs = Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime) == Dim>;
1421 ResultType res(other.rows(), other.cols());
1422 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other;
1423 res.row(OtherRows - 1) = other.row(OtherRows - 1);
1429template <
typename TransformType,
typename MatrixType,
int RhsCols>
1430struct transform_right_product_impl<TransformType, MatrixType, 2, RhsCols> {
1432 Dim = TransformType::Dim,
1433 HDim = TransformType::HDim,
1434 OtherRows = MatrixType::RowsAtCompileTime,
1435 OtherCols = MatrixType::ColsAtCompileTime
1438 using ResultType =
typename MatrixType::PlainObject;
1440 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other) {
1441 EIGEN_STATIC_ASSERT(OtherRows == Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1443 using TopLeftLhs = Block<ResultType, Dim, OtherCols, true>;
1445 Replicate<typename TransformType::ConstTranslationPart, 1, OtherCols>(T.translation(), 1, other.cols()));
1446 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
1452template <
typename TransformType,
typename MatrixType>
1453struct transform_right_product_impl<TransformType, MatrixType, 2, 1>
1455 using TransformMatrix =
typename TransformType::MatrixType;
1457 Dim = TransformType::Dim,
1458 HDim = TransformType::HDim,
1459 OtherRows = MatrixType::RowsAtCompileTime,
1460 WorkingRows = plain_enum_min(TransformMatrix::RowsAtCompileTime, HDim)
1463 using ResultType =
typename MatrixType::PlainObject;
1465 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other) {
1466 EIGEN_STATIC_ASSERT(OtherRows == Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1468 Matrix<typename ResultType::Scalar, Dim + 1, 1> rhs;
1469 rhs.template head<Dim>() = other;
1470 rhs[Dim] =
typename ResultType::Scalar(1);
1471 Matrix<typename ResultType::Scalar, WorkingRows, 1> res(T.matrix() * rhs);
1472 return res.template head<Dim>();
1481template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1482struct transform_left_product_impl<Other, Mode, Options, Dim, HDim, HDim, HDim> {
1483 using TransformType = Transform<typename Other::Scalar, Dim, Mode, Options>;
1484 using MatrixType =
typename TransformType::MatrixType;
1485 using ResultType = Transform<typename Other::Scalar, Dim, Projective, Options>;
1486 static EIGEN_DEVICE_FUNC ResultType run(
const Other& other,
const TransformType& tr) {
1487 return ResultType(other * tr.matrix());
1492template <
typename Other,
int Options,
int Dim,
int HDim>
1493struct transform_left_product_impl<Other,
AffineCompact, Options, Dim, HDim, HDim, HDim> {
1494 using TransformType = Transform<typename Other::Scalar, Dim, AffineCompact, Options>;
1495 using MatrixType =
typename TransformType::MatrixType;
1496 using ResultType = Transform<typename Other::Scalar, Dim, Projective, Options>;
1497 static EIGEN_DEVICE_FUNC ResultType run(
const Other& other,
const TransformType& tr) {
1499 res.matrix().noalias() = other.template block<HDim, Dim>(0, 0) * tr.matrix();
1500 res.matrix().col(Dim) += other.col(Dim);
1506template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1507struct transform_left_product_impl<Other, Mode, Options, Dim, HDim, Dim, HDim> {
1508 using TransformType = Transform<typename Other::Scalar, Dim, Mode, Options>;
1509 using MatrixType =
typename TransformType::MatrixType;
1510 using ResultType = TransformType;
1511 static EIGEN_DEVICE_FUNC ResultType run(
const Other& other,
const TransformType& tr) {
1513 res.affine().noalias() = other * tr.matrix();
1514 res.matrix().row(Dim) = tr.matrix().row(Dim);
1520template <
typename Other,
int Options,
int Dim,
int HDim>
1521struct transform_left_product_impl<Other,
AffineCompact, Options, Dim, HDim, Dim, HDim> {
1522 using TransformType = Transform<typename Other::Scalar, Dim, AffineCompact, Options>;
1523 using MatrixType =
typename TransformType::MatrixType;
1524 using ResultType = TransformType;
1525 static EIGEN_DEVICE_FUNC ResultType run(
const Other& other,
const TransformType& tr) {
1527 res.matrix().noalias() = other.template block<Dim, Dim>(0, 0) * tr.matrix();
1528 res.translation() += other.col(Dim);
1534template <
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1535struct transform_left_product_impl<Other, Mode, Options, Dim, HDim, Dim, Dim> {
1536 using TransformType = Transform<typename Other::Scalar, Dim, Mode, Options>;
1537 using MatrixType =
typename TransformType::MatrixType;
1538 using ResultType = TransformType;
1539 static EIGEN_DEVICE_FUNC ResultType run(
const Other& other,
const TransformType& tr) {
1541 EIGEN_IF_CONSTEXPR (Mode !=
int(AffineCompact)) res.matrix().row(Dim) = tr.matrix().row(Dim);
1542 res.matrix().template topRows<Dim>().noalias() = other * tr.matrix().template topRows<Dim>();
1551template <
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1552struct transform_transform_product_impl<Transform<Scalar, Dim, LhsMode, LhsOptions>,
1553 Transform<Scalar, Dim, RhsMode, RhsOptions>, false> {
1554 enum { ResultMode = transform_product_result<LhsMode, RhsMode>::Mode };
1555 using Lhs = Transform<Scalar, Dim, LhsMode, LhsOptions>;
1556 using Rhs = Transform<Scalar, Dim, RhsMode, RhsOptions>;
1557 using ResultType = Transform<Scalar, Dim, ResultMode, LhsOptions>;
1558 static EIGEN_DEVICE_FUNC ResultType run(
const Lhs& lhs,
const Rhs& rhs) {
1560 res.linear().noalias() = lhs.linear() * rhs.linear();
1561 res.translation().noalias() = lhs.linear() * rhs.translation() + lhs.translation();
1567template <
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1568struct transform_transform_product_impl<Transform<Scalar, Dim, LhsMode, LhsOptions>,
1569 Transform<Scalar, Dim, RhsMode, RhsOptions>, true> {
1570 using Lhs = Transform<Scalar, Dim, LhsMode, LhsOptions>;
1571 using Rhs = Transform<Scalar, Dim, RhsMode, RhsOptions>;
1572 using ResultType = Transform<Scalar, Dim, Projective>;
1573 static EIGEN_DEVICE_FUNC ResultType run(
const Lhs& lhs,
const Rhs& rhs) {
1574 return ResultType(lhs.matrix() * rhs.matrix());
1578template <
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1579struct transform_transform_product_impl<Transform<Scalar, Dim,
AffineCompact, LhsOptions>,
1580 Transform<Scalar, Dim,
Projective, RhsOptions>, true> {
1581 using Lhs = Transform<Scalar, Dim, AffineCompact, LhsOptions>;
1582 using Rhs = Transform<Scalar, Dim, Projective, RhsOptions>;
1583 using ResultType = Transform<Scalar, Dim, Projective>;
1584 static EIGEN_DEVICE_FUNC ResultType run(
const Lhs& lhs,
const Rhs& rhs) {
1586 res.matrix().template topRows<Dim>().noalias() = lhs.matrix() * rhs.matrix();
1587 res.matrix().row(Dim) = rhs.matrix().row(Dim);
1592template <
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1593struct transform_transform_product_impl<Transform<Scalar, Dim,
Projective, LhsOptions>,
1595 using Lhs = Transform<Scalar, Dim, Projective, LhsOptions>;
1596 using Rhs = Transform<Scalar, Dim, AffineCompact, RhsOptions>;
1597 using ResultType = Transform<Scalar, Dim, Projective>;
1598 static EIGEN_DEVICE_FUNC ResultType run(
const Lhs& lhs,
const Rhs& rhs) {
1599 ResultType res(lhs.matrix().template leftCols<Dim>() * rhs.matrix());
1600 res.matrix().col(Dim) += lhs.matrix().col(Dim);
Expression of a fixed-size or dynamic-size block.
Definition Block.h:111
Base class for diagonal matrices and expressions.
Definition DiagonalMatrix.h:34
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition JacobiSVD.h:616
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
constexpr const DiagonalWrapper< const Derived > asDiagonal() const
Definition DiagonalMatrix.h:428
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
constexpr Scalar & coeffRef(Index rowId, Index colId)
Definition PlainObjectBase.h:205
Common base class for compact rotation representations.
Definition RotationBase.h:33
const SingularValuesType & singularValues() const
Definition SVDBase.h:203
const MatrixUType & matrixU() const
Definition SVDBase.h:176
const MatrixVType & matrixV() const
Definition SVDBase.h:192
Represents a translation transformation.
Definition Translation.h:34
TransformTraits
Definition Constants.h:470
@ DontAlign
Definition Constants.h:325
@ RowMajor
Definition Constants.h:321
@ Affine
Definition Constants.h:475
@ Projective
Definition Constants.h:479
@ AffineCompact
Definition Constants.h:477
@ Isometry
Definition Constants.h:472
constexpr unsigned int RowMajorBit
Definition Constants.h:71
Definition EigenBase.h:34
constexpr Derived & derived()
Definition EigenBase.h:50