geo_homogeneous.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 #include <Eigen/Geometry>
12 
13 template<typename Scalar,int Size> void homogeneous(void)
14 {
15  /* this test covers the following files:
16  Homogeneous.h
17  */
18 
21 
22  typedef Matrix<Scalar,Size+1,Size> HMatrixType;
23  typedef Matrix<Scalar,Size+1,1> HVectorType;
24 
25  typedef Matrix<Scalar,Size,Size+1> T1MatrixType;
26  typedef Matrix<Scalar,Size+1,Size+1> T2MatrixType;
27  typedef Matrix<Scalar,Size+1,Size> T3MatrixType;
28 
29  VectorType v0 = VectorType::Random(),
30  ones = VectorType::Ones();
31 
32  HVectorType hv0 = HVectorType::Random();
33 
34  MatrixType m0 = MatrixType::Random();
35 
36  HMatrixType hm0 = HMatrixType::Random();
37 
38  hv0 << v0, 1;
39  VERIFY_IS_APPROX(v0.homogeneous(), hv0);
40  VERIFY_IS_APPROX(v0, hv0.hnormalized());
41 
42  VERIFY_IS_APPROX(v0.homogeneous().sum(), hv0.sum());
43  VERIFY_IS_APPROX(v0.homogeneous().minCoeff(), hv0.minCoeff());
44  VERIFY_IS_APPROX(v0.homogeneous().maxCoeff(), hv0.maxCoeff());
45 
46  hm0 << m0, ones.transpose();
47  VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
48  VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
49  hm0.row(Size-1).setRandom();
50  for(int j=0; j<Size; ++j)
51  m0.col(j) = hm0.col(j).head(Size) / hm0(Size,j);
52  VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
53 
54  T1MatrixType t1 = T1MatrixType::Random();
55  VERIFY_IS_APPROX(t1 * (v0.homogeneous().eval()), t1 * v0.homogeneous());
56  VERIFY_IS_APPROX(t1 * (m0.colwise().homogeneous().eval()), t1 * m0.colwise().homogeneous());
57 
58  T2MatrixType t2 = T2MatrixType::Random();
59  VERIFY_IS_APPROX(t2 * (v0.homogeneous().eval()), t2 * v0.homogeneous());
60  VERIFY_IS_APPROX(t2 * (m0.colwise().homogeneous().eval()), t2 * m0.colwise().homogeneous());
61  VERIFY_IS_APPROX(t2 * (v0.homogeneous().asDiagonal()), t2 * hv0.asDiagonal());
62  VERIFY_IS_APPROX((v0.homogeneous().asDiagonal()) * t2, hv0.asDiagonal() * t2);
63 
64  VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2,
65  v0.transpose().rowwise().homogeneous() * t2);
66  VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2,
67  m0.transpose().rowwise().homogeneous() * t2);
68 
69  T3MatrixType t3 = T3MatrixType::Random();
70  VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t3,
71  v0.transpose().rowwise().homogeneous() * t3);
72  VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3,
73  m0.transpose().rowwise().homogeneous() * t3);
74 
75  // test product with a Transform object
81 
82  aff.affine().setRandom();
83  proj = caff = aff;
84  pts.setRandom(Size,internal::random<int>(1,20));
85 
86  pts1 = pts.colwise().homogeneous();
87  VERIFY_IS_APPROX(aff * pts.colwise().homogeneous(), (aff * pts1).colwise().hnormalized());
88  VERIFY_IS_APPROX(caff * pts.colwise().homogeneous(), (caff * pts1).colwise().hnormalized());
89  VERIFY_IS_APPROX(proj * pts.colwise().homogeneous(), (proj * pts1));
90 
91  VERIFY_IS_APPROX((aff * pts1).colwise().hnormalized(), aff * pts);
92  VERIFY_IS_APPROX((caff * pts1).colwise().hnormalized(), caff * pts);
93 
94  pts2 = pts1;
95  pts2.row(Size).setRandom();
96  VERIFY_IS_APPROX((aff * pts2).colwise().hnormalized(), aff * pts2.colwise().hnormalized());
97  VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized());
98  VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized());
99 
100  // Test combination of homogeneous
101 
102  VERIFY_IS_APPROX( (t2 * v0.homogeneous()).hnormalized(),
103  (t2.template topLeftCorner<Size,Size>() * v0 + t2.template topRightCorner<Size,1>())
104  / ((t2.template bottomLeftCorner<1,Size>()*v0).value() + t2(Size,Size)) );
105 
106  VERIFY_IS_APPROX( (t2 * pts.colwise().homogeneous()).colwise().hnormalized(),
107  (Matrix<Scalar, Size+1, Dynamic>(t2 * pts1).colwise().hnormalized()) );
108 
109  VERIFY_IS_APPROX( (t2 .lazyProduct( v0.homogeneous() )).hnormalized(), (t2 * v0.homogeneous()).hnormalized() );
110  VERIFY_IS_APPROX( (t2 .lazyProduct ( pts.colwise().homogeneous() )).colwise().hnormalized(), (t2 * pts1).colwise().hnormalized() );
111 
112  VERIFY_IS_APPROX( (v0.transpose().homogeneous() .lazyProduct( t2 )).hnormalized(), (v0.transpose().homogeneous()*t2).hnormalized() );
113  VERIFY_IS_APPROX( (pts.transpose().rowwise().homogeneous() .lazyProduct( t2 )).rowwise().hnormalized(), (pts1.transpose()*t2).rowwise().hnormalized() );
114 
115  VERIFY_IS_APPROX( (t2.template triangularView<Lower>() * v0.homogeneous()).eval(), (t2.template triangularView<Lower>()*hv0) );
116 }
117 
118 EIGEN_DECLARE_TEST(geo_homogeneous)
119 {
120  for(int i = 0; i < g_repeat; i++) {
121  CALL_SUBTEST_1(( homogeneous<float,1>() ));
122  CALL_SUBTEST_2(( homogeneous<double,3>() ));
123  CALL_SUBTEST_3(( homogeneous<double,8>() ));
124  }
125 }
Eigen::Transform::affine
EIGEN_DEVICE_FUNC ConstAffinePart affine() const
Definition: Transform.h:399
Eigen::PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::setRandom
Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom(Index size)
Definition: Random.h:151
Eigen::Transform
Represents an homogeneous transformation in a N dimensional space.
Definition: ForwardDeclarations.h:294
v0
static const double v0
Definition: testCal3DFisheye.cpp:31
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(geo_homogeneous)
Definition: geo_homogeneous.cpp:118
m0
static const DiscreteKey m0(M(0), 2)
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
homogeneous
void homogeneous(void)
Definition: geo_homogeneous.cpp:13
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
main.h
hv0
static const HybridValues hv0
Definition: testHybridGaussianConditional.cpp:46
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
VectorType
Definition: FFTW.cpp:65
triangularView< Lower >
A triangularView< Lower >().adjoint().solveInPlace(B)
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
ones
MatrixXcf ones
Definition: ComplexEigenSolver_eigenvalues.cpp:1


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:37