如何在 std::vector 中获取 vtkDoubleArray 的值 [英] How to get the the values of a vtkDoubleArray in a std::vector

查看:27
本文介绍了如何在 std::vector 中获取 vtkDoubleArray 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

目前我有这个错误:

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

是否有一些 vtk 方法(希望更健壮和高效)已经实现了这一点?

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

推荐答案

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

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());

参见std::vector::data 了解更多信息.

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

这篇关于如何在 std::vector 中获取 vtkDoubleArray 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