[2229] | 1 | /*========================================================================= |
---|
| 2 | |
---|
| 3 | Program: Visualization Toolkit |
---|
| 4 | Module: $RCSfile: Cone.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 creates a polygonal model of a cone, and then renders it to |
---|
| 17 | // the screen. It will rotate the cone 360 degrees and then exit. The basic |
---|
| 18 | // setup of source -> mapper -> actor -> renderer -> renderwindow is |
---|
| 19 | // typical of most VTK programs. |
---|
| 20 | // |
---|
| 21 | |
---|
| 22 | // First include the required header files for the VTK classes we are using. |
---|
| 23 | #include "vtkConeSource.h" |
---|
| 24 | #include "vtkPolyDataMapper.h" |
---|
| 25 | #include "vtkRenderWindow.h" |
---|
| 26 | #include "vtkCamera.h" |
---|
| 27 | #include "vtkActor.h" |
---|
| 28 | #include "vtkRenderer.h" |
---|
| 29 | |
---|
| 30 | int main( int argc, char *argv[] ) |
---|
| 31 | { |
---|
| 32 | // |
---|
| 33 | // Next we create an instance of vtkConeSource and set some of its |
---|
| 34 | // properties. The instance of vtkConeSource "cone" is part of a |
---|
| 35 | // visualization pipeline (it is a source process object); it produces data |
---|
| 36 | // (output type is vtkPolyData) which other filters may process. |
---|
| 37 | // |
---|
| 38 | vtkConeSource *cone = vtkConeSource::New(); |
---|
| 39 | cone->SetHeight( 3.0 ); |
---|
| 40 | cone->SetRadius( 1.0 ); |
---|
| 41 | cone->SetResolution( 10 ); |
---|
| 42 | |
---|
| 43 | // |
---|
| 44 | // In this example we terminate the pipeline with a mapper process object. |
---|
| 45 | // (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
| 46 | // between the source and the mapper.) We create an instance of |
---|
| 47 | // vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
| 48 | // connect the output of the cone souece to the input of this mapper. |
---|
| 49 | // |
---|
| 50 | vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New(); |
---|
| 51 | coneMapper->SetInput( cone->GetOutput() ); |
---|
| 52 | |
---|
| 53 | // |
---|
| 54 | // Create an actor to represent the cone. The actor orchestrates rendering |
---|
| 55 | // of the mapper's graphics primitives. An actor also refers to properties |
---|
| 56 | // via a vtkProperty instance, and includes an internal transformation |
---|
| 57 | // matrix. We set this actor's mapper to be coneMapper which we created |
---|
| 58 | // above. |
---|
| 59 | // |
---|
| 60 | vtkActor *coneActor = vtkActor::New(); |
---|
| 61 | coneActor->SetMapper( coneMapper ); |
---|
| 62 | |
---|
| 63 | // |
---|
| 64 | // Create the Renderer and assign actors to it. A renderer is like a |
---|
| 65 | // viewport. It is part or all of a window on the screen and it is |
---|
| 66 | // responsible for drawing the actors it has. We also set the background |
---|
| 67 | // color here. |
---|
| 68 | // |
---|
| 69 | vtkRenderer *ren1= vtkRenderer::New(); |
---|
| 70 | ren1->AddActor( coneActor ); |
---|
| 71 | ren1->SetBackground( 0.1, 0.2, 0.4 ); |
---|
| 72 | |
---|
| 73 | // |
---|
| 74 | // Finally we create the render window which will show up on the screen. |
---|
| 75 | // We put our renderer into the render window using AddRenderer. We also |
---|
| 76 | // set the size to be 300 pixels by 300. |
---|
| 77 | // |
---|
| 78 | vtkRenderWindow *renWin = vtkRenderWindow::New(); |
---|
| 79 | renWin->AddRenderer( ren1 ); |
---|
| 80 | renWin->SetSize( 300, 300 ); |
---|
| 81 | |
---|
| 82 | // |
---|
| 83 | // Now we loop over 360 degreeees and render the cone each time. |
---|
| 84 | // |
---|
| 85 | int i; |
---|
| 86 | for (i = 0; i < 360; ++i) |
---|
| 87 | { |
---|
| 88 | // render the image |
---|
| 89 | renWin->Render(); |
---|
| 90 | // rotate the active camera by one degree |
---|
| 91 | ren1->GetActiveCamera()->Azimuth( 1 ); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // |
---|
| 95 | // Free up any objects we created. All instances in VTK are deleted by |
---|
| 96 | // using the Delete() method. |
---|
| 97 | // |
---|
| 98 | cone->Delete(); |
---|
| 99 | coneMapper->Delete(); |
---|
| 100 | coneActor->Delete(); |
---|
| 101 | ren1->Delete(); |
---|
| 102 | renWin->Delete(); |
---|
| 103 | |
---|
| 104 | return 0; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|