CylinderAndPolarAxes.py 2.24 KB
Newer Older
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
############################################################
from vtk import *
############################################################

# Create pole for camera aim and polar axes pole
pole = [1., 12., 3.]

# Create camera
camera = vtkCamera()
camera.SetClippingRange( 1.0, 100.0 )
camera.SetFocalPoint( pole )
camera.SetPosition( 10., 10., 13. )

# Create cylinder
cylinder = vtkCylinderSource()
cylinder.SetRadius( 6. )
cylinder.SetCenter( 1., 2., 3. )
cylinder.SetHeight( 15 )
cylinder.SetResolution( 32 )
cylinder.Update()

# Create mappers
mapper = vtkPolyDataMapper()
mapper.SetInputConnection( cylinder.GetOutputPort() )

# Create cylinder actor
cylactor = vtkActor()
cylactor.SetMapper( mapper )
cylactor.GetProperty().SetColor( .5, .5, .5 )
cylactor.SetOrigin( pole )
cylactor.RotateX( 90. )

33
34
35
36
37
38
39
# Create renderer
renderer = vtkRenderer()
renderer.GradientBackgroundOn()
renderer.SetBackground( .8, .8 ,.8 )
renderer.SetBackground2( 1., 1. ,1. )
renderer.SetActiveCamera( camera )

40
41
42
43
44
45
# Create polar axes
polaxes = vtkPolarAxesActor()
polaxes.SetBounds( cylinder.GetOutput().GetBounds() )
polaxes.SetPole( pole )
polaxes.SetAutoScaleRadius( 0 )
polaxes.SetMaximumRadius( 4.5 )
Philippe Pébay's avatar
Philippe Pébay committed
46
47
polaxes.SetMinimumAngle( -60. )
polaxes.SetMaximumAngle( 210. )
48
polaxes.SetNumberOfRadialAxes( 10 )
49
polaxes.SetNumberOfPolarAxisTicks( 9 )
50
polaxes.SetAutoSubdividePolarAxis( 0 )
51
polaxes.SetCamera( renderer.GetActiveCamera() )
52
polaxes.SetPolarLabelFormat( "%6.1f" )
53
54
polaxes.GetRadialAxesProperty().SetColor( .0, .0, 1. )
polaxes.GetPolarArcsProperty().SetColor( 1., .0, 0. )
55
56
57
polaxes.GetPolarAxisProperty().SetColor( 0., 1., 0. )
polaxes.GetPolarAxisTitleTextProperty().SetColor( 0., 1., 0. )
polaxes.GetPolarAxisLabelTextProperty().SetColor( 0., 1., 0. )
58
polaxes.SetEnableDistanceLOD( 0 )
59
polaxes.SetDistanceLODThreshold( .4 )
60
polaxes.SetEnableViewAngleLOD( 0 )
61
polaxes.SetViewAngleLODThreshold( .2 )
62
polaxes.SetScreenSize( 8. )
63
64
65

# Create render window
window = vtkRenderWindow()
66
67
renderer.AddViewProp( cylactor )
renderer.AddViewProp( polaxes )
68
69
70
71
72
73
74
75
76
window.AddRenderer( renderer )
window.SetSize( 500, 500 )

# Create interactor
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow( window )

# Start interaction
window.Render()
77
78
79
80

polaxes.SetMaximumAngle( 120. )
window.Render()

81
interactor.Start()