Reputation: 860
I'm trying to initialize a Eigen::Matrix3Xd with 3D values from a std::vector of an object that saves the x, y and z coordinates, from some code samples I do:
Eigen::Matrix3Xd matRef;
for (size_t i = 0; i < m_mapReference.size(); i++)
{
matRef << m_mapReference[i].x, m_mapReference[i].y, m_mapReference[i].z;
}
And I have an error in runtime: System.NullReferenceException: 'Object reference not set to an instance of an object.'
If I add the size in the constructor of the Matrix3Xd:
Eigen::Matrix3Xd matRef(10);
I have a compile error:
error C2338: YOU_TRIED_CALLING_A_VECTOR_METHOD_ON_A_MATRIX
What am I doing wrong?
Upvotes: 1
Views: 2167
Reputation: 860
I'm having a bad day, this one is easy:
Eigen::Matrix3Xd matRef(3, mapCountFound);
Matrix3Xd is a semi dynamic matrix, where rows=3 is implicit, but we still have to put it in the initialization.
To fill it up:
Eigen::Matrix3Xd matRef;
for (size_t i = 0; i < m_mapReference.size(); i++)
{
matRef.col(i) << m_mapReference[i].x, m_mapReference[i].y, m_mapReference[i].z;
}
Upvotes: 3