我正在使用vtkImageViewer类来显示3D体积中的不同平面。然后我喜欢覆盖垂直和水平线以标记当前鼠标位置。 我使用以下代码向查看器添加vtkActor2D:
imageViewer = vtk.vtkImageViewer()
...
line = vtk.vtkLineSource()
line.SetResolution(20)
mapper = vtk.vtkPolyDataMapper2D()
mapper.SetInputConnection(line.GetOutputPort())
actor = vtk.vtkActor2D()
actor.SetMapper(mapper)
imageViewer.GetRenderer().AddActor2D(actor)
...
line.SetPoint1(x,0.0,0.0)
line.SetPoint2(x,y,0.0)
actor.GetProperty().SetColor(color)
actor.GetProperty().SetOpacity(0.75)
...
imageViewer.Render()
在Mac OS X上它按预期工作,但是当我尝试使用我的Windows机器时,该线路根本没有显示。
更新: 如果我改为vtkActor而不是在imageViewer后面渲染actor,我该如何将vtkActor带到前台?
imageViewer = vtk.vtkImageViewer()
...
line = vtk.vtkLineSource()
line.SetResolution(20)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(line.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
imageViewer.GetRenderer().AddActor(actor)
...
line.SetPoint1(x,0.0,0.0)
line.SetPoint2(x,y,0.0)
actor.GetProperty().SetColor(color)
actor.GetProperty().SetOpacity(0.75)
...
imageViewer.Render()