diff options
author | Gael Guennebaud <g.gael@free.fr> | 2011-03-02 19:26:38 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2011-03-02 19:26:38 +0100 |
commit | d30f0c0953fa544bb4271234da6853a947ac1a7c (patch) | |
tree | bc21444783d4cb9e73c1d372bfdfb079f140cf89 /Eigen | |
parent | adacacb28586a69b7496105cbe48b2bcea69055c (diff) |
fix transform * matrix products: in particular it now truely considers the rhs as a set of (homogeneous) points and do not neglect the homogeneous coordinates in the case of affine transform
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Geometry/Transform.h | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index cc3e26304..6ced2d1e5 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -43,7 +43,9 @@ struct transform_traits template< typename TransformType, typename MatrixType, - bool IsProjective = transform_traits<TransformType>::IsProjective> + int Case = transform_traits<TransformType>::IsProjective ? 0 + : int(MatrixType::RowsAtCompileTime) == int(transform_traits<TransformType>::HDim) ? 1 + : 2> struct transform_right_product_impl; template< typename Other, @@ -1204,7 +1206,7 @@ struct transform_product_result }; template< typename TransformType, typename MatrixType > -struct transform_right_product_impl< TransformType, MatrixType, true > +struct transform_right_product_impl< TransformType, MatrixType, 0 > { typedef typename MatrixType::PlainObject ResultType; @@ -1215,7 +1217,7 @@ struct transform_right_product_impl< TransformType, MatrixType, true > }; template< typename TransformType, typename MatrixType > -struct transform_right_product_impl< TransformType, MatrixType, false > +struct transform_right_product_impl< TransformType, MatrixType, 1 > { enum { Dim = TransformType::Dim, @@ -1228,20 +1230,39 @@ struct transform_right_product_impl< TransformType, MatrixType, false > EIGEN_STRONG_INLINE static ResultType run(const TransformType& T, const MatrixType& other) { - EIGEN_STATIC_ASSERT(OtherRows==Dim || OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); + EIGEN_STATIC_ASSERT(OtherRows==HDim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); typedef Block<ResultType, Dim, OtherCols> TopLeftLhs; - typedef Block<const MatrixType, Dim, OtherCols> TopLeftRhs; ResultType res(other.rows(),other.cols()); + TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.affine() * other; + res.row(OtherRows-1) = other.row(OtherRows-1); + + return res; + } +}; - TopLeftLhs(res, 0, 0, Dim, other.cols()) = - ( T.linear() * TopLeftRhs(other, 0, 0, Dim, other.cols()) ).colwise() + - T.translation(); +template< typename TransformType, typename MatrixType > +struct transform_right_product_impl< TransformType, MatrixType, 2 > +{ + enum { + Dim = TransformType::Dim, + HDim = TransformType::HDim, + OtherRows = MatrixType::RowsAtCompileTime, + OtherCols = MatrixType::ColsAtCompileTime + }; + + typedef typename MatrixType::PlainObject ResultType; - // we need to take .rows() because OtherRows might be Dim or HDim - if (OtherRows==HDim) - res.row(other.rows()) = other.row(other.rows()); + EIGEN_STRONG_INLINE static ResultType run(const TransformType& T, const MatrixType& other) + { + EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); + + typedef Block<ResultType, Dim, OtherCols> TopLeftLhs; + + ResultType res(other.rows(),other.cols()); + TopLeftLhs(res, 0, 0, Dim, other.cols()).noalias() = T.linear() * other; + TopLeftLhs(res, 0, 0, Dim, other.cols()).colwise() += T.translation(); return res; } |