如何将vtkDoubleArray转换为Eigen :: matrix [英] How to convert a vtkDoubleArray to an Eigen::matrix
问题描述
我找到了Eigen :: Map类,用于将原始数组转换为Eigen类(以及一些有用的摘要,请参见 https: //stackoverflow.com/a/12007784/1136458 )
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 )
是否有任何本征或vtk类将vtk数组转换为本征类(并返回)?
我现在正在尝试的是:
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:
- 将vtkDoubleArray转换为std :: vector的std :: vector(如< a href = https://stackoverflow.com/questions/24650468/how-to-get-the-the-values-of-a-vtkdoublearray-in-a-stdvector>如何获取vtkDoubleArray的值在std :: vector 中)
-
使用地图具有矩阵xd
- 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)
但是我收到以下错误:
错误C2665:'Eigen :: Map :: Map':4个重载都不能转换所有参数类型
error C2665: 'Eigen::Map::Map' : none of the 4 overloads could convert all the argument types
如果有直接方法也可以的话,我不一定需要中间cpp_matrix
I don't necessarily need the intermediate cpp_matrix, if there is a direct method that would be fine as well
推荐答案
std :: vector< std :: vector< double>的内存布局。 >
与 Eigen :: Map
所期望的不兼容。所有条目必须顺序存储在内存中,每列之间有一个可选的恒定空间。因此,如果 vtkDoubleArray
的内存布局不兼容,那么您别无选择,只能使用手动for循环复制值。
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.
这篇关于如何将vtkDoubleArray转换为Eigen :: matrix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!