12 #ifndef EIGEN_TRANSFORM_H
13 #define EIGEN_TRANSFORM_H
19 template<
typename Transform>
31 template<
typename TransformType,
36 int RhsCols = MatrixType::ColsAtCompileTime>
39 template<
typename Other,
44 int OtherRows=Other::RowsAtCompileTime,
45 int OtherCols=Other::ColsAtCompileTime>
48 template<
typename Lhs,
55 template<
typename Other,
60 int OtherRows=Other::RowsAtCompileTime,
61 int OtherCols=Other::ColsAtCompileTime>
66 template<
typename _Scalar,
int _Dim,
int _Mode,
int _Options>
75 ColsAtCompileTime = Dim1,
76 MaxRowsAtCompileTime = RowsAtCompileTime,
77 MaxColsAtCompileTime = ColsAtCompileTime,
200 template<
typename _Scalar,
int _Dim,
int _Mode,
int _Options>
278 template<
typename Derived>
291 template<
typename OtherDerived>
295 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
302 template<
typename OtherDerived>
306 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
312 template<
int OtherOptions>
320 template<
int OtherMode,
int OtherOptions>
327 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
332 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
338 if(ModeIsAffineCompact == OtherModeIsAffineCompact)
343 m_matrix.template block<Dim,Dim+1>(0,0) = other.
matrix().template block<Dim,Dim+1>(0,0);
346 else if(OtherModeIsAffineCompact)
361 template<
typename OtherDerived>
368 template<
typename OtherDerived>
375 #ifdef EIGEN_QT_SUPPORT
378 inline QMatrix toQMatrix(
void)
const;
379 inline Transform(
const QTransform& other);
381 inline QTransform toQTransform(
void)
const;
439 template<
typename OtherDerived>
451 template<
typename OtherDerived>
friend
462 template<
typename DiagonalDerived>
477 template<
typename DiagonalDerived>
482 res.
linear().noalias() =
a*
b.linear();
485 res.
matrix().row(Dim) =
b.matrix().row(Dim);
489 template<
typename OtherDerived>
507 template<
int OtherMode,
int OtherOptions>
struct icc_11_workaround
510 typedef typename ProductType::ResultType ResultType;
515 template<
int OtherMode,
int OtherOptions>
516 inline typename icc_11_workaround<OtherMode,OtherOptions>::ResultType
517 operator * (
const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
const
519 typedef typename icc_11_workaround<OtherMode,OtherOptions>::ProductType ProductType;
524 template<
int OtherMode,
int OtherOptions>
525 EIGEN_DEVICE_FUNC
inline typename internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::ResultType
541 return Transform(MatrixType::Identity());
544 template<
typename OtherDerived>
548 template<
typename OtherDerived>
555 template<
typename OtherDerived>
559 template<
typename OtherDerived>
563 template<
typename RotationType>
567 template<
typename RotationType>
598 template<
typename Derived>
600 template<
typename Derived>
602 template<
typename Derived>
606 template<
typename RotationMatrixType,
typename ScalingMatrixType>
609 template<
typename ScalingMatrixType,
typename RotationMatrixType>
613 template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
631 template<
typename NewScalarType>
636 template<
typename OtherScalarType>
662 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
668 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
675 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
681 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
684 #ifdef EIGEN_TRANSFORM_PLUGIN
685 #include EIGEN_TRANSFORM_PLUGIN
689 #ifndef EIGEN_PARSED_BY_DOXYGEN
738 #ifdef EIGEN_QT_SUPPORT
743 template<
typename Scalar,
int Dim,
int Mode,
int Options>
746 check_template_params();
754 template<
typename Scalar,
int Dim,
int Mode,
int Options>
759 m_matrix << other.m11(), other.m21(), other.dx(),
760 other.m12(), other.m22(), other.dy();
762 m_matrix << other.m11(), other.m21(), other.dx(),
763 other.m12(), other.m22(), other.dy(),
774 template<
typename Scalar,
int Dim,
int Mode,
int Options>
775 QMatrix Transform<Scalar,Dim,Mode,Options>::toQMatrix(
void)
const
777 check_template_params();
779 return QMatrix(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0),
788 template<
typename Scalar,
int Dim,
int Mode,
int Options>
791 check_template_params();
799 template<
typename Scalar,
int Dim,
int Mode,
int Options>
802 check_template_params();
805 m_matrix << other.m11(), other.m21(), other.dx(),
806 other.m12(), other.m22(), other.dy();
808 m_matrix << other.m11(), other.m21(), other.dx(),
809 other.m12(), other.m22(), other.dy(),
810 other.m13(), other.m23(), other.m33();
818 template<
typename Scalar,
int Dim,
int Mode,
int Options>
819 QTransform Transform<Scalar,Dim,Mode,Options>::toQTransform(
void)
const
823 return QTransform(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0),
827 return QTransform(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0), m_matrix.
coeff(2,0),
841 template<
typename Scalar,
int Dim,
int Mode,
int Options>
842 template<
typename OtherDerived>
843 EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
848 linearExt().noalias() = (linearExt() * other.
asDiagonal());
856 template<
typename Scalar,
int Dim,
int Mode,
int Options>
868 template<
typename Scalar,
int Dim,
int Mode,
int Options>
869 template<
typename OtherDerived>
875 affine().noalias() = (other.
asDiagonal() * affine());
883 template<
typename Scalar,
int Dim,
int Mode,
int Options>
887 m_matrix.template topRows<Dim>() *=
s;
895 template<
typename Scalar,
int Dim,
int Mode,
int Options>
896 template<
typename OtherDerived>
901 translationExt() += linearExt() * other;
909 template<
typename Scalar,
int Dim,
int Mode,
int Options>
910 template<
typename OtherDerived>
916 affine() += other * m_matrix.row(Dim);
918 translation() += other;
939 template<
typename Scalar,
int Dim,
int Mode,
int Options>
940 template<
typename RotationType>
944 linearExt() *= internal::toRotationMatrix<Scalar,Dim>(rotation);
955 template<
typename Scalar,
int Dim,
int Mode,
int Options>
956 template<
typename RotationType>
960 m_matrix.template block<Dim,HDim>(0,0) = internal::toRotationMatrix<Scalar,Dim>(rotation)
961 * m_matrix.template block<Dim,HDim>(0,0);
970 template<
typename Scalar,
int Dim,
int Mode,
int Options>
976 VectorType tmp = linear().col(0)*sy + linear().col(1);
977 linear() << linear().col(0) + linear().col(1)*sx, tmp;
986 template<
typename Scalar,
int Dim,
int Mode,
int Options>
992 m_matrix.template block<Dim,HDim>(0,0) =
LinearMatrixType(1, sx, sy, 1) * m_matrix.template block<Dim,HDim>(0,0);
1000 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1004 translation() = t.
vector();
1009 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1017 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1021 linear().diagonal().fill(
s.factor());
1026 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1027 template<
typename Derived>
1030 linear() = internal::toRotationMatrix<Scalar,Dim>(r);
1031 translation().setZero();
1036 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1037 template<
typename Derived>
1056 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1077 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1078 template<
typename RotationMatrixType,
typename ScalingMatrixType>
1083 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant();
1086 if(scaling) scaling->lazyAssign(svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint());
1091 rotation->lazyAssign(m * svd.matrixV().adjoint());
1106 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1107 template<
typename ScalingMatrixType,
typename RotationMatrixType>
1112 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant();
1115 if(scaling) scaling->lazyAssign(svd.matrixU() * sv.asDiagonal() * svd.matrixU().adjoint());
1120 rotation->lazyAssign(m * svd.matrixV().adjoint());
1127 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1128 template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
1133 linear() = internal::toRotationMatrix<Scalar,Dim>(orientation);
1135 translation() = position;
1143 struct transform_make_affine
1145 template<
typename MatrixType>
1148 static const int Dim = MatrixType::ColsAtCompileTime-1;
1149 mat.template block<1,Dim>(Dim,0).setZero();
1157 template<
typename MatrixType> EIGEN_DEVICE_FUNC
static void run(
MatrixType &) { }
1161 template<
typename TransformType,
int Mode=TransformType::Mode>
1164 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType&, TransformType&)
1168 template<
typename TransformType>
1171 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType& m, TransformType& res)
1173 res.matrix() = m.matrix().inverse();
1200 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1201 EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>
1213 res.
matrix().template topLeftCorner<Dim,Dim>() = linear().transpose();
1217 res.
matrix().template topLeftCorner<Dim,Dim>() = linear().inverse();
1221 eigen_assert(
false &&
"Invalid transform traits in Transform::Inverse");
1224 res.
matrix().template topRightCorner<Dim,1>()
1225 = - res.
matrix().template topLeftCorner<Dim,Dim>() * translation();
1237 template<
typename TransformType>
struct transform_take_affine_part {
1239 typedef typename TransformType::AffinePart
AffinePart;
1242 {
return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
1244 {
return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
1247 template<
typename Scalar,
int Dim,
int Options>
1258 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1269 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1274 transform->
affine() = other;
1279 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1283 { transform->
matrix() = other; }
1286 template<
typename Other,
int Options,
int Dim,
int HDim>
1290 { transform->
matrix() = other.template block<Dim,HDim>(0,0); }
1297 template<
int LhsMode,
int RhsMode>
1310 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1317 return T.matrix() * other;
1321 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1325 Dim = TransformType::Dim,
1326 HDim = TransformType::HDim,
1327 OtherRows = MatrixType::RowsAtCompileTime,
1328 OtherCols = MatrixType::ColsAtCompileTime
1337 typedef Block<
ResultType, Dim, OtherCols,
int(MatrixType::RowsAtCompileTime)==Dim> TopLeftLhs;
1340 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other;
1341 res.row(OtherRows-1) = other.row(OtherRows-1);
1347 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1351 Dim = TransformType::Dim,
1352 HDim = TransformType::HDim,
1353 OtherRows = MatrixType::RowsAtCompileTime,
1354 OtherCols = MatrixType::ColsAtCompileTime
1365 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
1371 template<
typename TransformType,
typename MatrixType >
1376 Dim = TransformType::Dim,
1377 HDim = TransformType::HDim,
1378 OtherRows = MatrixType::RowsAtCompileTime,
1391 return res.template head<Dim>();
1400 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1411 template<
typename Other,
int Options,
int Dim,
int HDim>
1420 res.
matrix().noalias() = other.template block<HDim,Dim>(0,0) * tr.
matrix();
1421 res.
matrix().col(Dim) += other.col(Dim);
1427 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1443 template<
typename Other,
int Options,
int Dim,
int HDim>
1452 res.
matrix().noalias() = other.template block<Dim,Dim>(0,0) * tr.
matrix();
1459 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1470 res.
matrix().template topRows<Dim>().noalias()
1471 = other * tr.
matrix().template topRows<Dim>();
1480 template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1497 template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1509 template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1524 template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1542 #endif // EIGEN_TRANSFORM_H