[2229] | 1 | # |
---|
| 2 | # This example creates a polygonal model of a cone, and then renders it to |
---|
| 3 | # the screen. It will rotate the cone 360 degrees and then exit. The basic |
---|
| 4 | # setup of source -> mapper -> actor -> renderer -> renderwindow is |
---|
| 5 | # typical of most VTK programs. |
---|
| 6 | # |
---|
| 7 | |
---|
| 8 | # |
---|
| 9 | # First we include the VTK Tcl packages which will make available |
---|
| 10 | # all of the VTK commands to Tcl. |
---|
| 11 | # |
---|
| 12 | package require vtk |
---|
| 13 | |
---|
| 14 | # |
---|
| 15 | # Next we create an instance of vtkConeSource and set some of its |
---|
| 16 | # properties. The instance of vtkConeSource "cone" is part of a visualization |
---|
| 17 | # pipeline (it is a source process object); it produces data (output type is |
---|
| 18 | # vtkPolyData) which other filters may process. |
---|
| 19 | # |
---|
| 20 | vtkConeSource cone |
---|
| 21 | cone SetHeight 3.0 |
---|
| 22 | cone SetRadius 1.0 |
---|
| 23 | cone SetResolution 10 |
---|
| 24 | |
---|
| 25 | # |
---|
| 26 | # In this example we terminate the pipeline with a mapper process object. |
---|
| 27 | # (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
| 28 | # between the source and the mapper.) We create an instance of |
---|
| 29 | # vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
| 30 | # connect the output of the cone souece to the input of this mapper. |
---|
| 31 | # |
---|
| 32 | vtkPolyDataMapper coneMapper |
---|
| 33 | coneMapper SetInput [cone GetOutput] |
---|
| 34 | |
---|
| 35 | # |
---|
| 36 | # Create an actor to represent the cone. The actor orchestrates rendering of |
---|
| 37 | # the mapper's graphics primitives. An actor also refers to properties via a |
---|
| 38 | # vtkProperty instance, and includes an internal transformation matrix. We |
---|
| 39 | # set this actor's mapper to be coneMapper which we created above. |
---|
| 40 | # |
---|
| 41 | vtkActor coneActor |
---|
| 42 | coneActor SetMapper coneMapper |
---|
| 43 | |
---|
| 44 | # |
---|
| 45 | # Create the Renderer and assign actors to it. A renderer is like a |
---|
| 46 | # viewport. It is part or all of a window on the screen and it is responsible |
---|
| 47 | # for drawing the actors it has. We also set the background color here. |
---|
| 48 | # |
---|
| 49 | vtkRenderer ren1 |
---|
| 50 | ren1 AddActor coneActor |
---|
| 51 | ren1 SetBackground 0.1 0.2 0.4 |
---|
| 52 | |
---|
| 53 | # |
---|
| 54 | # Finally we create the render window which will show up on the screen |
---|
| 55 | # We put our renderer into the render window using AddRenderer. We also |
---|
| 56 | # set the size to be 300 pixels by 300. |
---|
| 57 | # |
---|
| 58 | vtkRenderWindow renWin |
---|
| 59 | renWin AddRenderer ren1 |
---|
| 60 | renWin SetSize 300 300 |
---|
| 61 | |
---|
| 62 | # |
---|
| 63 | # Now we loop over 360 degreeees and render the cone each time. |
---|
| 64 | # |
---|
| 65 | for {set i 0} {$i < 360} {incr i} { |
---|
| 66 | after 10 |
---|
| 67 | # render the image |
---|
| 68 | renWin Render |
---|
| 69 | # rotate the active camera by one degree |
---|
| 70 | [ren1 GetActiveCamera] Azimuth 1 |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | # |
---|
| 74 | # Free up any objects we created. |
---|
| 75 | # |
---|
| 76 | vtkCommand DeleteAllObjects |
---|
| 77 | |
---|
| 78 | # |
---|
| 79 | # Exit the application. |
---|
| 80 | # |
---|
| 81 | exit |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|