1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # This example creates a polygonal model of a cone, and then renders it to |
---|
4 | # the screen. It will rotate the cone 360 degrees and then exit. The basic |
---|
5 | # setup of source -> mapper -> actor -> renderer -> renderwindow is |
---|
6 | # typical of most VTK programs. |
---|
7 | # |
---|
8 | |
---|
9 | # |
---|
10 | # First we include the VTK Python packages that will make available |
---|
11 | # all of the VTK commands to Python. |
---|
12 | # |
---|
13 | import vtk |
---|
14 | import time |
---|
15 | |
---|
16 | # |
---|
17 | # Next we create an instance of vtkConeSource and set some of its |
---|
18 | # properties. The instance of vtkConeSource "cone" is part of a visualization |
---|
19 | # pipeline (it is a source process object); it produces data (output type is |
---|
20 | # vtkPolyData) which other filters may process. |
---|
21 | # |
---|
22 | cone = vtk.vtkConeSource() |
---|
23 | cone.SetHeight( 3.0 ) |
---|
24 | cone.SetRadius( 1.0 ) |
---|
25 | cone.SetResolution( 10 ) |
---|
26 | |
---|
27 | # |
---|
28 | # In this example we terminate the pipeline with a mapper process object. |
---|
29 | # (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
30 | # between the source and the mapper.) We create an instance of |
---|
31 | # vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
32 | # connect the output of the cone souece to the input of this mapper. |
---|
33 | # |
---|
34 | coneMapper = vtk.vtkPolyDataMapper() |
---|
35 | coneMapper.SetInput( cone.GetOutput() ) |
---|
36 | |
---|
37 | # |
---|
38 | # Create an actor to represent the cone. The actor orchestrates rendering of |
---|
39 | # the mapper's graphics primitives. An actor also refers to properties via a |
---|
40 | # vtkProperty instance, and includes an internal transformation matrix. We |
---|
41 | # set this actor's mapper to be coneMapper which we created above. |
---|
42 | # |
---|
43 | coneActor = vtk.vtkActor() |
---|
44 | coneActor.SetMapper( coneMapper ) |
---|
45 | |
---|
46 | # |
---|
47 | # Create the Renderer and assign actors to it. A renderer is like a |
---|
48 | # viewport. It is part or all of a window on the screen and it is |
---|
49 | # responsible for drawing the actors it has. We also set the background |
---|
50 | # color here |
---|
51 | # |
---|
52 | ren1= vtk.vtkRenderer() |
---|
53 | ren1.AddActor( coneActor ) |
---|
54 | ren1.SetBackground( 0.1, 0.2, 0.4 ) |
---|
55 | |
---|
56 | # |
---|
57 | # Finally we create the render window which will show up on the screen |
---|
58 | # We put our renderer into the render window using AddRenderer. We also |
---|
59 | # set the size to be 300 pixels by 300 |
---|
60 | # |
---|
61 | renWin = vtk.vtkRenderWindow() |
---|
62 | renWin.AddRenderer( ren1 ) |
---|
63 | renWin.SetSize( 300, 300 ) |
---|
64 | |
---|
65 | # |
---|
66 | # now we loop over 360 degreeees and render the cone each time |
---|
67 | # |
---|
68 | for i in range(0,360): |
---|
69 | time.sleep(0.03) |
---|
70 | |
---|
71 | renWin.Render() |
---|
72 | ren1.GetActiveCamera().Azimuth( 1 ) |
---|