How to convert a vtkDoubleArray to an Eigen::matrix

ぐ巨炮叔叔 提交于 2019-12-25 02:32:13

问题


I've found the Eigen::Map class for converting a raw array to an Eigen class (and some useful snippets here https://stackoverflow.com/a/12007784/1136458 )

Is there any Eigen or vtk class to convert a vtk array to an Eigen class (and back)? What I am trying right now is:

  • convert vtkDoubleArray to std::vector of std::vector (as in How to get the the values of a vtkDoubleArray in a std::vector )
  • using map to have a matrixxd

    Eigen::MatrixXd eig_arr; 
    eig_arr = Eigen::Map<Eigen::MatrixXd> (cpp_matrix.data(), n_rows, n_components)
    

But I get the following error:

error C2665: 'Eigen::Map::Map' : none of the 4 overloads could convert all the argument types

I don't necessarily need the intermediate cpp_matrix, if there is a direct method that would be fine as well


回答1:


The memory layout of a std::vector<std::vector<double> > is not compatible with what Eigen::Map is expecting. All entries must be sequentially stored in memory with an optional constant space between each column. So if the memory layout of vtkDoubleArray is not comptable, then you have no other choice but copy the values using a manual for loop.




回答2:


What about converting vtkMappedDataArray to Eigen::matrix?

I stumpled upon "vtkMappedDataArray" and this discussion about "InSituDataStructures" for VTK. Unfortunatly I don't know any details but maybe it helps. Please let us know.



来源:https://stackoverflow.com/questions/24651271/how-to-convert-a-vtkdoublearray-to-an-eigenmatrix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!