1 package vtk.rendering.awt;
3 import java.awt.event.MouseEvent;
4 import java.awt.event.MouseMotionAdapter;
5 import java.util.concurrent.locks.ReentrantLock;
8 import vtk.vtkGenericRenderWindowInteractor;
9 import vtk.vtkInteractorStyle;
10 import vtk.vtkInteractorStyleTrackballCamera;
12 import vtk.vtkRenderWindow;
13 import vtk.vtkRenderer;
14 import vtk.rendering.vtkComponent;
15 import vtk.rendering.vtkInteractorForwarder;
18 * Provide AWT based vtk rendering component using the vtkPanel class
19 * while exposing everything as a new rendering component.
21 * @author Sebastien Jourdain - sebastien.jourdain@kitware.com
23 * Notes: This class should be replaced down the road by the vtkAwtComponent
24 * but on some platform such as Windows the vtkAwtComponent
25 * produce a runtime error regarding invalid pixel format while
26 * the vtkPanelComponent which use vtkPanel works fine.
27 * For now, this class provide a good substitute with just a minor overhead.
30 public class vtkPanelComponent implements vtkComponent<vtkPanel> {
31 protected vtkPanel panel;
32 protected ReentrantLock lock;
33 protected vtkGenericRenderWindowInteractor windowInteractor;
34 protected vtkInteractorForwarder eventForwarder;
36 public vtkPanelComponent() {
37 this.panel = new vtkPanel();
38 this.lock = new ReentrantLock();
41 this.windowInteractor = new vtkGenericRenderWindowInteractor();
42 this.windowInteractor.SetRenderWindow(this.panel.GetRenderWindow());
43 this.windowInteractor.TimerEventResetsTimerOff();
45 this.windowInteractor.SetSize(200, 200);
46 this.windowInteractor.ConfigureEvent();
49 vtkInteractorStyleTrackballCamera style = new vtkInteractorStyleTrackballCamera();
50 this.windowInteractor.SetInteractorStyle(style);
52 // Setup event forwarder
53 this.eventForwarder = new vtkInteractorForwarder(this);
54 this.windowInteractor.AddObserver("CreateTimerEvent", this.eventForwarder, "StartTimer");
55 this.windowInteractor.AddObserver("DestroyTimerEvent", this.eventForwarder, "DestroyTimer");
57 // Remove unwanted listeners
58 this.panel.removeKeyListener(this.panel);
59 this.panel.removeMouseListener(this.panel);
60 this.panel.removeMouseMotionListener(this.panel);
61 this.panel.removeMouseWheelListener(this.panel);
63 // Add mouse listener that update interactor
64 this.panel.addMouseListener(this.eventForwarder);
65 this.panel.addMouseMotionListener(this.eventForwarder);
66 this.panel.addMouseWheelListener(this.eventForwarder);
68 // Make sure we update the light position when interacting
69 this.panel.addMouseMotionListener(new MouseMotionAdapter() {
70 public void mouseDragged(MouseEvent e) {
76 public void resetCamera() {
77 this.panel.resetCamera();
80 public void resetCameraClippingRange() {
81 this.panel.resetCameraClippingRange();
84 public vtkCamera getActiveCamera() {
85 return this.panel.GetRenderer().GetActiveCamera();
88 public vtkRenderer getRenderer() {
89 return this.panel.GetRenderer();
92 public vtkRenderWindow getRenderWindow() {
93 return this.panel.GetRenderWindow();
96 public vtkGenericRenderWindowInteractor getRenderWindowInteractor() {
97 return this.windowInteractor;
100 public void setInteractorStyle(vtkInteractorStyle style) {
101 this.getRenderWindowInteractor().SetInteractorStyle(style);
104 public void setSize(int w, int h) {
105 this.panel.setSize(w, h);
106 this.getRenderWindowInteractor().SetSize(w, h);
109 public vtkPanel getComponent() {
113 public void Delete() {
117 public void Render() {
121 public vtkInteractorForwarder getInteractorForwarder() {
122 return this.eventForwarder;
125 public ReentrantLock getVTKLock() {