我已经从vtk文件中看到了一些箭头,现在我试图通过使用VTK包来可视化python中的流线。我可以得到箭头而不是streamLines。代码;
# 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()
我看不出我错过了什么。
答案 0 :(得分:1)
我几乎没有可视化流线型的经验,我的经验是vtkteem(vtkSeedTracts)。
我假设你指定的点被用作形成流线的种子。如果是这种情况,您是否也应该为这些点指定位置?我不知道你的数据是什么样的,但我觉得流线是不可见的,因为没有正确指定种子点。
希望有所帮助!