gpt4 book ai didi

python - vtk/python VTKFloatArray 元组和组件的 setter 不交换

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:41 25 4
gpt4 key购买 nike

问题

以下代码片段配置了一个 python/VTKFloatArray,以便将来填充单位立方体的顶点坐标。设置 3 个分量 (x,y,z) 的 8 个元组。看来二传手不通勤。这是预期的行为吗?似乎必须首先设置组件的数量。有人能重现这个吗?谢谢您的回答

import vtk
import numpy as np
from itertools import product as itprod

vertices = np.array(list(itprod([0, 1], repeat=3)))

print vertices.shape[0] //8 vertices
print vertices.shape[1] //3 coordinates x-y-z

array = vtk.vtkFloatArray()
array.SetNumberOfComponents(vertices.shape[1])
array.SetNumberOfTuples(vertices.shape[0])
print array // number of tuples is 8, number of components is 3 OK

array = vtk.vtkFloatArray()
array.SetNumberOfTuples(vertices.shape[0])
array.SetNumberOfComponents(vertices.shape[1])
print array // number of tuples is 2 number of components is 3 WRONG

最佳答案

VTK 总是善变的,尤其是在文档方面。我在SetNumberOfTuples上找到了一些信息和SetNumberOfComponents在相应的链接。

前者(SetNumberOfTuples):

Set the number of tuples (a component group) in the array.

Note that this may allocate space depending on the number of components. [...]

后者(SetNumberOfComponents):

Set/Get the dimension (n) of the components.

Must be >= 1. Make sure that this is set before allocation.

据我所知,前者可以分配空间,但后者必须在任何分配之前调用。所以,他们确实不通勤,你需要先调用后者,这应该是工作顺序(这与你的结果一致)。

这些链接显然与 python 实现不对应,但事实上 C++ 版本不应该交换,因此您也不应该期望 python 中的交换性。

关于python - vtk/python VTKFloatArray 元组和组件的 setter 不交换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40824954/

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