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 | # |
---|
14 | package require vtk |
---|
15 | package 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 | # |
---|
23 | vtkConeSource cone |
---|
24 | cone SetHeight 3.0 |
---|
25 | cone SetRadius 1.0 |
---|
26 | cone 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 | # |
---|
35 | vtkPolyDataMapper coneMapper |
---|
36 | coneMapper 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 | # |
---|
44 | vtkActor coneActor |
---|
45 | coneActor 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 | # |
---|
52 | vtkRenderer ren1 |
---|
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 | vtkRenderWindow renWin |
---|
62 | renWin AddRenderer ren1 |
---|
63 | renWin 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. |
---|
71 | vtkRenderWindowInteractor iren |
---|
72 | iren 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. |
---|
80 | vtkInteractorStyleTrackballCamera style |
---|
81 | iren 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 | # |
---|
100 | iren 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 | # |
---|
109 | iren 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 | # |
---|
115 | wm withdraw . |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|