geo_transformations.cpp File Reference
#include "main.h"
#include <Eigen/Geometry>
#include <Eigen/LU>
#include <Eigen/SVD>

Functions

template<typename T >
Matrix< T, 2, 1 > angleToVec (T a)
 
template<typename T >
EIGEN_DONT_INLINE void dont_over_optimize (T &x)
 
template<typename Scalar , int Mode, int Options>
void non_projective_only ()
 
template<typename Scalar , int Mode, int Options>
void transformations ()
 
template<typename A1 , typename A2 , typename P , typename Q , typename V , typename H >
void transform_associativity_left (const A1 &a1, const A2 &a2, const P &p, const Q &q, const V &v, const H &h)
 
template<typename A1 , typename A2 , typename P , typename Q , typename V , typename H >
void transform_associativity2 (const A1 &a1, const A2 &a2, const P &p, const Q &q, const V &v, const H &h)
 
template<typename Scalar , int Dim, int Options, typename RotationType >
void transform_associativity (const RotationType &R)
 
template<typename Scalar >
void transform_alignment ()
 
template<typename Scalar , int Dim, int Options>
void transform_products ()
 
template<typename Scalar , int Mode, int Options>
void transformations_no_scale ()
 
template<typename Scalar , int Mode, int Options>
void transformations_computed_scaling_continuity ()
 
 EIGEN_DECLARE_TEST (geo_transformations)
 

Function Documentation

◆ angleToVec()

template<typename T >
Matrix<T, 2, 1> angleToVec ( T  a)
16  {
17  return Matrix<T, 2, 1>(std::cos(a), std::sin(a));
18 }
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, cos(), and sin().

Referenced by transformations().

◆ dont_over_optimize()

template<typename T >
EIGEN_DONT_INLINE void dont_over_optimize ( T x)
22  {
23  volatile typename T::Scalar tmp = x(0);
24  x(0) = tmp;
25 }
SCALAR Scalar
Definition: bench_gemm.cpp:45
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
list x
Definition: plotDoE.py:28

References tmp, and plotDoE::x.

