12 #ifndef EIGEN_TRANSFORM_H
13 #define EIGEN_TRANSFORM_H
19 template<
typename Transform>
25 HDim = Transform::HDim,
26 Mode = Transform::Mode,
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>
69 typedef _Scalar Scalar;
73 Dim1 = _Dim==
Dynamic ? _Dim : _Dim + 1,
74 RowsAtCompileTime = _Mode==
Projective ? Dim1 : _Dim,
75 ColsAtCompileTime = Dim1,
76 MaxRowsAtCompileTime = RowsAtCompileTime,
77 MaxColsAtCompileTime = ColsAtCompileTime,
203 template<
typename _Scalar,
int _Dim,
int _Mode,
int _Options>
247 enum { TransformTimeDiagonalMode = ((Mode==int(
Isometry))?
Affine:
int(Mode)) };
261 check_template_params();
267 check_template_params();
270 EIGEN_DEVICE_FUNC
inline explicit Transform(
const UniformScaling<Scalar>& s)
272 check_template_params();
275 template<
typename Derived>
276 EIGEN_DEVICE_FUNC
inline explicit Transform(
const RotationBase<Derived, Dim>& r)
278 check_template_params();
282 typedef internal::transform_take_affine_part<Transform> take_affine_part;
285 template<
typename OtherDerived>
289 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
291 check_template_params();
296 template<
typename OtherDerived>
300 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
306 template<
int OtherOptions>
309 check_template_params();
311 m_matrix = other.
matrix();
314 template<
int OtherMode,
int OtherOptions>
315 EIGEN_DEVICE_FUNC
inline Transform(
const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
317 check_template_params();
321 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
326 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
332 if(EIGEN_CONST_CONDITIONAL(ModeIsAffineCompact == OtherModeIsAffineCompact))
337 m_matrix.template block<Dim,Dim+1>(0,0) = other.matrix().template block<Dim,Dim+1>(0,0);
340 else if(EIGEN_CONST_CONDITIONAL(OtherModeIsAffineCompact))
343 internal::transform_construct_from_matrix<OtherMatrixType,Mode,Options,Dim,HDim>::run(
this, other.matrix());
350 linear() = other.linear();
355 template<
typename OtherDerived>
356 EIGEN_DEVICE_FUNC
Transform(
const ReturnByValue<OtherDerived>& other)
358 check_template_params();
362 template<
typename OtherDerived>
369 #ifdef EIGEN_QT_SUPPORT
372 inline QMatrix toQMatrix(
void)
const;
373 inline Transform(
const QTransform& other);
375 inline QTransform toQTransform(
void)
const;
378 EIGEN_DEVICE_FUNC
Index rows()
const {
return int(Mode)==int(
Projective) ? m_matrix.cols() : (m_matrix.cols()-1); }
379 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_matrix.cols(); }
433 template<
typename OtherDerived>
445 template<
typename OtherDerived>
friend
456 template<
typename DiagonalDerived>
461 res.linearExt() *= b;
471 template<
typename DiagonalDerived>
483 template<
typename OtherDerived>
501 template<
int OtherMode,
int OtherOptions>
struct icc_11_workaround
504 typedef typename ProductType::ResultType ResultType;
509 template<
int OtherMode,
int OtherOptions>
510 inline typename icc_11_workaround<OtherMode,OtherOptions>::ResultType
511 operator * (
const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
const
513 typedef typename icc_11_workaround<OtherMode,OtherOptions>::ProductType ProductType;
514 return ProductType::run(*
this,other);
518 template<
int OtherMode,
int OtherOptions>
519 EIGEN_DEVICE_FUNC
inline typename internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::ResultType
535 return Transform(MatrixType::Identity());
538 template<
typename OtherDerived>
542 template<
typename OtherDerived>
549 template<
typename OtherDerived>
553 template<
typename OtherDerived>
557 template<
typename RotationType>
561 template<
typename RotationType>
579 inline Transform& operator*=(
const UniformScaling<Scalar>& s) {
return scale(s.factor()); }
585 res.scale(s.factor());
590 inline Transform& operator*=(
const DiagonalMatrix<Scalar,Dim>& s) { linearExt() *= s;
return *
this; }
592 template<
typename Derived>
594 template<
typename Derived>
595 EIGEN_DEVICE_FUNC
inline Transform& operator*=(
const RotationBase<Derived,Dim>& r) {
return rotate(r.toRotationMatrix()); }
596 template<
typename Derived>
597 EIGEN_DEVICE_FUNC
inline Transform operator*(
const RotationBase<Derived,Dim>& r)
const;
600 EIGEN_DEVICE_FUNC RotationReturnType
rotation()
const;
602 template<
typename RotationMatrixType,
typename ScalingMatrixType>
605 template<
typename ScalingMatrixType,
typename RotationMatrixType>
609 template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
611 Transform& fromPositionOrientationScale(
const MatrixBase<PositionDerived> &position,
612 const OrientationType& orientation,
const MatrixBase<ScaleDerived> &scale);
627 template<
typename NewScalarType>
632 template<
typename OtherScalarType>
635 check_template_params();
636 m_matrix = other.
matrix().template cast<Scalar>();
644 {
return m_matrix.isApprox(other.m_matrix, prec); }
658 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
663 EIGEN_DEVICE_FUNC
inline const Block<
MatrixType,int(Mode)==int(
Projective)?HDim:Dim,Dim> linearExt()
const
664 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
670 EIGEN_DEVICE_FUNC
inline Block<
MatrixType,int(Mode)==int(
Projective)?HDim:Dim,1> translationExt()
671 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
676 EIGEN_DEVICE_FUNC
inline const Block<
MatrixType,int(Mode)==int(
Projective)?HDim:Dim,1> translationExt()
const
677 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
680 #ifdef EIGEN_TRANSFORM_PLUGIN
681 #include EIGEN_TRANSFORM_PLUGIN
685 #ifndef EIGEN_PARSED_BY_DOXYGEN
686 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE
void check_template_params()
688 EIGEN_STATIC_ASSERT((Options & (
DontAlign|
RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS)
695 typedef Transform<float,2,Isometry> Isometry2f;
697 typedef Transform<float,3,Isometry> Isometry3f;
699 typedef Transform<double,2,Isometry> Isometry2d;
701 typedef Transform<double,3,Isometry> Isometry3d;
704 typedef Transform<float,2,Affine> Affine2f;
706 typedef Transform<float,3,Affine> Affine3f;
708 typedef Transform<double,2,Affine> Affine2d;
710 typedef Transform<double,3,Affine> Affine3d;
713 typedef Transform<float,2,AffineCompact> AffineCompact2f;
715 typedef Transform<float,3,AffineCompact> AffineCompact3f;
717 typedef Transform<double,2,AffineCompact> AffineCompact2d;
719 typedef Transform<double,3,AffineCompact> AffineCompact3d;
722 typedef Transform<float,2,Projective> Projective2f;
724 typedef Transform<float,3,Projective> Projective3f;
726 typedef Transform<double,2,Projective> Projective2d;
728 typedef Transform<double,3,Projective> Projective3d;
734 #ifdef EIGEN_QT_SUPPORT
739 template<
typename Scalar,
int Dim,
int Mode,
int Options>
742 check_template_params();
750 template<
typename Scalar,
int Dim,
int Mode,
int Options>
753 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
755 m_matrix << other.m11(), other.m21(), other.dx(),
756 other.m12(), other.m22(), other.dy();
758 m_matrix << other.m11(), other.m21(), other.dx(),
759 other.m12(), other.m22(), other.dy(),
770 template<
typename Scalar,
int Dim,
int Mode,
int Options>
771 QMatrix Transform<Scalar,Dim,Mode,Options>::toQMatrix(
void)
const
773 check_template_params();
774 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
775 return QMatrix(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0),
784 template<
typename Scalar,
int Dim,
int Mode,
int Options>
787 check_template_params();
795 template<
typename Scalar,
int Dim,
int Mode,
int Options>
798 check_template_params();
799 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
801 m_matrix << other.m11(), other.m21(), other.dx(),
802 other.m12(), other.m22(), other.dy();
804 m_matrix << other.m11(), other.m21(), other.dx(),
805 other.m12(), other.m22(), other.dy(),
806 other.m13(), other.m23(), other.m33();
814 template<
typename Scalar,
int Dim,
int Mode,
int Options>
815 QTransform Transform<Scalar,Dim,Mode,Options>::toQTransform(
void)
const
817 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
819 return QTransform(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0),
823 return QTransform(m_matrix.
coeff(0,0), m_matrix.
coeff(1,0), m_matrix.
coeff(2,0),
837 template<
typename Scalar,
int Dim,
int Mode,
int Options>
838 template<
typename OtherDerived>
839 EIGEN_DEVICE_FUNC Transform<Scalar,Dim,Mode,Options>&
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().noalias() = (linearExt() * other.
asDiagonal());
852 template<
typename Scalar,
int Dim,
int Mode,
int Options>
855 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
864 template<
typename Scalar,
int Dim,
int Mode,
int Options>
865 template<
typename OtherDerived>
869 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
870 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
871 affine().noalias() = (other.
asDiagonal() * affine());
879 template<
typename Scalar,
int Dim,
int Mode,
int Options>
882 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
883 m_matrix.template topRows<Dim>() *= s;
891 template<
typename Scalar,
int Dim,
int Mode,
int Options>
892 template<
typename OtherDerived>
896 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
897 translationExt() += linearExt() * other;
905 template<
typename Scalar,
int Dim,
int Mode,
int Options>
906 template<
typename OtherDerived>
910 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,
int(Dim))
911 if(EIGEN_CONST_CONDITIONAL(
int(Mode)==
int(
Projective)))
912 affine() += other * m_matrix.row(Dim);
914 translation() += other;
935 template<
typename Scalar,
int Dim,
int Mode,
int Options>
936 template<
typename RotationType>
940 linearExt() *= internal::toRotationMatrix<Scalar,Dim>(rotation);
951 template<
typename Scalar,
int Dim,
int Mode,
int Options>
952 template<
typename RotationType>
956 m_matrix.template block<Dim,HDim>(0,0) = internal::toRotationMatrix<Scalar,Dim>(rotation)
957 * m_matrix.template block<Dim,HDim>(0,0);
966 template<
typename Scalar,
int Dim,
int Mode,
int Options>
970 EIGEN_STATIC_ASSERT(
int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
971 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
972 VectorType tmp = linear().col(0)*sy + linear().col(1);
973 linear() << linear().col(0) + linear().col(1)*sx, tmp;
982 template<
typename Scalar,
int Dim,
int Mode,
int Options>
986 EIGEN_STATIC_ASSERT(
int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
987 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
988 m_matrix.template block<Dim,HDim>(0,0) =
LinearMatrixType(1, sx, sy, 1) * m_matrix.template block<Dim,HDim>(0,0);
996 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1000 translation() = t.vector();
1005 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1008 Transform res = *
this;
1009 res.translate(t.vector());
1013 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1017 linear().diagonal().fill(s.factor());
1022 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1023 template<
typename Derived>
1026 linear() = internal::toRotationMatrix<Scalar,Dim>(r);
1027 translation().setZero();
1032 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1033 template<
typename Derived>
1036 Transform res = *
this;
1037 res.rotate(r.derived());
1045 namespace internal {
1046 template<
int Mode>
struct transform_rotation_impl {
1047 template<
typename TransformType>
1048 EIGEN_DEVICE_FUNC
static inline
1049 const typename TransformType::LinearMatrixType run(
const TransformType& t)
1051 typedef typename TransformType::LinearMatrixType LinearMatrixType;
1052 LinearMatrixType result;
1053 t.computeRotationScaling(&result, (LinearMatrixType*)0);
1057 template<>
struct transform_rotation_impl<
Isometry> {
1058 template<
typename TransformType>
1059 EIGEN_DEVICE_FUNC
static inline
1060 typename TransformType::ConstLinearPart run(
const TransformType& t)
1076 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1078 typename Transform<Scalar,Dim,Mode,Options>::RotationReturnType
1096 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1097 template<
typename RotationMatrixType,
typename ScalingMatrixType>
1102 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant();
1105 if(scaling) *scaling = svd.matrixV() * sv.asDiagonal() * svd.matrixV().adjoint();
1110 *rotation = m * svd.matrixV().adjoint();
1125 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1126 template<
typename ScalingMatrixType,
typename RotationMatrixType>
1131 Scalar x = (svd.matrixU() * svd.matrixV().adjoint()).determinant();
1134 if(scaling) *scaling = svd.matrixU() * sv.asDiagonal() * svd.matrixU().adjoint();
1139 *rotation = m * svd.matrixV().adjoint();
1146 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1147 template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
1152 linear() = internal::toRotationMatrix<Scalar,Dim>(orientation);
1154 translation() = position;
1159 namespace internal {
1164 template<
typename MatrixType>
1165 EIGEN_DEVICE_FUNC
static void run(MatrixType &mat)
1167 static const int Dim = MatrixType::ColsAtCompileTime-1;
1168 mat.template block<1,Dim>(Dim,0).setZero();
1169 mat.coeffRef(Dim,Dim) =
typename MatrixType::Scalar(1);
1176 template<
typename MatrixType> EIGEN_DEVICE_FUNC
static void run(MatrixType &) { }
1180 template<
typename TransformType,
int Mode=TransformType::Mode>
1183 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType&, TransformType&)
1187 template<
typename TransformType>
1190 EIGEN_DEVICE_FUNC
static inline void run(
const TransformType& m, TransformType& res)
1192 res.matrix() = m.matrix().inverse();
1219 template<
typename Scalar,
int Dim,
int Mode,
int Options>
1232 res.
matrix().template topLeftCorner<Dim,Dim>() = linear().transpose();
1236 res.
matrix().template topLeftCorner<Dim,Dim>() = linear().inverse();
1240 eigen_assert(
false &&
"Invalid transform traits in Transform::Inverse");
1243 res.
matrix().template topRightCorner<Dim,1>()
1244 = - res.
matrix().template topLeftCorner<Dim,Dim>() * translation();
1250 namespace internal {
1257 typedef typename TransformType::MatrixType MatrixType;
1258 typedef typename TransformType::AffinePart AffinePart;
1259 typedef typename TransformType::ConstAffinePart ConstAffinePart;
1260 static inline AffinePart run(MatrixType& m)
1261 {
return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
1262 static inline ConstAffinePart run(
const MatrixType& m)
1263 {
return m.template block<TransformType::Dim,TransformType::HDim>(0,0); }
1266 template<
typename Scalar,
int Dim,
int Options>
1277 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1282 transform->
linear() = other;
1288 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1293 transform->
affine() = other;
1298 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1302 { transform->
matrix() = other; }
1305 template<
typename Other,
int Options,
int Dim,
int HDim>
1309 { transform->
matrix() = other.template block<Dim,HDim>(0,0); }
1316 template<
int LhsMode,
int RhsMode>
1329 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1332 typedef typename MatrixType::PlainObject ResultType;
1334 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1336 return T.matrix() * other;
1340 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1344 Dim = TransformType::Dim,
1345 HDim = TransformType::HDim,
1346 OtherRows = MatrixType::RowsAtCompileTime,
1347 OtherCols = MatrixType::ColsAtCompileTime
1350 typedef typename MatrixType::PlainObject ResultType;
1352 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1354 EIGEN_STATIC_ASSERT(OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1356 typedef Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime)==Dim> TopLeftLhs;
1358 ResultType res(other.rows(),other.cols());
1359 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other;
1360 res.row(OtherRows-1) = other.row(OtherRows-1);
1366 template<
typename TransformType,
typename MatrixType,
int RhsCols>
1370 Dim = TransformType::Dim,
1371 HDim = TransformType::HDim,
1372 OtherRows = MatrixType::RowsAtCompileTime,
1373 OtherCols = MatrixType::ColsAtCompileTime
1376 typedef typename MatrixType::PlainObject ResultType;
1378 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1380 EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1384 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
1390 template<
typename TransformType,
typename MatrixType >
1393 typedef typename TransformType::MatrixType TransformMatrix;
1395 Dim = TransformType::Dim,
1396 HDim = TransformType::HDim,
1397 OtherRows = MatrixType::RowsAtCompileTime,
1398 WorkingRows = EIGEN_PLAIN_ENUM_MIN(TransformMatrix::RowsAtCompileTime,HDim)
1401 typedef typename MatrixType::PlainObject ResultType;
1403 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1405 EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1408 rhs.template head<Dim>() = other; rhs[Dim] =
typename ResultType::Scalar(1);
1410 return res.template head<Dim>();
1419 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1430 template<
typename Other,
int Options,
int Dim,
int HDim>
1439 res.
matrix().noalias() = other.template block<HDim,Dim>(0,0) * tr.
matrix();
1440 res.
matrix().col(Dim) += other.col(Dim);
1446 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1462 template<
typename Other,
int Options,
int Dim,
int HDim>
1471 res.
matrix().noalias() = other.template block<Dim,Dim>(0,0) * tr.
matrix();
1478 template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1489 res.
matrix().template topRows<Dim>().noalias()
1490 = other * tr.
matrix().template topRows<Dim>();
1499 template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1516 template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1528 template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1543 template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1561 #endif // EIGEN_TRANSFORM_H