From 52fed69baa36afc6dba77bdb112f80da486c0b7e Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 27 Jan 2011 11:21:38 -0500 Subject: [PATCH] add test for geometry with eigen2_ prefixes. fix that stuff. --- Eigen/src/Core/Matrix.h | 7 + Eigen/src/Core/MatrixBase.h | 2 +- Eigen/src/Core/util/ForwardDeclarations.h | 3 +- Eigen/src/Eigen2Support/Geometry/AlignedBox.h | 5 +- Eigen/src/Eigen2Support/Geometry/All.h | 8 + Eigen/src/Eigen2Support/Geometry/AngleAxis.h | 6 +- Eigen/src/Eigen2Support/Geometry/Hyperplane.h | 17 +- .../Eigen2Support/Geometry/ParametrizedLine.h | 14 +- Eigen/src/Eigen2Support/Geometry/Quaternion.h | 15 +- Eigen/src/Eigen2Support/Geometry/Rotation2D.h | 6 +- .../src/Eigen2Support/Geometry/RotationBase.h | 5 +- Eigen/src/Eigen2Support/Geometry/Scaling.h | 6 +- Eigen/src/Eigen2Support/Geometry/Transform.h | 6 +- .../src/Eigen2Support/Geometry/Translation.h | 6 +- Eigen/src/Eigen2Support/LeastSquares.h | 6 +- Eigen/src/Eigen2Support/SVD.h | 12 +- test/eigen2/CMakeLists.txt | 1 + .../eigen2_geometry_with_eigen2_prefix.cpp | 449 ++++++++++++++++++ 18 files changed, 508 insertions(+), 66 deletions(-) create mode 100644 test/eigen2/eigen2_geometry_with_eigen2_prefix.cpp diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 70b7eb66c..f41d554ec 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -336,6 +336,13 @@ class Matrix template Matrix& operator=(const RotationBase& r); + #ifdef EIGEN2_SUPPORT + template + explicit Matrix(const eigen2_RotationBase& r); + template + Matrix& operator=(const eigen2_RotationBase& r); + #endif + // allow to extend Matrix outside Eigen #ifdef EIGEN_MATRIX_PLUGIN #include EIGEN_MATRIX_PLUGIN diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 096438f96..5864cdbd6 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -204,7 +204,7 @@ template class MatrixBase template typename internal::scalar_product_traits::Scalar,typename internal::traits::Scalar>::ReturnType #if EIGEN2_SUPPORT_STAGE == STAGE15_RESOLVE_API_CONFLICTS_WARN - EIGEN_DEPRECATED Scalar + EIGEN_DEPRECATED #endif dot(const MatrixBase& other) const; #endif diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index e873f15cb..00742e4b1 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -220,7 +220,6 @@ template class JacobiRotation; template class RotationBase; template class Cross; template class QuaternionBase; -template class Quaternion; template class Rotation2D; template class AngleAxis; template class Translation; @@ -239,6 +238,7 @@ template class eigen2_Scaling; #endif #if EIGEN2_SUPPORT_STAGE < STAGE20_RESOLVE_API_CONFLICTS +template class Quaternion; template class Transform; template class ParametrizedLine; template class Hyperplane; @@ -246,6 +246,7 @@ template class Scaling; #endif #if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS +template class Quaternion; template class Transform; template class ParametrizedLine; template class Hyperplane; diff --git a/Eigen/src/Eigen2Support/Geometry/AlignedBox.h b/Eigen/src/Eigen2Support/Geometry/AlignedBox.h index cedce218c..1c915be22 100644 --- a/Eigen/src/Eigen2Support/Geometry/AlignedBox.h +++ b/Eigen/src/Eigen2Support/Geometry/AlignedBox.h @@ -22,8 +22,7 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_ALIGNEDBOX_H -#define EIGEN_ALIGNEDBOX_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway /** \geometry_module \ingroup Geometry_Module * \nonstableyet @@ -169,5 +168,3 @@ inline Scalar AlignedBox::squaredExteriorDistance(const Vecto } return dist2; } - -#endif // EIGEN_ALIGNEDBOX_H diff --git a/Eigen/src/Eigen2Support/Geometry/All.h b/Eigen/src/Eigen2Support/Geometry/All.h index a399549fe..7b076806b 100644 --- a/Eigen/src/Eigen2Support/Geometry/All.h +++ b/Eigen/src/Eigen2Support/Geometry/All.h @@ -58,6 +58,10 @@ #define Hyperplane eigen2_Hyperplane #define ParametrizedLine eigen2_ParametrizedLine +#define ei_toRotationMatrix eigen2_ei_toRotationMatrix +#define ei_quaternion_assign_impl eigen2_ei_quaternion_assign_impl +#define ei_transform_product_impl eigen2_ei_transform_product_impl + #include "RotationBase.h" #include "Rotation2D.h" #include "Quaternion.h" @@ -69,6 +73,10 @@ #include "Hyperplane.h" #include "ParametrizedLine.h" +#undef ei_toRotationMatrix +#undef ei_quaternion_assign_impl +#undef ei_transform_product_impl + #undef RotationBase #undef Rotation2D #undef Rotation2Df diff --git a/Eigen/src/Eigen2Support/Geometry/AngleAxis.h b/Eigen/src/Eigen2Support/Geometry/AngleAxis.h index d1b784066..f7b2d51e3 100644 --- a/Eigen/src/Eigen2Support/Geometry/AngleAxis.h +++ b/Eigen/src/Eigen2Support/Geometry/AngleAxis.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_ANGLEAXIS_H -#define EIGEN_ANGLEAXIS_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + /** \geometry_module \ingroup Geometry_Module * @@ -224,5 +224,3 @@ AngleAxis::toRotationMatrix(void) const return res; } - -#endif // EIGEN_ANGLEAXIS_H diff --git a/Eigen/src/Eigen2Support/Geometry/Hyperplane.h b/Eigen/src/Eigen2Support/Geometry/Hyperplane.h index 420b30fe9..81c4f55b1 100644 --- a/Eigen/src/Eigen2Support/Geometry/Hyperplane.h +++ b/Eigen/src/Eigen2Support/Geometry/Hyperplane.h @@ -23,8 +23,7 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_HYPERPLANE_H -#define EIGEN_HYPERPLANE_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway /** \geometry_module \ingroup Geometry_Module * @@ -71,7 +70,7 @@ public: : m_coeffs(n.size()+1) { normal() = n; - offset() = -e.dot(n); + offset() = -e.eigen2_dot(n); } /** Constructs a plane from its normal \a n and distance to the origin \a d @@ -92,7 +91,7 @@ public: { Hyperplane result(p0.size()); result.normal() = (p1 - p0).unitOrthogonal(); - result.offset() = -result.normal().dot(p0); + result.offset() = -result.normal().eigen2_dot(p0); return result; } @@ -104,7 +103,7 @@ public: EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 3) Hyperplane result(p0.size()); result.normal() = (p2 - p0).cross(p1 - p0).normalized(); - result.offset() = -result.normal().dot(p0); + result.offset() = -result.normal().eigen2_dot(p0); return result; } @@ -116,7 +115,7 @@ public: explicit Hyperplane(const ParametrizedLine& parametrized) { normal() = parametrized.direction().unitOrthogonal(); - offset() = -normal().dot(parametrized.origin()); + offset() = -normal().eigen2_dot(parametrized.origin()); } ~Hyperplane() {} @@ -133,7 +132,7 @@ public: /** \returns the signed distance between the plane \c *this and a point \a p. * \sa absDistance() */ - inline Scalar signedDistance(const VectorType& p) const { return p.dot(normal()) + offset(); } + inline Scalar signedDistance(const VectorType& p) const { return p.eigen2_dot(normal()) + offset(); } /** \returns the absolute distance between the plane \c *this and a point \a p. * \sa signedDistance() @@ -231,7 +230,7 @@ public: TransformTraits traits = Affine) { transform(t.linear(), traits); - offset() -= t.translation().dot(normal()); + offset() -= t.translation().eigen2_dot(normal()); return *this; } @@ -264,5 +263,3 @@ protected: Coefficients m_coeffs; }; - -#endif // EIGEN_HYPERPLANE_H diff --git a/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h b/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h index d48f44a79..411c4b570 100644 --- a/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h +++ b/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h @@ -23,8 +23,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_PARAMETRIZEDLINE_H -#define EIGEN_PARAMETRIZEDLINE_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + /** \geometry_module \ingroup Geometry_Module * @@ -85,7 +85,7 @@ public: RealScalar squaredDistance(const VectorType& p) const { VectorType diff = p-origin(); - return (diff - diff.dot(direction())* direction()).squaredNorm(); + return (diff - diff.eigen2_dot(direction())* direction()).squaredNorm(); } /** \returns the distance of a point \a p to its projection onto the line \c *this. * \sa squaredDistance() @@ -94,7 +94,7 @@ public: /** \returns the projection of a point \a p onto the line \c *this. */ VectorType projection(const VectorType& p) const - { return origin() + (p-origin()).dot(direction()) * direction(); } + { return origin() + (p-origin()).eigen2_dot(direction()) * direction(); } Scalar intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane); @@ -148,8 +148,6 @@ inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane template inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane) { - return -(hyperplane.offset()+origin().dot(hyperplane.normal())) - /(direction().dot(hyperplane.normal())); + return -(hyperplane.offset()+origin().eigen2_dot(hyperplane.normal())) + /(direction().eigen2_dot(hyperplane.normal())); } - -#endif // EIGEN_PARAMETRIZEDLINE_H diff --git a/Eigen/src/Eigen2Support/Geometry/Quaternion.h b/Eigen/src/Eigen2Support/Geometry/Quaternion.h index c81a3f92a..a75fa42ae 100644 --- a/Eigen/src/Eigen2Support/Geometry/Quaternion.h +++ b/Eigen/src/Eigen2Support/Geometry/Quaternion.h @@ -22,8 +22,7 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_QUATERNION_H -#define EIGEN_QUATERNION_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway template& Quaternion::setFromTwoVectors(const MatrixBas { Vector3 v0 = a.normalized(); Vector3 v1 = b.normalized(); - Scalar c = v0.dot(v1); + Scalar c = v0.eigen2_dot(v1); // if dot == 1, vectors are the same if (ei_isApprox(c,Scalar(1))) @@ -412,12 +411,12 @@ inline Quaternion Quaternion::conjugate() const } /** \returns the angle (in radian) between two rotations - * \sa dot() + * \sa eigen2_dot() */ template inline Scalar Quaternion::angularDistance(const Quaternion& other) const { - double d = ei_abs(this->dot(other)); + double d = ei_abs(this->eigen2_dot(other)); if (d>=1.0) return 0; return Scalar(2) * std::acos(d); @@ -430,7 +429,7 @@ template Quaternion Quaternion::slerp(Scalar t, const Quaternion& other) const { static const Scalar one = Scalar(1) - machine_epsilon(); - Scalar d = this->dot(other); + Scalar d = this->eigen2_dot(other); Scalar absD = ei_abs(d); Scalar scale0; @@ -505,5 +504,3 @@ struct ei_quaternion_assign_impl q.coeffs() = vec; } }; - -#endif // EIGEN_QUATERNION_H diff --git a/Eigen/src/Eigen2Support/Geometry/Rotation2D.h b/Eigen/src/Eigen2Support/Geometry/Rotation2D.h index dfa60d0b3..ee7c80e7e 100644 --- a/Eigen/src/Eigen2Support/Geometry/Rotation2D.h +++ b/Eigen/src/Eigen2Support/Geometry/Rotation2D.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_ROTATION2D_H -#define EIGEN_ROTATION2D_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + /** \geometry_module \ingroup Geometry_Module * @@ -155,5 +155,3 @@ Rotation2D::toRotationMatrix(void) const Scalar cosA = ei_cos(m_angle); return (Matrix2() << cosA, -sinA, sinA, cosA).finished(); } - -#endif // EIGEN_ROTATION2D_H diff --git a/Eigen/src/Eigen2Support/Geometry/RotationBase.h b/Eigen/src/Eigen2Support/Geometry/RotationBase.h index 5fec0f18d..2f494f198 100644 --- a/Eigen/src/Eigen2Support/Geometry/RotationBase.h +++ b/Eigen/src/Eigen2Support/Geometry/RotationBase.h @@ -22,8 +22,7 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_ROTATIONBASE_H -#define EIGEN_ROTATIONBASE_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway // this file aims to contains the various representations of rotation/orientation // in 2D and 3D space excepted Matrix and Quaternion. @@ -133,5 +132,3 @@ inline static const MatrixBase& ei_toRotationMatrix(const MatrixBa YOU_MADE_A_PROGRAMMING_MISTAKE) return mat; } - -#endif // EIGEN_ROTATIONBASE_H diff --git a/Eigen/src/Eigen2Support/Geometry/Scaling.h b/Eigen/src/Eigen2Support/Geometry/Scaling.h index 747ce1d97..108e6d7d5 100644 --- a/Eigen/src/Eigen2Support/Geometry/Scaling.h +++ b/Eigen/src/Eigen2Support/Geometry/Scaling.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_SCALING_H -#define EIGEN_SCALING_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + /** \geometry_module \ingroup Geometry_Module * @@ -177,5 +177,3 @@ Scaling::operator* (const TransformType& t) const res.prescale(m_coeffs); return res; } - -#endif // EIGEN_SCALING_H diff --git a/Eigen/src/Eigen2Support/Geometry/Transform.h b/Eigen/src/Eigen2Support/Geometry/Transform.h index 1374a77dd..88956c86c 100644 --- a/Eigen/src/Eigen2Support/Geometry/Transform.h +++ b/Eigen/src/Eigen2Support/Geometry/Transform.h @@ -23,8 +23,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_TRANSFORM_H -#define EIGEN_TRANSFORM_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + // Note that we have to pass Dim and HDim because it is not allowed to use a template // parameter to define a template specialization. To be more precise, in the following @@ -796,5 +796,3 @@ struct ei_transform_product_impl { return ((tr.linear() * other) + tr.translation()) * (Scalar(1) / ( (tr.matrix().template block<1,Dim>(Dim,0) * other).coeff(0) + tr.matrix().coeff(Dim,Dim))); } }; - -#endif // EIGEN_TRANSFORM_H diff --git a/Eigen/src/Eigen2Support/Geometry/Translation.h b/Eigen/src/Eigen2Support/Geometry/Translation.h index ca5a9115f..e651e3102 100644 --- a/Eigen/src/Eigen2Support/Geometry/Translation.h +++ b/Eigen/src/Eigen2Support/Geometry/Translation.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_TRANSLATION_H -#define EIGEN_TRANSLATION_H +// no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway + /** \geometry_module \ingroup Geometry_Module * @@ -194,5 +194,3 @@ Translation::operator* (const TransformType& t) const res.pretranslate(m_coeffs); return res; } - -#endif // EIGEN_TRANSLATION_H diff --git a/Eigen/src/Eigen2Support/LeastSquares.h b/Eigen/src/Eigen2Support/LeastSquares.h index b2595ede1..4b62ffa92 100644 --- a/Eigen/src/Eigen2Support/LeastSquares.h +++ b/Eigen/src/Eigen2Support/LeastSquares.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_LEASTSQUARES_H -#define EIGEN_LEASTSQUARES_H +#ifndef EIGEN2_LEASTSQUARES_H +#define EIGEN2_LEASTSQUARES_H /** \ingroup LeastSquares_Module * @@ -179,4 +179,4 @@ void fitHyperplane(int numPoints, } -#endif // EIGEN_LEASTSQUARES_H +#endif // EIGEN2_LEASTSQUARES_H diff --git a/Eigen/src/Eigen2Support/SVD.h b/Eigen/src/Eigen2Support/SVD.h index dfb43ac7c..528a0dcd0 100644 --- a/Eigen/src/Eigen2Support/SVD.h +++ b/Eigen/src/Eigen2Support/SVD.h @@ -22,8 +22,8 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifndef EIGEN_SVD_H -#define EIGEN_SVD_H +#ifndef EIGEN2_SVD_H +#define EIGEN2_SVD_H /** \ingroup SVD_Module * \nonstableyet @@ -150,7 +150,7 @@ void SVD::compute(const MatrixType& matrix) if ((k < nct) && (m_sigma[k] != 0.0)) { // Apply the transformation. - Scalar t = matA.col(k).end(m-k).dot(matA.col(j).end(m-k)); // FIXME dot product or cwise prod + .sum() ?? + Scalar t = matA.col(k).end(m-k).eigen2_dot(matA.col(j).end(m-k)); // FIXME dot product or cwise prod + .sum() ?? t = -t/matA(k,k); matA.col(j).end(m-k) += t * matA.col(k).end(m-k); } @@ -216,7 +216,7 @@ void SVD::compute(const MatrixType& matrix) { for (j = k+1; j < nu; ++j) { - Scalar t = m_matU.col(k).end(m-k).dot(m_matU.col(j).end(m-k)); // FIXME is it really a dot product we want ? + Scalar t = m_matU.col(k).end(m-k).eigen2_dot(m_matU.col(j).end(m-k)); // FIXME is it really a dot product we want ? t = -t/m_matU(k,k); m_matU.col(j).end(m-k) += t * m_matU.col(k).end(m-k); } @@ -242,7 +242,7 @@ void SVD::compute(const MatrixType& matrix) { for (j = k+1; j < nu; ++j) { - Scalar t = m_matV.col(k).end(n-k-1).dot(m_matV.col(j).end(n-k-1)); // FIXME is it really a dot product we want ? + Scalar t = m_matV.col(k).end(n-k-1).eigen2_dot(m_matV.col(j).end(n-k-1)); // FIXME is it really a dot product we want ? t = -t/m_matV(k+1,k); m_matV.col(j).end(n-k-1) += t * m_matV.col(k).end(n-k-1); } @@ -646,4 +646,4 @@ MatrixBase::svd() const return SVD(derived()); } -#endif // EIGEN_SVD_H +#endif // EIGEN2_SVD_H diff --git a/test/eigen2/CMakeLists.txt b/test/eigen2/CMakeLists.txt index 45b0bbd84..4b470c869 100644 --- a/test/eigen2/CMakeLists.txt +++ b/test/eigen2/CMakeLists.txt @@ -36,6 +36,7 @@ ei_add_test(eigen2_qr) ei_add_test(eigen2_eigensolver " " "${GSL_LIBRARIES}") ei_add_test(eigen2_svd) ei_add_test(eigen2_geometry) +ei_add_test(eigen2_geometry_with_eigen2_prefix) ei_add_test(eigen2_hyperplane) ei_add_test(eigen2_parametrizedline) ei_add_test(eigen2_alignedbox) diff --git a/test/eigen2/eigen2_geometry_with_eigen2_prefix.cpp b/test/eigen2/eigen2_geometry_with_eigen2_prefix.cpp new file mode 100644 index 000000000..202218a05 --- /dev/null +++ b/test/eigen2/eigen2_geometry_with_eigen2_prefix.cpp @@ -0,0 +1,449 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#define EIGEN2_SUPPORT_STAGE15_RESOLVE_API_CONFLICTS_WARN + +#include "main.h" +#include +#include +#include + +template void geometry(void) +{ + /* this test covers the following files: + Cross.h Quaternion.h, Transform.cpp + */ + + typedef Matrix Matrix2; + typedef Matrix Matrix3; + typedef Matrix Matrix4; + typedef Matrix Vector2; + typedef Matrix Vector3; + typedef Matrix Vector4; + typedef eigen2_Quaternion Quaternionx; + typedef eigen2_AngleAxis AngleAxisx; + typedef eigen2_Transform Transform2; + typedef eigen2_Transform Transform3; + typedef eigen2_Scaling Scaling2; + typedef eigen2_Scaling Scaling3; + typedef eigen2_Translation Translation2; + typedef eigen2_Translation Translation3; + + Scalar largeEps = test_precision(); + if (ei_is_same_type::ret) + largeEps = 1e-2f; + + Vector3 v0 = Vector3::Random(), + v1 = Vector3::Random(), + v2 = Vector3::Random(); + Vector2 u0 = Vector2::Random(); + Matrix3 matrot1; + + Scalar a = ei_random(-Scalar(M_PI), Scalar(M_PI)); + + // cross product + VERIFY_IS_MUCH_SMALLER_THAN(v1.cross(v2).eigen2_dot(v1), Scalar(1)); + Matrix3 m; + m << v0.normalized(), + (v0.cross(v1)).normalized(), + (v0.cross(v1).cross(v0)).normalized(); + VERIFY(m.isUnitary()); + + // Quaternion: Identity(), setIdentity(); + Quaternionx q1, q2; + q2.setIdentity(); + VERIFY_IS_APPROX(Quaternionx(Quaternionx::Identity()).coeffs(), q2.coeffs()); + q1.coeffs().setRandom(); + VERIFY_IS_APPROX(q1.coeffs(), (q1*q2).coeffs()); + + // unitOrthogonal + VERIFY_IS_MUCH_SMALLER_THAN(u0.unitOrthogonal().eigen2_dot(u0), Scalar(1)); + VERIFY_IS_MUCH_SMALLER_THAN(v0.unitOrthogonal().eigen2_dot(v0), Scalar(1)); + VERIFY_IS_APPROX(u0.unitOrthogonal().norm(), Scalar(1)); + VERIFY_IS_APPROX(v0.unitOrthogonal().norm(), Scalar(1)); + + + VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0); + VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(M_PI), v0.unitOrthogonal()) * v0); + VERIFY_IS_APPROX(ei_cos(a)*v0.squaredNorm(), v0.eigen2_dot(AngleAxisx(a, v0.unitOrthogonal()) * v0)); + m = AngleAxisx(a, v0.normalized()).toRotationMatrix().adjoint(); + VERIFY_IS_APPROX(Matrix3::Identity(), m * AngleAxisx(a, v0.normalized())); + VERIFY_IS_APPROX(Matrix3::Identity(), AngleAxisx(a, v0.normalized()) * m); + + q1 = AngleAxisx(a, v0.normalized()); + q2 = AngleAxisx(a, v1.normalized()); + + // angular distance + Scalar refangle = ei_abs(AngleAxisx(q1.inverse()*q2).angle()); + if (refangle>Scalar(M_PI)) + refangle = Scalar(2)*Scalar(M_PI) - refangle; + + if((q1.coeffs()-q2.coeffs()).norm() > 10*largeEps) + { + VERIFY(ei_isApprox(q1.angularDistance(q2), refangle, largeEps)); + } + + // rotation matrix conversion + VERIFY_IS_APPROX(q1 * v2, q1.toRotationMatrix() * v2); + VERIFY_IS_APPROX(q1 * q2 * v2, + q1.toRotationMatrix() * q2.toRotationMatrix() * v2); + + VERIFY( (q2*q1).isApprox(q1*q2, largeEps) || !(q2 * q1 * v2).isApprox( + q1.toRotationMatrix() * q2.toRotationMatrix() * v2)); + + q2 = q1.toRotationMatrix(); + VERIFY_IS_APPROX(q1*v1,q2*v1); + + matrot1 = AngleAxisx(Scalar(0.1), Vector3::UnitX()) + * AngleAxisx(Scalar(0.2), Vector3::UnitY()) + * AngleAxisx(Scalar(0.3), Vector3::UnitZ()); + VERIFY_IS_APPROX(matrot1 * v1, + AngleAxisx(Scalar(0.1), Vector3(1,0,0)).toRotationMatrix() + * (AngleAxisx(Scalar(0.2), Vector3(0,1,0)).toRotationMatrix() + * (AngleAxisx(Scalar(0.3), Vector3(0,0,1)).toRotationMatrix() * v1))); + + // angle-axis conversion + AngleAxisx aa = q1; + VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1); + VERIFY_IS_NOT_APPROX(q1 * v1, Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1); + + // from two vector creation + VERIFY_IS_APPROX(v2.normalized(),(q2.setFromTwoVectors(v1,v2)*v1).normalized()); + VERIFY_IS_APPROX(v2.normalized(),(q2.setFromTwoVectors(v1,v2)*v1).normalized()); + + // inverse and conjugate + VERIFY_IS_APPROX(q1 * (q1.inverse() * v1), v1); + VERIFY_IS_APPROX(q1 * (q1.conjugate() * v1), v1); + + // AngleAxis + VERIFY_IS_APPROX(AngleAxisx(a,v1.normalized()).toRotationMatrix(), + Quaternionx(AngleAxisx(a,v1.normalized())).toRotationMatrix()); + + AngleAxisx aa1; + m = q1.toRotationMatrix(); + aa1 = m; + VERIFY_IS_APPROX(AngleAxisx(m).toRotationMatrix(), + Quaternionx(m).toRotationMatrix()); + + // Transform + // TODO complete the tests ! + a = 0; + while (ei_abs(a)(-Scalar(0.4)*Scalar(M_PI), Scalar(0.4)*Scalar(M_PI)); + q1 = AngleAxisx(a, v0.normalized()); + Transform3 t0, t1, t2; + // first test setIdentity() and Identity() + t0.setIdentity(); + VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity()); + t0.matrix().setZero(); + t0 = Transform3::Identity(); + VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity()); + + t0.linear() = q1.toRotationMatrix(); + t1.setIdentity(); + t1.linear() = q1.toRotationMatrix(); + + v0 << 50, 2, 1;//= ei_random_matrix().cwiseProduct(Vector3(10,2,0.5)); + t0.scale(v0); + t1.prescale(v0); + + VERIFY_IS_APPROX( (t0 * Vector3(1,0,0)).norm(), v0.x()); + //VERIFY(!ei_isApprox((t1 * Vector3(1,0,0)).norm(), v0.x())); + + t0.setIdentity(); + t1.setIdentity(); + v1 << 1, 2, 3; + t0.linear() = q1.toRotationMatrix(); + t0.pretranslate(v0); + t0.scale(v1); + t1.linear() = q1.conjugate().toRotationMatrix(); + t1.prescale(v1.cwise().inverse()); + t1.translate(-v0); + + VERIFY((t0.matrix() * t1.matrix()).isIdentity(test_precision())); + + t1.fromPositionOrientationScale(v0, q1, v1); + 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(AngleAxisx(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()); + + // More transform constructors, operator=, operator*= + + Matrix3 mat3 = Matrix3::Random(); + Matrix4 mat4; + mat4 << mat3 , Vector3::Zero() , Vector4::Zero().transpose(); + Transform3 tmat3(mat3), tmat4(mat4); + tmat4.matrix()(3,3) = Scalar(1); + VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix()); + + Scalar a3 = ei_random(-Scalar(M_PI), Scalar(M_PI)); + Vector3 v3 = Vector3::Random().normalized(); + AngleAxisx aa3(a3, v3); + Transform3 t3(aa3); + Transform3 t4; + t4 = aa3; + VERIFY_IS_APPROX(t3.matrix(), t4.matrix()); + t4.rotate(AngleAxisx(-a3,v3)); + VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity()); + t4 *= aa3; + VERIFY_IS_APPROX(t3.matrix(), t4.matrix()); + + v3 = Vector3::Random(); + Translation3 tv3(v3); + Transform3 t5(tv3); + t4 = tv3; + VERIFY_IS_APPROX(t5.matrix(), t4.matrix()); + t4.translate(-v3); + VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity()); + t4 *= tv3; + VERIFY_IS_APPROX(t5.matrix(), t4.matrix()); + + Scaling3 sv3(v3); + Transform3 t6(sv3); + t4 = sv3; + VERIFY_IS_APPROX(t6.matrix(), t4.matrix()); + t4.scale(v3.cwise().inverse()); + VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity()); + t4 *= sv3; + VERIFY_IS_APPROX(t6.matrix(), t4.matrix()); + + // matrix * transform + VERIFY_IS_APPROX(Transform3(t3.matrix()*t4).matrix(), Transform3(t3*t4).matrix()); + + // chained Transform product + VERIFY_IS_APPROX(((t3*t4)*t5).matrix(), (t3*(t4*t5)).matrix()); + + // check that Transform product doesn't have aliasing problems + t5 = t4; + t5 = t5*t5; + VERIFY_IS_APPROX(t5, t4*t4); + + // 2D transformation + Transform2 t20, t21; + Vector2 v20 = Vector2::Random(); + Vector2 v21 = Vector2::Random(); + for (int k=0; k<2; ++k) + if (ei_abs(v21[k])(a).toRotationMatrix(); + VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(), + t21.pretranslate(v20).scale(v21).matrix()); + + t21.setIdentity(); + t21.linear() = Rotation2D(-a).toRotationMatrix(); + VERIFY( (t20.fromPositionOrientationScale(v20,a,v21) + * (t21.prescale(v21.cwise().inverse()).translate(-v20))).matrix().isIdentity(test_precision()) ); + + // Transform - new API + // 3D + t0.setIdentity(); + t0.rotate(q1).scale(v0).translate(v0); + // mat * scaling and mat * translation + t1 = (Matrix3(q1) * Scaling3(v0)) * Translation3(v0); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + // mat * transformation and scaling * translation + t1 = Matrix3(q1) * (Scaling3(v0) * Translation3(v0)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + t0.setIdentity(); + t0.prerotate(q1).prescale(v0).pretranslate(v0); + // translation * scaling and transformation * mat + t1 = (Translation3(v0) * Scaling3(v0)) * Matrix3(q1); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + // scaling * mat and translation * mat + t1 = Translation3(v0) * (Scaling3(v0) * Matrix3(q1)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + t0.setIdentity(); + t0.scale(v0).translate(v0).rotate(q1); + // translation * mat and scaling * transformation + t1 = Scaling3(v0) * (Translation3(v0) * Matrix3(q1)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + // transformation * scaling + t0.scale(v0); + t1 = t1 * Scaling3(v0); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + // transformation * translation + t0.translate(v0); + t1 = t1 * Translation3(v0); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + // translation * transformation + t0.pretranslate(v0); + t1 = Translation3(v0) * t1; + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // transform * quaternion + t0.rotate(q1); + t1 = t1 * q1; + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // translation * quaternion + t0.translate(v1).rotate(q1); + t1 = t1 * (Translation3(v1) * q1); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // scaling * quaternion + t0.scale(v1).rotate(q1); + t1 = t1 * (Scaling3(v1) * q1); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // quaternion * transform + t0.prerotate(q1); + t1 = q1 * t1; + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // quaternion * translation + t0.rotate(q1).translate(v1); + t1 = t1 * (q1 * Translation3(v1)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // quaternion * scaling + t0.rotate(q1).scale(v1); + t1 = t1 * (q1 * Scaling3(v1)); + VERIFY_IS_APPROX(t0.matrix(), t1.matrix()); + + // translation * vector + t0.setIdentity(); + t0.translate(v0); + VERIFY_IS_APPROX(t0 * v1, Translation3(v0) * v1); + + // scaling * vector + t0.setIdentity(); + t0.scale(v0); + VERIFY_IS_APPROX(t0 * v1, Scaling3(v0) * v1); + + // test transform inversion + t0.setIdentity(); + t0.translate(v0); + t0.linear().setRandom(); + VERIFY_IS_APPROX(t0.inverse(Affine), t0.matrix().inverse()); + t0.setIdentity(); + t0.translate(v0).rotate(q1); + VERIFY_IS_APPROX(t0.inverse(Isometry), t0.matrix().inverse()); + + // test extract rotation and scaling + t0.setIdentity(); + t0.translate(v0).rotate(q1).scale(v1); + VERIFY_IS_APPROX(t0.rotation() * v1, Matrix3(q1) * v1); + + Matrix3 mat_rotation, mat_scaling; + t0.setIdentity(); + t0.translate(v0).rotate(q1).scale(v1); + t0.computeRotationScaling(&mat_rotation, &mat_scaling); + VERIFY_IS_APPROX(t0.linear(), mat_rotation * mat_scaling); + VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity()); + VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1)); + t0.computeScalingRotation(&mat_scaling, &mat_rotation); + VERIFY_IS_APPROX(t0.linear(), mat_scaling * mat_rotation); + VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity()); + VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1)); + + // test casting + eigen2_Transform t1f = t1.template cast(); + VERIFY_IS_APPROX(t1f.template cast(),t1); + eigen2_Transform t1d = t1.template cast(); + VERIFY_IS_APPROX(t1d.template cast(),t1); + + Translation3 tr1(v0); + eigen2_Translation tr1f = tr1.template cast(); + VERIFY_IS_APPROX(tr1f.template cast(),tr1); + eigen2_Translation tr1d = tr1.template cast(); + VERIFY_IS_APPROX(tr1d.template cast(),tr1); + + Scaling3 sc1(v0); + eigen2_Scaling sc1f = sc1.template cast(); + VERIFY_IS_APPROX(sc1f.template cast(),sc1); + eigen2_Scaling sc1d = sc1.template cast(); + VERIFY_IS_APPROX(sc1d.template cast(),sc1); + + eigen2_Quaternion q1f = q1.template cast(); + VERIFY_IS_APPROX(q1f.template cast(),q1); + eigen2_Quaternion q1d = q1.template cast(); + VERIFY_IS_APPROX(q1d.template cast(),q1); + + eigen2_AngleAxis aa1f = aa1.template cast(); + VERIFY_IS_APPROX(aa1f.template cast(),aa1); + eigen2_AngleAxis aa1d = aa1.template cast(); + VERIFY_IS_APPROX(aa1d.template cast(),aa1); + + eigen2_Rotation2D r2d1(ei_random()); + eigen2_Rotation2D r2d1f = r2d1.template cast(); + VERIFY_IS_APPROX(r2d1f.template cast(),r2d1); + eigen2_Rotation2D r2d1d = r2d1.template cast(); + VERIFY_IS_APPROX(r2d1d.template cast(),r2d1); + + m = q1; +// m.col(1) = Vector3(0,ei_random(),ei_random()).normalized(); +// m.col(0) = Vector3(-1,0,0).normalized(); +// m.col(2) = m.col(0).cross(m.col(1)); + #define VERIFY_EULER(I,J,K, X,Y,Z) { \ + Vector3 ea = m.eulerAngles(I,J,K); \ + Matrix3 m1 = Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z())); \ + VERIFY_IS_APPROX(m, Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \ + } + VERIFY_EULER(0,1,2, X,Y,Z); + VERIFY_EULER(0,1,0, X,Y,X); + VERIFY_EULER(0,2,1, X,Z,Y); + VERIFY_EULER(0,2,0, X,Z,X); + + VERIFY_EULER(1,2,0, Y,Z,X); + VERIFY_EULER(1,2,1, Y,Z,Y); + VERIFY_EULER(1,0,2, Y,X,Z); + VERIFY_EULER(1,0,1, Y,X,Y); + + VERIFY_EULER(2,0,1, Z,X,Y); + VERIFY_EULER(2,0,2, Z,X,Z); + VERIFY_EULER(2,1,0, Z,Y,X); + VERIFY_EULER(2,1,2, Z,Y,Z); + + // colwise/rowwise cross product + mat3.setRandom(); + Vector3 vec3 = Vector3::Random(); + Matrix3 mcross; + int i = ei_random(0,2); + mcross = mat3.colwise().cross(vec3); + VERIFY_IS_APPROX(mcross.col(i), mat3.col(i).cross(vec3)); + mcross = mat3.rowwise().cross(vec3); + VERIFY_IS_APPROX(mcross.row(i), mat3.row(i).cross(vec3)); + + +} + +void test_eigen2_geometry_with_eigen2_prefix() +{ + std::cout << "eigen2 support: " << EIGEN2_SUPPORT_STAGE << std::endl; + for(int i = 0; i < g_repeat; i++) { + CALL_SUBTEST_1( geometry() ); + CALL_SUBTEST_2( geometry() ); + } +}