source: development/steve/visualisation/Tutorial/Step4/Cone4.java @ 3322

Last change on this file since 3322 was 2229, checked in by steve, 19 years ago

Moved directories into production and development parent directories

File size: 4.3 KB
Line 
1//
2// This example demonstrates the creation of multiple actors and the
3// manipulation of their properties and transformations. It is a
4// derivative of Cone.py, see that example for more information.
5//
6
7import java.lang.Thread;
8
9// we import the vtk wrapped classes forst
10import vtk.*;
11
12// then we define our class
13public class Cone4 {
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) throws Exception {
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
31    // data (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 first cone. The actor's properties are
50    // modified to give it different surface properties. By default, an actor
51    // is create with a property so the GetProperty() method can be used.
52    //
53    vtkActor coneActor = new vtkActor();
54    coneActor.SetMapper(coneMapper);
55    coneActor.GetProperty().SetColor(0.2, 0.63, 0.79);
56    coneActor.GetProperty().SetDiffuse(0.7);
57    coneActor.GetProperty().SetSpecular(0.4);
58    coneActor.GetProperty().SetSpecularPower(20);
59
60    //
61    // Create a property and directly manipulate it. Assign it to the
62    // second actor.
63    //
64    vtkProperty property = new vtkProperty();
65    property.SetColor(1.0, 0.3882, 0.2784);
66    property.SetDiffuse(0.7);
67    property.SetSpecular(0.4);
68    property.SetSpecularPower(20);
69
70    //
71    // Create a second actor and a property. The property is directly
72    // manipulated and then assigned to the actor. In this way, a single
73    // property can be shared among many actors. Note also that we use the
74    // same mapper as the first actor did. This way we avoid duplicating
75    // geometry, which may save lots of memory if the geoemtry is large.
76    vtkActor coneActor2 = new vtkActor();
77    coneActor2.SetMapper(coneMapper);
78    coneActor2.GetProperty().SetColor(0.2, 0.63, 0.79);
79    coneActor2.SetProperty(property);
80    coneActor2.SetPosition(0, 2, 0);
81   
82    //
83    // Create the Renderer and assign actors to it. A renderer is like a
84    // viewport. It is part or all of a window on the screen and it is
85    // responsible for drawing the actors it has.  We also set the
86    // background color here.
87    //
88    vtkRenderer ren1 = new vtkRenderer();
89    ren1.AddActor(coneActor);
90    ren1.AddActor(coneActor2);
91    ren1.SetBackground(0.1, 0.2, 0.4);
92   
93    //
94    // Finally we create the render window which will show up on the screen.
95    // We add our two renderers into the render window using AddRenderer. We also
96    // set the size to be 600 pixels by 300.
97    //
98    vtkRenderWindow renWin = new vtkRenderWindow();
99    renWin.AddRenderer( ren1 );
100    renWin.SetSize(300, 300);
101   
102    //
103    // Make one camera view 90 degrees from other.
104    //
105    ren1.GetActiveCamera().Azimuth(90);
106   
107    //
108    // now we loop over 360 degreeees and render the cone each time
109    //
110    int i;
111    for (i = 0; i < 360; ++i)
112      {
113      Thread.sleep(10);
114      // render the image
115      renWin.Render();
116      // rotate the active camera by one degree
117      ren1.GetActiveCamera().Azimuth( 1 );
118      }
119    } 
120}
121
Note: See TracBrowser for help on using the repository browser.