Extract Streamlines from a vtkUnstructuredGrid

Hi,

I have a vtkUnstructuredGrid file from which I want to extract streamlines of the Velocity vector.
If I use Paraview the streamlines are generated correctly, however by using the python vtk library I do not get any result.
Here is the code I’m using:

import vtk

seeds = vtk.vtkPlaneSource()
seeds.SetXResolution(4)
seeds.SetYResolution(4)
seeds.SetOrigin(2, -2, 26)
seeds.SetPoint1(2, 2, 26)
seeds.SetPoint2(2, -2, 32)

reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName('./0005.vtk')
reader.Update()

streamline = vtk.vtkStreamTracer()
streamline.SetInputConnection(reader.GetOutputPort())
streamline.SetSourceConnection(seeds.GetOutputPort())
streamline.SetMaximumPropagation(200)
streamline.SetInitialIntegrationStep(.2)
streamline.SetIntegrationDirectionToBoth()

streamline_mapper = vtk.vtkPolyDataMapper()
streamline_mapper.SetInputConnection(streamline.GetOutputPort())
streamline_actor = vtk.vtkActor()
streamline_actor.SetMapper(streamline_mapper)
streamline_actor.VisibilityOn()
streamline_actor.GetProperty().SetColor(255, 255, 255)

outline = vtk.vtkOutlineFilter()
outline.SetInputData(reader.GetOutput())
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(255, 255, 255)

renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
render_window.SetWindowName('StreamLines')

interactor = vtk.vtkRenderWindowInteractor()
interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
render_window.SetInteractor(interactor)

renderer.AddActor(streamline_actor)
renderer.AddActor(outline_actor)

interactor.Initialize()
render_window.Render()
render_window.Render()
interactor.Start()

Since I am a new user I cannot upload files, therefore here is a link from which you can download the unstructuredGrid I am working on: 55.2 MB file on MEGA

Thanks

Just a quick couple of reactions (without looking at the data): you may have to indicate to vtkStreamTracer the array to use as the vector field: see the method SetInputArrayToProcess(). There is a test TestCellLocatorInterpolatedVelocityField.py that does this.

Also, make sure that the seeds are inside the dataset.

1 Like