1 | # |
---|
2 | # This example demonstrates the creation of multiple actors and the |
---|
3 | # manipulation of their properties and transformations. It is a |
---|
4 | # derivative of Cone.tcl, see that example for more information. |
---|
5 | # |
---|
6 | |
---|
7 | # |
---|
8 | # First we include the VTK Tcl packages which will make available |
---|
9 | # all of the VTK commands to Tcl. |
---|
10 | # |
---|
11 | package require vtk |
---|
12 | |
---|
13 | # |
---|
14 | # Next we create an instance of vtkConeSource and set some of its |
---|
15 | # properties. The instance of vtkConeSource "cone" is part of a visualization |
---|
16 | # pipeline (it is a source process object); it produces data (output type is |
---|
17 | # vtkPolyData) which other filters may process. |
---|
18 | # |
---|
19 | vtkConeSource cone |
---|
20 | cone SetHeight 3.0 |
---|
21 | cone SetRadius 1.0 |
---|
22 | cone SetResolution 10 |
---|
23 | |
---|
24 | # |
---|
25 | # In this example we terminate the pipeline with a mapper process object. |
---|
26 | # (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
27 | # between the source and the mapper.) We create an instance of |
---|
28 | # vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
29 | # connect the output of the cone souece to the input of this mapper. |
---|
30 | # |
---|
31 | vtkPolyDataMapper coneMapper |
---|
32 | coneMapper SetInput [cone GetOutput] |
---|
33 | |
---|
34 | # |
---|
35 | # Create an actor to represent the first cone. The actor's properties are |
---|
36 | # modified to give it different surface properties. By default, an actor |
---|
37 | # is create with a property so the GetProperty() method can be used. |
---|
38 | # |
---|
39 | vtkActor coneActor |
---|
40 | coneActor SetMapper coneMapper |
---|
41 | [coneActor GetProperty] SetColor 0.2 0.63 0.79 |
---|
42 | [coneActor GetProperty] SetDiffuse 0.7 |
---|
43 | [coneActor GetProperty] SetSpecular 0.4 |
---|
44 | [coneActor GetProperty] SetSpecularPower 20 |
---|
45 | |
---|
46 | # |
---|
47 | # Create a property and directly manipulate it. Assign it to the |
---|
48 | # second actor. |
---|
49 | # |
---|
50 | vtkProperty property |
---|
51 | property SetColor 1.0 0.3882 0.2784 |
---|
52 | property SetDiffuse 0.7 |
---|
53 | property SetSpecular 0.4 |
---|
54 | property SetSpecularPower 20 |
---|
55 | |
---|
56 | # |
---|
57 | # Create a second actor and a property. The property is directly |
---|
58 | # manipulated and then assigned to the actor. In this way, a single |
---|
59 | # property can be shared among many actors. Note also that we use the |
---|
60 | # same mapper as the first actor did. This way we avoid duplicating |
---|
61 | # geometry, which may save lots of memory if the geoemtry is large. |
---|
62 | vtkActor coneActor2 |
---|
63 | coneActor2 SetMapper coneMapper |
---|
64 | [coneActor2 GetProperty] SetColor 0.2 0.63 0.79 |
---|
65 | coneActor2 SetProperty property |
---|
66 | coneActor2 SetPosition 0 2 0 |
---|
67 | |
---|
68 | # |
---|
69 | # Create the Renderer and assign actors to it. A renderer is like a |
---|
70 | # viewport. It is part or all of a window on the screen and it is responsible |
---|
71 | # for drawing the actors it has. We also set the background color here. |
---|
72 | # |
---|
73 | vtkRenderer ren1 |
---|
74 | ren1 AddActor coneActor |
---|
75 | ren1 AddActor coneActor2 |
---|
76 | ren1 SetBackground 0.1 0.2 0.4 |
---|
77 | |
---|
78 | # |
---|
79 | # Finally we create the render window which will show up on the screen |
---|
80 | # We put our renderer into the render window using AddRenderer. We also |
---|
81 | # set the size to be 300 pixels by 300. |
---|
82 | # |
---|
83 | vtkRenderWindow renWin |
---|
84 | renWin AddRenderer ren1 |
---|
85 | renWin SetSize 300 300 |
---|
86 | |
---|
87 | # |
---|
88 | # Now we loop over 360 degreeees and render the cone each time. |
---|
89 | # |
---|
90 | for {set i 0} {$i < 360} {incr i} { |
---|
91 | after 10 |
---|
92 | # render the image |
---|
93 | renWin Render |
---|
94 | # rotate the active camera by one degree |
---|
95 | [ren1 GetActiveCamera] Azimuth 1 |
---|
96 | } |
---|
97 | |
---|
98 | # |
---|
99 | # Free up any objects we created. |
---|
100 | # |
---|
101 | vtkCommand DeleteAllObjects |
---|
102 | |
---|
103 | # |
---|
104 | # Exit the application. |
---|
105 | # |
---|
106 | exit |
---|
107 | |
---|
108 | |
---|
109 | |
---|