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

标签 python vtk

问题

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

相关文章:

python - 读取多个 hdf5 文件并将它们附加到新字典

python - PyQt4 QTableWidget - 过滤和修改 mySQL 数据库中的数据

python - VTK 检查多数据点对象的交集

python - 如何使用 while 循环从列表中的每个整数中减去最小的数字?

python - sqlalchemy 中缺少 zxJDBC 连接器(使用 DB2)

python - MongoDB 使用 $push 更新匹配条件的数组元素

c++ - 如何围绕特定点旋转 vtk 场景?

java - 配置 CMake C++/Java 项目以与 Eclipse 配合使用

c++ - 使用 CMake-GUI 3.2.2 安装 VTK 6.2.0 和 Qt 5.4

c++ - 使用自己的继承类初始化 vtkSmartPointer