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 | // We import the vtk wrapped classes first. |
---|
9 | import vtk.*; |
---|
10 | |
---|
11 | // Then we define our class. |
---|
12 | public class Cone { |
---|
13 | |
---|
14 | // In the static contructor we load in the native code. |
---|
15 | // The libraries must be in your path to work. |
---|
16 | static { |
---|
17 | System.loadLibrary("vtkCommonJava"); |
---|
18 | System.loadLibrary("vtkFilteringJava"); |
---|
19 | System.loadLibrary("vtkIOJava"); |
---|
20 | System.loadLibrary("vtkImagingJava"); |
---|
21 | System.loadLibrary("vtkGraphicsJava"); |
---|
22 | System.loadLibrary("vtkRenderingJava"); |
---|
23 | } |
---|
24 | |
---|
25 | // now the main program |
---|
26 | public static void main (String []args) { |
---|
27 | // |
---|
28 | // Next we create an instance of vtkConeSource and set some of its |
---|
29 | // properties. The instance of vtkConeSource "cone" is part of a |
---|
30 | // visualization pipeline (it is a source process object); it produces data |
---|
31 | // (output type is vtkPolyData) which other filters may process. |
---|
32 | // |
---|
33 | vtkConeSource cone = new vtkConeSource(); |
---|
34 | cone.SetHeight( 3.0 ); |
---|
35 | cone.SetRadius( 1.0 ); |
---|
36 | cone.SetResolution( 10 ); |
---|
37 | |
---|
38 | // |
---|
39 | // In this example we terminate the pipeline with a mapper process object. |
---|
40 | // (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
41 | // between the source and the mapper.) We create an instance of |
---|
42 | // vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
43 | // connect the output of the cone souece to the input of this mapper. |
---|
44 | // |
---|
45 | vtkPolyDataMapper coneMapper = new vtkPolyDataMapper(); |
---|
46 | coneMapper.SetInput( cone.GetOutput() ); |
---|
47 | |
---|
48 | // |
---|
49 | // Create an actor to represent the cone. The actor orchestrates rendering |
---|
50 | // of the mapper's graphics primitives. An actor also refers to properties |
---|
51 | // via a vtkProperty instance, and includes an internal transformation |
---|
52 | // matrix. We set this actor's mapper to be coneMapper which we created |
---|
53 | // above. |
---|
54 | // |
---|
55 | vtkActor coneActor = new vtkActor(); |
---|
56 | coneActor.SetMapper( coneMapper ); |
---|
57 | |
---|
58 | // |
---|
59 | // Create the Renderer and assign actors to it. A renderer is like a |
---|
60 | // viewport. It is part or all of a window on the screen and it is |
---|
61 | // responsible for drawing the actors it has. We also set the background |
---|
62 | // color here |
---|
63 | // |
---|
64 | vtkRenderer ren1 = new vtkRenderer(); |
---|
65 | ren1.AddActor( coneActor ); |
---|
66 | ren1.SetBackground( 0.1, 0.2, 0.4 ); |
---|
67 | |
---|
68 | // |
---|
69 | // Finally we create the render window which will show up on the screen |
---|
70 | // We put our renderer into the render window using AddRenderer. We also |
---|
71 | // set the size to be 300 pixels by 300 |
---|
72 | // |
---|
73 | vtkRenderWindow renWin = new vtkRenderWindow(); |
---|
74 | renWin.AddRenderer( ren1 ); |
---|
75 | renWin.SetSize( 300, 300 ); |
---|
76 | |
---|
77 | // |
---|
78 | // now we loop over 360 degreeees and render the cone each time |
---|
79 | // |
---|
80 | int i; |
---|
81 | for (i = 0; i < 360; ++i) |
---|
82 | { |
---|
83 | // render the image |
---|
84 | renWin.Render(); |
---|
85 | // rotate the active camera by one degree |
---|
86 | ren1.GetActiveCamera().Azimuth( 1 ); |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|