12#ifndef EIGEN_TRANSFORM_H
13#define EIGEN_TRANSFORM_H
19template<
typename Transform>
25 HDim = Transform::HDim,
26 Mode = Transform::Mode,
31template<
typename TransformType,
38template<
typename Other,
43 int OtherRows=Other::RowsAtCompileTime,
44 int OtherCols=Other::ColsAtCompileTime>
47template<
typename Lhs,
54template<
typename Other,
59 int OtherRows=Other::RowsAtCompileTime,
60 int OtherCols=Other::ColsAtCompileTime>
65template<
typename _Scalar,
int _Dim,
int _Mode,
int _Options>
68 typedef _Scalar Scalar;
69 typedef Eigen::Index StorageIndex;
74 ColsAtCompileTime = Dim1,
75 MaxRowsAtCompileTime = RowsAtCompileTime,
76 MaxColsAtCompileTime = ColsAtCompileTime,
199template<
typename _Scalar,
int _Dim,
int _Mode,
int _Options>
213 typedef Eigen::Index StorageIndex;
243 enum { TransformTimeDiagonalMode = ((Mode==int(
Isometry))?
Affine:int(Mode)) };
257 check_template_params();
263 check_template_params();
264 m_matrix = other.m_matrix;
269 check_template_params();
272 inline explicit Transform(
const UniformScaling<Scalar>& s)
274 check_template_params();
277 template<
typename Derived>
278 inline explicit Transform(
const RotationBase<Derived, Dim>& r)
280 check_template_params();
285 { m_matrix = other.m_matrix;
return *
this; }
287 typedef internal::transform_take_affine_part<Transform> take_affine_part;
290 template<
typename OtherDerived>
294 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
296 check_template_params();
301 template<
typename OtherDerived>
305 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY);
311 template<
int OtherOptions>
314 check_template_params();
316 m_matrix = other.matrix();
319 template<
int OtherMode,
int OtherOptions>
320 inline Transform(
const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
322 check_template_params();
326 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
331 YOU_PERFORMED_AN_INVALID_TRANSFORMATION_CONVERSION)
337 if(ModeIsAffineCompact == OtherModeIsAffineCompact)
342 m_matrix.template block<Dim,Dim+1>(0,0) = other.matrix().template block<Dim,Dim+1>(0,0);
345 else if(OtherModeIsAffineCompact)
348 internal::transform_construct_from_matrix<OtherMatrixType,Mode,Options,Dim,HDim>::run(
this, other.matrix());
355 linear() = other.linear();
360 template<
typename OtherDerived>
361 Transform(
const ReturnByValue<OtherDerived>& other)
363 check_template_params();
367 template<
typename OtherDerived>
368 Transform& operator=(
const ReturnByValue<OtherDerived>& other)
374 #ifdef EIGEN_QT_SUPPORT
377 inline QMatrix toQMatrix(
void)
const;
378 inline Transform(
const QTransform& other);
379 inline Transform& operator=(
const QTransform& other);
380 inline QTransform toQTransform(
void)
const;
383 Index rows()
const {
return int(Mode)==int(
Projective) ? m_matrix.cols() : (m_matrix.cols()-1); }
384 Index cols()
const {
return m_matrix.cols(); }
438 template<
typename OtherDerived>
439 EIGEN_STRONG_INLINE
const typename OtherDerived::PlainObject
450 template<
typename OtherDerived>
friend
461 template<
typename DiagonalDerived>
476 template<
typename DiagonalDerived>
481 res.linear().noalias() = a*b.
linear();
484 res.matrix().row(Dim) = b.
matrix().row(Dim);
488 template<
typename OtherDerived>
509 typedef typename ProductType::ResultType ResultType;
514 template<
int OtherMode,
int OtherOptions>
515 inline typename icc_11_workaround<OtherMode,OtherOptions>::ResultType
516 operator * (
const Transform<Scalar,Dim,OtherMode,OtherOptions>& other)
const
518 typedef typename icc_11_workaround<OtherMode,OtherOptions>::ProductType ProductType;
519 return ProductType::run(*
this,other);
523 template<
int OtherMode,
int OtherOptions>
524 inline typename internal::transform_transform_product_impl<Transform,Transform<Scalar,Dim,OtherMode,OtherOptions> >::ResultType
540 return Transform(MatrixType::Identity());
543 template<
typename OtherDerived>
546 template<
typename OtherDerived>
552 template<
typename OtherDerived>
555 template<
typename OtherDerived>
558 template<
typename RotationType>
561 template<
typename RotationType>
571 inline Transform& operator=(
const UniformScaling<Scalar>& t);
572 inline Transform& operator*=(
const UniformScaling<Scalar>& s) {
return scale(s.factor()); }
576 res.scale(s.factor());
580 inline Transform& operator*=(
const DiagonalMatrix<Scalar,Dim>& s) {
linear() *= s;
return *
this; }
582 template<
typename Derived>
583 inline Transform& operator=(
const RotationBase<Derived,Dim>& r);
584 template<
typename Derived>
585 inline Transform& operator*=(
const RotationBase<Derived,Dim>& r) {
return rotate(r.toRotationMatrix()); }
586 template<
typename Derived>
590 template<
typename RotationMatrixType,
typename ScalingMatrixType>
592 template<
typename ScalingMatrixType,
typename RotationMatrixType>
595 template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
596 Transform& fromPositionOrientationScale(
const MatrixBase<PositionDerived> &position,
597 const OrientationType& orientation,
const MatrixBase<ScaleDerived> &scale);
611 template<
typename NewScalarType>
616 template<
typename OtherScalarType>
619 check_template_params();
628 {
return m_matrix.isApprox(other.m_matrix,
prec); }
648 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,Dim>(0,0); }
655 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
661 {
return m_matrix.template block<int(Mode)==int(Projective)?HDim:Dim,1>(0,Dim); }
664 #ifdef EIGEN_TRANSFORM_PLUGIN
665 #include EIGEN_TRANSFORM_PLUGIN
669 #ifndef EIGEN_PARSED_BY_DOXYGEN
670 static EIGEN_STRONG_INLINE
void check_template_params()
672 EIGEN_STATIC_ASSERT((Options & (
DontAlign|
RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS)
679typedef Transform<float,2,Isometry> Isometry2f;
681typedef Transform<float,3,Isometry> Isometry3f;
683typedef Transform<double,2,Isometry> Isometry2d;
685typedef Transform<double,3,Isometry> Isometry3d;
688typedef Transform<float,2,Affine> Affine2f;
690typedef Transform<float,3,Affine> Affine3f;
692typedef Transform<double,2,Affine> Affine2d;
694typedef Transform<double,3,Affine> Affine3d;
697typedef Transform<float,2,AffineCompact> AffineCompact2f;
699typedef Transform<float,3,AffineCompact> AffineCompact3f;
701typedef Transform<double,2,AffineCompact> AffineCompact2d;
703typedef Transform<double,3,AffineCompact> AffineCompact3d;
706typedef Transform<float,2,Projective> Projective2f;
708typedef Transform<float,3,Projective> Projective3f;
710typedef Transform<double,2,Projective> Projective2d;
712typedef Transform<double,3,Projective> Projective3d;
718#ifdef EIGEN_QT_SUPPORT
723template<
typename Scalar,
int Dim,
int Mode,
int Options>
724Transform<Scalar,Dim,Mode,Options>::Transform(
const QMatrix& other)
726 check_template_params();
734template<
typename Scalar,
int Dim,
int Mode,
int Options>
735Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(
const QMatrix& other)
737 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
739 m_matrix << other.m11(), other.m21(), other.dx(),
740 other.m12(), other.m22(), other.dy();
742 m_matrix << other.m11(), other.m21(), other.dx(),
743 other.m12(), other.m22(), other.dy(),
754template<
typename Scalar,
int Dim,
int Mode,
int Options>
755QMatrix Transform<Scalar,Dim,Mode,Options>::toQMatrix(
void)
const
757 check_template_params();
758 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
759 return QMatrix(m_matrix.coeff(0,0), m_matrix.coeff(1,0),
760 m_matrix.coeff(0,1), m_matrix.coeff(1,1),
761 m_matrix.coeff(0,2), m_matrix.coeff(1,2));
768template<
typename Scalar,
int Dim,
int Mode,
int Options>
769Transform<Scalar,Dim,Mode,Options>::Transform(
const QTransform& other)
771 check_template_params();
779template<
typename Scalar,
int Dim,
int Mode,
int Options>
780Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(
const QTransform& other)
782 check_template_params();
783 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
785 m_matrix << other.m11(), other.m21(), other.dx(),
786 other.m12(), other.m22(), other.dy();
788 m_matrix << other.m11(), other.m21(), other.dx(),
789 other.m12(), other.m22(), other.dy(),
790 other.m13(), other.m23(), other.m33();
798template<
typename Scalar,
int Dim,
int Mode,
int Options>
799QTransform Transform<Scalar,Dim,Mode,Options>::toQTransform(
void)
const
801 EIGEN_STATIC_ASSERT(Dim==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
803 return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0),
804 m_matrix.coeff(0,1), m_matrix.coeff(1,1),
805 m_matrix.coeff(0,2), m_matrix.coeff(1,2));
807 return QTransform(m_matrix.coeff(0,0), m_matrix.coeff(1,0), m_matrix.coeff(2,0),
808 m_matrix.coeff(0,1), m_matrix.coeff(1,1), m_matrix.coeff(2,1),
809 m_matrix.coeff(0,2), m_matrix.coeff(1,2), m_matrix.coeff(2,2));
821template<
typename Scalar,
int Dim,
int Mode,
int Options>
822template<
typename OtherDerived>
823Transform<Scalar,Dim,Mode,Options>&
826 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
OtherDerived,
int(Dim))
827 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
828 linearExt().noalias() = (linearExt() * other.asDiagonal());
836template<
typename Scalar,
int Dim,
int Mode,
int Options>
839 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
848template<
typename Scalar,
int Dim,
int Mode,
int Options>
849template<
typename OtherDerived>
853 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
OtherDerived,
int(Dim))
854 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
863template<
typename Scalar,
int Dim,
int Mode,
int Options>
866 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
875template<
typename Scalar,
int Dim,
int Mode,
int Options>
876template<
typename OtherDerived>
880 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
OtherDerived,
int(Dim))
881 translationExt() += linearExt() * other;
889template<
typename Scalar,
int Dim,
int Mode,
int Options>
890template<
typename OtherDerived>
894 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
OtherDerived,
int(Dim))
896 affine() += other * m_matrix.row(Dim);
898 translation() += other;
919template<
typename Scalar,
int Dim,
int Mode,
int Options>
920template<
typename RotationType>
924 linearExt() *= internal::toRotationMatrix<Scalar,Dim>(rotation);
935template<
typename Scalar,
int Dim,
int Mode,
int Options>
936template<
typename RotationType>
940 m_matrix.template
block<Dim,HDim>(0,0) = internal::toRotationMatrix<Scalar,Dim>(rotation)
950template<
typename Scalar,
int Dim,
int Mode,
int Options>
954 EIGEN_STATIC_ASSERT(
int(Dim)==2, YOU_MADE_A_PROGRAMMING_MISTAKE)
955 EIGEN_STATIC_ASSERT(Mode!=
int(
Isometry), THIS_METHOD_IS_ONLY_FOR_SPECIFIC_TRANSFORMATIONS)
957 linear() << linear().col(0) + linear().col(1)*
sx, tmp;
966template<
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)
980template<
typename Scalar,
int Dim,
int Mode,
int Options>
984 translation() = t.vector();
989template<
typename Scalar,
int Dim,
int Mode,
int Options>
990inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(
const TranslationType& t)
const
992 Transform res = *
this;
993 res.translate(t.vector());
997template<
typename Scalar,
int Dim,
int Mode,
int Options>
998inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(
const UniformScaling<Scalar>& s)
1001 linear().diagonal().fill(s.factor());
1006template<
typename Scalar,
int Dim,
int Mode,
int Options>
1007template<
typename Derived>
1008inline Transform<Scalar,Dim,Mode,Options>& Transform<Scalar,Dim,Mode,Options>::operator=(
const RotationBase<Derived,Dim>& r)
1010 linear() = internal::toRotationMatrix<Scalar,Dim>(r);
1011 translation().setZero();
1016template<
typename Scalar,
int Dim,
int Mode,
int Options>
1017template<
typename Derived>
1018inline Transform<Scalar,Dim,Mode,Options> Transform<Scalar,Dim,Mode,Options>::operator*(
const RotationBase<Derived,Dim>& r)
const
1020 Transform res = *
this;
1021 res.rotate(r.derived());
1036template<
typename Scalar,
int Dim,
int Mode,
int Options>
1037const typename Transform<Scalar,Dim,Mode,Options>::LinearMatrixType
1057template<
typename Scalar,
int Dim,
int Mode,
int Options>
1058template<
typename RotationMatrixType,
typename ScalingMatrixType>
1063 Scalar x = (
svd.matrixU() *
svd.matrixV().adjoint()).determinant();
1065 sv.coeffRef(0) *= x;
1071 rotation->lazyAssign(m *
svd.matrixV().adjoint());
1086template<
typename Scalar,
int Dim,
int Mode,
int Options>
1087template<
typename ScalingMatrixType,
typename RotationMatrixType>
1092 Scalar x = (
svd.matrixU() *
svd.matrixV().adjoint()).determinant();
1094 sv.coeffRef(0) *= x;
1100 rotation->lazyAssign(m *
svd.matrixV().adjoint());
1107template<
typename Scalar,
int Dim,
int Mode,
int Options>
1108template<
typename PositionDerived,
typename OrientationType,
typename ScaleDerived>
1113 linear() = internal::toRotationMatrix<Scalar,Dim>(
orientation);
1114 linear() *= scale.asDiagonal();
1115 translation() = position;
1125 template<
typename MatrixType>
1126 static void run(MatrixType &
mat)
1128 static const int Dim = MatrixType::ColsAtCompileTime-1;
1130 mat.coeffRef(Dim,Dim) =
typename MatrixType::Scalar(1);
1137 template<
typename MatrixType>
static void run(MatrixType &) { }
1141template<
typename TransformType,
int Mode=TransformType::Mode>
1144 static inline void run(
const TransformType&, TransformType&)
1148template<
typename TransformType>
1151 static inline void run(
const TransformType& m, TransformType& res)
1153 res.matrix() = m.matrix().inverse();
1180template<
typename Scalar,
int Dim,
int Mode,
int Options>
1201 eigen_assert(
false &&
"Invalid transform traits in Transform::Inverse");
1218 typedef typename TransformType::MatrixType MatrixType;
1219 typedef typename TransformType::AffinePart AffinePart;
1220 typedef typename TransformType::ConstAffinePart ConstAffinePart;
1221 static inline AffinePart run(MatrixType& m)
1223 static inline ConstAffinePart run(
const MatrixType& m)
1227template<
typename Scalar,
int Dim,
int Options>
1238template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1243 transform->linear() = other;
1244 transform->translation().setZero();
1245 transform->makeAffine();
1249template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1254 transform->affine() = other;
1255 transform->makeAffine();
1259template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1263 { transform->matrix() = other; }
1266template<
typename Other,
int Options,
int Dim,
int HDim>
1277template<
int LhsMode,
int RhsMode>
1290template<
typename TransformType,
typename MatrixType >
1293 typedef typename MatrixType::PlainObject ResultType;
1295 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1297 return T.matrix() * other;
1301template<
typename TransformType,
typename MatrixType >
1305 Dim = TransformType::Dim,
1306 HDim = TransformType::HDim,
1307 OtherRows = MatrixType::RowsAtCompileTime,
1308 OtherCols = MatrixType::ColsAtCompileTime
1311 typedef typename MatrixType::PlainObject ResultType;
1313 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1315 EIGEN_STATIC_ASSERT(OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1317 typedef Block<ResultType, Dim, OtherCols, int(MatrixType::RowsAtCompileTime)==Dim>
TopLeftLhs;
1319 ResultType res(other.rows(),other.cols());
1320 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other;
1321 res.row(OtherRows-1) = other.row(OtherRows-1);
1327template<
typename TransformType,
typename MatrixType >
1331 Dim = TransformType::Dim,
1332 HDim = TransformType::HDim,
1333 OtherRows = MatrixType::RowsAtCompileTime,
1334 OtherCols = MatrixType::ColsAtCompileTime
1337 typedef typename MatrixType::PlainObject ResultType;
1339 static EIGEN_STRONG_INLINE ResultType run(
const TransformType& T,
const MatrixType& other)
1341 EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES);
1345 TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() += T.linear() * other;
1356template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1360 typedef typename TransformType::MatrixType MatrixType;
1367template<
typename Other,
int Options,
int Dim,
int HDim>
1371 typedef typename TransformType::MatrixType MatrixType;
1377 res.matrix().col(Dim) += other.col(Dim);
1383template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1387 typedef typename TransformType::MatrixType MatrixType;
1392 res.affine().noalias() = other *
tr.matrix();
1393 res.matrix().row(Dim) =
tr.matrix().row(Dim);
1399template<
typename Other,
int Options,
int Dim,
int HDim>
1403 typedef typename TransformType::MatrixType MatrixType;
1409 res.translation() += other.col(Dim);
1415template<
typename Other,
int Mode,
int Options,
int Dim,
int HDim>
1419 typedef typename TransformType::MatrixType MatrixType;
1425 res.matrix().row(Dim) =
tr.matrix().row(Dim);
1436template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1446 res.linear() = lhs.linear() * rhs.linear();
1447 res.translation() = lhs.linear() * rhs.translation() + lhs.translation();
1453template<
typename Scalar,
int Dim,
int LhsMode,
int LhsOptions,
int RhsMode,
int RhsOptions>
1461 return ResultType( lhs.matrix() * rhs.matrix() );
1465template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1474 res.matrix().template
topRows<Dim>() = lhs.matrix() * rhs.matrix();
1475 res.matrix().row(Dim) = rhs.matrix().row(Dim);
1480template<
typename Scalar,
int Dim,
int LhsOptions,
int RhsOptions>
1489 res.matrix().col(Dim) += lhs.matrix().col(Dim);
Expression of a fixed-size or dynamic-size block.
Definition Block.h:106
Pseudo expression representing a solving operation.
Definition Solve.h:63
TransformTraits
Enum used to specify how a particular transformation is stored in a matrix.
Definition Constants.h:445
@ DontAlign
Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated,...
Definition Constants.h:326
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
@ ComputeFullV
Used in JacobiSVD to indicate that the square matrix V is to be computed.
Definition Constants.h:387
@ ComputeFullU
Used in JacobiSVD to indicate that the square matrix U is to be computed.
Definition Constants.h:383
@ Affine
Transformation is an affine transformation stored as a (Dim+1)^2 matrix whose last row is assumed to ...
Definition Constants.h:450
@ Projective
Transformation is a general projective transformation stored as a (Dim+1)^2 matrix.
Definition Constants.h:454
@ AffineCompact
Transformation is an affine transformation stored as a (Dim) x (Dim+1) matrix.
Definition Constants.h:452
@ Isometry
Transformation is an isometry.
Definition Constants.h:447
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
The type used to identify a dense storage.
Definition Constants.h:490
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition XprHelper.h:500
Definition ForwardDeclarations.h:17