1 | /*========================================================================= |
---|
2 | |
---|
3 | Program: Visualization Toolkit |
---|
4 | Module: $RCSfile: Cone3.cxx,v $ |
---|
5 | |
---|
6 | Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen |
---|
7 | All rights reserved. |
---|
8 | See Copyright.txt or http://www.kitware.com/Copyright.htm for details. |
---|
9 | |
---|
10 | This software is distributed WITHOUT ANY WARRANTY; without even |
---|
11 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
12 | PURPOSE. See the above copyright notice for more information. |
---|
13 | |
---|
14 | =========================================================================*/ |
---|
15 | // |
---|
16 | // This example demonstrates how to use multiple renderers within a |
---|
17 | // render window. It is a variation of the Cone.cxx example. Please |
---|
18 | // refer to that example for additional documentation. |
---|
19 | // |
---|
20 | |
---|
21 | // First include the required header files for the VTK classes we are using. |
---|
22 | #include "vtkConeSource.h" |
---|
23 | #include "vtkPolyDataMapper.h" |
---|
24 | #include "vtkRenderWindow.h" |
---|
25 | #include "vtkCamera.h" |
---|
26 | #include "vtkActor.h" |
---|
27 | #include "vtkRenderer.h" |
---|
28 | |
---|
29 | int main( int argc, char *argv[] ) |
---|
30 | { |
---|
31 | // |
---|
32 | // Next we create an instance of vtkConeSource and set some of its |
---|
33 | // properties. The instance of vtkConeSource "cone" is part of a |
---|
34 | // visualization pipeline (it is a source process object); it produces data |
---|
35 | // (output type is vtkPolyData) which other filters may process. |
---|
36 | // |
---|
37 | vtkConeSource *cone = vtkConeSource::New(); |
---|
38 | cone->SetHeight( 3.0 ); |
---|
39 | cone->SetRadius( 1.0 ); |
---|
40 | cone->SetResolution( 10 ); |
---|
41 | |
---|
42 | // |
---|
43 | // In this example we terminate the pipeline with a mapper process object. |
---|
44 | // (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
45 | // between the source and the mapper.) We create an instance of |
---|
46 | // vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
47 | // connect the output of the cone souece to the input of this mapper. |
---|
48 | // |
---|
49 | vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); |
---|
50 | coneMapper->SetInput( cone->GetOutput() ); |
---|
51 | |
---|
52 | // |
---|
53 | // Create an actor to represent the cone. The actor orchestrates rendering |
---|
54 | // of the mapper's graphics primitives. An actor also refers to properties |
---|
55 | // via a vtkProperty instance, and includes an internal transformation |
---|
56 | // matrix. We set this actor's mapper to be coneMapper which we created |
---|
57 | // above. |
---|
58 | // |
---|
59 | vtkActor *coneActor = vtkActor::New(); |
---|
60 | coneActor->SetMapper( coneMapper ); |
---|
61 | |
---|
62 | // |
---|
63 | // Create two renderers and assign actors to them. A renderer renders into |
---|
64 | // a viewport within the vtkRenderWindow. It is part or all of a window on |
---|
65 | // the screen and it is responsible for drawing the actors it has. We also |
---|
66 | // set the background color here. In this example we are adding the same |
---|
67 | // actor to two different renderers; it is okay to add different actors to |
---|
68 | // different renderers as well. |
---|
69 | // |
---|
70 | vtkRenderer *ren1= vtkRenderer::New(); |
---|
71 | ren1->AddActor( coneActor ); |
---|
72 | ren1->SetBackground( 0.1, 0.2, 0.4 ); |
---|
73 | ren1->SetViewport(0.0, 0.0, 0.5, 1.0); |
---|
74 | |
---|
75 | vtkRenderer *ren2= vtkRenderer::New(); |
---|
76 | ren2->AddActor( coneActor ); |
---|
77 | ren2->SetBackground( 0.2, 0.3, 0.5 ); |
---|
78 | ren2->SetViewport(0.5, 0.0, 1.0, 1.0); |
---|
79 | |
---|
80 | // |
---|
81 | // Finally we create the render window which will show up on the screen. |
---|
82 | // We put our renderer into the render window using AddRenderer. We also |
---|
83 | // set the size to be 300 pixels by 300. |
---|
84 | // |
---|
85 | vtkRenderWindow *renWin = vtkRenderWindow::New(); |
---|
86 | renWin->AddRenderer( ren1 ); |
---|
87 | renWin->AddRenderer( ren2 ); |
---|
88 | renWin->SetSize( 600, 300 ); |
---|
89 | |
---|
90 | // |
---|
91 | // Make one view 90 degrees from other. |
---|
92 | // |
---|
93 | ren1->GetActiveCamera()->Azimuth(90); |
---|
94 | |
---|
95 | // |
---|
96 | // Now we loop over 360 degreeees and render the cone each time. |
---|
97 | // |
---|
98 | int i; |
---|
99 | for (i = 0; i < 360; ++i) |
---|
100 | { |
---|
101 | // render the image |
---|
102 | renWin->Render(); |
---|
103 | // rotate the active camera by one degree |
---|
104 | ren1->GetActiveCamera()->Azimuth( 1 ); |
---|
105 | ren2->GetActiveCamera()->Azimuth( 1 ); |
---|
106 | } |
---|
107 | |
---|
108 | // |
---|
109 | // Free up any objects we created. All instances in VTK are deleted by |
---|
110 | // using the Delete() method. |
---|
111 | // |
---|
112 | cone->Delete(); |
---|
113 | coneMapper->Delete(); |
---|
114 | coneActor->Delete(); |
---|
115 | ren1->Delete(); |
---|
116 | ren2->Delete(); |
---|
117 | renWin->Delete(); |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|