2009-03-05 18:25:22 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-23 02:25:33 +08:00
|
|
|
// for linear algebra.
|
2009-03-05 18:25:22 +08:00
|
|
|
//
|
2010-06-25 05:21:58 +08:00
|
|
|
// Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-03-05 18:25:22 +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/.
|
2009-03-05 18:25:22 +08:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include <Eigen/Geometry>
|
|
|
|
|
|
|
|
template<typename Scalar,int Size> void homogeneous(void)
|
|
|
|
{
|
|
|
|
/* this test covers the following files:
|
|
|
|
Homogeneous.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef Matrix<Scalar,Size,Size> MatrixType;
|
2010-06-24 21:13:41 +08:00
|
|
|
typedef Matrix<Scalar,Size,1, ColMajor> VectorType;
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2009-03-05 18:25:22 +08:00
|
|
|
typedef Matrix<Scalar,Size+1,Size> HMatrixType;
|
|
|
|
typedef Matrix<Scalar,Size+1,1> HVectorType;
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2009-03-06 00:40:56 +08:00
|
|
|
typedef Matrix<Scalar,Size,Size+1> T1MatrixType;
|
|
|
|
typedef Matrix<Scalar,Size+1,Size+1> T2MatrixType;
|
|
|
|
typedef Matrix<Scalar,Size+1,Size> T3MatrixType;
|
2009-03-05 18:25:22 +08:00
|
|
|
|
|
|
|
VectorType v0 = VectorType::Random(),
|
|
|
|
ones = VectorType::Ones();
|
|
|
|
|
2011-11-06 06:30:49 +08:00
|
|
|
HVectorType hv0 = HVectorType::Random();
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2011-11-06 06:30:49 +08:00
|
|
|
MatrixType m0 = MatrixType::Random();
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2011-11-06 06:30:49 +08:00
|
|
|
HMatrixType hm0 = HMatrixType::Random();
|
2009-03-05 18:25:22 +08:00
|
|
|
|
|
|
|
hv0 << v0, 1;
|
|
|
|
VERIFY_IS_APPROX(v0.homogeneous(), hv0);
|
|
|
|
VERIFY_IS_APPROX(v0, hv0.hnormalized());
|
2014-08-01 23:00:20 +08:00
|
|
|
|
|
|
|
VERIFY_IS_APPROX(v0.homogeneous().sum(), hv0.sum());
|
|
|
|
VERIFY_IS_APPROX(v0.homogeneous().minCoeff(), hv0.minCoeff());
|
|
|
|
VERIFY_IS_APPROX(v0.homogeneous().maxCoeff(), hv0.maxCoeff());
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2009-03-05 18:25:22 +08:00
|
|
|
hm0 << m0, ones.transpose();
|
|
|
|
VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
|
|
|
|
VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
|
|
|
|
hm0.row(Size-1).setRandom();
|
|
|
|
for(int j=0; j<Size; ++j)
|
2010-01-05 10:24:43 +08:00
|
|
|
m0.col(j) = hm0.col(j).head(Size) / hm0(Size,j);
|
2009-03-05 18:25:22 +08:00
|
|
|
VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2009-03-06 00:40:56 +08:00
|
|
|
T1MatrixType t1 = T1MatrixType::Random();
|
|
|
|
VERIFY_IS_APPROX(t1 * (v0.homogeneous().eval()), t1 * v0.homogeneous());
|
|
|
|
VERIFY_IS_APPROX(t1 * (m0.colwise().homogeneous().eval()), t1 * m0.colwise().homogeneous());
|
2009-05-18 23:55:50 +08:00
|
|
|
|
2009-03-06 00:40:56 +08:00
|
|
|
T2MatrixType t2 = T2MatrixType::Random();
|
|
|
|
VERIFY_IS_APPROX(t2 * (v0.homogeneous().eval()), t2 * v0.homogeneous());
|
|
|
|
VERIFY_IS_APPROX(t2 * (m0.colwise().homogeneous().eval()), t2 * m0.colwise().homogeneous());
|
2009-05-18 23:55:50 +08:00
|
|
|
|
|
|
|
VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2,
|
2009-03-06 00:40:56 +08:00
|
|
|
v0.transpose().rowwise().homogeneous() * t2);
|
|
|
|
VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2,
|
|
|
|
m0.transpose().rowwise().homogeneous() * t2);
|
|
|
|
|
|
|
|
T3MatrixType t3 = T3MatrixType::Random();
|
|
|
|
VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t3,
|
|
|
|
v0.transpose().rowwise().homogeneous() * t3);
|
|
|
|
VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3,
|
|
|
|
m0.transpose().rowwise().homogeneous() * t3);
|
2009-05-18 23:55:50 +08:00
|
|
|
|
|
|
|
// test product with a Transform object
|
2011-03-03 02:34:39 +08:00
|
|
|
Transform<Scalar, Size, Affine> aff;
|
|
|
|
Transform<Scalar, Size, AffineCompact> caff;
|
|
|
|
Transform<Scalar, Size, Projective> proj;
|
|
|
|
Matrix<Scalar, Size, Dynamic> pts;
|
|
|
|
Matrix<Scalar, Size+1, Dynamic> pts1, pts2;
|
|
|
|
|
|
|
|
aff.affine().setRandom();
|
|
|
|
proj = caff = aff;
|
|
|
|
pts.setRandom(Size,internal::random<int>(1,20));
|
|
|
|
|
|
|
|
pts1 = pts.colwise().homogeneous();
|
|
|
|
VERIFY_IS_APPROX(aff * pts.colwise().homogeneous(), (aff * pts1).colwise().hnormalized());
|
|
|
|
VERIFY_IS_APPROX(caff * pts.colwise().homogeneous(), (caff * pts1).colwise().hnormalized());
|
|
|
|
VERIFY_IS_APPROX(proj * pts.colwise().homogeneous(), (proj * pts1));
|
2014-07-31 20:54:54 +08:00
|
|
|
|
2011-03-03 02:34:39 +08:00
|
|
|
VERIFY_IS_APPROX((aff * pts1).colwise().hnormalized(), aff * pts);
|
|
|
|
VERIFY_IS_APPROX((caff * pts1).colwise().hnormalized(), caff * pts);
|
|
|
|
|
|
|
|
pts2 = pts1;
|
|
|
|
pts2.row(Size).setRandom();
|
|
|
|
VERIFY_IS_APPROX((aff * pts2).colwise().hnormalized(), aff * pts2.colwise().hnormalized());
|
|
|
|
VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized());
|
|
|
|
VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized());
|
2015-06-08 21:43:41 +08:00
|
|
|
|
|
|
|
// Test combination of homogeneous
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (t2 * v0.homogeneous()).hnormalized(),
|
|
|
|
(t2.template topLeftCorner<Size,Size>() * v0 + t2.template topRightCorner<Size,1>())
|
|
|
|
/ ((t2.template bottomLeftCorner<1,Size>()*v0).value() + t2(Size,Size)) );
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (t2 * pts.colwise().homogeneous()).colwise().hnormalized(),
|
|
|
|
(Matrix<Scalar, Size+1, Dynamic>(t2 * pts1).colwise().hnormalized()) );
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (t2 .lazyProduct( v0.homogeneous() )).hnormalized(), (t2 * v0.homogeneous()).hnormalized() );
|
|
|
|
VERIFY_IS_APPROX( (t2 .lazyProduct ( pts.colwise().homogeneous() )).colwise().hnormalized(), (t2 * pts1).colwise().hnormalized() );
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( (v0.transpose().homogeneous() .lazyProduct( t2 )).hnormalized(), (v0.transpose().homogeneous()*t2).hnormalized() );
|
|
|
|
VERIFY_IS_APPROX( (pts.transpose().rowwise().homogeneous() .lazyProduct( t2 )).rowwise().hnormalized(), (pts1.transpose()*t2).rowwise().hnormalized() );
|
2009-03-05 18:25:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_geo_homogeneous()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < g_repeat; i++) {
|
2009-10-29 06:19:29 +08:00
|
|
|
CALL_SUBTEST_1(( homogeneous<float,1>() ));
|
|
|
|
CALL_SUBTEST_2(( homogeneous<double,3>() ));
|
|
|
|
CALL_SUBTEST_3(( homogeneous<double,8>() ));
|
2009-03-05 18:25:22 +08:00
|
|
|
}
|
|
|
|
}
|