[英]How to fix 'non-type template argument is not a constant expression' in eigen3?
[英]Eigen3: extract a submatrix with a non constant number of columns
我使用Eigen3在C ++中编写了以下函数:
MatrixXf transformPoints(MatrixXf X, MatrixXf P)
{
// create a new matrix to host points
MatrixXf tempMatrix = MatrixXf::Zero(4, P.cols());
// extract rotational and traslational parts from X
MatrixXf rotmat = tempMatrix.block<2,2>(0,0);
Vector2f traMat = tempMatrix.block<2,1>(0,2);
// separate points from normals
// int cols_of_P = P.cols();
MatrixXf points = tempMatrix.block<2,P.cols()>(0,0);
MatrixXf normals = tempMatrix.block<2,P.cols()>(2,0);
}
以我的想法,在最后两行中,我应该能够从p提取一个子矩阵,该子矩阵的列数不是先验的,但取决于P的大小。 我收到以下错误:
home/ubisum/fuerte_workspace/thesis_pack/src/least_squares_utilities.h: In function ‘Eigen::MatrixXf least_squares::transformPoints(Eigen::MatrixXf, Eigen::MatrixXf)’:
/home/ubisum/fuerte_workspace/thesis_pack/src/least_squares_utilities.h:18:47: error: ‘P’ cannot appear in a constant-expression
/home/ubisum/fuerte_workspace/thesis_pack/src/least_squares_utilities.h:18:49: error: ‘.’ cannot appear in a constant-expression
/home/ubisum/fuerte_workspace/thesis_pack/src/least_squares_utilities.h:18:54: error: a function call cannot appear in a constant-expression
/home/ubisum/fuerte_workspace/thesis_pack/src/least_squares_utilities.h:18:60: error: no matching function for call to ‘Eigen::Matrix<float, -0x00000000000000001, -0x00000000000000001>::block(int, int)’
我什至尝试了以下修改:
int cols_of_P = P.cols();
MatrixXf points = tempMatrix.block<2,cols_of_P>(0,0);
MatrixXf normals = tempMatrix.block<2,cols_of_P>(2,0);
但什么都没有改变。 你能帮助我吗?
谢谢。
查看有关使用块操作的文档。
有两个版本,其语法如下:
从(i,j)
开始的块大小为(p,q)
块操作
版本构造一个动态大小的块表达式
matrix.block(i,j,p,q);
版本构造一个固定大小的块表达式
matrix.block<p,q>(i,j);
供您使用:
tempMatrix.block(0, 0, 2, 2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.