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);
但没有任何改变。
你能帮帮我吗?
谢谢。
查看使用块操作的文档。
有两个版本,语法如下:
块操作与
大小为 (p,q)
的块,从 (i,j)
开始
构建动态大小块表达式的版本
matrix.block(i,j,p,q);
版本构建
固定大小的块表达式
matrix.block<p,q>(i,j);
对于您的案例使用:
tempMatrix.block(0, 0, 2, 2)
我使用 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);
但没有任何改变。 你能帮帮我吗?
谢谢。
查看使用块操作的文档。
有两个版本,语法如下:
块操作与
大小为 (p,q)
的块,从 (i,j)
构建动态大小块表达式的版本
matrix.block(i,j,p,q);
版本构建 固定大小的块表达式
matrix.block<p,q>(i,j);
对于您的案例使用:
tempMatrix.block(0, 0, 2, 2)