From 14691d68363b4903621400d670d0b3649cb5b02a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 10 Mar 2009 11:55:50 +0000 Subject: [PATCH] fix compilation with old, and future gcc --- Eigen/src/Core/MapBase.h | 2 +- Eigen/src/Core/MatrixBase.h | 11 ++- Eigen/src/Geometry/Homogeneous.h | 38 ++++---- Eigen/src/Geometry/Transform.h | 151 +++++++++++++++---------------- 4 files changed, 98 insertions(+), 104 deletions(-) diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index c923bc340..ed3d2cbf8 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -176,7 +176,7 @@ template class MapBase { return Base::operator=(other); } - + using Base::operator*=; template diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 9b54ac28c..0f0958d09 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -585,11 +585,11 @@ template class MatrixBase select(typename ElseDerived::Scalar thenScalar, const MatrixBase& elseMatrix) const; template RealScalar lpNorm() const; - + template const Replicate replicate() const; const Replicate replicate(int rowFacor,int colFactor) const; - + Eigen::Reverse reverse(); const Eigen::Reverse reverse() const; void reverseInPlace(); @@ -630,11 +630,12 @@ template class MatrixBase typedef Block::ColsAtCompileTime==1 ? SizeMinusOne : 1, ei_traits::ColsAtCompileTime==1 ? 1 : SizeMinusOne> StartMinusOne; - typedef CwiseUnaryOp::Scalar>, + typedef CwiseUnaryOp::Scalar>, NestByValue > HNormalizedReturnType; - + const HNormalizedReturnType hnormalized() const; - const Homogeneous::ColsAtCompileTime==1?Vertical:Horizontal> homogeneous() const; + typedef Homogeneous::ColsAtCompileTime==1?Vertical:Horizontal> HomogeneousReturnType; + const HomogeneousReturnType homogeneous() const; /////////// Sparse module /////////// diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index b38932f48..0041ca51f 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -26,7 +26,7 @@ #define EIGEN_HOMOGENEOUS_H /** \geometry_module \ingroup Geometry_Module - * \nonstableyet + * \nonstableyet * \class Homogeneous * * \brief Expression of one (or a set of) homogeneous vector(s) @@ -83,7 +83,7 @@ template class Homogeneous return 1; return m_matrix.coeff(row, col); } - + template inline const ei_homogeneous_right_product_impl operator* (const MatrixBase& rhs) const @@ -91,16 +91,16 @@ template class Homogeneous ei_assert(Direction==Horizontal); return ei_homogeneous_right_product_impl(m_matrix,rhs.derived()); } - - template friend + + template friend inline const ei_homogeneous_left_product_impl operator* (const MatrixBase& lhs, const Homogeneous& rhs) { ei_assert(Direction==Vertical); return ei_homogeneous_left_product_impl(lhs.derived(),rhs.m_matrix); } - - template friend + + template friend inline const ei_homogeneous_left_product_impl::AffinePart> operator* (const Transform& tr, const Homogeneous& rhs) @@ -109,8 +109,8 @@ template class Homogeneous return ei_homogeneous_left_product_impl::AffinePart> (tr.affine(),rhs.m_matrix); } - - template friend + + template friend inline const ei_homogeneous_left_product_impl::MatrixType> operator* (const Transform& tr, const Homogeneous& rhs) @@ -125,9 +125,9 @@ template class Homogeneous }; /** \geometry_module - * \nonstableyet + * \nonstableyet * \return an expression of the equivalent homogeneous vector - * + * * \vectoronly * * Example: \include MatrixBase_homogeneous.cpp @@ -136,7 +136,7 @@ template class Homogeneous * \sa class Homogeneous */ template -inline const Homogeneous::ColsAtCompileTime==1?Vertical:Horizontal> +inline const typename MatrixBase::HomogeneousReturnType MatrixBase::homogeneous() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); @@ -144,7 +144,7 @@ MatrixBase::homogeneous() const } /** \geometry_module - * \nonstableyet + * \nonstableyet * \returns a matrix expression of homogeneous column (or row) vectors * * Example: \include PartialRedux_homogeneous.cpp @@ -159,7 +159,7 @@ PartialRedux::homogeneous() const } /** \geometry_module - * \nonstableyet + * \nonstableyet * \returns an expression of the homogeneous normalized vector of \c *this * * Example: \include MatrixBase_hnormalized.cpp @@ -177,7 +177,7 @@ MatrixBase::hnormalized() const } /** \geometry_module - * \nonstableyet + * \nonstableyet * \returns an expression of the homogeneous normalized vector of \c *this * * Example: \include DirectionWise_hnormalized.cpp @@ -214,7 +214,7 @@ struct ei_homogeneous_left_product_impl,Lhs> ei_homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs) : m_lhs(lhs), m_rhs(rhs) {} - + template void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible @@ -225,7 +225,7 @@ struct ei_homogeneous_left_product_impl,Lhs> dst += m_lhs.col(m_lhs.cols()-1).rowwise() .template replicate(m_rhs.cols()); } - + const typename Lhs::Nested m_lhs; const typename MatrixType::Nested m_rhs; }; @@ -240,7 +240,7 @@ struct ei_homogeneous_right_product_impl,Rhs> ei_homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) {} - + template void evalTo(Dest& dst) const { // FIXME investigate how to allow lazy evaluation of this product when possible @@ -251,10 +251,10 @@ struct ei_homogeneous_right_product_impl,Rhs> dst += m_rhs.row(m_rhs.rows()-1).colwise() .template replicate(m_lhs.rows()); } - + const typename MatrixType::Nested m_lhs; const typename Rhs::Nested m_rhs; - + }; #endif // EIGEN_HOMOGENEOUS_H diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index 2977a63ee..a8dc164e4 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -49,6 +49,14 @@ struct ei_transform_left_product_impl; template struct ei_transform_transform_product_impl; +template< typename Other, + int Mode, + int Dim, + int HDim, + int OtherRows=Other::RowsAtCompileTime, + int OtherCols=Other::ColsAtCompileTime> +struct ei_transform_construct_from_matrix; + /** \geometry_module \ingroup Geometry_Module * * \class Transform @@ -69,19 +77,19 @@ template struct ei_transform_transform_product_impl; * is available through the matrix() method. To understand the behavior of * this class you have to think a Transform object as its internal * matrix representation. The chosen convention is right multiply: - * + * * \code v' = T * v \endcode - * + * * Thefore, an affine transformation matrix M is shaped like this: - * + * * \f$ \left( \begin{array}{cc} * linear & translation\\ * 0 ... 0 & 1 * \end{array} \right) \f$ - * + * * Note that for a provective transformation the last row can be anything, * and then the interpretation of different parts might be sighlty different. - * + * * However, unlike a plain matrix, the Transform class provides many features * simplifying both its assembly and usage. In particular, it can be composed * with any other transformations (Transform,Trnaslation,RotationBase,Matrix) @@ -138,7 +146,7 @@ template struct ei_transform_transform_product_impl; * transformation of non homogeneous vectors by an affine transformation. In * that case the last matrix row can be ignored, and the product returns non * homogeneous vectors. - * + * * Since, for instance, a Dim x Dim matrix is interpreted as a linear transformation, * it is not possible to directly transform Dim vectors stored in a Dim x Dim matrix. * The solution is either to use a Dim x Dynamic matrix or explicitely request a @@ -147,7 +155,7 @@ template struct ei_transform_transform_product_impl; * m' = T * m.colwise().homogeneous(); * \endcode * Note that there is zero overhead. - * + * * Conversion methods from/to Qt's QMatrix and QTransform are available if the * preprocessor token EIGEN_QT_SUPPORT is defined. * @@ -193,7 +201,7 @@ public: inline Transform() { } inline Transform(const Transform& other) - { + { m_matrix = other.m_matrix; } @@ -205,95 +213,37 @@ public: inline Transform& operator=(const Transform& other) { m_matrix = other.m_matrix; return *this; } - template - struct construct_from_matrix; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { - transform->linear() = other; - transform->translation().setZero(); - transform->makeAffine(); - } - }; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { - transform->linear() = other; - transform->translation().setZero(); - } - }; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { - transform->affine() = other; - transform->makeAffine(); - } - }; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { transform->affine() = other; } - }; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { transform->matrix() = other; } - }; - - template struct construct_from_matrix - { - static inline void run(Transform *transform, const MatrixBase& other) - { transform->matrix() = other.template block(0,0); } - }; - typedef ei_transform_take_affine_part take_affine_part; /** Constructs and initializes a transformation from a Dim^2 or a (Dim+1)^2 matrix. */ template inline explicit Transform(const MatrixBase& other) { - construct_from_matrix::run(this, other); + ei_transform_construct_from_matrix::run(this, other.derived()); } /** Set \c *this from a Dim^2 or (Dim+1)^2 matrix. */ template inline Transform& operator=(const MatrixBase& other) { - construct_from_matrix::run(this, other); + ei_transform_construct_from_matrix::run(this, other.derived()); return *this; } - + template inline Transform(const Transform& other) { ei_assert(OtherMode!=Projective && "You cannot directly assign a projective transform to an affine one."); typedef typename Transform::MatrixType OtherMatrixType; - construct_from_matrix::run(this, other.matrix()); + ei_transform_construct_from_matrix::run(this, other.matrix()); } - + template Transform(const ReturnByValue& other) { other.evalTo(*this); } - + template Transform& operator=(const ReturnByValue& other) { @@ -326,7 +276,7 @@ public: inline const LinearPart linear() const { return m_matrix.template block(0,0); } /** \returns a writable expression of the linear part of the transformation */ inline LinearPart linear() { return m_matrix.template block(0,0); } - + /** \returns a read-only expression of the Dim x HDim affine part of the transformation */ inline const AffinePart affine() const { return take_affine_part::run(m_matrix); } /** \returns a writable expression of the Dim x HDim affine part of the transformation */ @@ -365,7 +315,7 @@ public: inline const typename ei_transform_left_product_impl::ResultType operator * (const MatrixBase &a, const Transform &b) { return ei_transform_left_product_impl::run(a.derived(),b); } - + template inline Transform& operator*=(const MatrixBase& other) { return *this = *this * other; } @@ -374,7 +324,7 @@ public: { return ei_transform_transform_product_impl::run(*this,other); } - + /** Contatenates two different transformations */ template inline const typename ei_transform_transform_product_impl< @@ -474,7 +424,7 @@ public: matrix().coeffRef(Dim,Dim) = 1; } } - + /** \internal * \returns the Dim x Dim linear part if the transformation is affine, * and the HDim x Dim part for projective transformations. @@ -487,7 +437,7 @@ public: */ inline const Block linearExt() const { return m_matrix.template block(0,0); } - + /** \internal * \returns the translation part if the transformation is affine, * and the last column for projective transformations. @@ -500,7 +450,7 @@ public: */ inline const Block translationExt() const { return m_matrix.template block(0,Dim); } - + }; /** \ingroup Geometry_Module */ @@ -889,7 +839,7 @@ template template void Transform::computeScalingRotation(ScalingMatrixType *scaling, RotationMatrixType *rotation) const { - linear().svd().computeScalingRotation(scaling, rotation); + linear().svd().computeScalingRotation(scaling, rotation); } /** Convenient method to set \c *this from a position, orientation and scale @@ -958,6 +908,10 @@ Transform::inverse(TransformTraits hint) const } } +/***************************************************** +*** Specializations of take affine part *** +*****************************************************/ + template struct ei_transform_take_affine_part { typedef typename TransformType::MatrixType MatrixType; typedef typename TransformType::AffinePart AffinePart; @@ -974,6 +928,45 @@ struct ei_transform_take_affine_part > { static inline const MatrixType& run(const MatrixType& m) { return m; } }; +/***************************************************** +*** Specializations of construct from matix *** +*****************************************************/ + +template +struct ei_transform_construct_from_matrix +{ + static inline void run(Transform::Scalar,Dim,Mode> *transform, const Other& other) + { + transform->linear() = other; + transform->translation().setZero(); + transform->makeAffine(); + } +}; + +template +struct ei_transform_construct_from_matrix +{ + static inline void run(Transform::Scalar,Dim,Mode> *transform, const Other& other) + { + transform->affine() = other; + transform->makeAffine(); + } +}; + +template +struct ei_transform_construct_from_matrix +{ + static inline void run(Transform::Scalar,Dim,Mode> *transform, const Other& other) + { transform->matrix() = other; } +}; + +template +struct ei_transform_construct_from_matrix +{ + static inline void run(Transform::Scalar,Dim,AffineCompact> *transform, const Other& other) + { transform->matrix() = other.template block(0,0); } +}; + /***************************************************** *** Specializations of operator* with a MatrixBase *** *****************************************************/