A security patch will be applied between 1pm - 1:30pm, (UTC-0400), today- Aug 5th. No downtime is expected, but the site could be slow during that time.

Commit 4cb28678 authored by Sebastien Jourdain's avatar Sebastien Jourdain
Browse files

Fix JOGL interactor widget issue

The issue was related to the fact that the interactor was calling render on the view.
This does not work as in Java, external code can NOT request a direct render call.
Hence we deferred that render call to our Java component via a repaint().

Change-Id: I0c5db67dc2bc4d59e6628fdf781e24d51e3fb1ab
parent be117487
......@@ -65,11 +65,6 @@ public class vtkAbstractJoglComponent<T extends java.awt.Component> extends vtkA
vtkObject.JAVA_OBJECT_MANAGER.gc(false);
}
};
try {
this.uiComponent.getClass().getMethod("addGLEventListener", GLEventListener.class).invoke(this.uiComponent, this.glEventListener);
} catch (Exception e) {
throw new RuntimeException("Impossible to call addGLEventListener(listener) in a reflexive way.");
}
// Bind the interactor forwarder
vtkInteractorForwarder forwarder = this.getInteractorForwarder();
......@@ -80,6 +75,8 @@ public class vtkAbstractJoglComponent<T extends java.awt.Component> extends vtkA
// Make sure when VTK internaly request a Render, the Render get
// properly triggered
renderWindowToUse.AddObserver("WindowFrameEvent", this, "Render");
renderWindowToUse.GetInteractor().AddObserver("RenderEvent", this, "Render");
renderWindowToUse.GetInteractor().SetEnableRender(false);
}
public T getComponent() {
......
......@@ -19,5 +19,6 @@ public class vtkJoglCanvasComponent extends vtkAbstractJoglComponent<GLCanvas> {
public vtkJoglCanvasComponent(vtkRenderWindow renderWindow, GLCapabilities capabilities) {
super(renderWindow, new GLCanvas(capabilities));
this.getComponent().addGLEventListener(this.glEventListener);
}
}
......@@ -19,5 +19,6 @@ public class vtkJoglPanelComponent extends vtkAbstractJoglComponent<GLJPanel> {
public vtkJoglPanelComponent(vtkRenderWindow renderWindow, GLCapabilities capabilities) {
super(renderWindow, new GLJPanel(capabilities));
this.getComponent().addGLEventListener(this.glEventListener);
}
}
......@@ -2,10 +2,12 @@ package vtk.rendering;
import java.util.concurrent.locks.ReentrantLock;
import vtk.vtkAxesActor;
import vtk.vtkCamera;
import vtk.vtkGenericRenderWindowInteractor;
import vtk.vtkInteractorStyle;
import vtk.vtkInteractorStyleTrackballCamera;
import vtk.vtkOrientationMarkerWidget;
import vtk.vtkRenderWindow;
import vtk.vtkRenderer;
......@@ -156,4 +158,24 @@ public abstract class vtkAbstractComponent<T> implements vtkComponent<T> {
}
public abstract T getComponent();
/**
* Generic helper method used to attach orientation axes to a vtkComponent
*
* @param vtkComponent<?>
*/
public static void attachOrientationAxes(vtkComponent<?> component) {
// only build this once, because it creates its own renderer.
// Extra renderers causes issues with resetting.
vtkAxesActor axes = new vtkAxesActor();
vtkOrientationMarkerWidget axesWidget = new vtkOrientationMarkerWidget();
axesWidget.SetOutlineColor(0.9300, 0.5700, 0.1300);
axesWidget.SetOrientationMarker(axes);
axesWidget.SetInteractor(component.getRenderWindowInteractor());
axesWidget.SetDefaultRenderer(component.getRenderer());
axesWidget.SetViewport(0.0, 0.0, .2, .2);
axesWidget.EnabledOn();
axesWidget.InteractiveOff();
}
}
......@@ -8,9 +8,15 @@ import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import vtk.vtkActor;
import vtk.vtkBoxRepresentation;
import vtk.vtkBoxWidget2;
import vtk.vtkConeSource;
import vtk.vtkLookupTable;
import vtk.vtkNativeLibrary;
import vtk.vtkPolyDataMapper;
import vtk.vtkScalarBarRepresentation;
import vtk.vtkScalarBarWidget;
import vtk.vtkTransform;
import vtk.rendering.jogl.vtkAbstractJoglComponent;
import vtk.rendering.jogl.vtkJoglCanvasComponent;
import vtk.rendering.jogl.vtkJoglPanelComponent;
......@@ -38,11 +44,12 @@ public class JoglConeRendering {
// build VTK Pipeline
vtkConeSource cone = new vtkConeSource();
cone.SetResolution(8);
cone.Update();
vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
coneMapper.SetInputConnection(cone.GetOutputPort());
vtkActor coneActor = new vtkActor();
final vtkActor coneActor = new vtkActor();
coneActor.SetMapper(coneMapper);
// VTK rendering part
......@@ -51,6 +58,54 @@ public class JoglConeRendering {
joglWidget.getRenderer().AddActor(coneActor);
// Add orientation axes
vtkAbstractJoglComponent.attachOrientationAxes(joglWidget);
// Add Scalar bar widget
vtkLookupTable lut = new vtkLookupTable();
lut.SetHueRange(.66, 0);
lut.Build();
vtkScalarBarWidget scalarBar = new vtkScalarBarWidget();
scalarBar.SetInteractor(joglWidget.getRenderWindowInteractor());
scalarBar.GetScalarBarActor().SetTitle("Example");
scalarBar.GetScalarBarActor().SetLookupTable(lut);
scalarBar.GetScalarBarActor().SetOrientationToHorizontal();
scalarBar.GetScalarBarActor().SetTextPositionToPrecedeScalarBar();
vtkScalarBarRepresentation srep = (vtkScalarBarRepresentation) scalarBar.GetRepresentation();
srep.SetPosition(0.5, 0.053796);
srep.SetPosition2(0.33, 0.106455);
//scalarBar.ProcessEventsOff();
scalarBar.EnabledOn();
scalarBar.RepositionableOn();
// Add interactive 3D Widget
final vtkBoxRepresentation representation = new vtkBoxRepresentation();
representation.SetPlaceFactor(1.25);
representation.PlaceWidget(cone.GetOutput().GetBounds());
final vtkBoxWidget2 boxWidget = new vtkBoxWidget2();
boxWidget.SetRepresentation(representation);
boxWidget.SetInteractor(joglWidget.getRenderWindowInteractor());
boxWidget.SetPriority(1);
final Runnable callback = new Runnable() {
vtkTransform trasform = new vtkTransform();
public void run() {
vtkBoxRepresentation rep = (vtkBoxRepresentation) boxWidget.GetRepresentation();
rep.GetTransform(trasform);
coneActor.SetUserTransform(trasform);
}
};
// Bind widget
boxWidget.AddObserver("InteractionEvent", callback, "run");
representation.VisibilityOn();
representation.HandlesOn();
boxWidget.SetEnabled(1);
boxWidget.SetMoveFacesEnabled(1);
// UI part
JFrame frame = new JFrame("SimpleVTK");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
......@@ -60,13 +115,14 @@ public class JoglConeRendering {
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
joglWidget.resetCamera();
joglWidget.getComponent().requestFocus();
// Add r:ResetCamera and q:Quit key binding
joglWidget.getComponent().addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
if(e.getKeyChar() == 'r') {
if (e.getKeyChar() == 'r') {
joglWidget.resetCamera();
} else if (e.getKeyChar() == 'q') {
System.exit(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment