[vtkusers] Color Velocity StreamTracer

mdomenighini at gmail.com mdomenighini at gmail.com
Wed Dec 28 11:30:41 EST 2016


Hello,

I have just started using vtk with python and I am encountering some problems.
I’ve been trying to color the streamlines from vtkStreamTracer using the velocity data without much success. 
I am acquiring the velocity data from a .vti file and generating the streamlines. I was using SpeedScalarsOn() earlier, but there doesn’t seem to be an analogous function for vtkStreamTracer.
I tried using vtkAssignAttribute without much success.
My code (from the streamTracer onwards) is below.


output = reader.GetOutput()

# Get vectors
velocity_field = output.GetPointData().GetArray(0)
output.GetPointData().SetVectors(velocity_field);

#streamtracer 
streamtracer = vtk.vtkStreamTracer()
streamtracer.SetInput(output)
streamtracer.SetSource(seeds.GetOutput())
streamtracer.SetMaximumPropagation(200)
streamtracer.SetIntegrationDirectionToForward()
streamtracer.SetComputeVorticity(True)

##streamTube from streamlines
streamTube = vtk.vtkTubeFilter()
streamTube.SetInputConnection(streamtracer.GetOutputPort())
streamTube.SetInputArrayToProcess(1, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "vectors")
streamTube.SetRadius(0.2)
streamTube.SetNumberOfSides(12)
streamTube.SetVaryRadiusToVaryRadiusByVector()
streamTube.Update()

##streamtube mapper
mapStreamTube = vtk.vtkPolyDataMapper()
mapStreamTube.SetInputConnection(streamTube.GetOutputPort())

##black and White lookup table
lut = vtk.vtkLookupTable()
lut.SetHueRange(0.0, 0.0);
lut.SetSaturationRange(0.0, 0.0);
lut.SetValueRange(0.0, 1.0);
lut.SetVectorModeToMagnitude()
mapStreamTube.SetLookupTable(lut)

##streamtube actor
streamTubeActor = vtk.vtkActor()
streamTubeActor.SetMapper(mapStreamTube)
streamTubeActor.GetProperty().BackfaceCullingOn()

##rendering
renderer = vtk.vtkRenderer()
renderer.AddActor(streamTubeActor)
renderer.ResetCamera()
renderer.SetBackground(0.5,.5,.5);
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.Initialize()
renderWindowInteractor.Start()

Can anyone help?

Thank you, 

Matteo

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161228/a887bb36/attachment.html>


More information about the vtkusers mailing list