blob: 9aebe6226ff23907cb202c590cdc2b247ac09506 [file] [log] [blame]
 // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2009 Gael Guennebaud // // 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/. #include "main.h" #include template void homogeneous(void) { /* this test covers the following files: Homogeneous.h */ typedef Matrix MatrixType; typedef Matrix VectorType; typedef Matrix HMatrixType; typedef Matrix HVectorType; typedef Matrix T1MatrixType; typedef Matrix T2MatrixType; typedef Matrix T3MatrixType; VectorType v0 = VectorType::Random(), ones = VectorType::Ones(); HVectorType hv0 = HVectorType::Random(); MatrixType m0 = MatrixType::Random(); HMatrixType hm0 = HMatrixType::Random(); hv0 << v0, 1; VERIFY_IS_APPROX(v0.homogeneous(), hv0); VERIFY_IS_APPROX(v0, hv0.hnormalized()); VERIFY_IS_APPROX(v0.homogeneous().sum(), hv0.sum()); VERIFY_IS_APPROX(v0.homogeneous().minCoeff(), hv0.minCoeff()); VERIFY_IS_APPROX(v0.homogeneous().maxCoeff(), hv0.maxCoeff()); 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 aff; Transform caff; Transform proj; Matrix pts; Matrix pts1, pts2; aff.affine().setRandom(); proj = caff = aff; pts.setRandom(Size,internal::random(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)); 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()); // Test combination of homogeneous VERIFY_IS_APPROX( (t2 * v0.homogeneous()).hnormalized(), (t2.template topLeftCorner() * v0 + t2.template topRightCorner()) / ((t2.template bottomLeftCorner<1,Size>()*v0).value() + t2(Size,Size)) ); VERIFY_IS_APPROX( (t2 * pts.colwise().homogeneous()).colwise().hnormalized(), (Matrix(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() ); VERIFY_IS_APPROX( (t2.template triangularView() * v0.homogeneous()).eval(), (t2.template triangularView()*hv0) ); } EIGEN_DECLARE_TEST(geo_homogeneous) { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1(( homogeneous() )); CALL_SUBTEST_2(( homogeneous() )); CALL_SUBTEST_3(( homogeneous() )); } }