source: development/steve/visualisation/Tutorial/Step4/Cone4.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: 3.1 KB
Line 
1#!/usr/bin/env python
2#
3# This example demonstrates the creation of multiple actors and the
4# manipulation of their properties and transformations. It is a
5# derivative of Cone.py, see that example for more information.
6#
7
8import vtk
9import time
10
11#
12# Next we create an instance of vtkConeSource and set some of its
13# properties. The instance of vtkConeSource "cone" is part of a visualization
14# pipeline (it is a source process object); it produces data (output type is
15# vtkPolyData) which other filters may process.
16#
17cone = vtk.vtkConeSource ()
18cone.SetHeight( 3.0 )
19cone.SetRadius( 1.0 )
20cone.SetResolution( 10 )
21
22#
23# In this example we terminate the pipeline with a mapper process object.
24# (Intermediate filters such as vtkShrinkPolyData could be inserted in
25# between the source and the mapper.)  We create an instance of
26# vtkPolyDataMapper to map the polygonal data into graphics primitives. We
27# connect the output of the cone souece to the input of this mapper.
28#
29coneMapper = vtk.vtkPolyDataMapper()
30coneMapper.SetInput(cone.GetOutput())
31
32#
33# Create an actor to represent the first cone. The actor's properties are
34# modified to give it different surface properties. By default, an actor
35# is create with a property so the GetProperty() method can be used.
36#
37coneActor = vtk.vtkActor()
38coneActor.SetMapper(coneMapper)
39coneActor.GetProperty().SetColor(0.2, 0.63, 0.79)
40coneActor.GetProperty().SetDiffuse(0.7)
41coneActor.GetProperty().SetSpecular(0.4)
42coneActor.GetProperty().SetSpecularPower(20)
43
44#
45# Create a property and directly manipulate it. Assign it to the
46# second actor.
47#
48property = vtk.vtkProperty()
49property.SetColor(1.0, 0.3882, 0.2784)
50property.SetDiffuse(0.7)
51property.SetSpecular(0.4)
52property.SetSpecularPower(20)
53
54#
55# Create a second actor and a property. The property is directly
56# manipulated and then assigned to the actor. In this way, a single
57# property can be shared among many actors. Note also that we use the
58# same mapper as the first actor did. This way we avoid duplicating
59# geometry, which may save lots of memory if the geoemtry is large.
60coneActor2 = vtk.vtkActor()
61coneActor2.SetMapper(coneMapper)
62coneActor2.GetProperty().SetColor(0.2, 0.63, 0.79)
63coneActor2.SetProperty(property)
64coneActor2.SetPosition(0, 2, 0)
65
66#
67# Create the Renderer and assign actors to it. A renderer is like a
68# viewport. It is part or all of a window on the screen and it is responsible
69# for drawing the actors it has.  We also set the background color here.
70#
71ren1 = vtk.vtkRenderer()
72ren1.AddActor(coneActor)
73ren1.AddActor(coneActor2)
74ren1.SetBackground(0.1, 0.2, 0.4)
75
76#
77# Finally we create the render window which will show up on the screen
78# We put our renderer into the render window using AddRenderer. We also
79# set the size to be 300 pixels by 300.
80#
81renWin = vtk.vtkRenderWindow()
82renWin.AddRenderer(ren1)
83renWin.SetSize(300, 300)
84
85#
86# Now we loop over 360 degreeees and render the cone each time.
87#
88for i in range(0,360):
89    time.sleep(0.03)
90   
91    renWin.Render()
92    ren1.GetActiveCamera().Azimuth( 1 )
93
Note: See TracBrowser for help on using the repository browser.