source: development/steve/visualisation/Tutorial/Step1/Cone.py @ 2229

Last change on this file since 2229 was 2229, checked in by steve, 19 years ago

Moved directories into production and development parent directories

File size: 2.4 KB
Line 
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#
13import vtk
14import 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#
22cone = vtk.vtkConeSource()
23cone.SetHeight( 3.0 )
24cone.SetRadius( 1.0 )
25cone.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#
34coneMapper = vtk.vtkPolyDataMapper()
35coneMapper.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#
43coneActor = vtk.vtkActor()
44coneActor.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#
52ren1= vtk.vtkRenderer()
53ren1.AddActor( coneActor )
54ren1.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#
61renWin = vtk.vtkRenderWindow()
62renWin.AddRenderer( ren1 )
63renWin.SetSize( 300, 300 )
64
65#
66# now we loop over 360 degreeees and render the cone each time
67#
68for i in range(0,360):
69    time.sleep(0.03)
70
71    renWin.Render()
72    ren1.GetActiveCamera().Azimuth( 1 )
Note: See TracBrowser for help on using the repository browser.