1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # This example demonstrates how to use multiple renderers within a |
---|
4 | # render window. It is a variation of the Cone.py example. Please |
---|
5 | # refer to that example for additional documentation. |
---|
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 cone. The actor orchestrates rendering of |
---|
34 | # the mapper's graphics primitives. An actor also refers to properties via a |
---|
35 | # vtkProperty instance, and includes an internal transformation matrix. We |
---|
36 | # set this actor's mapper to be coneMapper which we created above. |
---|
37 | # |
---|
38 | coneActor = vtk.vtkActor() |
---|
39 | coneActor.SetMapper(coneMapper) |
---|
40 | |
---|
41 | # |
---|
42 | # Create two renderers and assign actors to them. A renderer renders into a |
---|
43 | # viewport within the vtkRenderWindow. It is part or all of a window on the |
---|
44 | # screen and it is responsible for drawing the actors it has. We also set |
---|
45 | # the background color here. In this example we are adding the same actor |
---|
46 | # to two different renderers; it is okay to add different actors to |
---|
47 | # different renderers as well. |
---|
48 | # |
---|
49 | ren1 = vtk.vtkRenderer() |
---|
50 | ren1.AddActor(coneActor) |
---|
51 | ren1.SetBackground(0.1, 0.2, 0.4) |
---|
52 | ren1.SetViewport(0.0, 0.0, 0.5, 1.0) |
---|
53 | |
---|
54 | ren2 = vtk.vtkRenderer() |
---|
55 | ren2.AddActor(coneActor) |
---|
56 | ren2.SetBackground(0.1, 0.2, 0.4) |
---|
57 | ren2.SetViewport(0.5, 0.0, 1.0, 1.0) |
---|
58 | |
---|
59 | # |
---|
60 | # Finally we create the render window which will show up on the screen. |
---|
61 | # We add our two renderers into the render window using AddRenderer. We also |
---|
62 | # set the size to be 600 pixels by 300. |
---|
63 | # |
---|
64 | renWin = vtk.vtkRenderWindow() |
---|
65 | renWin.AddRenderer( ren1 ) |
---|
66 | renWin.AddRenderer( ren2 ) |
---|
67 | renWin.SetSize(600, 300) |
---|
68 | |
---|
69 | # |
---|
70 | # Make one camera view 90 degrees from other. |
---|
71 | # |
---|
72 | ren1.GetActiveCamera().Azimuth(90) |
---|
73 | |
---|
74 | # |
---|
75 | # Now we loop over 360 degreeees and render the cone each time. |
---|
76 | # |
---|
77 | for i in range(0,360): |
---|
78 | time.sleep(0.03) |
---|
79 | |
---|
80 | renWin.Render() |
---|
81 | ren1.GetActiveCamera().Azimuth( 1 ) |
---|
82 | ren2.GetActiveCamera().Azimuth( 1 ) |
---|