00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026 #include <Eigen/Geometry>
00027
00028 template<typename Scalar,int Size> void homogeneous(void)
00029 {
00030
00031
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
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 }