From 5c8c09e02188ab4441a99bb07c5feb1308ab068f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 30 Aug 2008 23:10:46 +0000 Subject: [PATCH] add uniform scale/prescale functions in Tranform --- Eigen/src/Geometry/RotationBase.h | 4 ++-- Eigen/src/Geometry/Transform.h | 26 ++++++++++++++++++++++++++ test/geometry.cpp | 18 ++++++++++-------- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Eigen/src/Geometry/RotationBase.h b/Eigen/src/Geometry/RotationBase.h index e436f8fe6..dff905528 100644 --- a/Eigen/src/Geometry/RotationBase.h +++ b/Eigen/src/Geometry/RotationBase.h @@ -77,7 +77,7 @@ template Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> ::Matrix(const RotationBase& r) { - EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,OtherDerived::Dim,OtherDerived::Dim); + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)); *this = r.toRotationMatrix(); } @@ -91,7 +91,7 @@ Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols>& Matrix<_Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols> ::operator=(const RotationBase& r) { - EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,OtherDerived::Dim,OtherDerived::Dim); + EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Matrix,int(OtherDerived::Dim),int(OtherDerived::Dim)); return *this = r.toRotationMatrix(); } diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index da457fc38..7475b75df 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -188,6 +188,9 @@ public: template inline Transform& prescale(const MatrixBase &other); + inline Transform& scale(Scalar s); + inline Transform& prescale(Scalar s); + template inline Transform& translate(const MatrixBase &other); @@ -310,6 +313,17 @@ Transform::scale(const MatrixBase &other) return *this; } +/** Applies on the right a uniform scale of a factor \a c to \c *this + * and returns a reference to \c *this. + * \sa prescale(Scalar) + */ +template +inline Transform& Transform::scale(Scalar s) +{ + linear() *= s; + return *this; +} + /** Applies on the left the non uniform scale transformation represented * by the vector \a other to \c *this and returns a reference to \c *this. * \sa scale() @@ -324,6 +338,17 @@ Transform::prescale(const MatrixBase &other) return *this; } +/** Applies on the left a uniform scale of a factor \a c to \c *this + * and returns a reference to \c *this. + * \sa scale(Scalar) + */ +template +inline Transform& Transform::prescale(Scalar s) +{ + m_matrix.template corner(TopLeft) *= s; + return *this; +} + /** Applies on the right the translation matrix represented by the vector \a other * to \c *this and returns a reference to \c *this. * \sa pretranslate() @@ -516,6 +541,7 @@ Transform::extractRotation(TransformTraits traits) const return linear(); else ei_assert("invalid traits value in Transform::inverse()"); + return LinearMatrixType(); } /** Convenient method to set \c *this from a position, orientation and scale diff --git a/test/geometry.cpp b/test/geometry.cpp index 2bad57f62..0654bed65 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -157,6 +157,16 @@ template void geometry(void) VERIFY_IS_APPROX(t1.matrix(), t0.matrix()); VERIFY_IS_APPROX(t1*v1, t0*v1); + t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix()); + t1.setIdentity(); t1.scale(v0).rotate(q1); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + t0.setIdentity(); t0.scale(v0).rotate(AngleAxis(q1)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + VERIFY_IS_APPROX(t0.scale(a).matrix(), t1.scale(Vector3::Constant(a)).matrix()); + VERIFY_IS_APPROX(t0.prescale(a).matrix(), t1.prescale(Vector3::Constant(a)).matrix()); + // 2D transformation Transform2 t20, t21; Vector2 v20 = test_random_matrix(); @@ -173,14 +183,6 @@ template void geometry(void) VERIFY( (t20.fromPositionOrientationScale(v20,a,v21) * (t21.prescale(v21.cwise().inverse()).translate(-v20))).isIdentity(test_precision()) ); - - t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix()); - t1.setIdentity(); t1.scale(v0).rotate(q1); - VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); - - t0.setIdentity(); t0.scale(v0).rotate(AngleAxis(q1)); - VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); - // Transform - new API // 3D t0.setIdentity();