如何在同一渲染器中渲染 2 个 .vtp 切片 Window
How to render 2 .vtp slices in the same render Window
我需要一些 .vtp 格式的切片(也是 vtm),我想将它们一起可视化以便之后处理它们。
我已经设置了读取器、映射器、演员、渲染器 window 和相机坐标,但是当图像被渲染时,它只给我第一个切片 (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()
我希望在同一个渲染中有两个切片 window 一个在另一个之上可能有一些距离但中心相同,以便将它们一起保存为一个独特的图像并对其进行处理
您的代码大部分是正确的,只是您为两个不同的演员设置了相同的映射器,所以实际上您显示了两次相同的几何图形(第 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)
它会起作用。
我需要一些 .vtp 格式的切片(也是 vtm),我想将它们一起可视化以便之后处理它们。
我已经设置了读取器、映射器、演员、渲染器 window 和相机坐标,但是当图像被渲染时,它只给我第一个切片 (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()
我希望在同一个渲染中有两个切片 window 一个在另一个之上可能有一些距离但中心相同,以便将它们一起保存为一个独特的图像并对其进行处理
您的代码大部分是正确的,只是您为两个不同的演员设置了相同的映射器,所以实际上您显示了两次相同的几何图形(第 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)
它会起作用。