gpt4 book ai didi

c++ - 遍历 vtkFloatArray

转载 作者:行者123 更新时间:2023-11-30 05:40:26 25 4
gpt4 key购买 nike

我注意到我正在调用的函数的返回类型是 vtkFloatArray。我想检查此数组的组件,但不确定如何遍历其组件。

因为当我尝试遍历元素时,出现了以下错误:

TypeError: 'vtkobject' object is not iterable

为什么会出现这样的错误?

谢谢。

最佳答案

如果您的数组不是元组:

float value;
for(int i = 0; i < array->GetNumberOfTuples(); i++)
{
value = array->GetValue(i);
std::cout << value << std::endl;
}

如果你的数组是一个大小为 3 的元组:

double * values;
for(int i = 0; i < array->GetNumberOfTuples(); i++)
{
values = array->GetTuple3(i);
std::cout << values[0] << " " << values[1] << " " << values[2] << std::endl;
}

关于c++ - 遍历 vtkFloatArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31638648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com