source: pacpussensors/trunk/Vislab/lib3dv/eigen/test/geo_homogeneous.cpp@ 138

Last change on this file since 138 was 136, checked in by ldecherf, 8 years ago

Doc

File size: 4.1 KB
Line 
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
13template<typename Scalar,int Size> void homogeneous(void)
14{
15 /* this test covers the following files:
16 Homogeneous.h
17 */
18
19 typedef Matrix<Scalar,Size,Size> MatrixType;
20 typedef Matrix<Scalar,Size,1, ColMajor> VectorType;
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 hm0 << m0, ones.transpose();
43 VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
44 VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
45 hm0.row(Size-1).setRandom();
46 for(int j=0; j<Size; ++j)
47 m0.col(j) = hm0.col(j).head(Size) / hm0(Size,j);
48 VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
49
50 T1MatrixType t1 = T1MatrixType::Random();
51 VERIFY_IS_APPROX(t1 * (v0.homogeneous().eval()), t1 * v0.homogeneous());
52 VERIFY_IS_APPROX(t1 * (m0.colwise().homogeneous().eval()), t1 * m0.colwise().homogeneous());
53
54 T2MatrixType t2 = T2MatrixType::Random();
55 VERIFY_IS_APPROX(t2 * (v0.homogeneous().eval()), t2 * v0.homogeneous());
56 VERIFY_IS_APPROX(t2 * (m0.colwise().homogeneous().eval()), t2 * m0.colwise().homogeneous());
57 VERIFY_IS_APPROX(t2 * (v0.homogeneous().asDiagonal()), t2 * hv0.asDiagonal());
58 VERIFY_IS_APPROX((v0.homogeneous().asDiagonal()) * t2, hv0.asDiagonal() * t2);
59
60 VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2,
61 v0.transpose().rowwise().homogeneous() * t2);
62 m0.transpose().rowwise().homogeneous().eval();
63 VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2,
64 m0.transpose().rowwise().homogeneous() * t2);
65
66 T3MatrixType t3 = T3MatrixType::Random();
67 VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t3,
68 v0.transpose().rowwise().homogeneous() * t3);
69 VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3,
70 m0.transpose().rowwise().homogeneous() * t3);
71
72 // test product with a Transform object
73 Transform<Scalar, Size, Affine> aff;
74 Transform<Scalar, Size, AffineCompact> caff;
75 Transform<Scalar, Size, Projective> proj;
76 Matrix<Scalar, Size, Dynamic> pts;
77 Matrix<Scalar, Size+1, Dynamic> pts1, pts2;
78
79 aff.affine().setRandom();
80 proj = caff = aff;
81 pts.setRandom(Size,internal::random<int>(1,20));
82
83 pts1 = pts.colwise().homogeneous();
84 VERIFY_IS_APPROX(aff * pts.colwise().homogeneous(), (aff * pts1).colwise().hnormalized());
85 VERIFY_IS_APPROX(caff * pts.colwise().homogeneous(), (caff * pts1).colwise().hnormalized());
86 VERIFY_IS_APPROX(proj * pts.colwise().homogeneous(), (proj * pts1));
87
88 VERIFY_IS_APPROX((aff * pts1).colwise().hnormalized(), aff * pts);
89 VERIFY_IS_APPROX((caff * pts1).colwise().hnormalized(), caff * pts);
90
91 pts2 = pts1;
92 pts2.row(Size).setRandom();
93 VERIFY_IS_APPROX((aff * pts2).colwise().hnormalized(), aff * pts2.colwise().hnormalized());
94 VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized());
95 VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized());
96}
97
98void test_geo_homogeneous()
99{
100 for(int i = 0; i < g_repeat; i++) {
101 CALL_SUBTEST_1(( homogeneous<float,1>() ));
102 CALL_SUBTEST_2(( homogeneous<double,3>() ));
103 CALL_SUBTEST_3(( homogeneous<double,8>() ));
104 }
105}
Note: See TracBrowser for help on using the repository browser.