Search code examples
eigenceres-solver

How to get the row address of an Eigen::Matrix


I have an Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> intensityEigenMat;

I would like to pass it row by row to a ceres cost function, so I would like to access the reference to its individual rows.

I tried using:

intensityEigenMat.row(0)

&intensityEigenMat.row(0)

&intensityEigenMat.row(0).data()

But none of these worked. What is the right syntax please?


Solution

  • First you need to check the storage order option, which can be ColMajor or RowMajor. Default is ColMajor, so you need a complex way to read the matrix row by row (including a stride factor)

    If you are allowed to change the definition of your matrix to:

    Eigen::Matrix<double, Eigen::Dynamic, Eigen::dynamic, Eigen::RowMajor > intensityEigenMat;

    Then things will be easier, and you can use intensityEigenMat.row(i).data() or intensityEigenMat.data()+i*rowSize