2008-06-03 15:32:12 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-23 02:25:33 +08:00
|
|
|
// for linear algebra.
|
2008-06-03 15:32:12 +08:00
|
|
|
//
|
2010-06-25 05:21:58 +08:00
|
|
|
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2008-06-03 15:32:12 +08:00
|
|
|
//
|
2012-07-14 02:42:47 +08:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-06-03 15:32:12 +08:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include <Eigen/Geometry>
|
2008-06-16 01:22:41 +08:00
|
|
|
#include <Eigen/LU>
|
2009-01-23 00:39:08 +08:00
|
|
|
#include <Eigen/SVD>
|
2008-06-03 15:32:12 +08:00
|
|
|
|
2015-11-23 17:53:55 +08:00
|
|
|
template<typename T>
|
|
|
|
Matrix<T,2,1> angleToVec(T a)
|
|
|
|
{
|
|
|
|
return Matrix<T,2,1>(std::cos(a), std::sin(a));
|
|
|
|
}
|
|
|
|
|
2011-01-27 23:07:33 +08:00
|
|
|
template<typename Scalar, int Mode, int Options> void non_projective_only()
|
2010-08-20 01:25:35 +08:00
|
|
|
{
|
|
|
|
/* this test covers the following files:
|
|
|
|
Cross.h Quaternion.h, Transform.cpp
|
|
|
|
*/
|
|
|
|
typedef Matrix<Scalar,3,1> Vector3;
|
|
|
|
typedef Quaternion<Scalar> Quaternionx;
|
|
|
|
typedef AngleAxis<Scalar> AngleAxisx;
|
2011-01-27 23:07:33 +08:00
|
|
|
typedef Transform<Scalar,3,Mode,Options> Transform3;
|
2010-08-20 01:25:35 +08:00
|
|
|
typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
|
|
|
|
typedef Translation<Scalar,3> Translation3;
|
|
|
|
|
|
|
|
Vector3 v0 = Vector3::Random(),
|
|
|
|
v1 = Vector3::Random();
|
|
|
|
|
|
|
|
Transform3 t0, t1, t2;
|
|
|
|
|
2015-06-10 23:12:10 +08:00
|
|
|
Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
|
2010-08-20 01:25:35 +08:00
|
|
|
|
|
|
|
Quaternionx q1, q2;
|
|
|
|
|
|
|
|
q1 = AngleAxisx(a, v0.normalized());
|
|
|
|
|
|
|
|
t0 = Transform3::Identity();
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
|
|
|
|
|
|
|
t0.linear() = q1.toRotationMatrix();
|
|
|
|
|
|
|
|
v0 << 50, 2, 1;
|
|
|
|
t0.scale(v0);
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (t0 * Vector3(1,0,0)).template head<3>().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.cwiseInverse());
|
|
|
|
t1.translate(-v0);
|
|
|
|
|
|
|
|
VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
|
|
|
|
|
|
|
|
t1.fromPositionOrientationScale(v0, q1, v1);
|
|
|
|
VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
|
|
|
|
VERIFY_IS_APPROX(t1*v1, t0*v1);
|
|
|
|
|
|
|
|
// translation * vector
|
|
|
|
t0.setIdentity();
|
|
|
|
t0.translate(v0);
|
|
|
|
VERIFY_IS_APPROX((t0 * v1).template head<3>(), Translation3(v0) * v1);
|
|
|
|
|
|
|
|
// AlignedScaling * vector
|
|
|
|
t0.setIdentity();
|
|
|
|
t0.scale(v0);
|
|
|
|
VERIFY_IS_APPROX((t0 * v1).template head<3>(), AlignedScaling3(v0) * v1);
|
|
|
|
}
|
|
|
|
|
2011-01-27 23:07:33 +08:00
|
|
|
template<typename Scalar, int Mode, int Options> void transformations()
|
2008-06-03 15:32:12 +08:00
|
|
|
{
|
|
|
|
/* this test covers the following files:
|
2008-06-15 16:33:44 +08:00
|
|
|
Cross.h Quaternion.h, Transform.cpp
|
2008-06-03 15:32:12 +08:00
|
|
|
*/
|
2012-11-06 22:25:50 +08:00
|
|
|
using std::cos;
|
|
|
|
using std::abs;
|
2008-06-03 15:32:12 +08:00
|
|
|
typedef Matrix<Scalar,3,3> Matrix3;
|
|
|
|
typedef Matrix<Scalar,4,4> Matrix4;
|
2008-06-16 01:22:41 +08:00
|
|
|
typedef Matrix<Scalar,2,1> Vector2;
|
2008-06-03 15:32:12 +08:00
|
|
|
typedef Matrix<Scalar,3,1> Vector3;
|
|
|
|
typedef Matrix<Scalar,4,1> Vector4;
|
2008-10-26 07:10:21 +08:00
|
|
|
typedef Quaternion<Scalar> Quaternionx;
|
|
|
|
typedef AngleAxis<Scalar> AngleAxisx;
|
2011-01-27 23:07:33 +08:00
|
|
|
typedef Transform<Scalar,2,Mode,Options> Transform2;
|
|
|
|
typedef Transform<Scalar,3,Mode,Options> Transform3;
|
2009-03-08 19:35:30 +08:00
|
|
|
typedef typename Transform3::MatrixType MatrixType;
|
2009-01-29 00:26:06 +08:00
|
|
|
typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
|
2008-08-30 08:08:23 +08:00
|
|
|
typedef Translation<Scalar,2> Translation2;
|
|
|
|
typedef Translation<Scalar,3> Translation3;
|
2008-06-03 15:32:12 +08:00
|
|
|
|
2008-09-02 01:31:21 +08:00
|
|
|
Vector3 v0 = Vector3::Random(),
|
2012-02-03 20:30:48 +08:00
|
|
|
v1 = Vector3::Random();
|
2009-02-17 17:53:05 +08:00
|
|
|
Matrix3 matrot1, m;
|
2008-06-03 15:32:12 +08:00
|
|
|
|
2015-06-10 23:12:10 +08:00
|
|
|
Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
|
2014-10-20 17:04:32 +08:00
|
|
|
Scalar s0 = internal::random<Scalar>(), s1 = internal::random<Scalar>();
|
2014-12-16 23:50:30 +08:00
|
|
|
|
|
|
|
while(v0.norm() < test_precision<Scalar>()) v0 = Vector3::Random();
|
|
|
|
while(v1.norm() < test_precision<Scalar>()) v1 = Vector3::Random();
|
2008-06-03 21:43:29 +08:00
|
|
|
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
|
2015-06-10 23:12:10 +08:00
|
|
|
VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(EIGEN_PI), v0.unitOrthogonal()) * v0);
|
2014-12-16 23:50:30 +08:00
|
|
|
if(abs(cos(a)) > test_precision<Scalar>())
|
|
|
|
{
|
|
|
|
VERIFY_IS_APPROX(cos(a)*v0.squaredNorm(), v0.dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
|
|
|
|
}
|
2008-10-26 07:10:21 +08:00
|
|
|
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);
|
2008-08-25 07:16:51 +08:00
|
|
|
|
2009-02-17 17:53:05 +08:00
|
|
|
Quaternionx q1, q2;
|
2008-10-26 07:10:21 +08:00
|
|
|
q1 = AngleAxisx(a, v0.normalized());
|
|
|
|
q2 = AngleAxisx(a, v1.normalized());
|
2008-06-03 15:32:12 +08:00
|
|
|
|
2008-06-03 21:43:29 +08:00
|
|
|
// rotation matrix conversion
|
2009-01-22 04:06:16 +08:00
|
|
|
matrot1 = AngleAxisx(Scalar(0.1), Vector3::UnitX())
|
|
|
|
* AngleAxisx(Scalar(0.2), Vector3::UnitY())
|
|
|
|
* AngleAxisx(Scalar(0.3), Vector3::UnitZ());
|
2008-07-19 21:03:23 +08:00
|
|
|
VERIFY_IS_APPROX(matrot1 * v1,
|
2009-01-22 04:06:16 +08:00
|
|
|
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)));
|
2008-06-16 01:22:41 +08:00
|
|
|
|
|
|
|
// angle-axis conversion
|
2009-11-13 23:41:51 +08:00
|
|
|
AngleAxisx aa = AngleAxisx(q1);
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
|
2014-12-16 23:50:30 +08:00
|
|
|
|
2015-11-23 17:53:55 +08:00
|
|
|
// The following test is stable only if 2*angle != angle and v1 is not colinear with axis
|
|
|
|
if( (abs(aa.angle()) > test_precision<Scalar>()) && (abs(aa.axis().dot(v1.normalized()))<(Scalar(1)-Scalar(4)*test_precision<Scalar>())) )
|
2014-12-16 23:50:30 +08:00
|
|
|
{
|
|
|
|
VERIFY( !(q1 * v1).isApprox(Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1) );
|
|
|
|
}
|
2008-06-16 01:22:41 +08:00
|
|
|
|
2010-02-02 16:27:41 +08:00
|
|
|
aa.fromRotationMatrix(aa.toRotationMatrix());
|
|
|
|
VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
|
2015-11-23 17:53:55 +08:00
|
|
|
// The following test is stable only if 2*angle != angle and v1 is not colinear with axis
|
|
|
|
if( (abs(aa.angle()) > test_precision<Scalar>()) && (abs(aa.axis().dot(v1.normalized()))<(Scalar(1)-Scalar(4)*test_precision<Scalar>())) )
|
2014-12-16 23:50:30 +08:00
|
|
|
{
|
|
|
|
VERIFY( !(q1 * v1).isApprox(Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1) );
|
|
|
|
}
|
2010-02-02 16:27:41 +08:00
|
|
|
|
2008-06-16 01:22:41 +08:00
|
|
|
// AngleAxis
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(AngleAxisx(a,v1.normalized()).toRotationMatrix(),
|
|
|
|
Quaternionx(AngleAxisx(a,v1.normalized())).toRotationMatrix());
|
2008-06-16 01:22:41 +08:00
|
|
|
|
2008-10-26 07:10:21 +08:00
|
|
|
AngleAxisx aa1;
|
2008-06-16 01:22:41 +08:00
|
|
|
m = q1.toRotationMatrix();
|
2008-06-21 23:01:49 +08:00
|
|
|
aa1 = m;
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(AngleAxisx(m).toRotationMatrix(),
|
|
|
|
Quaternionx(m).toRotationMatrix());
|
2008-06-16 01:22:41 +08:00
|
|
|
|
2008-06-15 16:33:44 +08:00
|
|
|
// Transform
|
|
|
|
// TODO complete the tests !
|
|
|
|
a = 0;
|
2012-11-06 22:25:50 +08:00
|
|
|
while (abs(a)<Scalar(0.1))
|
2015-06-10 23:12:10 +08:00
|
|
|
a = internal::random<Scalar>(-Scalar(0.4)*Scalar(EIGEN_PI), Scalar(0.4)*Scalar(EIGEN_PI));
|
2008-10-26 07:10:21 +08:00
|
|
|
q1 = AngleAxisx(a, v0.normalized());
|
2008-06-15 16:33:44 +08:00
|
|
|
Transform3 t0, t1, t2;
|
2009-09-20 07:59:49 +08:00
|
|
|
|
|
|
|
// first test setIdentity() and Identity()
|
2008-06-15 16:33:44 +08:00
|
|
|
t0.setIdentity();
|
2009-09-20 07:59:49 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
|
|
|
t0.matrix().setZero();
|
|
|
|
t0 = Transform3::Identity();
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
|
2009-11-19 01:15:19 +08:00
|
|
|
|
2008-06-15 16:33:44 +08:00
|
|
|
t0.setIdentity();
|
|
|
|
t1.setIdentity();
|
|
|
|
v1 << 1, 2, 3;
|
2008-08-22 01:02:47 +08:00
|
|
|
t0.linear() = q1.toRotationMatrix();
|
2008-06-15 16:33:44 +08:00
|
|
|
t0.pretranslate(v0);
|
|
|
|
t0.scale(v1);
|
2008-08-22 01:02:47 +08:00
|
|
|
t1.linear() = q1.conjugate().toRotationMatrix();
|
2009-12-11 05:00:35 +08:00
|
|
|
t1.prescale(v1.cwiseInverse());
|
2008-06-15 16:33:44 +08:00
|
|
|
t1.translate(-v0);
|
|
|
|
|
2009-03-08 19:35:30 +08:00
|
|
|
VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
|
2008-06-15 19:54:18 +08:00
|
|
|
|
|
|
|
t1.fromPositionOrientationScale(v0, q1, v1);
|
|
|
|
VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
|
2008-06-16 01:22:41 +08:00
|
|
|
|
2008-08-31 07:10:46 +08:00
|
|
|
t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix());
|
|
|
|
t1.setIdentity(); t1.scale(v0).rotate(q1);
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
|
2008-10-26 07:10:21 +08:00
|
|
|
t0.setIdentity(); t0.scale(v0).rotate(AngleAxisx(q1));
|
2008-08-31 07:10:46 +08:00
|
|
|
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());
|
|
|
|
|
2008-12-20 00:16:39 +08:00
|
|
|
// More transform constructors, operator=, operator*=
|
2008-12-20 00:31:22 +08:00
|
|
|
|
2009-01-05 22:26:34 +08:00
|
|
|
Matrix3 mat3 = Matrix3::Random();
|
|
|
|
Matrix4 mat4;
|
|
|
|
mat4 << mat3 , Vector3::Zero() , Vector4::Zero().transpose();
|
|
|
|
Transform3 tmat3(mat3), tmat4(mat4);
|
2009-03-08 19:35:30 +08:00
|
|
|
if(Mode!=int(AffineCompact))
|
|
|
|
tmat4.matrix()(3,3) = Scalar(1);
|
2009-01-05 22:26:34 +08:00
|
|
|
VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix());
|
|
|
|
|
2015-06-10 23:12:10 +08:00
|
|
|
Scalar a3 = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
|
2008-12-19 22:52:03 +08:00
|
|
|
Vector3 v3 = Vector3::Random().normalized();
|
|
|
|
AngleAxisx aa3(a3, v3);
|
|
|
|
Transform3 t3(aa3);
|
|
|
|
Transform3 t4;
|
|
|
|
t4 = aa3;
|
|
|
|
VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
|
2008-12-19 23:55:35 +08:00
|
|
|
t4.rotate(AngleAxisx(-a3,v3));
|
2009-03-08 19:35:30 +08:00
|
|
|
VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
|
2008-12-20 00:16:39 +08:00
|
|
|
t4 *= aa3;
|
|
|
|
VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
|
2008-12-19 22:52:03 +08:00
|
|
|
|
2015-11-23 17:53:55 +08:00
|
|
|
do {
|
|
|
|
v3 = Vector3::Random();
|
|
|
|
} while (v3.cwiseAbs().minCoeff()<NumTraits<Scalar>::epsilon());
|
2008-12-19 22:52:03 +08:00
|
|
|
Translation3 tv3(v3);
|
|
|
|
Transform3 t5(tv3);
|
|
|
|
t4 = tv3;
|
|
|
|
VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
|
|
|
|
t4.translate(-v3);
|
2009-03-08 19:35:30 +08:00
|
|
|
VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
|
2008-12-20 00:16:39 +08:00
|
|
|
t4 *= tv3;
|
|
|
|
VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
|
2008-12-19 22:52:03 +08:00
|
|
|
|
2009-01-29 00:26:06 +08:00
|
|
|
AlignedScaling3 sv3(v3);
|
2008-12-19 22:52:03 +08:00
|
|
|
Transform3 t6(sv3);
|
|
|
|
t4 = sv3;
|
|
|
|
VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
|
2009-12-11 05:00:35 +08:00
|
|
|
t4.scale(v3.cwiseInverse());
|
2009-03-08 19:35:30 +08:00
|
|
|
VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
|
2008-12-20 00:16:39 +08:00
|
|
|
t4 *= sv3;
|
|
|
|
VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
|
2008-12-19 22:52:03 +08:00
|
|
|
|
2008-12-20 00:31:22 +08:00
|
|
|
// matrix * transform
|
2009-03-08 19:35:30 +08:00
|
|
|
VERIFY_IS_APPROX((t3.matrix()*t4).matrix(), (t3*t4).matrix());
|
2008-12-20 00:31:22 +08:00
|
|
|
|
2008-12-19 22:52:03 +08:00
|
|
|
// chained Transform product
|
2008-12-20 00:16:39 +08:00
|
|
|
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);
|
|
|
|
|
2008-06-16 01:22:41 +08:00
|
|
|
// 2D transformation
|
|
|
|
Transform2 t20, t21;
|
2008-09-02 01:31:21 +08:00
|
|
|
Vector2 v20 = Vector2::Random();
|
|
|
|
Vector2 v21 = Vector2::Random();
|
2008-08-23 23:14:20 +08:00
|
|
|
for (int k=0; k<2; ++k)
|
2012-11-06 22:25:50 +08:00
|
|
|
if (abs(v21[k])<Scalar(1e-3)) v21[k] = Scalar(1e-3);
|
2008-06-16 01:22:41 +08:00
|
|
|
t21.setIdentity();
|
2008-08-22 01:02:47 +08:00
|
|
|
t21.linear() = Rotation2D<Scalar>(a).toRotationMatrix();
|
2008-06-16 01:22:41 +08:00
|
|
|
VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(),
|
|
|
|
t21.pretranslate(v20).scale(v21).matrix());
|
|
|
|
|
|
|
|
t21.setIdentity();
|
2008-08-22 01:02:47 +08:00
|
|
|
t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
|
2008-08-23 23:14:20 +08:00
|
|
|
VERIFY( (t20.fromPositionOrientationScale(v20,a,v21)
|
2009-12-11 05:00:35 +08:00
|
|
|
* (t21.prescale(v21.cwiseInverse()).translate(-v20))).matrix().isIdentity(test_precision<Scalar>()) );
|
2008-08-30 08:08:23 +08:00
|
|
|
|
|
|
|
// Transform - new API
|
|
|
|
// 3D
|
|
|
|
t0.setIdentity();
|
|
|
|
t0.rotate(q1).scale(v0).translate(v0);
|
2009-01-29 00:26:06 +08:00
|
|
|
// mat * aligned scaling and mat * translation
|
|
|
|
t1 = (Matrix3(q1) * AlignedScaling3(v0)) * Translation3(v0);
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = (Matrix3(q1) * Eigen::Scaling(v0)) * Translation3(v0);
|
2009-01-29 00:26:06 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = (q1 * Eigen::Scaling(v0)) * Translation3(v0);
|
2009-01-29 00:26:06 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
// mat * transformation and aligned scaling * translation
|
|
|
|
t1 = Matrix3(q1) * (AlignedScaling3(v0) * Translation3(v0));
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
|
2010-03-03 00:38:40 +08:00
|
|
|
|
|
|
|
t0.setIdentity();
|
|
|
|
t0.scale(s0).translate(v0);
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = Eigen::Scaling(s0) * Translation3(v0);
|
2010-03-03 00:38:40 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
t0.prescale(s0);
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = Eigen::Scaling(s0) * t1;
|
2010-03-03 00:38:40 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2010-11-19 22:38:37 +08:00
|
|
|
|
|
|
|
t0 = t3;
|
|
|
|
t0.scale(s0);
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = t3 * Eigen::Scaling(s0,s0,s0);
|
2010-11-19 22:38:37 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
t0.prescale(s0);
|
2012-01-31 16:14:01 +08:00
|
|
|
t1 = Eigen::Scaling(s0,s0,s0) * t1;
|
2010-11-19 22:38:37 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2010-03-03 00:38:40 +08:00
|
|
|
|
2014-02-12 20:37:23 +08:00
|
|
|
t0 = t3;
|
|
|
|
t0.scale(s0);
|
|
|
|
t1 = t3 * Eigen::Scaling(s0);
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
t0.prescale(s0);
|
|
|
|
t1 = Eigen::Scaling(s0) * t1;
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2010-03-03 00:38:40 +08:00
|
|
|
|
2008-08-30 08:08:23 +08:00
|
|
|
t0.setIdentity();
|
|
|
|
t0.prerotate(q1).prescale(v0).pretranslate(v0);
|
2009-01-29 00:26:06 +08:00
|
|
|
// translation * aligned scaling and transformation * mat
|
2010-08-20 01:25:35 +08:00
|
|
|
t1 = (Translation3(v0) * AlignedScaling3(v0)) * Transform3(q1);
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
// scaling * mat and translation * mat
|
2010-08-20 01:25:35 +08:00
|
|
|
t1 = Translation3(v0) * (AlignedScaling3(v0) * Transform3(q1));
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2008-10-26 07:10:21 +08:00
|
|
|
|
2008-08-30 08:08:23 +08:00
|
|
|
t0.setIdentity();
|
|
|
|
t0.scale(v0).translate(v0).rotate(q1);
|
2009-01-29 00:26:06 +08:00
|
|
|
// translation * mat and aligned scaling * transformation
|
2010-08-20 01:25:35 +08:00
|
|
|
t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2009-01-29 00:26:06 +08:00
|
|
|
// transformation * aligned scaling
|
2008-08-30 08:08:23 +08:00
|
|
|
t0.scale(v0);
|
2010-08-20 01:25:35 +08:00
|
|
|
t1 *= AlignedScaling3(v0);
|
2008-08-30 08:08:23 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
// transformation * translation
|
|
|
|
t0.translate(v0);
|
|
|
|
t1 = t1 * Translation3(v0);
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
2008-10-26 07:10:21 +08:00
|
|
|
// translation * transformation
|
2008-08-30 08:08:23 +08:00
|
|
|
t0.pretranslate(v0);
|
|
|
|
t1 = Translation3(v0) * t1;
|
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
|
2008-08-31 04:11:04 +08:00
|
|
|
// 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());
|
|
|
|
|
2009-01-29 00:26:06 +08:00
|
|
|
// aligned scaling * quaternion
|
2008-08-31 04:11:04 +08:00
|
|
|
t0.scale(v1).rotate(q1);
|
2009-01-29 00:26:06 +08:00
|
|
|
t1 = t1 * (AlignedScaling3(v1) * q1);
|
2008-08-31 04:11:04 +08:00
|
|
|
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());
|
|
|
|
|
2009-01-29 00:26:06 +08:00
|
|
|
// quaternion * aligned scaling
|
2008-08-31 04:11:04 +08:00
|
|
|
t0.rotate(q1).scale(v1);
|
2009-01-29 00:26:06 +08:00
|
|
|
t1 = t1 * (q1 * AlignedScaling3(v1));
|
2008-08-31 04:11:04 +08:00
|
|
|
VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
|
|
|
|
|
2008-08-30 20:42:06 +08:00
|
|
|
// test transform inversion
|
2009-10-29 06:19:29 +08:00
|
|
|
t0.setIdentity();
|
|
|
|
t0.translate(v0);
|
2014-12-16 23:50:30 +08:00
|
|
|
do {
|
|
|
|
t0.linear().setRandom();
|
|
|
|
} while(t0.linear().jacobiSvd().singularValues()(2)<test_precision<Scalar>());
|
2009-10-29 06:19:29 +08:00
|
|
|
Matrix4 t044 = Matrix4::Zero();
|
|
|
|
t044(3,3) = 1;
|
|
|
|
t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
|
|
|
|
VERIFY_IS_APPROX(t0.inverse(Affine).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));
|
|
|
|
t0.setIdentity();
|
|
|
|
t0.translate(v0).rotate(q1);
|
|
|
|
t044 = Matrix4::Zero();
|
|
|
|
t044(3,3) = 1;
|
|
|
|
t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
|
|
|
|
VERIFY_IS_APPROX(t0.inverse(Isometry).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));
|
2008-08-30 23:22:45 +08:00
|
|
|
|
2009-01-23 00:39:08 +08:00
|
|
|
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));
|
2008-10-26 07:10:21 +08:00
|
|
|
|
|
|
|
// test casting
|
2009-03-08 19:35:30 +08:00
|
|
|
Transform<float,3,Mode> t1f = t1.template cast<float>();
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(t1f.template cast<Scalar>(),t1);
|
2009-03-08 19:35:30 +08:00
|
|
|
Transform<double,3,Mode> t1d = t1.template cast<double>();
|
2008-10-26 07:10:21 +08:00
|
|
|
VERIFY_IS_APPROX(t1d.template cast<Scalar>(),t1);
|
|
|
|
|
|
|
|
Translation3 tr1(v0);
|
|
|
|
Translation<float,3> tr1f = tr1.template cast<float>();
|
|
|
|
VERIFY_IS_APPROX(tr1f.template cast<Scalar>(),tr1);
|
|
|
|
Translation<double,3> tr1d = tr1.template cast<double>();
|
|
|
|
VERIFY_IS_APPROX(tr1d.template cast<Scalar>(),tr1);
|
|
|
|
|
|
|
|
AngleAxis<float> aa1f = aa1.template cast<float>();
|
|
|
|
VERIFY_IS_APPROX(aa1f.template cast<Scalar>(),aa1);
|
|
|
|
AngleAxis<double> aa1d = aa1.template cast<double>();
|
|
|
|
VERIFY_IS_APPROX(aa1d.template cast<Scalar>(),aa1);
|
|
|
|
|
2010-10-25 22:15:22 +08:00
|
|
|
Rotation2D<Scalar> r2d1(internal::random<Scalar>());
|
2008-10-26 07:10:21 +08:00
|
|
|
Rotation2D<float> r2d1f = r2d1.template cast<float>();
|
|
|
|
VERIFY_IS_APPROX(r2d1f.template cast<Scalar>(),r2d1);
|
|
|
|
Rotation2D<double> r2d1d = r2d1.template cast<double>();
|
|
|
|
VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);
|
2015-07-07 23:27:12 +08:00
|
|
|
|
|
|
|
for(int k=0; k<100; ++k)
|
|
|
|
{
|
|
|
|
Scalar angle = internal::random<Scalar>(-100,100);
|
|
|
|
Rotation2D<Scalar> rot2(angle);
|
|
|
|
VERIFY( rot2.smallestPositiveAngle() >= 0 );
|
2015-11-23 17:53:55 +08:00
|
|
|
VERIFY( rot2.smallestPositiveAngle() <= Scalar(2)*Scalar(EIGEN_PI) );
|
|
|
|
VERIFY_IS_APPROX( angleToVec(rot2.smallestPositiveAngle()), angleToVec(rot2.angle()) );
|
2015-07-07 23:27:12 +08:00
|
|
|
|
|
|
|
VERIFY( rot2.smallestAngle() >= -Scalar(EIGEN_PI) );
|
|
|
|
VERIFY( rot2.smallestAngle() <= Scalar(EIGEN_PI) );
|
2015-11-23 17:53:55 +08:00
|
|
|
VERIFY_IS_APPROX( angleToVec(rot2.smallestAngle()), angleToVec(rot2.angle()) );
|
2015-12-04 05:25:26 +08:00
|
|
|
|
|
|
|
Matrix<Scalar,2,2> rot2_as_mat(rot2);
|
|
|
|
Rotation2D<Scalar> rot3(rot2_as_mat);
|
|
|
|
VERIFY_IS_APPROX( angleToVec(rot2.smallestAngle()), angleToVec(rot3.angle()) );
|
2015-07-07 23:27:12 +08:00
|
|
|
}
|
2009-11-19 01:15:19 +08:00
|
|
|
|
2015-07-07 23:27:12 +08:00
|
|
|
s0 = internal::random<Scalar>(-100,100);
|
|
|
|
s1 = internal::random<Scalar>(-100,100);
|
2014-10-20 17:04:32 +08:00
|
|
|
Rotation2D<Scalar> R0(s0), R1(s1);
|
|
|
|
|
|
|
|
t20 = Translation2(v20) * (R0 * Eigen::Scaling(s0));
|
|
|
|
t21 = Translation2(v20) * R0 * Eigen::Scaling(s0);
|
|
|
|
VERIFY_IS_APPROX(t20,t21);
|
|
|
|
|
|
|
|
t20 = Translation2(v20) * (R0 * R0.inverse() * Eigen::Scaling(s0));
|
|
|
|
t21 = Translation2(v20) * Eigen::Scaling(s0);
|
2012-07-05 00:25:07 +08:00
|
|
|
VERIFY_IS_APPROX(t20,t21);
|
2014-09-30 22:59:28 +08:00
|
|
|
|
2014-10-20 17:04:32 +08:00
|
|
|
VERIFY_IS_APPROX(s0, (R0.slerp(0, R1)).angle());
|
2015-11-23 17:53:55 +08:00
|
|
|
VERIFY_IS_APPROX( angleToVec(R1.smallestPositiveAngle()), angleToVec((R0.slerp(1, R1)).smallestPositiveAngle()) );
|
2015-07-07 23:27:12 +08:00
|
|
|
VERIFY_IS_APPROX(R0.smallestPositiveAngle(), (R0.slerp(0.5, R0)).smallestPositiveAngle());
|
|
|
|
|
|
|
|
if(std::cos(s0)>0)
|
|
|
|
VERIFY_IS_MUCH_SMALLER_THAN((R0.slerp(0.5, R0.inverse())).smallestAngle(), Scalar(1));
|
|
|
|
else
|
|
|
|
VERIFY_IS_APPROX(Scalar(EIGEN_PI), (R0.slerp(0.5, R0.inverse())).smallestPositiveAngle());
|
|
|
|
|
|
|
|
// Check path length
|
|
|
|
Scalar l = 0;
|
2015-11-23 17:53:55 +08:00
|
|
|
int path_steps = 100;
|
|
|
|
for(int k=0; k<path_steps; ++k)
|
2015-07-07 23:27:12 +08:00
|
|
|
{
|
2015-11-23 17:53:55 +08:00
|
|
|
Scalar a1 = R0.slerp(Scalar(k)/Scalar(path_steps), R1).angle();
|
|
|
|
Scalar a2 = R0.slerp(Scalar(k+1)/Scalar(path_steps), R1).angle();
|
2015-07-07 23:27:12 +08:00
|
|
|
l += std::abs(a2-a1);
|
|
|
|
}
|
2016-05-05 19:35:45 +08:00
|
|
|
VERIFY(l<=Scalar(EIGEN_PI)*(Scalar(1)+NumTraits<Scalar>::epsilon()*Scalar(path_steps/2)));
|
2014-10-20 17:04:32 +08:00
|
|
|
|
2014-09-30 22:59:28 +08:00
|
|
|
// check basic features
|
|
|
|
{
|
|
|
|
Rotation2D<Scalar> r1; // default ctor
|
|
|
|
r1 = Rotation2D<Scalar>(s0); // copy assignment
|
|
|
|
VERIFY_IS_APPROX(r1.angle(),s0);
|
|
|
|
Rotation2D<Scalar> r2(r1); // copy ctor
|
|
|
|
VERIFY_IS_APPROX(r2.angle(),s0);
|
|
|
|
}
|
2008-06-03 15:32:12 +08:00
|
|
|
}
|
|
|
|
|
2011-01-27 23:07:33 +08:00
|
|
|
template<typename Scalar> void transform_alignment()
|
|
|
|
{
|
2011-01-28 00:17:06 +08:00
|
|
|
typedef Transform<Scalar,3,Projective,AutoAlign> Projective3a;
|
|
|
|
typedef Transform<Scalar,3,Projective,DontAlign> Projective3u;
|
2011-01-27 23:07:33 +08:00
|
|
|
|
2015-07-29 17:11:23 +08:00
|
|
|
EIGEN_ALIGN_MAX Scalar array1[16];
|
|
|
|
EIGEN_ALIGN_MAX Scalar array2[16];
|
|
|
|
EIGEN_ALIGN_MAX Scalar array3[16+1];
|
2011-01-27 23:07:33 +08:00
|
|
|
Scalar* array3u = array3+1;
|
|
|
|
|
2011-01-28 00:17:06 +08:00
|
|
|
Projective3a *p1 = ::new(reinterpret_cast<void*>(array1)) Projective3a;
|
|
|
|
Projective3u *p2 = ::new(reinterpret_cast<void*>(array2)) Projective3u;
|
|
|
|
Projective3u *p3 = ::new(reinterpret_cast<void*>(array3u)) Projective3u;
|
2011-01-27 23:07:33 +08:00
|
|
|
|
|
|
|
p1->matrix().setRandom();
|
|
|
|
*p2 = *p1;
|
|
|
|
*p3 = *p1;
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX(p1->matrix(), p2->matrix());
|
|
|
|
VERIFY_IS_APPROX(p1->matrix(), p3->matrix());
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (*p1) * (*p1), (*p2)*(*p3));
|
|
|
|
|
2015-07-29 17:11:23 +08:00
|
|
|
#if defined(EIGEN_VECTORIZE) && EIGEN_MAX_STATIC_ALIGN_BYTES>0
|
2011-05-20 15:59:15 +08:00
|
|
|
if(internal::packet_traits<Scalar>::Vectorizable)
|
|
|
|
VERIFY_RAISES_ASSERT((::new(reinterpret_cast<void*>(array3u)) Projective3a));
|
2011-01-27 23:07:33 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-31 05:22:29 +08:00
|
|
|
template<typename Scalar, int Dim, int Options> void transform_products()
|
|
|
|
{
|
|
|
|
typedef Matrix<Scalar,Dim+1,Dim+1> Mat;
|
|
|
|
typedef Transform<Scalar,Dim,Projective,Options> Proj;
|
|
|
|
typedef Transform<Scalar,Dim,Affine,Options> Aff;
|
|
|
|
typedef Transform<Scalar,Dim,AffineCompact,Options> AffC;
|
|
|
|
|
|
|
|
Proj p; p.matrix().setRandom();
|
|
|
|
Aff a; a.linear().setRandom(); a.translation().setRandom();
|
|
|
|
AffC ac = a;
|
|
|
|
|
|
|
|
Mat p_m(p.matrix()), a_m(a.matrix());
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX((p*p).matrix(), p_m*p_m);
|
|
|
|
VERIFY_IS_APPROX((a*a).matrix(), a_m*a_m);
|
|
|
|
VERIFY_IS_APPROX((p*a).matrix(), p_m*a_m);
|
|
|
|
VERIFY_IS_APPROX((a*p).matrix(), a_m*p_m);
|
|
|
|
VERIFY_IS_APPROX((ac*a).matrix(), a_m*a_m);
|
|
|
|
VERIFY_IS_APPROX((a*ac).matrix(), a_m*a_m);
|
|
|
|
VERIFY_IS_APPROX((p*ac).matrix(), p_m*a_m);
|
|
|
|
VERIFY_IS_APPROX((ac*p).matrix(), a_m*p_m);
|
|
|
|
}
|
|
|
|
|
2009-02-17 17:53:05 +08:00
|
|
|
void test_geo_transformations()
|
2008-06-03 15:32:12 +08:00
|
|
|
{
|
|
|
|
for(int i = 0; i < g_repeat; i++) {
|
2011-01-27 23:07:33 +08:00
|
|
|
CALL_SUBTEST_1(( transformations<double,Affine,AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_1(( non_projective_only<double,Affine,AutoAlign>() ));
|
2010-08-20 01:25:35 +08:00
|
|
|
|
2011-01-27 23:07:33 +08:00
|
|
|
CALL_SUBTEST_2(( transformations<float,AffineCompact,AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_2(( non_projective_only<float,AffineCompact,AutoAlign>() ));
|
2011-05-20 15:59:15 +08:00
|
|
|
CALL_SUBTEST_2(( transform_alignment<float>() ));
|
|
|
|
|
2011-01-27 23:07:33 +08:00
|
|
|
CALL_SUBTEST_3(( transformations<double,Projective,AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_3(( transformations<double,Projective,DontAlign>() ));
|
|
|
|
CALL_SUBTEST_3(( transform_alignment<double>() ));
|
2011-02-22 21:26:32 +08:00
|
|
|
|
|
|
|
CALL_SUBTEST_4(( transformations<float,Affine,RowMajor|AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_4(( non_projective_only<float,Affine,RowMajor>() ));
|
|
|
|
|
|
|
|
CALL_SUBTEST_5(( transformations<double,AffineCompact,RowMajor|AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_5(( non_projective_only<double,AffineCompact,RowMajor>() ));
|
2011-02-22 21:14:38 +08:00
|
|
|
|
2011-02-22 21:26:32 +08:00
|
|
|
CALL_SUBTEST_6(( transformations<double,Projective,RowMajor|AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_6(( transformations<double,Projective,RowMajor|DontAlign>() ));
|
2012-03-31 05:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
CALL_SUBTEST_7(( transform_products<double,3,RowMajor|AutoAlign>() ));
|
|
|
|
CALL_SUBTEST_7(( transform_products<float,2,AutoAlign>() ));
|
2008-06-03 15:32:12 +08:00
|
|
|
}
|
|
|
|
}
|