Referenced by transformations().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( geo_transformations  )
695  {
696  for (int i = 0; i < g_repeat; i++) {
697  CALL_SUBTEST_1((transformations<double, Affine, AutoAlign>()));
698  CALL_SUBTEST_1((non_projective_only<double, Affine, AutoAlign>()));
699  CALL_SUBTEST_1((transformations_computed_scaling_continuity<double, Affine, AutoAlign>()));
700 
701  CALL_SUBTEST_2((transformations<float, AffineCompact, AutoAlign>()));
702  CALL_SUBTEST_2((non_projective_only<float, AffineCompact, AutoAlign>()));
703  CALL_SUBTEST_2((transform_alignment<float>()));
704 
705  CALL_SUBTEST_3((transformations<double, Projective, AutoAlign>()));
706  CALL_SUBTEST_3((transformations<double, Projective, DontAlign>()));
707  CALL_SUBTEST_3((transform_alignment<double>()));
708 
709  CALL_SUBTEST_4((transformations<float, Affine, RowMajor | AutoAlign>()));
710  CALL_SUBTEST_4((non_projective_only<float, Affine, RowMajor>()));
711 
712  CALL_SUBTEST_5((transformations<double, AffineCompact, RowMajor | AutoAlign>()));
713  CALL_SUBTEST_5((non_projective_only<double, AffineCompact, RowMajor>()));
714 
715  CALL_SUBTEST_6((transformations<double, Projective, RowMajor | AutoAlign>()));
716  CALL_SUBTEST_6((transformations<double, Projective, RowMajor | DontAlign>()));
717 
718  CALL_SUBTEST_7((transform_products<double, 3, RowMajor | AutoAlign>()));
719  CALL_SUBTEST_7((transform_products<float, 2, AutoAlign>()));
720 
721  CALL_SUBTEST_8((transform_associativity<double, 2, ColMajor>(
722  Rotation2D<double>(internal::random<double>() * double(EIGEN_PI)))));
723  CALL_SUBTEST_8((transform_associativity<double, 3, ColMajor>(Quaterniond::UnitRandom())));
724 
725  CALL_SUBTEST_9((transformations_no_scale<double, Affine, AutoAlign>()));
726  CALL_SUBTEST_9((transformations_no_scale<double, Isometry, AutoAlign>()));
727  }
728 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_PI
Definition: MathFunctions.h:16
Represents a rotation/orientation in a 2 dimensional space.
Definition: Rotation2D.h:44
static int g_repeat
Definition: main.h:191
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, EIGEN_PI, Eigen::g_repeat, and i.

◆ non_projective_only()

template<typename Scalar , int Mode, int Options>
void non_projective_only ( )
28  {
29  /* this test covers the following files:
30  Cross.h Quaternion.h, Transform.cpp
31 */
32  typedef Matrix<Scalar, 3, 1> Vector3;
33  typedef Quaternion<Scalar> Quaternionx;
34  typedef AngleAxis<Scalar> AngleAxisx;
35  typedef Transform<Scalar, 3, Mode, Options> Transform3;
36  typedef DiagonalMatrix<Scalar, 3> AlignedScaling3;
37  typedef Translation<Scalar, 3> Translation3;
38 
39  Vector3 v0 = Vector3::Random(), v1 = Vector3::Random();
40 
41  Transform3 t0, t1, t2;
42 
43  Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
44 
45  Quaternionx q1, q2;
46 
47  q1 = AngleAxisx(a, v0.normalized());
48 
49  t0 = Transform3::Identity();
50  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
51 
52  t0.linear() = q1.toRotationMatrix();
53 
54  v0 << 50, 2, 1;
55  t0.scale(v0);
56 
57  VERIFY_IS_APPROX((t0 * Vector3(1, 0, 0)).template head<3>().norm(), v0.x());
58 
59  t0.setIdentity();
60  t1.setIdentity();
61  v1 << 1, 2, 3;
62  t0.linear() = q1.toRotationMatrix();
63  t0.pretranslate(v0);
64  t0.scale(v1);
65  t1.linear() = q1.conjugate().toRotationMatrix();
66  t1.prescale(v1.cwiseInverse());
67  t1.translate(-v0);
68 
69  VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
70 
71  t1.fromPositionOrientationScale(v0, q1, v1);
72  VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
73  VERIFY_IS_APPROX(t1 * v1, t0 * v1);
74 
75  // translation * vector
76  t0.setIdentity();
77  t0.translate(v0);
78  VERIFY_IS_APPROX((t0 * v1).template head<3>(), Translation3(v0) * v1);
79 
80  // AlignedScaling * vector
81  t0.setIdentity();
82  t0.scale(v0);
83  VERIFY_IS_APPROX((t0 * v1).template head<3>(), AlignedScaling3(v0) * v1);
84 }
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
Represents a 3D rotation as a rotation angle around an arbitrary 3D axis.
Definition: AngleAxis.h:52
Represents a diagonal matrix with its storage.
Definition: DiagonalMatrix.h:172
The quaternion class used to represent 3D orientations and rotations.
Definition: Eigen/Eigen/src/Geometry/Quaternion.h:285
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:192
Represents a translation transformation.
Definition: Translation.h:33
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY(a)
Definition: main.h:362

References a, EIGEN_PI, matrix(), v1(), VERIFY, and VERIFY_IS_APPROX.

◆ transform_alignment()

template<typename Scalar >
void transform_alignment ( )
563  {
564  typedef Transform<Scalar, 3, Projective, AutoAlign> Projective3a;
565  typedef Transform<Scalar, 3, Projective, DontAlign> Projective3u;
566 
567  EIGEN_ALIGN_MAX Scalar array1[16];
568  EIGEN_ALIGN_MAX Scalar array2[16];
569  EIGEN_ALIGN_MAX Scalar array3[16 + 1];
570  Scalar* array3u = array3 + 1;
571 
572  Projective3a* p1 = ::new (reinterpret_cast<void*>(array1)) Projective3a;
573  Projective3u* p2 = ::new (reinterpret_cast<void*>(array2)) Projective3u;
574  Projective3u* p3 = ::new (reinterpret_cast<void*>(array3u)) Projective3u;
575 
576  p1->matrix().setRandom();
577  *p2 = *p1;
578  *p3 = *p1;
579 
580  VERIFY_IS_APPROX(p1->matrix(), p2->matrix());
581  VERIFY_IS_APPROX(p1->matrix(), p3->matrix());
582 
583  VERIFY_IS_APPROX((*p1) * (*p1), (*p2) * (*p3));
584 }
#define EIGEN_ALIGN_MAX
Definition: ConfigureVectorization.h:146
Vector3f p1
Definition: MatrixBase_all.cpp:2

References EIGEN_ALIGN_MAX, p1, and VERIFY_IS_APPROX.

◆ transform_associativity()

template<typename Scalar , int Dim, int Options, typename RotationType >
void transform_associativity ( const RotationType &  R)
517  {
519  typedef Matrix<Scalar, Dim + 1, 1> HVectorType;
520  typedef Matrix<Scalar, Dim, Dim> LinearType;
522  typedef Transform<Scalar, Dim, AffineCompact, Options> AffineCompactType;
523  typedef Transform<Scalar, Dim, Affine, Options> AffineType;
524  typedef Transform<Scalar, Dim, Projective, Options> ProjectiveType;
525  typedef DiagonalMatrix<Scalar, Dim> ScalingType;
526  typedef Translation<Scalar, Dim> TranslationType;
527 
528  AffineCompactType A1c;
529  A1c.matrix().setRandom();
530  AffineCompactType A2c;
531  A2c.matrix().setRandom();
532  AffineType A1(A1c);
533  AffineType A2(A2c);
534  ProjectiveType P1;
535  P1.matrix().setRandom();
536  VectorType v1 = VectorType::Random();
537  VectorType v2 = VectorType::Random();
538  HVectorType h1 = HVectorType::Random();
539  Scalar s1 = internal::random<Scalar>();
540  LinearType L = LinearType::Random();
541  MatrixType M = MatrixType::Random();
542 
543  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, A2, v2, h1));
544  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, A2c, v2, h1));
545  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, v1.asDiagonal(), v2, h1));
546  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, ScalingType(v1), v2, h1));
547  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, Scaling(v1), v2, h1));
548  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, Scaling(s1), v2, h1));
549  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, TranslationType(v1), v2, h1));
550  CALL_SUBTEST(transform_associativity_left(A1c, A1, P1, L, v2, h1));
551  CALL_SUBTEST(transform_associativity2(A1c, A1, P1, R, v2, h1));
552 
553  VERIFY_IS_APPROX(A1 * (M * h1), (A1 * M) * h1);
554  VERIFY_IS_APPROX(A1c * (M * h1), (A1c * M) * h1);
555  VERIFY_IS_APPROX(P1 * (M * h1), (P1 * M) * h1);
556 
557  VERIFY_IS_APPROX(M * (A1 * h1), (M * A1) * h1);
558  VERIFY_IS_APPROX(M * (A1c * h1), (M * A1c) * h1);
559  VERIFY_IS_APPROX(M * (P1 * h1), ((M * P1) * h1));
560 }
MatrixXd L
Definition: LLT_example.cpp:6
@ R
Definition: StatisticsVector.h:21
Map< RowVectorXf > v2(M2.data(), M2.size())
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
void transform_associativity_left(const A1 &a1, const A2 &a2, const P &p, const Q &q, const V &v, const H &h)
Definition: geo_transformations.cpp:501
void transform_associativity2(const A1 &a1, const A2 &a2, const P &p, const Q &q, const V &v, const H &h)
Definition: geo_transformations.cpp:508
#define CALL_SUBTEST(FUNC)
Definition: main.h:382
UniformScaling< float > Scaling(float s)
Definition: Eigen/src/Geometry/Scaling.h:138
Definition: fft_test_shared.h:66

