diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-05-18 17:55:50 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-05-18 17:55:50 +0200 |
commit | e1867288672b7f8acff34fbdee59e7bb05ab9ead (patch) | |
tree | a484d649ed4188ed941ef22293ec9083ca939c83 | |
parent | e0832d5d9312d722f488704f1571b7b9780d463e (diff) |
fix #1 : need to nest by value the affine part in homogeneous product
-rw-r--r-- | Eigen/src/Geometry/Homogeneous.h | 4 | ||||
-rw-r--r-- | Eigen/src/Geometry/Transform.h | 4 | ||||
-rw-r--r-- | test/geo_homogeneous.cpp | 29 | ||||
-rw-r--r-- | test/sparse_solvers.cpp | 10 |
4 files changed, 31 insertions, 16 deletions
diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 0041ca51f..34d4d074b 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -102,11 +102,11 @@ template<typename MatrixType,int Direction> class Homogeneous template<typename Scalar, int Dim, int Mode> friend inline const ei_homogeneous_left_product_impl<Homogeneous, - typename Transform<Scalar,Dim,Mode>::AffinePart> + typename Transform<Scalar,Dim,Mode>::AffinePartNested> operator* (const Transform<Scalar,Dim,Mode>& tr, const Homogeneous& rhs) { ei_assert(Direction==Vertical); - return ei_homogeneous_left_product_impl<Homogeneous,typename Transform<Scalar,Dim,Mode>::AffinePart> + return ei_homogeneous_left_product_impl<Homogeneous,typename Transform<Scalar,Dim,Mode>::AffinePartNested > (tr.affine(),rhs.m_matrix); } diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index 186580ab4..77a06fe17 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -184,6 +184,10 @@ public: typedef typename ei_meta_if<int(Mode)==int(AffineCompact), MatrixType&, Block<MatrixType,Dim,HDim> >::ret AffinePart; + /** type of read/write reference to the affine part of the transformation */ + typedef typename ei_meta_if<int(Mode)==int(AffineCompact), + MatrixType&, + NestByValue<Block<MatrixType,Dim,HDim> > >::ret AffinePartNested; /** type of a vector */ typedef Matrix<Scalar,Dim,1> VectorType; /** type of a read/write reference to the translation part of the rotation */ diff --git a/test/geo_homogeneous.cpp b/test/geo_homogeneous.cpp index 5deb0d530..bf568bb03 100644 --- a/test/geo_homogeneous.cpp +++ b/test/geo_homogeneous.cpp @@ -33,10 +33,10 @@ template<typename Scalar,int Size> void homogeneous(void) typedef Matrix<Scalar,Size,Size> MatrixType; typedef Matrix<Scalar,Size,1> VectorType; - + typedef Matrix<Scalar,Size+1,Size> HMatrixType; typedef Matrix<Scalar,Size+1,1> HVectorType; - + typedef Matrix<Scalar,Size,Size+1> T1MatrixType; typedef Matrix<Scalar,Size+1,Size+1> T2MatrixType; typedef Matrix<Scalar,Size+1,Size> T3MatrixType; @@ -51,17 +51,17 @@ template<typename Scalar,int Size> void homogeneous(void) HVectorType hv0 = HVectorType::Random(), hv1 = HVectorType::Random(); - + MatrixType m0 = MatrixType::Random(), m1 = MatrixType::Random(); - + HMatrixType hm0 = HMatrixType::Random(), hm1 = HMatrixType::Random(); hv0 << v0, 1; VERIFY_IS_APPROX(v0.homogeneous(), hv0); VERIFY_IS_APPROX(v0, hv0.hnormalized()); - + hm0 << m0, ones.transpose(); VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0); VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized()); @@ -69,16 +69,16 @@ template<typename Scalar,int Size> void homogeneous(void) for(int j=0; j<Size; ++j) m0.col(j) = hm0.col(j).start(Size) / hm0(Size,j); VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized()); - + 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()); - + 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()); - - VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2, + + VERIFY_IS_APPROX((v0.transpose().rowwise().homogeneous().eval()) * t2, v0.transpose().rowwise().homogeneous() * t2); VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t2, m0.transpose().rowwise().homogeneous() * t2); @@ -88,6 +88,17 @@ template<typename Scalar,int Size> void homogeneous(void) v0.transpose().rowwise().homogeneous() * t3); VERIFY_IS_APPROX((m0.transpose().rowwise().homogeneous().eval()) * t3, m0.transpose().rowwise().homogeneous() * t3); + + // test product with a Transform object + Transform<Scalar, Size, Affine> Rt; + Matrix<Scalar, Size, Dynamic> pts, Rt_pts1; + + Rt.setIdentity(); + pts.setRandom(Size,5); + + Rt_pts1 = Rt * pts.colwise().homogeneous(); + std::cerr << (Rt_pts1 - pts).sum() << "\n"; + VERIFY_IS_MUCH_SMALLER_THAN( (Rt_pts1 - pts).sum(), Scalar(1)); } void test_geo_homogeneous() diff --git a/test/sparse_solvers.cpp b/test/sparse_solvers.cpp index 1f159801b..de308e018 100644 --- a/test/sparse_solvers.cpp +++ b/test/sparse_solvers.cpp @@ -72,12 +72,12 @@ template<typename Scalar> void sparse_solvers(int rows, int cols) initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, &zeroCoords, &nonzeroCoords); VERIFY_IS_APPROX(refMat2.template marked<UpperTriangular>().solveTriangular(vec2), m2.template triangular<UpperTriangular>().solve(vec3)); - + // TODO test row major - + SparseMatrix<Scalar> matB(rows, rows); DenseMatrix refMatB = DenseMatrix::Zero(rows, rows); - + // lower - sparse initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular); initSparse<Scalar>(density, refMatB, matB); @@ -91,7 +91,7 @@ template<typename Scalar> void sparse_solvers(int rows, int cols) refMat2.template marked<UpperTriangular>().solveTriangularInPlace(refMatB); m2.template triangular<UpperTriangular>().solveInPlace(matB); VERIFY_IS_APPROX(matB, refMatB); - + // test deprecated API initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); VERIFY_IS_APPROX(refMat2.template marked<LowerTriangular>().solveTriangular(vec2), @@ -122,7 +122,7 @@ template<typename Scalar> void sparse_solvers(int rows, int cols) SparseLLT<SparseSelfAdjointMatrix,Cholmod>(m2).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision<Scalar>()) && "LLT: cholmod"); #endif - + #ifdef EIGEN_TAUCS_SUPPORT x = b; SparseLLT<SparseSelfAdjointMatrix,Taucs>(m2,IncompleteFactorization).solveInPlace(x); |