[2229] | 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 | |
---|
| 8 | import vtk |
---|
| 9 | import 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 | # |
---|
| 17 | cone = vtk.vtkConeSource () |
---|
| 18 | cone.SetHeight( 3.0 ) |
---|
| 19 | cone.SetRadius( 1.0 ) |
---|
| 20 | cone.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 | # |
---|
| 29 | coneMapper = vtk.vtkPolyDataMapper() |
---|
| 30 | coneMapper.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 | # |
---|
| 37 | coneActor = vtk.vtkActor() |
---|
| 38 | coneActor.SetMapper(coneMapper) |
---|
| 39 | coneActor.GetProperty().SetColor(0.2, 0.63, 0.79) |
---|
| 40 | coneActor.GetProperty().SetDiffuse(0.7) |
---|
| 41 | coneActor.GetProperty().SetSpecular(0.4) |
---|
| 42 | coneActor.GetProperty().SetSpecularPower(20) |
---|
| 43 | |
---|
| 44 | # |
---|
| 45 | # Create a property and directly manipulate it. Assign it to the |
---|
| 46 | # second actor. |
---|
| 47 | # |
---|
| 48 | property = vtk.vtkProperty() |
---|
| 49 | property.SetColor(1.0, 0.3882, 0.2784) |
---|
| 50 | property.SetDiffuse(0.7) |
---|
| 51 | property.SetSpecular(0.4) |
---|
| 52 | property.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. |
---|
| 60 | coneActor2 = vtk.vtkActor() |
---|
| 61 | coneActor2.SetMapper(coneMapper) |
---|
| 62 | coneActor2.GetProperty().SetColor(0.2, 0.63, 0.79) |
---|
| 63 | coneActor2.SetProperty(property) |
---|
| 64 | coneActor2.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 | # |
---|
| 71 | ren1 = vtk.vtkRenderer() |
---|
| 72 | ren1.AddActor(coneActor) |
---|
| 73 | ren1.AddActor(coneActor2) |
---|
| 74 | ren1.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 | # |
---|
| 81 | renWin = vtk.vtkRenderWindow() |
---|
| 82 | renWin.AddRenderer(ren1) |
---|
| 83 | renWin.SetSize(300, 300) |
---|
| 84 | |
---|
| 85 | # |
---|
| 86 | # Now we loop over 360 degreeees and render the cone each time. |
---|
| 87 | # |
---|
| 88 | for i in range(0,360): |
---|
| 89 | time.sleep(0.03) |
---|
| 90 | |
---|
| 91 | renWin.Render() |
---|
| 92 | ren1.GetActiveCamera().Azimuth( 1 ) |
---|
| 93 | |
---|