我使用 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);
但没有任何改变。你能帮助我吗?
谢谢你。