[英]python vtk tube filter returns empty array
I am trying to use the vtkTubeFilter object to get a tube around a line of points.我正在尝试使用 vtkTubeFilter 对象围绕点线获取管。 As I have my own specialized rendering code, I want to get the vertices directly, not just the filter object.由于我有自己的专用渲染代码,我想直接获取顶点,而不仅仅是过滤器对象。 I am trying the following to convert between numpy
arrays and the VTK data structures我正在尝试使用以下方法在numpy
数组和 VTK 数据结构之间进行转换
field = vtk.vtkFieldData()
field.AddArray(vtk_numpy_support.numpy_to_vtk(center_line))
but in the end it seems like the code just returns an empty array.但最后似乎代码只是返回一个空数组。
Do I have to execute the filter somehow?我必须以某种方式执行过滤器吗? Or maybe the method of putting the points into the data structure is wrong?或者也许把点放入数据结构的方法是错误的? I have not done anything with VTK before, so I am not very familiar with the filter pipeline structure yet.我之前没有对VTK做过任何事情,所以我对过滤器管道结构还不是很熟悉。 Any pointers into the right direction would be greatly appreciated!任何指向正确方向的指针将不胜感激!
Below the full code to reproduce the issue:下面是重现问题的完整代码:
import numpy as np
import vtk
from vtk.util import numpy_support as vtk_numpy_support
n = 6
radius = 5.0
center_line = np.array([[-36.78, 19.78, -37.82],
[37.65, 20.04, -35.89],
[-38.85, 20.39, -32.84],
[-39.85, 20.68, -29.65],
[-40.57, 20.89, -26.37],
[-40.98, 21. , -23.02],
[-41.05, 21.01, -19.67],
[-40.78, 20.93, -16.34],
[-40.21, 20.75, -13.07],
[-39.33, 20.48, -9.86],
[-38.14, 20.12, -6.72],
[-36.66, 19.67, -3.68],
[-34.95, 19.15, -0.75]])
tube_filter = vtk.vtkTubeFilter()
tube_filter.SetNumberOfSides(n)
tube_filter.SetCapping(True)
tube_filter.SetRadius(radius)
field = vtk.vtkFieldData()
field.AddArray(vtk_numpy_support.numpy_to_vtk(center_line))
data_obj = vtk.vtkDataObject()
data_obj.SetFieldData(field)
tube_filter.SetInputData(data_obj)
vertices = vtk_numpy_support.vtk_to_numpy(tube_filter.GetOutput().GetVerts().GetData())
print(vertices)
output:输出:
/home/user/anaconda3/lib/python3.6/site-packages/vtk/util/numpy_support.py:137: FutureWarning: Conversion of the second argument of issubdtype from `complex` to `np.complexfloating` is deprecated. In future, it will be treated as `np.complex128 == np.dtype(complex).type`.
assert not numpy.issubdtype(z.dtype, complex), \
[]
PS: I am also not quite sure why the array is interpreted to be of type complex. PS:我也不太确定为什么将数组解释为复杂类型。 In my debugger it is shown as normal float64
numbers.在我的调试器中,它显示为正常的float64
数字。
With vtkplotter :使用vtkplotter :
from vtkplotter import Tube
center_line = [ [-36.78, 19.78, -37.82],
[-37.65, 20.04, -35.89],
[-38.85, 20.39, -32.84],
[-39.85, 20.68, -29.65],
[-40.57, 20.89, -26.37],
[-40.98, 21. , -23.02],
[-41.05, 21.01, -19.67],
[-40.78, 20.93, -16.34],
[-40.21, 20.75, -13.07],
[-39.33, 20.48, -9.86],
[-38.14, 20.12, -6.72],
[-36.66, 19.67, -3.68],
[-34.95, 19.15, -0.75] ]
t = Tube(center_line, r=5, cap=True, res=6)
print(t.points()) # numpy array
t.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.