References CALL_SUBTEST, L, R, Eigen::Scaling(), transform_associativity2(), transform_associativity_left(), v1(), v2(), and VERIFY_IS_APPROX.

◆ transform_associativity2()

template<typename A1 , typename A2 , typename P , typename Q , typename V , typename H >
void transform_associativity2 ( const A1 &  a1,
const A2 &  a2,
const P p,
const Q q,
const V v,
const H h 
)
508  {
509  VERIFY_IS_APPROX(a1 * (q * v), (a1 * q) * v);
510  VERIFY_IS_APPROX(a2 * (q * v), (a2 * q) * v);
511  VERIFY_IS_APPROX(p * (q * v).homogeneous(), (p * q) * v.homogeneous());
512 
513  transform_associativity_left(a1, a2, p, q, v, h);
514 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
float * p
Definition: Tutorial_Map_using.cpp:9
void homogeneous(void)
Definition: geo_homogeneous.cpp:14
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019

References homogeneous(), p, Eigen::numext::q, transform_associativity_left(), v, and VERIFY_IS_APPROX.

Referenced by transform_associativity().

◆ transform_associativity_left()

template<typename A1 , typename A2 , typename P , typename Q , typename V , typename H >
void transform_associativity_left ( const A1 &  a1,
const A2 &  a2,
const P p,
const Q q,
const V v,
const H h 
)
501  {
502  VERIFY_IS_APPROX(q * (a1 * v), (q * a1) * v);
503  VERIFY_IS_APPROX(q * (a2 * v), (q * a2) * v);
504  VERIFY_IS_APPROX(q * (p * h).hnormalized(), ((q * p) * h).hnormalized());
505 }

References p, Eigen::numext::q, v, and VERIFY_IS_APPROX.

Referenced by transform_associativity(), and transform_associativity2().

◆ transform_products()

template<typename Scalar , int Dim, int Options>
void transform_products ( )
587  {
592 
593  Proj p;
594  p.matrix().setRandom();
595  Aff a;
596  a.linear().setRandom();
597  a.translation().setRandom();
598  AffC ac = a;
599 
600  Mat p_m(p.matrix()), a_m(a.matrix());
601 
602  VERIFY_IS_APPROX((p * p).matrix(), p_m * p_m);
603  VERIFY_IS_APPROX((a * a).matrix(), a_m * a_m);
604  VERIFY_IS_APPROX((p * a).matrix(), p_m * a_m);
605  VERIFY_IS_APPROX((a * p).matrix(), a_m * p_m);
606  VERIFY_IS_APPROX((ac * a).matrix(), a_m * a_m);
607  VERIFY_IS_APPROX((a * ac).matrix(), a_m * a_m);
608  VERIFY_IS_APPROX((p * ac).matrix(), p_m * a_m);
609  VERIFY_IS_APPROX((ac * p).matrix(), a_m * p_m);
610 }
Matrix< Scalar, Dynamic, Dynamic > Mat
Definition: gemm_common.h:15

References a, matrix(), p, and VERIFY_IS_APPROX.

◆ transformations()

template<typename Scalar , int Mode, int Options>
void transformations ( )
87  {
88  /* this test covers the following files:
89  Cross.h Quaternion.h, Transform.cpp
90  */
91  using std::abs;
92  using std::cos;
93  typedef Matrix<Scalar, 3, 3> Matrix3;
94  typedef Matrix<Scalar, 4, 4> Matrix4;
95  typedef Matrix<Scalar, 2, 1> Vector2;
96  typedef Matrix<Scalar, 3, 1> Vector3;
97  typedef Matrix<Scalar, 4, 1> Vector4;
98  typedef Quaternion<Scalar> Quaternionx;
99  typedef AngleAxis<Scalar> AngleAxisx;
100  typedef Transform<Scalar, 2, Mode, Options> Transform2;
101  typedef Transform<Scalar, 3, Mode, Options> Transform3;
102  typedef typename Transform3::MatrixType MatrixType;
103  typedef DiagonalMatrix<Scalar, 3> AlignedScaling3;
104  typedef Translation<Scalar, 2> Translation2;
105  typedef Translation<Scalar, 3> Translation3;
106 
107  Vector3 v0 = Vector3::Random(), v1 = Vector3::Random();
108  Matrix3 matrot1, m;
109 
110  Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
111  Scalar s0 = internal::random<Scalar>(), s1 = internal::random<Scalar>();
112 
113  while (v0.norm() < test_precision<Scalar>()) v0 = Vector3::Random();
114  while (v1.norm() < test_precision<Scalar>()) v1 = Vector3::Random();
115 
116  VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
117  VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(EIGEN_PI), v0.unitOrthogonal()) * v0);
118  if (abs(cos(a)) > test_precision<Scalar>()) {
119  VERIFY_IS_APPROX(cos(a) * v0.squaredNorm(), v0.dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
120  }
121  m = AngleAxisx(a, v0.normalized()).toRotationMatrix().adjoint();
122  VERIFY_IS_APPROX(Matrix3::Identity(), m * AngleAxisx(a, v0.normalized()));
123  VERIFY_IS_APPROX(Matrix3::Identity(), AngleAxisx(a, v0.normalized()) * m);
124 
125  Quaternionx q1, q2;
126  q1 = AngleAxisx(a, v0.normalized());
127  q2 = AngleAxisx(a, v1.normalized());
128 
129  // rotation matrix conversion
130  matrot1 = AngleAxisx(Scalar(0.1), Vector3::UnitX()) * AngleAxisx(Scalar(0.2), Vector3::UnitY()) *
131  AngleAxisx(Scalar(0.3), Vector3::UnitZ());
132  VERIFY_IS_APPROX(matrot1 * v1, AngleAxisx(Scalar(0.1), Vector3(1, 0, 0)).toRotationMatrix() *
133  (AngleAxisx(Scalar(0.2), Vector3(0, 1, 0)).toRotationMatrix() *
134  (AngleAxisx(Scalar(0.3), Vector3(0, 0, 1)).toRotationMatrix() * v1)));
135 
136  // angle-axis conversion
137  AngleAxisx aa = AngleAxisx(q1);
138  VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
139 
140  // The following test is stable only if 2*angle != angle and v1 is not colinear with axis
141  if ((abs(aa.angle()) > test_precision<Scalar>()) &&
142  (abs(aa.axis().dot(v1.normalized())) < (Scalar(1) - Scalar(4) * test_precision<Scalar>()))) {
143  VERIFY(!(q1 * v1).isApprox(Quaternionx(AngleAxisx(aa.angle() * 2, aa.axis())) * v1));
144  }
145 
146  aa.fromRotationMatrix(aa.toRotationMatrix());
147  VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
148  // The following test is stable only if 2*angle != angle and v1 is not colinear with axis
149  if ((abs(aa.angle()) > test_precision<Scalar>()) &&
150  (abs(aa.axis().dot(v1.normalized())) < (Scalar(1) - Scalar(4) * test_precision<Scalar>()))) {
151  VERIFY(!(q1 * v1).isApprox(Quaternionx(AngleAxisx(aa.angle() * 2, aa.axis())) * v1));
152  }
153 
154  // AngleAxis
155  VERIFY_IS_APPROX(AngleAxisx(a, v1.normalized()).toRotationMatrix(),
156  Quaternionx(AngleAxisx(a, v1.normalized())).toRotationMatrix());
157 
158  AngleAxisx aa1;
159  m = q1.toRotationMatrix();
160  aa1 = m;
161  VERIFY_IS_APPROX(AngleAxisx(m).toRotationMatrix(), Quaternionx(m).toRotationMatrix());
162 
163  // Transform
164  // TODO complete the tests !
165  a = 0;
166  while (abs(a) < Scalar(0.1))
167  a = internal::random<Scalar>(-Scalar(0.4) * Scalar(EIGEN_PI), Scalar(0.4) * Scalar(EIGEN_PI));
168  q1 = AngleAxisx(a, v0.normalized());
169  Transform3 t0, t1, t2;
170 
171  // first test setIdentity() and Identity()
172  t0.setIdentity();
173  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
174  t0.matrix().setZero();
175  t0 = Transform3::Identity();
176  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
177 
178  t0.setIdentity();
179  t1.setIdentity();
180  v1 << 1, 2, 3;
181  t0.linear() = q1.toRotationMatrix();
182  t0.pretranslate(v0);
183  t0.scale(v1);
184  t1.linear() = q1.conjugate().toRotationMatrix();
185  t1.prescale(v1.cwiseInverse());
186  t1.translate(-v0);
187 
188  VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
189 
190  t1.fromPositionOrientationScale(v0, q1, v1);
191  VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
192 
193  t0.setIdentity();
194  t0.scale(v0).rotate(q1.toRotationMatrix());
195  t1.setIdentity();
196  t1.scale(v0).rotate(q1);
197  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
198 
199  t0.setIdentity();
200  t0.scale(v0).rotate(AngleAxisx(q1));
201  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
202 
203  VERIFY_IS_APPROX(t0.scale(a).matrix(), t1.scale(Vector3::Constant(a)).matrix());
204  VERIFY_IS_APPROX(t0.prescale(a).matrix(), t1.prescale(Vector3::Constant(a)).matrix());
205 
206  // More transform constructors, operator=, operator*=
207 
208  Matrix3 mat3 = Matrix3::Random();
209  Matrix4 mat4;
210  mat4 << mat3, Vector3::Zero(), Vector4::Zero().transpose();
211  Transform3 tmat3(mat3), tmat4(mat4);
212  if (Mode != int(AffineCompact)) tmat4.matrix()(3, 3) = Scalar(1);
213  VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix());
214 
215  Scalar a3 = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
216  Vector3 v3 = Vector3::Random().normalized();
217  AngleAxisx aa3(a3, v3);
218  Transform3 t3(aa3);
219  Transform3 t4;
220  t4 = aa3;
221  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
222  t4.rotate(AngleAxisx(-a3, v3));
223  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
224  t4 *= aa3;
225  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
226 
227  do {
228  v3 = Vector3::Random();
229  dont_over_optimize(v3);
230  } while (v3.cwiseAbs().minCoeff() < NumTraits<Scalar>::epsilon());
231  Translation3 tv3(v3);
232  Transform3 t5(tv3);
233  t4 = tv3;
234  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
235  t4.translate((-v3).eval());
236  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
237  t4 *= tv3;
238  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
239 
240  AlignedScaling3 sv3(v3);
241  Transform3 t6(sv3);
242  t4 = sv3;
243  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
244  t4.scale(v3.cwiseInverse());
245  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
246  t4 *= sv3;
247  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
248 
249  // matrix * transform
250  VERIFY_IS_APPROX((t3.matrix() * t4).matrix(), (t3 * t4).matrix());
251 
252  // chained Transform product
253  VERIFY_IS_APPROX(((t3 * t4) * t5).matrix(), (t3 * (t4 * t5)).matrix());
254 
255  // check that Transform product doesn't have aliasing problems
256  t5 = t4;
257  t5 = t5 * t5;
258  VERIFY_IS_APPROX(t5, t4 * t4);
259 
260  // 2D transformation
261  Transform2 t20, t21;
262  Vector2 v20 = Vector2::Random();
263  Vector2 v21 = Vector2::Random();
264  for (int k = 0; k < 2; ++k)
265  if (abs(v21[k]) < Scalar(1e-3)) v21[k] = Scalar(1e-3);
266  t21.setIdentity();
267  t21.linear() = Rotation2D<Scalar>(a).toRotationMatrix();
268  VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20, a, v21).matrix(), t21.pretranslate(v20).scale(v21).matrix());
269 
270  t21.setIdentity();
271  t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
272  VERIFY((t20.fromPositionOrientationScale(v20, a, v21) * (t21.prescale(v21.cwiseInverse()).translate(-v20)))
273  .matrix()
274  .isIdentity(test_precision<Scalar>()));
275 
276  t20.setIdentity();
277  t20.shear(Scalar(2), Scalar(3));
278  Transform2 t23 = t20 * t21;
279  t21.preshear(Scalar(2), Scalar(3));
280  VERIFY_IS_APPROX(t21, t23);
281 
282  // Transform - new API
283  // 3D
284  t0.setIdentity();
285  t0.rotate(q1).scale(v0).translate(v0);
286  // mat * aligned scaling and mat * translation
287  t1 = (Matrix3(q1) * AlignedScaling3(v0)) * Translation3(v0);
288  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
289  t1 = (Matrix3(q1) * Eigen::Scaling(v0)) * Translation3(v0);
290  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
291  t1 = (q1 * Eigen::Scaling(v0)) * Translation3(v0);
292  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
293  // mat * transformation and aligned scaling * translation
294  t1 = Matrix3(q1) * (AlignedScaling3(v0) * Translation3(v0));
295  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
296 
297  t0.setIdentity();
298  t0.scale(s0).translate(v0);
299  t1 = Eigen::Scaling(s0) * Translation3(v0);
300  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
301  t0.prescale(s0);
302  t1 = Eigen::Scaling(s0) * t1;
303  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
304 
305  t0 = t3;
306  t0.scale(s0);
307  t1 = t3 * Eigen::Scaling(s0, s0, s0);
308  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
309  t0.prescale(s0);
310  t1 = Eigen::Scaling(s0, s0, s0) * t1;
311  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
312 
313  t0 = t3;
314  t0.scale(s0);
315  t1 = t3 * Eigen::Scaling(s0);
316  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
317  t0.prescale(s0);
318  t1 = Eigen::Scaling(s0) * t1;
319  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
320 
321  t0.setIdentity();
322  t0.prerotate(q1).prescale(v0).pretranslate(v0);
323  // translation * aligned scaling and transformation * mat
324  t1 = (Translation3(v0) * AlignedScaling3(v0)) * Transform3(q1);
325  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
326  // scaling * mat and translation * mat
327  t1 = Translation3(v0) * (AlignedScaling3(v0) * Transform3(q1));
328  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
329 
330  t0.setIdentity();
331  t0.scale(v0).translate(v0).rotate(q1);
332  // translation * mat and aligned scaling * transformation
333  t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
334  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
335  // transformation * aligned scaling
336  t0.scale(v0);
337  t1 *= AlignedScaling3(v0);
338  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
339  t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
340  t1 = t1 * v0.asDiagonal();
341  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
342  // transformation * translation
343  t0.translate(v0);
344  t1 = t1 * Translation3(v0);
345  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
346  // translation * transformation
347  t0.pretranslate(v0);
348  t1 = Translation3(v0) * t1;
349  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
350 
351  // transform * quaternion
352  t0.rotate(q1);
353  t1 = t1 * q1;
354  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
355 
356  // translation * quaternion
357  t0.translate(v1).rotate(q1);
358  t1 = t1 * (Translation3(v1) * q1);
359  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
360 
361  // aligned scaling * quaternion
362  t0.scale(v1).rotate(q1);
363  t1 = t1 * (AlignedScaling3(v1) * q1);
364  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
365 
366  // quaternion * transform
367  t0.prerotate(q1);
368  t1 = q1 * t1;
369  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
370 
371  // quaternion * translation
372  t0.rotate(q1).translate(v1);
373  t1 = t1 * (q1 * Translation3(v1));
374  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
375 
376  // quaternion * aligned scaling
377  t0.rotate(q1).scale(v1);
378  t1 = t1 * (q1 * AlignedScaling3(v1));
379  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
380 
381  // test transform inversion
382  t0.setIdentity();
383  t0.translate(v0);
384  do {
385  t0.linear().setRandom();
386  } while (t0.linear().jacobiSvd().singularValues()(2) < test_precision<Scalar>());
387  Matrix4 t044 = Matrix4::Zero();
388  t044(3, 3) = 1;
389  t044.block(0, 0, t0.matrix().rows(), 4) = t0.matrix();
390  VERIFY_IS_APPROX(t0.inverse(Affine).matrix(), t044.inverse().block(0, 0, t0.matrix().rows(), 4));
391  t0.setIdentity();
392  t0.translate(v0).rotate(q1);
393  t044 = Matrix4::Zero();
394  t044(3, 3) = 1;
395  t044.block(0, 0, t0.matrix().rows(), 4) = t0.matrix();
396  VERIFY_IS_APPROX(t0.inverse(Isometry).matrix(), t044.inverse().block(0, 0, t0.matrix().rows(), 4));
397 
398  Matrix3 mat_rotation, mat_scaling;
399  t0.setIdentity();
400  t0.translate(v0).rotate(q1).scale(v1);
401  t0.computeRotationScaling(&mat_rotation, &mat_scaling);
402  VERIFY_IS_APPROX(t0.linear(), mat_rotation * mat_scaling);
403  VERIFY_IS_APPROX(mat_rotation * mat_rotation.adjoint(), Matrix3::Identity());
404  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));
405  t0.computeScalingRotation(&mat_scaling, &mat_rotation);
406  VERIFY_IS_APPROX(t0.linear(), mat_scaling * mat_rotation);
407  VERIFY_IS_APPROX(mat_rotation * mat_rotation.adjoint(), Matrix3::Identity());
408  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));
409 
410  // test casting
411  Transform<float, 3, Mode> t1f = t1.template cast<float>();
412  VERIFY_IS_APPROX(t1f.template cast<Scalar>(), t1);
413  Transform<double, 3, Mode> t1d = t1.template cast<double>();
414  VERIFY_IS_APPROX(t1d.template cast<Scalar>(), t1);
415 
416  Translation3 tr1(v0);
417  Translation<float, 3> tr1f = tr1.template cast<float>();
418  VERIFY_IS_APPROX(tr1f.template cast<Scalar>(), tr1);
419  Translation<double, 3> tr1d = tr1.template cast<double>();
420  VERIFY_IS_APPROX(tr1d.template cast<Scalar>(), tr1);
421 
422  AngleAxis<float> aa1f = aa1.template cast<float>();
423  VERIFY_IS_APPROX(aa1f.template cast<Scalar>(), aa1);
424  AngleAxis<double> aa1d = aa1.template cast<double>();
425  VERIFY_IS_APPROX(aa1d.template cast<Scalar>(), aa1);
426 
427  Rotation2D<Scalar> r2d1(internal::random<Scalar>());
428  Rotation2D<float> r2d1f = r2d1.template cast<float>();
429  VERIFY_IS_APPROX(r2d1f.template cast<Scalar>(), r2d1);
430  Rotation2D<double> r2d1d = r2d1.template cast<double>();
431  VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(), r2d1);
432 
433  for (int k = 0; k < 100; ++k) {
434  Scalar angle = internal::random<Scalar>(-100, 100);
436  VERIFY(rot2.smallestPositiveAngle() >= 0);
437  VERIFY(rot2.smallestPositiveAngle() <= Scalar(2) * Scalar(EIGEN_PI));
438  VERIFY_IS_APPROX(angleToVec(rot2.smallestPositiveAngle()), angleToVec(rot2.angle()));
439 
440  VERIFY(rot2.smallestAngle() >= -Scalar(EIGEN_PI));
441  VERIFY(rot2.smallestAngle() <= Scalar(EIGEN_PI));
442  VERIFY_IS_APPROX(angleToVec(rot2.smallestAngle()), angleToVec(rot2.angle()));
443 
444  Matrix<Scalar, 2, 2> rot2_as_mat(rot2);
445  Rotation2D<Scalar> rot3(rot2_as_mat);
446  VERIFY_IS_APPROX(angleToVec(rot2.smallestAngle()), angleToVec(rot3.angle()));
447  }
448 
449  s0 = internal::random<Scalar>(-100, 100);
450  s1 = internal::random<Scalar>(-100, 100);
451  Rotation2D<Scalar> R0(s0), R1(s1);
452 
453  t20 = Translation2(v20) * (R0 * Eigen::Scaling(s0));
454  t21 = Translation2(v20) * R0 * Eigen::Scaling(s0);
455  VERIFY_IS_APPROX(t20, t21);
456 
457  t20 = Translation2(v20) * (R0 * R0.inverse() * Eigen::Scaling(s0));
458  t21 = Translation2(v20) * Eigen::Scaling(s0);
459  VERIFY_IS_APPROX(t20, t21);
460 
461  VERIFY_IS_APPROX(s0, (R0.slerp(0, R1)).angle());
462  VERIFY_IS_APPROX(angleToVec(R1.smallestPositiveAngle()), angleToVec((R0.slerp(1, R1)).smallestPositiveAngle()));
463  VERIFY_IS_APPROX(R0.smallestPositiveAngle(), (R0.slerp(0.5, R0)).smallestPositiveAngle());
464 
465  if (std::cos(s0) > 0)
466  VERIFY_IS_MUCH_SMALLER_THAN((R0.slerp(0.5, R0.inverse())).smallestAngle(), Scalar(1));
467  else
468  VERIFY_IS_APPROX(Scalar(EIGEN_PI), (R0.slerp(0.5, R0.inverse())).smallestPositiveAngle());
469 
470  // Check path length
471  Scalar l = 0;
472  int path_steps = 100;
473  for (int k = 0; k < path_steps; ++k) {
474  Scalar a1 = R0.slerp(Scalar(k) / Scalar(path_steps), R1).angle();
475  Scalar a2 = R0.slerp(Scalar(k + 1) / Scalar(path_steps), R1).angle();
476  l += std::abs(a2 - a1);
477  }
478  VERIFY(l <= Scalar(EIGEN_PI) * (Scalar(1) + NumTraits<Scalar>::epsilon() * Scalar(path_steps / 2)));
479 
480  // check basic features
481  {
482  Rotation2D<Scalar> r1; // default ctor
483  r1 = Rotation2D<Scalar>(s0); // copy assignment
484  VERIFY_IS_APPROX(r1.angle(), s0);
485  Rotation2D<Scalar> r2(r1); // copy ctor
486  VERIFY_IS_APPROX(r2.angle(), s0);
487  }
488 
489  {
490  Transform3 t32(Matrix4::Random()), t33, t34;
491  t34 = t33 = t32;
492  t32.scale(v0);
493  t33 *= AlignedScaling3(v0);
494  VERIFY_IS_APPROX(t32.matrix(), t33.matrix());
495  t33 = t34 * AlignedScaling3(v0);
496  VERIFY_IS_APPROX(t32.matrix(), t33.matrix());
497  }
498 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC Matrix2 toRotationMatrix() const
Definition: Rotation2D.h:191
EIGEN_DEVICE_FUNC Scalar angle() const
Definition: Rotation2D.h:76
Matrix< T, 2, 1 > angleToVec(T a)
Definition: geo_transformations.cpp:16
EIGEN_DONT_INLINE void dont_over_optimize(T &x)
Definition: geo_transformations.cpp:22
@ Affine
Definition: Constants.h:458
@ AffineCompact
Definition: Constants.h:460
@ Isometry
Definition: Constants.h:455
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:371
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923
static EIGEN_DEVICE_FUNC Matrix< Scalar, 2, 2 > toRotationMatrix(const Scalar &s)
Definition: RotationBase.h:188
double angle(const double &t)
Angular position as a function of time t.
Definition: jeffery_orbit.cc:98
double Zero
Definition: pseudosolid_node_update_elements.cc:35
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References a, abs(), Eigen::Affine, Eigen::AffineCompact, Eigen::Rotation2D< Scalar_ >::angle(), Jeffery_Solution::angle(), angleToVec(), cos(), dont_over_optimize(), e(), EIGEN_PI, eval(), Eigen::internal::isApprox(), Eigen::Isometry, k, m, matrix(), Eigen::Scaling(), Eigen::Rotation2D< Scalar_ >::smallestAngle(), Eigen::Rotation2D< Scalar_ >::smallestPositiveAngle(), Eigen::Rotation2D< Scalar_ >::toRotationMatrix(), Eigen::internal::toRotationMatrix(), v1(), VERIFY, VERIFY_IS_APPROX, VERIFY_IS_MUCH_SMALLER_THAN, and oomph::PseudoSolidHelper::Zero.

