我正在使用 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 后面渲染演员,我如何将 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()