1#!/usr/bin/env python 2import vtk 3from vtk.test import Testing 4from vtk.util.misc import vtkGetDataRoot 5VTK_DATA_ROOT = vtkGetDataRoot() 6 7# This example illustrates how one may explicitly specify the range of each 8# axes that's used to define the prop, while displaying data with a different 9# set of bounds (unlike cubeAxes2.tcl). This example allows you to separate 10# the notion of extent of the axes in physical space (bounds) and the extent 11# of the values it represents. In other words, you can have the ticks and 12# labels show a different range. 13# 14# read in an interesting object and outline it 15# 16fohe = vtk.vtkBYUReader() 17fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g") 18 19normals = vtk.vtkPolyDataNormals() 20normals.SetInputConnection(fohe.GetOutputPort()) 21 22foheMapper = vtk.vtkPolyDataMapper() 23foheMapper.SetInputConnection(normals.GetOutputPort()) 24 25foheActor = vtk.vtkLODActor() 26foheActor.SetMapper(foheMapper) 27foheActor.GetProperty().SetDiffuseColor(0.7, 0.3, 0.0) 28 29outline = vtk.vtkOutlineFilter() 30outline.SetInputConnection(normals.GetOutputPort()) 31 32mapOutline = vtk.vtkPolyDataMapper() 33mapOutline.SetInputConnection(outline.GetOutputPort()) 34 35outlineActor = vtk.vtkActor() 36outlineActor.SetMapper(mapOutline) 37outlineActor.GetProperty().SetColor(0, 0, 0) 38 39# Create the RenderWindow, Renderer, and setup viewports 40camera = vtk.vtkCamera() 41camera.SetClippingRange(1.0, 100.0) 42camera.SetFocalPoint(0.9, 1.0, 0.0) 43camera.SetPosition(11.63, 6.0, 10.77) 44 45light = vtk.vtkLight() 46light.SetFocalPoint(0.21406, 1.5, 0) 47light.SetPosition(8.3761, 4.94858, 4.12505) 48 49ren2 = vtk.vtkRenderer() 50ren2.SetActiveCamera(camera) 51ren2.AddLight(light) 52 53renWin = vtk.vtkRenderWindow() 54renWin.SetMultiSamples(0) 55renWin.AddRenderer(ren2) 56renWin.SetWindowName("VTK - Cube Axes custom range") 57 58renWin.SetSize(600, 600) 59 60iren = vtk.vtkRenderWindowInteractor() 61iren.SetRenderWindow(renWin) 62 63# Add the actors to the renderer, set the background and size 64# 65ren2.AddViewProp(foheActor) 66ren2.AddViewProp(outlineActor) 67ren2.SetBackground(0.1, 0.2, 0.4) 68 69normals.Update() 70 71bounds = normals.GetOutput().GetBounds() 72axes2 = vtk.vtkCubeAxesActor() 73axes2.SetBounds( 74 bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]) 75axes2.SetXAxisRange(20, 300) 76axes2.SetYAxisRange(-0.01, 0.01) 77axes2.SetCamera(ren2.GetActiveCamera()) 78axes2.SetXLabelFormat("%6.1f") 79axes2.SetYLabelFormat("%6.1f") 80axes2.SetZLabelFormat("%6.1f") 81axes2.SetFlyModeToClosestTriad() 82axes2.SetScreenSize(20.0) 83 84ren2.AddViewProp(axes2) 85 86renWin.Render() 87ren2.ResetCamera() 88renWin.Render() 89 90# render the image 91# 92iren.Initialize() 93 94def TkCheckAbort (object_binding, event_name): 95 foo = renWin.GetEventPending() 96 if (foo != 0): 97 renWin.SetAbortRender(1) 98 pass 99 100renWin.AddObserver("AbortCheckEvent", TkCheckAbort) 101 102#iren.Start() 103