◆ transformations_computed_scaling_continuity()

template<typename Scalar , int Mode, int Options>
void transformations_computed_scaling_continuity ( )
671  {
672  typedef Matrix<Scalar, 3, 1> Vector3;
673  typedef Transform<Scalar, 3, Mode, Options> Transform3;
674  typedef Matrix<Scalar, 3, 3> Matrix3;
675 
676  // Given: two transforms that differ by '2*eps'.
677  Scalar eps(1e-3);
678  Vector3 v0 = Vector3::Random().normalized(), v1 = Vector3::Random().normalized(), v3 = Vector3::Random().normalized();
679  Transform3 t0, t1;
680  // The interesting case is when their determinants have different signs.
681  Matrix3 rank2 = 50 * v0 * v0.adjoint() + 20 * v1 * v1.adjoint();
682  t0.linear() = rank2 + eps * v3 * v3.adjoint();
683  t1.linear() = rank2 - eps * v3 * v3.adjoint();
684 
685  // When: computing the rotation-scaling parts
686  Matrix3 r0, s0, r1, s1;
687  t0.computeRotationScaling(&r0, &s0);
688  t1.computeRotationScaling(&r1, &s1);
689 
690  // Then: the scaling parts should differ by no more than '2*eps'.
691  const Scalar c(2.1); // 2 + room for rounding errors
692  VERIFY((s0 - s1).norm() < c * eps);
693 }
double eps
Definition: crbond_bessel.cc:24
int c
Definition: calibrate.py:100

