如何获取std::vector中vtkDoubleArray的值

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

本文关键字:vector vtkDoubleArray 的值 std 何获取 获取      更新时间:2023-10-16

我想将vtkDoubleArray的元素复制到C++std::vector中(如如何将vtkDoubleArray转换为Eigen::matrix(

我正在努力让它发挥作用:

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;
}

目前我有这个错误:

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

是否有某种vtk方法(希望更稳健、更高效(已经实现了这一点?

正如错误所说,您正在传递一个row_type(std::vector<double>(,它需要double*。也许您想传递一个指向底层数据的指针:

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

请参阅std::vector::data了解更多信息。