我必须以.vtp格式(也以vtm格式)显示一些切片,以便以后可以一起可视化。
我已经设置了阅读器,映射器,演员,渲染窗口和摄像机坐标,但是在渲染图像时,它仅给我第一个切片(Slice10),而没有给我第二个切片(Slice11)
import vtk
colors = vtk.vtkNamedColors()
Slice10 = 'Slice10_0_0.vtp'
reader1 = vtk.vtkXMLPolyDataReader()
reader1.SetFileName(Slice10)
Slice11 = 'Slice11_0_0.vtp'
reader2 = vtk.vtkXMLPolyDataReader()
reader2.SetFileName(Slice11)
# mapper
mapper1 = vtk.vtkPolyDataMapper()
mapper1.SetInputConnection(reader1.GetOutputPort())
mapper2 = vtk.vtkPolyDataMapper()
mapper2.SetInputConnection(reader2.GetOutputPort())
# actors
actor1 = vtk.vtkActor()
actor1.SetMapper(mapper1)
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper1)
'''RENDER'''
renderer = vtk.vtkRenderer()
# Background
renderer.SetBackground(1., 1., 1.)
# Add actor to the scene
renderer.AddActor(actor1)
renderer.AddActor(actor2)
'''Render window'''
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
'''Interactor'''
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
renderWindowInteractor.SetRenderWindow(renderWindow)
'''Add camera coordinates'''
axes = vtk.vtkAxesActor()
widget = vtk.vtkOrientationMarkerWidget()
widget.SetOutlineColor(0.9300, 0.5700, 0.1300)
widget.SetOrientationMarker(axes)
widget.SetInteractor(renderWindowInteractor)
widget.SetViewport(0.0, 0.0, 0.4, 0.4)
widget.SetEnabled(1)
widget.InteractiveOn()
# Reset camera
renderer.ResetCamera()
'''Begin interaction'''
renderWindow.Render()
renderWindowInteractor.Initialize()
renderWindowInteractor.Start()
renderWindowInteractor.Start()
我希望将两个切片放在同一渲染窗口中,彼此之间可能相隔一段距离,但要在同一中心,以便将它们保存为唯一的图像并进行处理
答案 0 :(得分:0)
您的代码基本上是正确的,除了您为两个不同的角色设置相同的映射器之外,因此实际上您要显示两次相同的几何图形(第19至24行)。更改:
# actors
actor1 = vtk.vtkActor()
actor1.SetMapper(mapper1)
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper1)
收件人:
# actors
actor1 = vtk.vtkActor()
actor1.SetMapper(mapper1)
actor2 = vtk.vtkActor()
actor2.SetMapper(mapper2)
它将起作用。