Convert Eigen Matrix to C array

后端 未结 7 1926
深忆病人
深忆病人 2020-11-30 03:33

The Eigen library can map existing memory into Eigen matrices.

float array[3];
Map(array, 3).fill(10);
int data[4] = 1, 2, 3, 4;
Matrix2i mat         


        
相关标签:
7条回答
  • 2020-11-30 04:17

    I tried this : passing the address of the element at (0,0) and iterating forward.

    Eigen::Matrix<double, 3, 8> coordinates3d;
    coordinates3d <<    0.0,  0.0,  1.0,  1.0,  0.0,  0.0,  1.0,  1.0,
                        0.0,  1.0,  1.0,  0.0,  0.0,  1.0,  1.0,  0.0,
                        1.0,  1.0,  1.0,  1.0,  0.0,  0.0,  0.0,  0.0;
    double *p = &coordinates3d(0,0);
    std::vector<double> x2y2;
    x2y2.assign(p, p + coordinates3d.size());
    
    for(int i=0;i < coordinates3d.size(); i++) {
        std::cout <<x2y2[i];
    }
    

    This is the output : 001011111101000010110100 The data is stored row-major it seems

    0 讨论(0)
提交回复
热议问题