我有一个矩阵(每列x,y,z),只想在x和y轴上执行2D变换,忽略z。似乎affine2d不能与块相乘,还有其他方法可以使它工作吗?
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;
输出错误:
> /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.
我发现下面的代码可以解决这个问题,但我不明白它为什么会起作用。
x2d = T * x2d.colwise().homogeneous();
答案 0 :(得分:0)
当与Eigen::Affine2d
相乘时,Eigen想要在编译时知道另一个矩阵的行数(因为取决于它,会采用不同的代码路径,并且运行时检查会在这里产生很大的开销)。
只需使用
创建x2d
矩阵即可
auto x2d = x3d.topRows<2>();