2017-08-01 4 views
0

J'ai une matrice (x, y, z chaque colonne), et je veux seulement effectuer une transformation 2D sur les axes x et y, en ignorant z. Il semble qu'affine2d ne peut pas se multiplier avec un bloc, y a-t-il un autre moyen de le faire fonctionner?Comment appliquer la transformation affine2d sur un bloc de matrice 3d?

Eigen::matrix<double, 3, 4> x3d; 
x3d << 
    1, 2, 3, 4, 
    2, 3, 4, 5, 
    1, 1, 1, 1; 
auto x2d = x3d.topRows(2); 
Eigen::Affine2d T = Eigen::Translation2d(1, 2) * Eigen::Scaling(1., 2.); 
x2d = T*x2d; 

erreur de sortie:

> /home/lei/Work/SurfTomo/./include/Eigen/src/Geometry/Transform.h:1361:5: 
> error: static_assert failed "YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES" 
>  EIGEN_STATIC_ASSERT(OtherRows==Dim, YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES); 
> ^     ~~~~~~~~~~~~~~ /home/lei/Work/SurfTomo/./include/Eigen/src/Core/util/StaticAssert.h:32:40: 
> note: expanded from macro 'EIGEN_STATIC_ASSERT' 
>  #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG); 
>          ^   ~ /home/lei/Work/SurfTomo/./include/Eigen/src/Geometry/Transform.h:442:77: 
> note: in instantiation of member function 
>  'Eigen::internal::transform_right_product_impl<Eigen::Transform<double, 
> 2, 2, 0>, Eigen::Block<Eigen::Matrix<double, 3, 4, 0, 3, 4>, -1, 4, 
>  false>, 2, 4>::run' requested here { return internal::transform_right_product_impl<Transform, 
> OtherDerived>::run(*this,other.derived()); } 
>                   ^/home/lei/Work/SurfTomo/test/test_3dto2d.cc:27:10: note: in 
> instantiation of function template specialization 
> 'Eigen::Transform<double, 2, 2, 
>  0>::operator*<Eigen::Block<Eigen::Matrix<double, 3, 4, 0, 3, 4>, -1, 4, false> >' requested here x2d = T*x2d; 
>  ^1 error generated. 

Je trouve les codes ci-dessous peuvent résoudre ce problème, même si je ne comprends pas pourquoi cela fonctionne.

x2d = T * x2d.colwise().homogeneous(); 

Répondre

0

Lors de la multiplication avec Eigen::Affine2d, Eigen veut connaître le nombre de lignes de l'autre matrice au moment de la compilation (car en fonction de cela, différents chemins de code sont prises, et exécuter à temps les contrôles peuvent faire une surcharge importante ici).

il suffit de créer votre matrice x2d utilisant

auto x2d = x3d.topRows<2>(); 
+0

Merci. Excellent explique. – Aristotle0