vtk/python 元组和组件的 VTKFloatArray 设置器不通勤

vtk/python VTKFloatArray setters for tuple and component don't commute

问题

以下代码片段配置了一个 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 and 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.

如我所见,前者可以分配space,但后者必须在任何分配之前调用。所以,他们确实不通勤,你需要先调用后者,这应该是工作顺序(符合你的结果)。

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