Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
Transform.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
7//
8// This Source Code Form is subject to the terms of the Mozilla
9// Public License v. 2.0. If a copy of the MPL was not distributed
10// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11// SPDX-License-Identifier: MPL-2.0
12
13#ifndef EIGEN_TRANSFORM_H
14#define EIGEN_TRANSFORM_H
15
16// IWYU pragma: private
17#include "./InternalHeaderCheck.h"
18
19namespace Eigen {
20
21namespace internal {
22
23template <typename Transform>
24struct transform_traits {
25 enum {
26 Dim = Transform::Dim,
27 HDim = Transform::HDim,
28 Mode = Transform::Mode,
29 IsProjective = (int(Mode) == int(Projective))
30 };
31};
32
33template <typename TransformType, typename MatrixType,
34 int Case = transform_traits<TransformType>::IsProjective ? 0
35 : int(MatrixType::RowsAtCompileTime) == int(transform_traits<TransformType>::HDim) ? 1
36 : 2,
37 int RhsCols = MatrixType::ColsAtCompileTime>
38struct transform_right_product_impl;
39
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;
43
44template <typename Lhs, typename Rhs,
45 bool AnyProjective = transform_traits<Lhs>::IsProjective || transform_traits<Rhs>::IsProjective>
46struct transform_transform_product_impl;
47
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;
51
52template <typename TransformType>
53struct transform_take_affine_part;
54
55template <typename LhsScalar, typename RhsScalar, typename BinaryOp, typename TargetScalar, typename = void>
56struct has_matching_binary_op_traits : std::false_type {};
57
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> {};
66
67template <typename TargetScalar, typename Derived, typename LhsScalar, typename RhsScalar, typename BinaryOp,
68 typename = void>
69struct transform_convert_arg {
70 EIGEN_DEVICE_FUNC static auto run(const MatrixBase<Derived>& mat) { return mat.template cast<TargetScalar>(); }
71};
72
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(); }
79};
80
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;
86 enum {
87 Dim1 = Dim_ == Dynamic ? Dim_ : Dim_ + 1,
88 RowsAtCompileTime = Mode_ == Projective ? Dim1 : Dim_,
89 ColsAtCompileTime = Dim1,
90 MaxRowsAtCompileTime = RowsAtCompileTime,
91 MaxColsAtCompileTime = ColsAtCompileTime,
92 Flags = 0
93 };
94};
95
96template <int Mode>
97struct transform_make_affine;
98
99} // end namespace internal
100
221template <typename Scalar_, int Dim_, int Mode_, int Options_>
223 public:
225 Dim_ == Dynamic ? Dynamic : (Dim_ + 1) * (Dim_ + 1))
226 enum {
227 Mode = Mode_,
228 Options = Options_,
229 Dim = Dim_,
230 HDim = Dim_ + 1,
231 Rows = int(Mode) == int(AffineCompact) ? Dim : HDim
232 };
233
234 using Scalar = Scalar_;
235 using StorageIndex = Eigen::Index;
236 using Index = Eigen::Index;
238 using MatrixType = typename internal::make_proper_matrix_type<Scalar, Rows, HDim, Options>::type;
244 using LinearPart = Block<MatrixType, Dim, Dim, int(Mode) == (AffineCompact) && (int(Options) & RowMajor) == 0>;
247 const Block<ConstMatrixType, Dim, Dim, int(Mode) == (AffineCompact) && (int(Options) & RowMajor) == 0>;
249 using AffinePart = std::conditional_t<int(Mode) == int(AffineCompact), MatrixType&, Block<MatrixType, Dim, HDim>>;
252 std::conditional_t<int(Mode) == int(AffineCompact), const MatrixType&, const Block<const MatrixType, Dim, HDim>>;
256 using TranslationPart = Block<MatrixType, Dim, 1, !(internal::traits<MatrixType>::Flags & RowMajorBit)>;
259 const Block<ConstMatrixType, Dim, 1, !(internal::traits<MatrixType>::Flags & RowMajorBit)>;
262
264 using TransformTimeDiagonalReturnType = Transform<Scalar, Dim, (Mode == int(Isometry)) ? int(Affine) : int(Mode)>;
265
266 protected:
267 MatrixType m_matrix;
268
269 public:
272 EIGEN_DEVICE_FUNC inline Transform() {
273 check_template_params();
274 internal::transform_make_affine<(int(Mode) == Affine || int(Mode) == Isometry) ? Affine : AffineCompact>::run(
275 m_matrix);
276 }
277
278 // These conversion ctors are intentionally `explicit`: keeping copy-init
279 // (`Transform t = rot;`) from compiling stops a Dim+1 x Dim+1 matrix
280 // from being silently materialized in function-call argument lists.
281 // Use direct-init (`Transform t(rot);`) or assignment (`Transform t; t = rot;`)
282 // instead. See bug #1209.
283 EIGEN_DEVICE_FUNC inline explicit Transform(const TranslationType& t) {
284 check_template_params();
285 *this = t;
286 }
287 EIGEN_DEVICE_FUNC inline explicit Transform(const UniformScaling<Scalar>& s) {
288 check_template_params();
289 *this = s;
290 }
291 template <typename Derived>
292 EIGEN_DEVICE_FUNC inline explicit Transform(const RotationBase<Derived, Dim>& r) {
293 check_template_params();
294 *this = r;
295 }
296
297 using take_affine_part = internal::transform_take_affine_part<Transform>;
298
301 template <typename OtherDerived>
302 EIGEN_DEVICE_FUNC inline explicit Transform(const EigenBase<OtherDerived>& other) {
303 EIGEN_STATIC_ASSERT(
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);
306
307 check_template_params();
308 internal::transform_construct_from_matrix<OtherDerived, Mode, Options, Dim, HDim>::run(this, other.derived());
309 }
310
313 template <typename OtherDerived>
314 EIGEN_DEVICE_FUNC inline Transform& operator=(const EigenBase<OtherDerived>& other) {
315 EIGEN_STATIC_ASSERT(
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);
318
319 internal::transform_construct_from_matrix<OtherDerived, Mode, Options, Dim, HDim>::run(this, other.derived());
320 return *this;
321 }
322
323 template <int OtherOptions>
324 EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar, Dim, Mode, OtherOptions>& other) {
325 check_template_params();
326 // only the options change, we can directly copy the matrices
327 m_matrix = other.matrix();
328 }
329
330 template <int OtherMode, int OtherOptions>
331 EIGEN_DEVICE_FUNC inline Transform(const Transform<Scalar, Dim, OtherMode, OtherOptions>& other) {
332 check_template_params();
333 // prevent conversions as:
334 // Affine | AffineCompact | Isometry = Projective
335 EIGEN_STATIC_ASSERT(internal::check_implication(OtherMode == int(Projective), Mode == int(Projective)),
336 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
337
338 // prevent conversions as:
339 // Isometry = Affine | AffineCompact
340 EIGEN_STATIC_ASSERT(
341 internal::check_implication(OtherMode == int(Affine) || OtherMode == int(AffineCompact), Mode != int(Isometry)),
342 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
343
344 enum {
345 ModeIsAffineCompact = Mode == int(AffineCompact),
346 OtherModeIsAffineCompact = OtherMode == int(AffineCompact)
347 };
348
349 if (EIGEN_CONST_CONDITIONAL(ModeIsAffineCompact == OtherModeIsAffineCompact)) {
350 // We need the block expression because the code is compiled for all
351 // combinations of transformations and will trigger a compile time error
352 // if one tries to assign the matrices directly
353 m_matrix.template block<Dim, Dim + 1>(0, 0) = other.matrix().template block<Dim, Dim + 1>(0, 0);
354 makeAffine();
355 } else if (EIGEN_CONST_CONDITIONAL(OtherModeIsAffineCompact)) {
357 internal::transform_construct_from_matrix<OtherMatrixType, Mode, Options, Dim, HDim>::run(this, other.matrix());
358 } else {
359 // here we know that Mode == AffineCompact and OtherMode != AffineCompact.
360 // if OtherMode were Projective, the static assert above would already have caught it.
361 // So the only possibility is that OtherMode == Affine
362 linear() = other.linear();
363 translation() = other.translation();
364 }
365 }
366
367 template <typename OtherDerived>
368 EIGEN_DEVICE_FUNC Transform(const ReturnByValue<OtherDerived>& other) {
369 check_template_params();
370 other.evalTo(*this);
371 }
372
373 template <typename OtherDerived>
374 EIGEN_DEVICE_FUNC Transform& operator=(const ReturnByValue<OtherDerived>& other) {
375 other.evalTo(*this);
376 return *this;
377 }
378
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;
384#endif
385 EIGEN_DEPRECATED_WITH_REASON("Copy the coefficients explicitly.") inline Transform(const QTransform& other);
386 EIGEN_DEPRECATED_WITH_REASON("Copy the coefficients explicitly.")
387 inline Transform& operator=(const QTransform& other);
388 EIGEN_DEPRECATED_WITH_REASON("Copy the coefficients explicitly.") inline QTransform toQTransform(void) const;
389#endif
390
391 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept {
392 return int(Mode) == int(Projective) ? m_matrix.cols() : (m_matrix.cols() - 1);
393 }
394 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return m_matrix.cols(); }
395
398 EIGEN_DEVICE_FUNC inline Scalar operator()(Index row, Index col) const { return m_matrix(row, col); }
401 EIGEN_DEVICE_FUNC inline Scalar& operator()(Index row, Index col) { return m_matrix(row, col); }
402
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]; }
410#endif
411
413 EIGEN_DEVICE_FUNC inline const MatrixType& matrix() const { return m_matrix; }
415 EIGEN_DEVICE_FUNC inline MatrixType& matrix() { return m_matrix; }
416
418 EIGEN_DEVICE_FUNC inline ConstLinearPart linear() const { return ConstLinearPart(m_matrix, 0, 0); }
420 EIGEN_DEVICE_FUNC inline LinearPart linear() { return LinearPart(m_matrix, 0, 0); }
421
423 EIGEN_DEVICE_FUNC inline ConstAffinePart affine() const { return take_affine_part::run(m_matrix); }
425 EIGEN_DEVICE_FUNC inline AffinePart affine() { return take_affine_part::run(m_matrix); }
426
428 EIGEN_DEVICE_FUNC inline ConstTranslationPart translation() const { return ConstTranslationPart(m_matrix, 0, Dim); }
430 EIGEN_DEVICE_FUNC inline TranslationPart translation() { return TranslationPart(m_matrix, 0, Dim); }
431
457 // note: this function is defined here because some compilers cannot find the respective declaration
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());
463 }
464
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);
477 }
478
485 template <typename DiagonalDerived>
486 EIGEN_DEVICE_FUNC inline const TransformTimeDiagonalReturnType operator*(
487 const DiagonalBase<DiagonalDerived>& b) const {
489 res.linearExt() *= b;
490 return res;
491 }
492
499 template <typename DiagonalDerived>
501 const Transform& b) {
503 res.linear().noalias() = a * b.linear();
504 res.translation().noalias() = a * b.translation();
505 if (EIGEN_CONST_CONDITIONAL(Mode != int(AffineCompact))) res.matrix().row(Dim) = b.matrix().row(Dim);
506 return res;
507 }
508
509 template <typename OtherDerived>
510 EIGEN_DEVICE_FUNC inline Transform& operator*=(const MatrixBase<OtherDerived>& other) {
511 return *this = *this * other;
512 }
513
515 EIGEN_DEVICE_FUNC inline const Transform operator*(const Transform& other) const {
516 return internal::transform_transform_product_impl<Transform, Transform>::run(*this, other);
517 }
518
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(
526 *this, other);
527 }
528
530 EIGEN_DEVICE_FUNC void setIdentity() { m_matrix.setIdentity(); }
531
536 EIGEN_DEVICE_FUNC static const Transform Identity() { return Transform(MatrixType::Identity()); }
537
538 template <typename OtherDerived>
539 EIGEN_DEVICE_FUNC inline Transform& scale(const MatrixBase<OtherDerived>& other);
540
541 template <typename OtherDerived>
542 EIGEN_DEVICE_FUNC inline Transform& prescale(const MatrixBase<OtherDerived>& other);
543
544 EIGEN_DEVICE_FUNC inline Transform& scale(const Scalar& s);
545 EIGEN_DEVICE_FUNC inline Transform& prescale(const Scalar& s);
546
547 template <typename OtherDerived>
548 EIGEN_DEVICE_FUNC inline Transform& translate(const MatrixBase<OtherDerived>& other);
549
550 template <typename OtherDerived>
551 EIGEN_DEVICE_FUNC inline Transform& pretranslate(const MatrixBase<OtherDerived>& other);
552
553 template <typename RotationType>
554 EIGEN_DEVICE_FUNC inline Transform& rotate(const RotationType& rotation);
555
556 template <typename RotationType>
557 EIGEN_DEVICE_FUNC inline Transform& prerotate(const RotationType& rotation);
558
559 EIGEN_DEVICE_FUNC Transform& shear(const Scalar& sx, const Scalar& sy);
560 EIGEN_DEVICE_FUNC Transform& preshear(const Scalar& sx, const Scalar& sy);
561
562 EIGEN_DEVICE_FUNC inline Transform& operator=(const TranslationType& t);
563
564 EIGEN_DEVICE_FUNC inline Transform& operator*=(const TranslationType& t) { return translate(t.vector()); }
565
566 EIGEN_DEVICE_FUNC inline Transform operator*(const TranslationType& t) const;
567
568 EIGEN_DEVICE_FUNC inline Transform& operator=(const UniformScaling<Scalar>& t);
569
570 EIGEN_DEVICE_FUNC inline Transform& operator*=(const UniformScaling<Scalar>& s) { return scale(s.factor()); }
571
572 EIGEN_DEVICE_FUNC inline TransformTimeDiagonalReturnType operator*(const UniformScaling<Scalar>& s) const {
574 res.scale(s.factor());
575 return res;
576 }
577
578 EIGEN_DEVICE_FUNC inline Transform& operator*=(const DiagonalMatrix<Scalar, Dim>& s) {
579 linearExt() *= s;
580 return *this;
581 }
582
583 template <typename Derived>
584 EIGEN_DEVICE_FUNC inline Transform& operator=(const RotationBase<Derived, Dim>& r);
585 template <typename Derived>
586 EIGEN_DEVICE_FUNC inline Transform& operator*=(const RotationBase<Derived, Dim>& r) {
587 return rotate(r.toRotationMatrix());
588 }
589 template <typename Derived>
590 EIGEN_DEVICE_FUNC inline Transform operator*(const RotationBase<Derived, Dim>& r) const;
591
592 using RotationReturnType = std::conditional_t<int(Mode) == Isometry, ConstLinearPart, const LinearMatrixType>;
593 EIGEN_DEVICE_FUNC RotationReturnType rotation() const;
594
595 template <typename RotationMatrixType, typename ScalingMatrixType>
596 EIGEN_DEVICE_FUNC void computeRotationScaling(RotationMatrixType* rotation, ScalingMatrixType* scaling) const;
597 template <typename ScalingMatrixType, typename RotationMatrixType>
598 EIGEN_DEVICE_FUNC void computeScalingRotation(ScalingMatrixType* scaling, RotationMatrixType* rotation) const;
599
600 template <typename PositionDerived, typename OrientationType, typename ScaleDerived>
601 EIGEN_DEVICE_FUNC Transform& fromPositionOrientationScale(const MatrixBase<PositionDerived>& position,
602 const OrientationType& orientation,
603 const MatrixBase<ScaleDerived>& scale);
604
605 EIGEN_DEVICE_FUNC inline Transform inverse(TransformTraits traits = (TransformTraits)Mode) const;
606
608 EIGEN_DEVICE_FUNC constexpr const Scalar* data() const { return m_matrix.data(); }
610 EIGEN_DEVICE_FUNC constexpr Scalar* data() { return m_matrix.data(); }
611
617 template <typename NewScalarType>
618 EIGEN_DEVICE_FUNC inline
619 typename internal::cast_return_type<Transform, Transform<NewScalarType, Dim, Mode, Options> >::type
620 cast() const {
621 return typename internal::cast_return_type<Transform, Transform<NewScalarType, Dim, Mode, Options> >::type(*this);
622 }
623
625 template <typename OtherScalarType>
626 EIGEN_DEVICE_FUNC inline explicit Transform(const Transform<OtherScalarType, Dim, Mode, Options>& other) {
627 check_template_params();
628 m_matrix = other.matrix().template cast<Scalar>();
629 }
630
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);
638 }
639
642 EIGEN_DEVICE_FUNC void makeAffine() { internal::transform_make_affine<int(Mode)>::run(m_matrix); }
643
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);
650 }
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);
657 }
658
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);
665 }
670 EIGEN_DEVICE_FUNC inline const Block<MatrixType, int(Mode) == int(Projective) ? HDim : Dim, 1> translationExt()
671 const {
672 return m_matrix.template block < int(Mode) == int(Projective) ? HDim : Dim, 1 > (0, Dim);
673 }
674
675#ifdef EIGEN_TRANSFORM_PLUGIN
676#include EIGEN_TRANSFORM_PLUGIN
677#endif
678
679 protected:
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)
683 }
684#endif
685};
686
688using Isometry2f = Transform<float, 2, Isometry>;
690using Isometry3f = Transform<float, 3, Isometry>;
692using Isometry2d = Transform<double, 2, Isometry>;
694using Isometry3d = Transform<double, 3, Isometry>;
695
697using Affine2f = Transform<float, 2, Affine>;
699using Affine3f = Transform<float, 3, Affine>;
701using Affine2d = Transform<double, 2, Affine>;
703using Affine3d = Transform<double, 3, Affine>;
704
706using AffineCompact2f = Transform<float, 2, AffineCompact>;
708using AffineCompact3f = Transform<float, 3, AffineCompact>;
710using AffineCompact2d = Transform<double, 2, AffineCompact>;
712using AffineCompact3d = Transform<double, 3, AffineCompact>;
713
715using Projective2f = Transform<float, 2, Projective>;
717using Projective3f = Transform<float, 3, Projective>;
719using Projective2d = Transform<double, 2, Projective>;
721using Projective3d = Transform<double, 3, Projective>;
722
723/**************************
724*** Optional QT support ***
725**************************/
726
727#ifdef EIGEN_QT_SUPPORT
728
729// The deprecated constructors call the deprecated assignment operators.
730EIGEN_DIAGNOSTICS(push)
731EIGEN_DIAGNOSTICS_OFF(disable : 4996, ignored "-Wdeprecated-declarations")
732
733#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
740template <typename Scalar, int Dim, int Mode, int Options>
742 check_template_params();
743 *this = other;
744}
745
752template <typename Scalar, int Dim, int Mode, int Options>
754 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
755 if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
756 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy();
757 else
758 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy(), 0, 0, 1;
759 return *this;
760}
761
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));
776}
777#endif
778
785template <typename Scalar, int Dim, int Mode, int Options>
787 check_template_params();
788 *this = other;
789}
790
797template <typename Scalar, int Dim, int Mode, int Options>
799 check_template_params();
800 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
801 if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
802 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy();
803 else
804 m_matrix << other.m11(), other.m21(), other.dx(), other.m12(), other.m22(), other.dy(), other.m13(), other.m23(),
805 other.m33();
806 return *this;
807}
808
815template <typename Scalar, int Dim, int Mode, int Options>
817 EIGEN_STATIC_ASSERT(Dim == 2, YOU_MADE_A_PROGRAMMING_MISTAKE)
818 if (EIGEN_CONST_CONDITIONAL(Mode == int(AffineCompact)))
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));
821 else
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));
825}
826
827EIGEN_DIAGNOSTICS(pop)
828#endif
829
830/*********************
831*** Procedural API ***
832*********************/
833
838template <typename Scalar, int Dim, int Mode, int Options>
839template <typename OtherDerived>
840EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::scale(
841 const MatrixBase<OtherDerived>& other) {
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();
845 return *this;
846}
847
852template <typename Scalar, int Dim, int Mode, int Options>
853EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::scale(
854 const Scalar& s) {
855 EIGEN_STATIC_ASSERT(Mode != int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
856 linearExt() *= s;
857 return *this;
858}
859
864template <typename Scalar, int Dim, int Mode, int Options>
865template <typename OtherDerived>
866EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::prescale(
867 const MatrixBase<OtherDerived>& other) {
868 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, int(Dim))
869 EIGEN_STATIC_ASSERT(Mode != int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
870 affine() = other.asDiagonal() * affine();
871 return *this;
872}
873
878template <typename Scalar, int Dim, int Mode, int Options>
879EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::prescale(
880 const Scalar& s) {
881 EIGEN_STATIC_ASSERT(Mode != int(Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
882 m_matrix.template topRows<Dim>() *= s;
883 return *this;
884}
885
890template <typename Scalar, int Dim, int Mode, int Options>
891template <typename OtherDerived>
892EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::translate(
893 const MatrixBase<OtherDerived>& other) {
894 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, int(Dim))
895 translationExt() +=
896 linearExt() *
897 internal::transform_convert_arg<Scalar, OtherDerived, Scalar, typename OtherDerived::Scalar,
898 internal::fast_mult_op<Scalar, typename OtherDerived::Scalar>>::run(other);
899 return *this;
900}
901
906template <typename Scalar, int Dim, int Mode, int Options>
907template <typename OtherDerived>
908EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::pretranslate(
909 const MatrixBase<OtherDerived>& other) {
910 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived, int(Dim))
911 if (EIGEN_CONST_CONDITIONAL(int(Mode) == int(Projective)))
912 affine() +=
913 internal::transform_convert_arg<Scalar, OtherDerived, typename OtherDerived::Scalar, Scalar,
914 internal::fast_mult_op<typename OtherDerived::Scalar, Scalar>>::run(other) *
915 m_matrix.row(Dim);
916 else
917 translation() +=
918 internal::transform_convert_arg<Scalar, OtherDerived, Scalar, typename OtherDerived::Scalar,
919 internal::scalar_sum_op<Scalar, typename OtherDerived::Scalar>>::run(other);
920 return *this;
921}
922
923namespace internal {
924
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);
929 }
930};
931
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);
940 }
941};
942
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());
949 }
950};
951
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());
957 }
958};
959
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);
966 }
967};
968
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);
979 }
980};
981
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());
988 }
989};
990
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());
996 }
997};
998
999} // end namespace internal
1000
1018template <typename Scalar, int Dim, int Mode, int Options>
1019template <typename RotationType>
1020EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::rotate(
1021 const RotationType& rotation) {
1022 internal::transform_rotate_impl<Transform, RotationType>::run(*this, rotation);
1023 return *this;
1024}
1025
1033template <typename Scalar, int Dim, int Mode, int Options>
1034template <typename RotationType>
1035EIGEN_DEVICE_FUNC Transform<Scalar, Dim, Mode, Options>& Transform<Scalar, Dim, Mode, Options>::prerotate(
1036 const RotationType& rotation) {
1037 internal::transform_prerotate_impl<Transform, RotationType>::run(*this, rotation);
1038 return *this;
1039}
1040
1046template <typename Scalar, int Dim, int Mode, int Options>
1048 const Scalar& sx, const Scalar& sy) {
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)
1051 linearExt() = linearExt() * LinearMatrixType({{1, sy}, {sx, 1}});
1052 return *this;
1053}
1054
1060template <typename Scalar, int Dim, int Mode, int Options>
1062 const Scalar& sx, const Scalar& sy) {
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);
1067 return *this;
1068}
1069
1070/******************************************************
1071*** Scaling, Translation and Rotation compatibility ***
1072******************************************************/
1073
1074template <typename Scalar, int Dim, int Mode, int Options>
1076 const TranslationType& t) {
1077 linear().setIdentity();
1078 translation() = t.vector();
1079 makeAffine();
1080 return *this;
1081}
1082
1083template <typename Scalar, int Dim, int Mode, int Options>
1084EIGEN_DEVICE_FUNC inline Transform<Scalar, Dim, Mode, Options> Transform<Scalar, Dim, Mode, Options>::operator*(
1085 const TranslationType& t) const {
1086 Transform res = *this;
1087 res.translate(t.vector());
1088 return res;
1089}
1090
1091template <typename Scalar, int Dim, int Mode, int Options>
1093 const UniformScaling<Scalar>& s) {
1094 m_matrix.setZero();
1095 linear().diagonal().fill(s.factor());
1096 makeAffine();
1097 return *this;
1098}
1099
1100template <typename Scalar, int Dim, int Mode, int Options>
1101template <typename Derived>
1103 const RotationBase<Derived, Dim>& r) {
1104 linear() = internal::toRotationMatrix<Scalar, Dim>(r);
1105 translation().setZero();
1106 makeAffine();
1107 return *this;
1108}
1109
1110template <typename Scalar, int Dim, int Mode, int Options>
1111template <typename Derived>
1113 const RotationBase<Derived, Dim>& r) const {
1114 Transform res = *this;
1115 res.rotate(r.derived());
1116 return res;
1117}
1118
1119/************************
1120*** Special functions ***
1121************************/
1122
1123namespace internal {
1124template <int Mode>
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);
1131 return result;
1132 }
1133};
1134template <>
1135struct transform_rotation_impl<Isometry> {
1136 template <typename TransformType>
1137 EIGEN_DEVICE_FUNC static inline typename TransformType::ConstLinearPart run(const TransformType& t) {
1138 return t.linear();
1139 }
1140};
1141} // namespace internal
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);
1156}
1157
1169template <typename Scalar, int Dim, int Mode, int Options>
1170template <typename RotationMatrixType, typename ScalingMatrixType>
1172 ScalingMatrixType* scaling) const {
1173 // Note that JacobiSVD is faster than BDCSVD for small matrices.
1175
1176 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant() < Scalar(0)
1177 ? Scalar(-1)
1178 : Scalar(1); // so x has absolute value 1
1179 VectorType sv(svd.singularValues());
1180 sv.coeffRef(Dim - 1) *= x;
1181 if (scaling) (*scaling).noalias() = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint();
1182 if (rotation) {
1183 LinearMatrixType m(svd.matrixU());
1184 m.col(Dim - 1) *= x;
1185 (*rotation).noalias() = m * svd.matrixV().adjoint();
1186 }
1187}
1188
1200template <typename Scalar, int Dim, int Mode, int Options>
1201template <typename ScalingMatrixType, typename RotationMatrixType>
1203 ScalingMatrixType* scaling, RotationMatrixType* rotation) const {
1204 // Note that JacobiSVD is faster than BDCSVD for small matrices.
1206
1207 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant() < Scalar(0)
1208 ? Scalar(-1)
1209 : Scalar(1); // so x has absolute value 1
1210 VectorType sv(svd.singularValues());
1211 sv.coeffRef(Dim - 1) *= x;
1212 if (scaling) *scaling = svd.matrixU() * sv.asDiagonal() * svd.matrixU().adjoint();
1213 if (rotation) {
1214 LinearMatrixType m(svd.matrixU());
1215 m.col(Dim - 1) *= x;
1216 *rotation = m * svd.matrixV().adjoint();
1217 }
1218}
1219
1223template <typename Scalar, int Dim, int Mode, int Options>
1224template <typename PositionDerived, typename OrientationType, typename ScaleDerived>
1226Transform<Scalar, Dim, Mode, Options>::fromPositionOrientationScale(const MatrixBase<PositionDerived>& position,
1227 const OrientationType& orientation,
1228 const MatrixBase<ScaleDerived>& scale) {
1229 linear() = internal::toRotationMatrix<Scalar, Dim>(orientation);
1230 linear() *= scale.asDiagonal();
1231 translation() = position;
1232 makeAffine();
1233 return *this;
1234}
1235
1236namespace internal {
1237
1238template <int Mode>
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);
1245 }
1246};
1247
1248template <>
1249struct transform_make_affine<AffineCompact> {
1250 template <typename MatrixType>
1251 EIGEN_DEVICE_FUNC static void run(MatrixType&) {}
1252};
1253
1254// Selector needed to avoid taking the inverse of a 3x4 matrix. Only a Projective transform can store a general
1255// inverse; for every other mode the type itself guarantees the transform is affine, so a Projective hint - which only
1256// asks that no extra structure be assumed - is honoured by the general affine inverse.
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); }
1260};
1261
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();
1266 }
1267};
1268
1269} // end namespace internal
1270
1291template <typename Scalar, int Dim, int Mode, int Options>
1293 TransformTraits hint) const {
1294 Transform res;
1295 if (hint == Projective) {
1296 internal::projective_transform_inverse<Transform>::run(*this, res);
1297 } else {
1298 if (hint == Isometry) {
1299 res.matrix().template topLeftCorner<Dim, Dim>() = linear().transpose();
1300 } else if (hint & Affine) {
1301 res.matrix().template topLeftCorner<Dim, Dim>() = linear().inverse();
1302 } else {
1303 eigen_assert(false && "Invalid transform traits in Transform::Inverse");
1304 }
1305 // translation and remaining parts
1306 res.matrix().template topRightCorner<Dim, 1>().noalias() =
1307 -res.matrix().template topLeftCorner<Dim, Dim>() * translation();
1308 res.makeAffine(); // we do need this, because in the beginning res is uninitialized
1309 }
1310 return res;
1311}
1312
1313namespace internal {
1314
1315/*****************************************************
1316*** Specializations of take affine part ***
1317*****************************************************/
1318
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);
1326 }
1327 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstAffinePart run(const MatrixType& m) {
1328 return m.template block<TransformType::Dim, TransformType::HDim>(0, 0);
1329 }
1330};
1331
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; }
1337};
1338
1339/*****************************************************
1340*** Specializations of construct from matrix ***
1341*****************************************************/
1342
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();
1350 }
1351};
1352
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();
1359 }
1360};
1361
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;
1367 // Affine and Isometry transforms require the last row to be [0 ... 0 1]; Projective keeps it as given.
1368 transform_make_affine<(int(Mode) == Affine || int(Mode) == Isometry) ? Affine : AffineCompact>::run(
1369 transform->matrix());
1370 }
1371};
1372
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);
1378 }
1379};
1380
1381/**********************************************************
1382*** Specializations of operator* with rhs MatrixBase ***
1383**********************************************************/
1384
1385template <int LhsMode, int RhsMode>
1386struct transform_product_result {
1387 enum {
1388 Mode = (LhsMode == (int)Projective || RhsMode == (int)Projective) ? Projective
1389 : (LhsMode == (int)Affine || RhsMode == (int)Affine) ? Affine
1390 : (LhsMode == (int)AffineCompact || RhsMode == (int)AffineCompact) ? AffineCompact
1391 : (LhsMode == (int)Isometry || RhsMode == (int)Isometry) ? Isometry
1392 : Projective
1393 };
1394};
1395
1396template <typename TransformType, typename MatrixType, int RhsCols>
1397struct transform_right_product_impl<TransformType, MatrixType, 0, RhsCols> {
1398 using ResultType = typename MatrixType::PlainObject;
1399
1400 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType run(const TransformType& T, const MatrixType& other) {
1401 return T.matrix() * other;
1402 }
1403};
1404
1405template <typename TransformType, typename MatrixType, int RhsCols>
1406struct transform_right_product_impl<TransformType, MatrixType, 1, RhsCols> {
1407 enum {
1408 Dim = TransformType::Dim,
1409 HDim = TransformType::HDim,
1410 OtherRows = MatrixType::RowsAtCompileTime,
1411 OtherCols = MatrixType::ColsAtCompileTime
1412 };
1413
1414 using ResultType = typename MatrixType::PlainObject;
1415
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);
1418
1419 using TopLeftLhs = Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime) == Dim>;
1420
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);
1424
1425 return res;
1426 }
1427};
1428
1429template <typename TransformType, typename MatrixType, int RhsCols>
1430struct transform_right_product_impl<TransformType, MatrixType, 2, RhsCols> {
1431 enum {
1432 Dim = TransformType::Dim,
1433 HDim = TransformType::HDim,
1434 OtherRows = MatrixType::RowsAtCompileTime,
1435 OtherCols = MatrixType::ColsAtCompileTime
1436 };
1437
1438 using ResultType = typename MatrixType::PlainObject;
1439
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);
1442
1443 using TopLeftLhs = Block<ResultType, Dim, OtherCols, true>;
1444 ResultType res(
1445 Replicate<typename TransformType::ConstTranslationPart, 1, OtherCols>(T.translation(), 1, other.cols()));
1446 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
1447
1448 return res;
1449 }
1450};
1451
1452template <typename TransformType, typename MatrixType>
1453struct transform_right_product_impl<TransformType, MatrixType, 2, 1> // rhs is a vector of size Dim
1454{
1455 using TransformMatrix = typename TransformType::MatrixType;
1456 enum {
1457 Dim = TransformType::Dim,
1458 HDim = TransformType::HDim,
1459 OtherRows = MatrixType::RowsAtCompileTime,
1460 WorkingRows = plain_enum_min(TransformMatrix::RowsAtCompileTime, HDim)
1461 };
1462
1463 using ResultType = typename MatrixType::PlainObject;
1464
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);
1467
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>();
1473 }
1474};
1475
1476/**********************************************************
1477*** Specializations of operator* with lhs EigenBase ***
1478**********************************************************/
1479
1480// generic HDim x HDim matrix * T => Projective
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());
1488 }
1489};
1490
1491// generic HDim x HDim matrix * AffineCompact => Projective
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) {
1498 ResultType res;
1499 res.matrix().noalias() = other.template block<HDim, Dim>(0, 0) * tr.matrix();
1500 res.matrix().col(Dim) += other.col(Dim);
1501 return res;
1502 }
1503};
1504
1505// affine matrix * T
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) {
1512 ResultType res;
1513 res.affine().noalias() = other * tr.matrix();
1514 res.matrix().row(Dim) = tr.matrix().row(Dim);
1515 return res;
1516 }
1517};
1518
1519// affine matrix * AffineCompact
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) {
1526 ResultType res;
1527 res.matrix().noalias() = other.template block<Dim, Dim>(0, 0) * tr.matrix();
1528 res.translation() += other.col(Dim);
1529 return res;
1530 }
1531};
1532
1533// linear matrix * T
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) {
1540 TransformType res;
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>();
1543 return res;
1544 }
1545};
1546
1547/**********************************************************
1548*** Specializations of operator* with another Transform ***
1549**********************************************************/
1550
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) {
1559 ResultType res;
1560 res.linear().noalias() = lhs.linear() * rhs.linear();
1561 res.translation().noalias() = lhs.linear() * rhs.translation() + lhs.translation();
1562 res.makeAffine();
1563 return res;
1564 }
1565};
1566
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());
1575 }
1576};
1577
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) {
1585 ResultType res;
1586 res.matrix().template topRows<Dim>().noalias() = lhs.matrix() * rhs.matrix();
1587 res.matrix().row(Dim) = rhs.matrix().row(Dim);
1588 return res;
1589 }
1590};
1591
1592template <typename Scalar, int Dim, int LhsOptions, int RhsOptions>
1593struct transform_transform_product_impl<Transform<Scalar, Dim, Projective, LhsOptions>,
1594 Transform<Scalar, Dim, AffineCompact, RhsOptions>, true> {
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);
1601 return res;
1602 }
1603};
1604
1605} // end namespace internal
1606
1607} // end namespace Eigen
1608
1609#endif // EIGEN_TRANSFORM_H
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 an homogeneous transformation in a N dimensional space.
Definition Transform.h:222
const internal::transform_right_product_impl< Transform, OtherDerived >::ResultType operator*(const MatrixBase< OtherDerived > &other) const
Definition Transform.h:461
ConstAffinePart affine() const
Definition Transform.h:423
ConstLinearPart linear() const
Definition Transform.h:418
static const Transform Identity()
Returns an identity transformation.
Definition Transform.h:536
Transform & preshear(const Scalar &sx, const Scalar &sy)
Definition Transform.h:1061
void computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const
Definition Transform.h:1202
Transform< Scalar, Dim,(Mode==int(Isometry)) ? int(Affine) :int(Mode)> TransformTimeDiagonalReturnType
Definition Transform.h:264
Translation< Scalar, Dim > TranslationType
Definition Transform.h:261
Scalar operator()(Index row, Index col) const
Definition Transform.h:398
Block< MatrixType, Dim, 1, !(internal::traits< MatrixType >::Flags &RowMajorBit)> TranslationPart
Definition Transform.h:256
Scalar & operator()(Index row, Index col)
Definition Transform.h:401
Matrix< Scalar, Dim, 1 > VectorType
Definition Transform.h:254
ConstTranslationPart translation() const
Definition Transform.h:428
std::conditional_t< int(Mode)==int(AffineCompact), const MatrixType &, const Block< const MatrixType, Dim, HDim > > ConstAffinePart
Definition Transform.h:251
bool isApprox(const Transform &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Transform.h:635
Eigen::Index Index
Definition Transform.h:236
AffinePart affine()
Definition Transform.h:425
const Block< ConstMatrixType, Dim, 1, !(internal::traits< MatrixType >::Flags &RowMajorBit)> ConstTranslationPart
Definition Transform.h:258
void computeRotationScaling(RotationMatrixType *rotation, ScalingMatrixType *scaling) const
Definition Transform.h:1171
Transform & scale(const Scalar &s)
Definition Transform.h:853
void setIdentity()
Definition Transform.h:530
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar_, Dim_==Dynamic ? Dynamic :(Dim_+1) *(Dim_+1)) enum
Definition Transform.h:224
constexpr Scalar * data()
Definition Transform.h:610
const Transform operator*(const Transform &other) const
Definition Transform.h:515
friend TransformTimeDiagonalReturnType operator*(const DiagonalBase< DiagonalDerived > &a, const Transform &b)
Definition Transform.h:500
Matrix< Scalar, Dim, Dim, Options > LinearMatrixType
Definition Transform.h:242
LinearPart linear()
Definition Transform.h:420
Block< MatrixType, Dim, Dim, int(Mode)==(AffineCompact) &&(int(Options) &RowMajor)==0 > LinearPart
Definition Transform.h:244
const MatrixType & matrix() const
Definition Transform.h:413
friend const internal::transform_left_product_impl< OtherDerived, Mode, Options, Dim_, Dim_+1 >::ResultType operator*(const MatrixBase< OtherDerived > &a, const Transform &b)
Definition Transform.h:475
const TransformTimeDiagonalReturnType operator*(const DiagonalBase< DiagonalDerived > &b) const
Definition Transform.h:486
Transform & prescale(const Scalar &s)
Definition Transform.h:879
Scalar Scalar
Definition Transform.h:234
Transform & operator=(const EigenBase< OtherDerived > &other)
Definition Transform.h:314
Transform(const Transform< OtherScalarType, Dim, Mode, Options > &other)
Definition Transform.h:626
Transform(const EigenBase< OtherDerived > &other)
Definition Transform.h:302
const Block< ConstMatrixType, Dim, Dim, int(Mode)==(AffineCompact) &&(int(Options) &RowMajor)==0 > ConstLinearPart
Definition Transform.h:246
internal::cast_return_type< Transform, Transform< NewScalarType, Dim, Mode, Options > >::type cast() const
Definition Transform.h:620
Transform inverse(TransformTraits traits=(TransformTraits) Mode) const
Definition Transform.h:1292
typename internal::make_proper_matrix_type< Scalar, Rows, HDim, Options >::type MatrixType
Definition Transform.h:238
std::conditional_t< int(Mode)==int(AffineCompact), MatrixType &, Block< MatrixType, Dim, HDim > > AffinePart
Definition Transform.h:249
const MatrixType ConstMatrixType
Definition Transform.h:240
void makeAffine()
Definition Transform.h:642
MatrixType & matrix()
Definition Transform.h:415
internal::transform_transform_product_impl< Transform, Transform< Scalar, Dim, OtherMode, OtherOptions > >::ResultType operator*(const Transform< Scalar, Dim, OtherMode, OtherOptions > &other) const
Definition Transform.h:524
Transform()
Definition Transform.h:272
constexpr const Scalar * data() const
Definition Transform.h:608
Transform & shear(const Scalar &sx, const Scalar &sy)
Definition Transform.h:1047
TranslationPart translation()
Definition Transform.h:430
Represents a translation transformation.
Definition Translation.h:34
Represents a generic uniform scaling transformation.
Definition Scaling.h:48
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