How to get the the values of a vtkDoubleArray in a std::vector

眉间皱痕 提交于 2019-12-11 01:29:34

问题


I want to copy the elements of a vtkDoubleArray into a C++ std::vector (as in How to convert a vtkDoubleArray to an Eigen::matrix)

I am trying to get this to work:

typedef std::vector<double> row_type;
typedef std::vector<row_type> matrix_type;

int n_components = vtk_arr->GetNumberOfComponents();
int n_rows = vtk_arr->GetNumberOfTuples();

row_type curTuple(n_components);
matrix_type cpp_matrix(n_rows, row_type(n_components));
for (int i=0; i<n_rows; i++) {
    vtk_arr->GetTuple(i, curTuple);
    cpp_matrix[i] = curTuple;
}

At the moment I have this error:

error C2664: 'void vtkDataArrayTemplate<T>::GetTuple(vtkIdType,double
*)' : cannot convert parameter 2 from 'row_type' to 'double *'

Is there some vtk method (hopefully, more robust and efficient) which already achieves this?


回答1:


As the errors says, you are passing a row_type (std::vector<double>) where it expects a double*. Perhaps you want to pass a pointer to the underlying data:

vtk_arr->GetTuple(i, curTuple.data());

See std::vector::data for more info.



来源:https://stackoverflow.com/questions/24650468/how-to-get-the-the-values-of-a-vtkdoublearray-in-a-stdvector

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