Reputation: 2956
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?
Upvotes: 2
Views: 1850
Reputation: 110698
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.
Upvotes: 1