简体   繁体   中英

python vtk tube filter returns empty array

I am trying to use the vtkTubeFilter object to get a tube around a line of points. 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

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. 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. In my debugger it is shown as normal float64 numbers.

With 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()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM