geo_homogeneous.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 #include <Eigen/Geometry>
00027 
00028 template<typename Scalar,int Size> void homogeneous(void)
00029 {
00030   /* this test covers the following files:
00031      Homogeneous.h
00032   */
00033 
00034   typedef Matrix<Scalar,Size,Size> MatrixType;
00035   typedef Matrix<Scalar,Size,1, ColMajor> VectorType;
00036 
00037   typedef Matrix<Scalar,Size+1,Size> HMatrixType;
00038   typedef Matrix<Scalar,Size+1,1> HVectorType;
00039 
00040   typedef Matrix<Scalar,Size,Size+1>   T1MatrixType;
00041   typedef Matrix<Scalar,Size+1,Size+1> T2MatrixType;
00042   typedef Matrix<Scalar,Size+1,Size> T3MatrixType;
00043 
00044   VectorType v0 = VectorType::Random(),
00045              v1 = VectorType::Random(),
00046              ones = VectorType::Ones();
00047 
00048   HVectorType hv0 = HVectorType::Random(),
00049               hv1 = HVectorType::Random();
00050 
00051   MatrixType m0 = MatrixType::Random(),
00052              m1 = MatrixType::Random();
00053 
00054   HMatrixType hm0 = HMatrixType::Random(),
00055               hm1 = HMatrixType::Random();
00056 
00057   hv0 << v0, 1;
00058   VERIFY_IS_APPROX(v0.homogeneous(), hv0);
00059   VERIFY_IS_APPROX(v0, hv0.hnormalized());
00060 
00061   hm0 << m0, ones.transpose();
00062   VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
00063   VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
00064   hm0.row(Size-1).setRandom();
00065   for(int j=0; j<Size; ++j)
00066     m0.col(j) = hm0.col(j).head(Size) / hm0(Size,j);
00067   VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
00068 
00069   T1MatrixType t1 = T1MatrixType::Random();
00070   VERIFY_IS_APPROX(t1 * (v0.homogeneous().eval()), t1 * v0.homogeneous());
00071   VERIFY_IS_APPROX(t1 * (m0.colwise().homogeneous().eval()), t1 * m0.colwise().homogeneous());
00072 
00073   T2MatrixType t2 = T2MatrixType::Random();
00074   VERIFY_IS_APPROX(t2 * (v0.homogeneous().eval()), t2 * v0.homogeneous());
00075   VERIFY_IS_APPROX(t2 * (m0.colwise().homogeneous().eval()), t2 * m0.colwise().homogeneous());
00076 
00077   VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2,
00078                     v0.transpose().rowwise().homogeneous() * t2);
00079                     m0.transpose().rowwise().homogeneous().eval();
00080   VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2,
00081                     m0.transpose().rowwise().homogeneous() * t2);
00082 
00083   T3MatrixType t3 = T3MatrixType::Random();
00084   VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t3,
00085                     v0.transpose().rowwise().homogeneous() * t3);
00086   VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3,
00087                     m0.transpose().rowwise().homogeneous() * t3);
00088 
00089   // test product with a Transform object
00090   Transform<Scalar, Size, Affine> aff;
00091   Transform<Scalar, Size, AffineCompact> caff;
00092   Transform<Scalar, Size, Projective> proj;
00093   Matrix<Scalar, Size, Dynamic>   pts;
00094   Matrix<Scalar, Size+1, Dynamic> pts1, pts2;
00095 
00096   aff.affine().setRandom();
00097   proj = caff = aff;
00098   pts.setRandom(Size,internal::random<int>(1,20));
00099   
00100   pts1 = pts.colwise().homogeneous();
00101   VERIFY_IS_APPROX(aff  * pts.colwise().homogeneous(), (aff  * pts1).colwise().hnormalized());
00102   VERIFY_IS_APPROX(caff * pts.colwise().homogeneous(), (caff * pts1).colwise().hnormalized());
00103   VERIFY_IS_APPROX(proj * pts.colwise().homogeneous(), (proj * pts1));
00104   
00105   VERIFY_IS_APPROX((aff  * pts1).colwise().hnormalized(),  aff  * pts);
00106   VERIFY_IS_APPROX((caff * pts1).colwise().hnormalized(), caff * pts);
00107   
00108   pts2 = pts1;
00109   pts2.row(Size).setRandom();
00110   VERIFY_IS_APPROX((aff  * pts2).colwise().hnormalized(), aff  * pts2.colwise().hnormalized());
00111   VERIFY_IS_APPROX((caff * pts2).colwise().hnormalized(), caff * pts2.colwise().hnormalized());
00112   VERIFY_IS_APPROX((proj * pts2).colwise().hnormalized(), (proj * pts2.colwise().hnormalized().colwise().homogeneous()).colwise().hnormalized());
00113 }
00114 
00115 void test_geo_homogeneous()
00116 {
00117   for(int i = 0; i < g_repeat; i++) {
00118     CALL_SUBTEST_1(( homogeneous<float,1>() ));
00119     CALL_SUBTEST_2(( homogeneous<double,3>() ));
00120     CALL_SUBTEST_3(( homogeneous<double,8>() ));
00121   }
00122 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:44