source: development/steve/visualisation/Tutorial/Step5/Cone5.tcl @ 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: 4.3 KB
Line 
1#
2# This example introduces the concepts of interaction into the
3# Tcl environment. First, a different interaction style (than
4# the default) is defined. Second, because Tcl is an interpretive
5# language, the VTK Tcl interaction GUI is set up.
6#
7#
8#
9# First we include the VTK Tcl packages which will make available
10# all of the VTK commands to Tcl. Note that package vtkinteraction
11# is required; thios package defines the Tcl/Tk GUI widget .vtkInteract
12# that is referred to later.
13#
14package require vtk
15package require vtkinteraction
16
17#
18# Next we create an instance of vtkConeSource and set some of its
19# properties. The instance of vtkConeSource "cone" is part of a visualization
20# pipeline (it is a source process object); it produces data (output type is
21# vtkPolyData) which other filters may process.
22#
23vtkConeSource cone
24cone SetHeight 3.0
25cone SetRadius 1.0
26cone SetResolution 10
27
28#
29# In this example we terminate the pipeline with a mapper process object.
30# (Intermediate filters such as vtkShrinkPolyData could be inserted in
31# between the source and the mapper.)  We create an instance of
32# vtkPolyDataMapper to map the polygonal data into graphics primitives. We
33# connect the output of the cone souece to the input of this mapper.
34#
35vtkPolyDataMapper coneMapper
36coneMapper SetInput [cone GetOutput]
37
38#
39# Create an actor to represent the cone. The actor orchestrates rendering of
40# the mapper's graphics primitives. An actor also refers to properties via a
41# vtkProperty instance, and includes an internal transformation matrix. We
42# set this actor's mapper to be coneMapper which we created above.
43#
44vtkActor coneActor
45coneActor SetMapper coneMapper
46
47#
48# Create the Renderer and assign actors to it. A renderer is like a
49# viewport. It is part or all of a window on the screen and it is responsible
50# for drawing the actors it has.  We also set the background color here.
51#
52vtkRenderer ren1
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#
61vtkRenderWindow renWin
62renWin AddRenderer ren1
63renWin SetSize 300 300
64
65#
66# The vtkRenderWindowInteractor class watches for events (e.g., keypress,
67# mouse) in the vtkRenderWindow. These events are translated into
68# event invocations that VTK understands (see VTK/Common/vtkCommand.h
69# for all events that VTK processes). Then observers of these VTK
70# events can process them as appropriate.
71vtkRenderWindowInteractor iren
72iren SetRenderWindow renWin
73
74#
75# By default the vtkRenderWindowInteractor instantiates an instance
76# of vtkInteractorStyle. vtkInteractorStyle translates a set of events
77# it observes into operations on the camera, actors, and/or properties
78# in the vtkRenderWindow associated with the vtkRenderWinodwInteractor.
79# Here we specify a particular interactor style.
80vtkInteractorStyleTrackballCamera style
81iren SetInteractorStyle style
82
83#
84# Unlike the previous scripts where we performed some operations and then
85# exited, here we leave an event loop running. The user can use the mouse
86# and keyboard to perform the operations on the scene according to the
87# current interaction style.
88#
89
90#
91# Another feature of Tcl/Tk is that in VTK a simple GUI for typing in
92# interpreted Tcl commands is provided. The so-called vtkInteractor appears
93# when the user types the "u" (for user) keypress. The "u" keypress is
94# translated into a UserEvent by the vtkRenderWindowInteractor. We observe
95# this event and invoke a commands to deiconify the vtkInteractor. (The
96# vtkInteractor is defined in the vtkinteraction package reference at the
97# beginning of this script.)
98#
99#
100iren AddObserver UserEvent {wm deiconify .vtkInteract}
101
102#
103# Initialize the event loop. The actual interaction starts after
104# wm withdraw . with the Tk event loop. Once the render window appears,
105# mouse in the window to move the camera. Note that keypress-e exits this
106# example. (Look in vtkInteractorStyle.h for a summary of events, or
107# the appropriate Doxygen documentation.)
108#
109iren Initialize
110
111#
112# Since we are in the Tcl/Tk environment, we prevent the empty "."
113# window from appearing with the Tk "withdraw" command.
114#
115wm withdraw .
116
117
118
119
120
Note: See TracBrowser for help on using the repository browser.