python vtk 多渲染器和方向小部件
python vtk multiple renderers and orientation widgets
我正在尝试为每个视口使用独立的方向小部件渲染同一演员的多个视图。但是,我似乎无法弄清楚如何将小部件分配给适当的渲染器和视口。这是一个工作示例,其中所有方向小部件仅在一个渲染器中结束:
import vtk
# Setup mesh mapper and actor
cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
# Create a render window, and set interaction styles
renderWindow = vtk.vtkRenderWindow()
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
renderWindow.SetSize(640, 480)
# Create multiple renderers and orientation widgets
axes_actor = vtk.vtkAxesActor()
orien_widgets = [vtk.vtkOrientationMarkerWidget() for _ in range(0,4)]
renderers = [vtk.vtkRenderer() for _ in range(0,4)]
# Create multiple views
for i,tup in enumerate(((0.0,0.0),
(0.5,0.0),
(0.0,0.5),
(0.5,0.5))):
# Add renderer i
renderers[i].SetViewport(tup[0],tup[1],
tup[0]+.5,tup[1]+.5)
renderers[i].SetBackground(1, 1, 1)
renderWindow.AddRenderer(renderers[i])
renderers[i].AddActor(cylinderActor)
# Add orientation widget and axes actor
orien_widgets[i].renderer = renderers[i]
orien_widgets[i].SetOutlineColor( 0.9300, 0.5700, 0.1300 )
orien_widgets[i].SetOrientationMarker(axes_actor)
orien_widgets[i].SetInteractor( renderWindowInteractor )
orien_widgets[i].SetViewport(tup[0],tup[1],
tup[0]+.5,tup[1]+.5)
orien_widgets[i].EnabledOn()
orien_widgets[i].InteractiveOn()
renderers[i].ResetCamera()
# Render and interact
renderWindow.Render()
renderWindowInteractor.Start()
这行不对:
orien_widgets[i].renderer = renderers[i]
替换为:
orien_widgets[i].SetCurrentRenderer(renderers[i])
我正在尝试为每个视口使用独立的方向小部件渲染同一演员的多个视图。但是,我似乎无法弄清楚如何将小部件分配给适当的渲染器和视口。这是一个工作示例,其中所有方向小部件仅在一个渲染器中结束:
import vtk
# Setup mesh mapper and actor
cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
# Create a render window, and set interaction styles
renderWindow = vtk.vtkRenderWindow()
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
renderWindow.SetSize(640, 480)
# Create multiple renderers and orientation widgets
axes_actor = vtk.vtkAxesActor()
orien_widgets = [vtk.vtkOrientationMarkerWidget() for _ in range(0,4)]
renderers = [vtk.vtkRenderer() for _ in range(0,4)]
# Create multiple views
for i,tup in enumerate(((0.0,0.0),
(0.5,0.0),
(0.0,0.5),
(0.5,0.5))):
# Add renderer i
renderers[i].SetViewport(tup[0],tup[1],
tup[0]+.5,tup[1]+.5)
renderers[i].SetBackground(1, 1, 1)
renderWindow.AddRenderer(renderers[i])
renderers[i].AddActor(cylinderActor)
# Add orientation widget and axes actor
orien_widgets[i].renderer = renderers[i]
orien_widgets[i].SetOutlineColor( 0.9300, 0.5700, 0.1300 )
orien_widgets[i].SetOrientationMarker(axes_actor)
orien_widgets[i].SetInteractor( renderWindowInteractor )
orien_widgets[i].SetViewport(tup[0],tup[1],
tup[0]+.5,tup[1]+.5)
orien_widgets[i].EnabledOn()
orien_widgets[i].InteractiveOn()
renderers[i].ResetCamera()
# Render and interact
renderWindow.Render()
renderWindowInteractor.Start()
这行不对:
orien_widgets[i].renderer = renderers[i]
替换为:
orien_widgets[i].SetCurrentRenderer(renderers[i])