References calibrate::c, e(), CRBond_Bessel::eps, v1(), and VERIFY.

◆ transformations_no_scale()

template<typename Scalar , int Mode, int Options>
void transformations_no_scale ( )
613  {
614  /* this test covers the following files:
615  Cross.h Quaternion.h, Transform.h
616 */
617  typedef Matrix<Scalar, 3, 1> Vector3;
618  typedef Matrix<Scalar, 4, 1> Vector4;
619  typedef Quaternion<Scalar> Quaternionx;
620  typedef AngleAxis<Scalar> AngleAxisx;
621  typedef Transform<Scalar, 3, Mode, Options> Transform3;
622  typedef Translation<Scalar, 3> Translation3;
623  typedef Matrix<Scalar, 4, 4> Matrix4;
624 
625  Vector3 v0 = Vector3::Random(), v1 = Vector3::Random();
626 
627  Transform3 t0, t1, t2;
628 
629  Scalar a = internal::random<Scalar>(-Scalar(EIGEN_PI), Scalar(EIGEN_PI));
630 
631  Quaternionx q1, q2;
632 
633  q1 = AngleAxisx(a, v0.normalized());
634 
635  t0 = Transform3::Identity();
636  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
637 
638  t0.setIdentity();
639  t1.setIdentity();
640  v1 = Vector3::Ones();
641  t0.linear() = q1.toRotationMatrix();
642  t0.pretranslate(v0);
643  t1.linear() = q1.conjugate().toRotationMatrix();
644  t1.translate(-v0);
645 
646  VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));
647 
648  t1.fromPositionOrientationScale(v0, q1, v1);
649  VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
650  VERIFY_IS_APPROX(t1 * v1, t0 * v1);
651 
652  // translation * vector
653  t0.setIdentity();
654  t0.translate(v0);
655  VERIFY_IS_APPROX((t0 * v1).template head<3>(), Translation3(v0) * v1);
656 
657  // Conversion to matrix.
658  Transform3 t3;
659  t3.linear() = q1.toRotationMatrix();
660  t3.translation() = v1;
661  Matrix4 m3 = t3.matrix();
662  VERIFY((m3 * m3.inverse()).isIdentity(test_precision<Scalar>()));
663  // Verify implicit last row is initialized.
664  VERIFY_IS_APPROX(Vector4(m3.row(3)), Vector4(0.0, 0.0, 0.0, 1.0));
665 
666  VERIFY_IS_APPROX(t3.rotation(), t3.linear());
667  if (Mode == Isometry) VERIFY(t3.rotation().data() == t3.linear().data());
668 }

References a, EIGEN_PI, Eigen::Isometry, matrix(), v1(), VERIFY, and VERIFY_IS_APPROX.