1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# read in an interesting object and outline it
#
fohe = vtk.vtkBYUReader()
fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g")
normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(fohe.GetOutputPort())
foheMapper = vtk.vtkPolyDataMapper()
foheMapper.SetInputConnection(normals.GetOutputPort())
foheActor = vtk.vtkLODActor()
foheActor.SetMapper(foheMapper)
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(normals.GetOutputPort())
mapOutline = vtk.vtkPolyDataMapper()
mapOutline.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(mapOutline)
outlineActor.GetProperty().SetColor(0, 0, 0)
# Create the RenderWindow, Renderer, and setup viewports
camera = vtk.vtkCamera()
camera.SetClippingRange(1.60187, 20.0842)
camera.SetFocalPoint(0.21406, 1.5, 0)
camera.SetPosition(11.63, 6.32, 5.77)
camera.SetViewUp(0.180325, 0.549245, -0.815974)
light = vtk.vtkLight()
light.SetFocalPoint(0.21406, 1.5, 0)
light.SetPosition(8.3761, 4.94858, 4.12505)
ren1 = vtk.vtkRenderer()
ren1.SetViewport(0, 0, 0.33, 0.5)
ren1.SetActiveCamera(camera)
ren1.AddLight(light)
ren2 = vtk.vtkRenderer()
ren2.SetViewport(0.33, 0, 0.66, 0.5)
ren2.SetActiveCamera(camera)
ren2.AddLight(light)
ren3 = vtk.vtkRenderer()
ren3.SetViewport(0.66, 0, 1.0, 0.5)
ren3.SetActiveCamera(camera)
ren3.AddLight(light)
ren4 = vtk.vtkRenderer()
ren4.SetViewport(0, 0.5, 0.5, 1.0)
ren4.SetActiveCamera(camera)
ren4.AddLight(light)
ren5 = vtk.vtkRenderer()
ren5.SetViewport(0.5, 0.5, 1.0, 1.0)
ren5.SetActiveCamera(camera)
ren5.AddLight(light)
renWin = vtk.vtkRenderWindow()
renWin.SetMultiSamples(0)
renWin.AddRenderer(ren1)
renWin.AddRenderer(ren2)
renWin.AddRenderer(ren3)
renWin.AddRenderer(ren4)
renWin.AddRenderer(ren5)
renWin.SetWindowName("VTK - Cube Axes")
renWin.SetSize(600, 600)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
#
ren1.AddViewProp(foheActor)
ren1.AddViewProp(outlineActor)
ren2.AddViewProp(foheActor)
ren2.AddViewProp(outlineActor)
ren3.AddViewProp(foheActor)
ren3.AddViewProp(outlineActor)
ren4.AddViewProp(foheActor)
ren4.AddViewProp(outlineActor)
ren5.AddViewProp(foheActor)
ren1.SetBackground(0.1, 0.2, 0.4)
ren2.SetBackground(0.1, 0.2, 0.4)
ren3.SetBackground(0.1, 0.2, 0.4)
ren4.SetBackground(0.1, 0.2, 0.4)
ren5.SetBackground(0.1, 0.2, 0.4)
normals.Update()
bounds = normals.GetOutput().GetBounds()
axes = vtk.vtkCubeAxesActor()
axes.SetBounds(
bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5])
axes.SetCamera(ren1.GetActiveCamera())
axes.SetXLabelFormat("%6.1f")
axes.SetYLabelFormat("%6.1f")
axes.SetZLabelFormat("%6.1f")
axes.SetFlyModeToOuterEdges()
ren1.AddViewProp(axes)
axes2 = vtk.vtkCubeAxesActor()
axes2.SetBounds(
bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5])
axes2.SetCamera(ren2.GetActiveCamera())
axes2.SetXLabelFormat(axes.GetXLabelFormat())
axes2.SetYLabelFormat(axes.GetYLabelFormat())
axes2.SetZLabelFormat(axes.GetZLabelFormat())
axes2.SetFlyModeToClosestTriad()
ren2.AddViewProp(axes2)
axes3 = vtk.vtkCubeAxesActor()
axes3.SetBounds(
bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5])
axes3.SetCamera(ren2.GetActiveCamera())
axes3.SetXLabelFormat(axes.GetXLabelFormat())
axes3.SetYLabelFormat(axes.GetYLabelFormat())
axes3.SetZLabelFormat(axes.GetZLabelFormat())
axes3.SetFlyModeToFurthestTriad()
ren3.AddViewProp(axes3)
bounds2 = axes3.GetBounds()
axes4 = vtk.vtkCubeAxesActor()
axes4.SetBounds(
bounds2[0], bounds2[1], bounds2[2], bounds2[3], bounds2[4], bounds2[5])
axes4.SetCamera(ren2.GetActiveCamera())
axes4.SetXLabelFormat(axes.GetXLabelFormat())
axes4.SetYLabelFormat(axes.GetYLabelFormat())
axes4.SetZLabelFormat(axes.GetZLabelFormat())
axes4.SetFlyModeToStaticTriad()
ren4.AddViewProp(axes4)
axes5 = vtk.vtkCubeAxesActor()
axes5.SetBounds(
bounds2[0], bounds2[1], bounds2[2], bounds2[3], bounds2[4], bounds2[5])
axes5.SetCamera(ren2.GetActiveCamera())
axes5.SetXLabelFormat(axes.GetXLabelFormat())
axes5.SetYLabelFormat(axes.GetYLabelFormat())
axes5.SetZLabelFormat(axes.GetZLabelFormat())
axes5.SetFlyModeToStaticEdges()
ren5.AddViewProp(axes5)
renWin.Render()
# render the image
#
iren.Initialize()
def TkCheckAbort (object_binding, event_name):
foo = renWin.GetEventPending()
if (foo != 0):
renWin.SetAbortRender(1)
pass
renWin.AddObserver("AbortCheckEvent", TkCheckAbort)
threshold = 13
#iren.Start()
|