diff options
Diffstat (limited to 'test/geo_transformations.cpp')
-rw-r--r--[-rwxr-xr-x] | test/geo_transformations.cpp | 100 |
1 files changed, 93 insertions, 7 deletions
diff --git a/test/geo_transformations.cpp b/test/geo_transformations.cpp index 278e527c2..72c6edac1 100755..100644 --- a/test/geo_transformations.cpp +++ b/test/geo_transformations.cpp @@ -582,11 +582,6 @@ template<typename Scalar> void transform_alignment() VERIFY_IS_APPROX(p1->matrix(), p3->matrix()); VERIFY_IS_APPROX( (*p1) * (*p1), (*p2)*(*p3)); - - #if defined(EIGEN_VECTORIZE) && EIGEN_MAX_STATIC_ALIGN_BYTES>0 - if(internal::packet_traits<Scalar>::Vectorizable) - VERIFY_RAISES_ASSERT((::new(reinterpret_cast<void*>(array3u)) Projective3a)); - #endif } template<typename Scalar, int Dim, int Options> void transform_products() @@ -612,11 +607,99 @@ template<typename Scalar, int Dim, int Options> void transform_products() VERIFY_IS_APPROX((ac*p).matrix(), a_m*p_m); } -void test_geo_transformations() +template<typename Scalar, int Mode, int Options> void transformations_no_scale() +{ + /* this test covers the following files: + Cross.h Quaternion.h, Transform.h + */ + typedef Matrix<Scalar,3,1> Vector3; + typedef Matrix<Scalar,4,1> Vector4; + typedef Quaternion<Scalar> Quaternionx; + typedef AngleAxis<Scalar> AngleAxisx; + typedef Transform<Scalar,3,Mode,Options> Transform3; + typedef Translation<Scalar,3> Translation3; + typedef Matrix<Scalar,4,4> Matrix4; + + Vector3 v0 = Vector3::Random(), + v1 = Vector3::Random(); + + Transform3 t0, t1, t2; + + Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI)); + + Quaternionx q1, q2; + + q1 = AngleAxisx(a, v0.normalized()); + + t0 = Transform3::Identity(); + VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity()); + + t0.setIdentity(); + t1.setIdentity(); + v1 = Vector3::Ones(); + t0.linear() = q1.toRotationMatrix(); + t0.pretranslate(v0); + t1.linear() = q1.conjugate().toRotationMatrix(); + 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); + + // Conversion to matrix. + Transform3 t3; + t3.linear() = q1.toRotationMatrix(); + t3.translation() = v1; + Matrix4 m3 = t3.matrix(); + VERIFY((m3 * m3.inverse()).isIdentity(test_precision<Scalar>())); + // Verify implicit last row is initialized. + VERIFY_IS_APPROX(Vector4(m3.row(3)), Vector4(0.0, 0.0, 0.0, 1.0)); + + VERIFY_IS_APPROX(t3.rotation(), t3.linear()); + if(Mode==Isometry) + VERIFY(t3.rotation().data()==t3.linear().data()); +} + +template<typename Scalar, int Mode, int Options> void transformations_computed_scaling_continuity() +{ + typedef Matrix<Scalar, 3, 1> Vector3; + typedef Transform<Scalar, 3, Mode, Options> Transform3; + typedef Matrix<Scalar, 3, 3> Matrix3; + + // Given: two transforms that differ by '2*eps'. + Scalar eps(1e-3); + Vector3 v0 = Vector3::Random().normalized(), + v1 = Vector3::Random().normalized(), + v3 = Vector3::Random().normalized(); + Transform3 t0, t1; + // The interesting case is when their determinants have different signs. + Matrix3 rank2 = 50 * v0 * v0.adjoint() + 20 * v1 * v1.adjoint(); + t0.linear() = rank2 + eps * v3 * v3.adjoint(); + t1.linear() = rank2 - eps * v3 * v3.adjoint(); + + // When: computing the rotation-scaling parts + Matrix3 r0, s0, r1, s1; + t0.computeRotationScaling(&r0, &s0); + t1.computeRotationScaling(&r1, &s1); + + // Then: the scaling parts should differ by no more than '2*eps'. + const Scalar c(2.1); // 2 + room for rounding errors + VERIFY((s0 - s1).norm() < c * eps); +} + +EIGEN_DECLARE_TEST(geo_transformations) { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1(( transformations<double,Affine,AutoAlign>() )); CALL_SUBTEST_1(( non_projective_only<double,Affine,AutoAlign>() )); + CALL_SUBTEST_1(( transformations_computed_scaling_continuity<double,Affine,AutoAlign>() )); CALL_SUBTEST_2(( transformations<float,AffineCompact,AutoAlign>() )); CALL_SUBTEST_2(( non_projective_only<float,AffineCompact,AutoAlign>() )); @@ -625,7 +708,7 @@ void test_geo_transformations() CALL_SUBTEST_3(( transformations<double,Projective,AutoAlign>() )); CALL_SUBTEST_3(( transformations<double,Projective,DontAlign>() )); CALL_SUBTEST_3(( transform_alignment<double>() )); - + CALL_SUBTEST_4(( transformations<float,Affine,RowMajor|AutoAlign>() )); CALL_SUBTEST_4(( non_projective_only<float,Affine,RowMajor>() )); @@ -641,5 +724,8 @@ void test_geo_transformations() CALL_SUBTEST_8(( transform_associativity<double,2,ColMajor>(Rotation2D<double>(internal::random<double>()*double(EIGEN_PI))) )); CALL_SUBTEST_8(( transform_associativity<double,3,ColMajor>(Quaterniond::UnitRandom()) )); + + CALL_SUBTEST_9(( transformations_no_scale<double,Affine,AutoAlign>() )); + CALL_SUBTEST_9(( transformations_no_scale<double,Isometry,AutoAlign>() )); } } |