1 | // |
---|
2 | // This example introduces the concepts of user interaction with VTK. |
---|
3 | // First, a different interaction style (than the default) is defined. |
---|
4 | // Second, the interaction is started. |
---|
5 | // |
---|
6 | // |
---|
7 | |
---|
8 | // we import the vtk wrapped classes forst |
---|
9 | import vtk.*; |
---|
10 | |
---|
11 | // then we define our class |
---|
12 | public class Cone5 { |
---|
13 | // in the static contructor we load in the native code |
---|
14 | // The libraries must be in your path to work |
---|
15 | static { |
---|
16 | System.loadLibrary("vtkCommonJava"); |
---|
17 | System.loadLibrary("vtkFilteringJava"); |
---|
18 | System.loadLibrary("vtkIOJava"); |
---|
19 | System.loadLibrary("vtkImagingJava"); |
---|
20 | System.loadLibrary("vtkGraphicsJava"); |
---|
21 | System.loadLibrary("vtkRenderingJava"); |
---|
22 | } |
---|
23 | |
---|
24 | // now the main program |
---|
25 | public static void main (String []args) throws Exception { |
---|
26 | // |
---|
27 | // Next we create an instance of vtkConeSource and set some of its |
---|
28 | // properties. The instance of vtkConeSource "cone" is part of a |
---|
29 | // visualization pipeline (it is a source process object); it produces |
---|
30 | // data (output type is vtkPolyData) which other filters may process. |
---|
31 | // |
---|
32 | vtkConeSource cone = new vtkConeSource(); |
---|
33 | cone.SetHeight( 3.0 ); |
---|
34 | cone.SetRadius( 1.0 ); |
---|
35 | cone.SetResolution( 10 ); |
---|
36 | |
---|
37 | // |
---|
38 | // In this example we terminate the pipeline with a mapper process object. |
---|
39 | // (Intermediate filters such as vtkShrinkPolyData could be inserted in |
---|
40 | // between the source and the mapper.) We create an instance of |
---|
41 | // vtkPolyDataMapper to map the polygonal data into graphics primitives. We |
---|
42 | // connect the output of the cone souece to the input of this mapper. |
---|
43 | // |
---|
44 | vtkPolyDataMapper coneMapper = new vtkPolyDataMapper(); |
---|
45 | coneMapper.SetInput(cone.GetOutput()); |
---|
46 | |
---|
47 | // |
---|
48 | // Create an actor to represent the cone. The actor orchestrates rendering of |
---|
49 | // the mapper's graphics primitives. An actor also refers to properties via a |
---|
50 | // vtkProperty instance, and includes an internal transformation matrix. We |
---|
51 | // set this actor's mapper to be coneMapper which we created above. |
---|
52 | // |
---|
53 | vtkActor coneActor = new vtkActor(); |
---|
54 | coneActor.SetMapper(coneMapper); |
---|
55 | |
---|
56 | // |
---|
57 | // Create the Renderer and assign actors to it. A renderer is like a |
---|
58 | // viewport. It is part or all of a window on the screen and it is |
---|
59 | // responsible for drawing the actors it has. We also set the |
---|
60 | // background color here. |
---|
61 | // |
---|
62 | vtkRenderer ren1 = new vtkRenderer(); |
---|
63 | ren1.AddActor(coneActor); |
---|
64 | ren1.SetBackground(0.1, 0.2, 0.4); |
---|
65 | |
---|
66 | // |
---|
67 | // Finally we create the render window which will show up on the screen. |
---|
68 | // We add our two renderers into the render window using AddRenderer. We also |
---|
69 | // set the size to be 600 pixels by 300. |
---|
70 | // |
---|
71 | vtkRenderWindow renWin = new vtkRenderWindow(); |
---|
72 | renWin.AddRenderer( ren1 ); |
---|
73 | renWin.SetSize(300, 300); |
---|
74 | |
---|
75 | // |
---|
76 | // Make one camera view 90 degrees from other. |
---|
77 | // |
---|
78 | ren1.GetActiveCamera().Azimuth(90); |
---|
79 | |
---|
80 | // |
---|
81 | // The vtkRenderWindowInteractor class watches for events (e.g., keypress, |
---|
82 | // mouse) in the vtkRenderWindow. These events are translated into event |
---|
83 | // invocations that VTK understands (see VTK/Common/vtkCommand.h for all |
---|
84 | // events that VTK processes). Then observers of these VTK events can |
---|
85 | // process them as appropriate. |
---|
86 | vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); |
---|
87 | iren.SetRenderWindow(renWin); |
---|
88 | |
---|
89 | // |
---|
90 | // By default the vtkRenderWindowInteractor instantiates an instance |
---|
91 | // of vtkInteractorStyle. vtkInteractorStyle translates a set of events |
---|
92 | // it observes into operations on the camera, actors, and/or properties |
---|
93 | // in the vtkRenderWindow associated with the vtkRenderWinodwInteractor. |
---|
94 | // Here we specify a particular interactor style. |
---|
95 | vtkInteractorStyleTrackballCamera style = |
---|
96 | new vtkInteractorStyleTrackballCamera(); |
---|
97 | iren.SetInteractorStyle(style); |
---|
98 | |
---|
99 | // |
---|
100 | // Unlike the previous examples where we performed some operations and then |
---|
101 | // exited, here we leave an event loop running. The user can use the mouse |
---|
102 | // and keyboard to perform the operations on the scene according to the |
---|
103 | // current interaction style. |
---|
104 | // |
---|
105 | |
---|
106 | // |
---|
107 | // Initialize and start the event loop. Once the render window appears, |
---|
108 | // mouse in the window to move the camera. The Start() method executes |
---|
109 | // an event loop which listens to user mouse and keyboard events. Note |
---|
110 | // that keypress-e exits the event loop. (Look in vtkInteractorStyle.h |
---|
111 | // for a summary of events, or the appropriate Doxygen documentation.) |
---|
112 | // |
---|
113 | iren.Initialize(); |
---|
114 | iren.Start(); |
---|
115 | } |
---|
116 | } |
---|