1

我已经从 vtk 文件中可视化了一些箭头,现在我正在尝试使用 VTK 包在 python 中可视化流线。我可以得到箭头,但不能得到流线。编码;

# File:        wind.py
from vtk import *

reader = vtkStructuredPointsReader()
reader.SetFileName("wind.vtk")
reader.Update()

cubeOutline = vtkOutlineFilter()
cubeOutline.SetInputConnection(reader.GetOutputPort())
cubeMapper = vtkPolyDataMapper()
cubeMapper.SetInputConnection(cubeOutline.GetOutputPort())

cubeActor = vtkActor()
cubeActor.SetMapper(cubeMapper)
cubeActor.GetProperty().SetColor(1.0,1.0,1.0)

arrow = vtkArrowSource()
arrow.SetTipRadius(0.2)
arrow.SetShaftRadius(0.075)

arrowGlyph = vtkGlyph3D()
arrowGlyph.SetInputConnection(reader.GetOutputPort())
arrowGlyph.SetSource(arrow.GetOutput())
arrowGlyph.SetScaleFactor(0.05)

arrowMapper = vtkPolyDataMapper()
arrowMapper.SetInputConnection(arrowGlyph.GetOutputPort())

arrowActor = vtkActor()
arrowActor.SetMapper(arrowMapper)

points = vtkPointSource()
points.SetRadius(3.0)
points.SetNumberOfPoints(20)

streamers = vtkStreamLine()
streamers.SetInputConnection(reader.GetOutputPort())
streamers.SetSource(points.GetOutput())
streamers.SpeedScalarsOn()
streamers.SetMaximumPropagationTime(100)
streamers.SetIntegrationStepLength(0.2)
streamers.SetTerminalSpeed(0.1)

streamMapper = vtkPolyDataMapper()
streamMapper.SetInputConnection(streamers.GetOutputPort())
streamMapper.SetScalarRange(reader.GetOutput().GetScalarRange())

streamActor = vtkActor()
streamActor.SetMapper(streamMapper)

ren = vtkRenderer()
ren.SetBackground(.2, .2, .2)

renWin = vtkRenderWindow()
renWin.SetSize(800, 600)
renWin.AddRenderer( ren )

iren = vtkRenderWindowInteractor()
iren.SetRenderWindow( renWin )

ren.AddActor(cubeActor)
ren.AddActor(arrowActor)
ren.AddActor(streamActor)

renWin.Render()
iren.Initialize()
iren.Start()

我看不到我错过了什么。

4

1 回答 1

2

I have little experience visualizing streamlines and the experience I do have is with vtkteem (vtkSeedTracts).

I assume that the points you are specifying are used as seeds for the streamlines to form from. If that is the case, shouldn't you also specify a location for these points? I don't know what your data is like, but I have a feeling that the streamlines aren't visible because the seed points aren't specified correctly.

Hope that helps!

于 2012-10-31T09:29:09.893 回答