Commit 86347484 authored by Sebastien Jourdain's avatar Sebastien Jourdain Committed by Kitware Robot

Merge topic 'java-jogl-update'

b6df9937 Fix VTK/Java JOGL
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1658
parents 71be20bd b6df9937
......@@ -47,7 +47,7 @@ if(VTK_JAVA_SWT_COMPONENT)
endif()
# Add the option for build the JOGL component to VTK.
set(JOGL_VERSION "2.0.2")
set(JOGL_VERSION "2.3.2")
option(VTK_JAVA_JOGL_COMPONENT "Need JOGL jar files" OFF)
if(VTK_JAVA_JOGL_COMPONENT)
......
......@@ -2,16 +2,35 @@ In order to build the JOGL rendering classes, you will need to have JOGL
libraries installed on your system. For that you can use Maven to download
for you the proper JARs.
List of possible classifiers:
- natives-android-aarch64
- natives-android-armv6
- natives-linux-amd64
- natives-linux-armv6
- natives-linux-armv6hf
- natives-linux-i586
- natives-macosx-universal
- natives-solaris-amd64
- natives-solaris-i586
- natives-windows-amd64
- natives-windows-i586
For that you can run the following command lines:
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get
-DrepoUrl=http://download.java.net/maven/2/
-Dartifact=org.jogamp.gluegen:gluegen-rt:2.0.2
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=org.jogamp.gluegen:gluegen-rt:2.3.2
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=org.jogamp.gluegen:gluegen-rt:2.3.2:jar:CLASSIFIER
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get
-DrepoUrl=http://download.java.net/maven/2/
-Dartifact=org.jogamp.jogl:jogl-all-main:2.0.2
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=org.jogamp.jogl:jogl-all:2.3.2
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get
-DrepoUrl=http://download.java.net/maven/2/
-Dartifact=org.jogamp.jogl:jogl-all:2.0.2
$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=org.jogamp.jogl:jogl-all:2.3.2:jar:CLASSIFIER
package vtk.rendering.jogl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLEventListener;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLEventListener;
import vtk.vtkGenericOpenGLRenderWindow;
import vtk.vtkObject;
......@@ -46,7 +46,7 @@ public class vtkAbstractJoglComponent<T extends java.awt.Component> extends vtkA
// Init VTK OpenGL RenderWindow
vtkAbstractJoglComponent.this.glRenderWindow.SetMapped(1);
vtkAbstractJoglComponent.this.glRenderWindow.SetPosition(0, 0);
vtkAbstractJoglComponent.this.setSize(drawable.getWidth(), drawable.getHeight());
vtkAbstractJoglComponent.this.setSize(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
vtkAbstractJoglComponent.this.glRenderWindow.OpenGLInit();
}
......
package vtk.rendering.jogl;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import vtk.vtkGenericOpenGLRenderWindow;
import vtk.vtkRenderWindow;
......
package vtk.rendering.jogl;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLJPanel;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLJPanel;
import vtk.vtkGenericOpenGLRenderWindow;
import vtk.vtkRenderWindow;
......
package vtk.rendering;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
......@@ -8,6 +10,7 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.lang.reflect.Field;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
......@@ -36,6 +39,7 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
private int shiftPressed;
private vtkComponent<?> component;
private double updateRate, updateRateRelease;
private double scaleFactor = 1;
private ScheduledExecutorService scheduler;
private Runnable eventTick;
private vtkEventInterceptor eventInterceptor;
......@@ -45,6 +49,7 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
this.lastX = this.lastY = this.ctrlPressed = 0;
this.updateRate = 5.0;
this.updateRateRelease = 0.01;
this.scaleFactor = vtkInteractorForwarder.getDisplayScale();
this.eventTick = new Runnable() {
......@@ -124,11 +129,14 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
return;
}
// Update scale factor if needed
this.scaleFactor = vtkInteractorForwarder.getGraphicDeviceScale(e.getComponent().getGraphicsConfiguration().getDevice());
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRate);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
component.getRenderWindowInteractor().SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, '0', 0, "0");
......@@ -164,8 +172,8 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRateRelease);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
component.getRenderWindowInteractor().SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, '0', 0, "0");
......@@ -201,8 +209,8 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRateRelease);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
component.getRenderWindowInteractor().SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, '0', 0, "0");
......@@ -236,8 +244,8 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRateRelease);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
component.getRenderWindowInteractor().SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, '0', 0, "0");
......@@ -262,8 +270,8 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRateRelease);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
component.getRenderWindowInteractor().SetEventInformationFlipY(lastX, lastY, ctrlPressed, shiftPressed, '0', 0, "0");
......@@ -295,8 +303,8 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
try {
component.getVTKLock().lockInterruptibly();
component.getRenderWindow().SetDesiredUpdateRate(this.updateRateRelease);
lastX = e.getX();
lastY = e.getY();
lastX = (int)(e.getX() * scaleFactor);
lastY = (int)(e.getY() * scaleFactor);
ctrlPressed = (e.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK ? 1 : 0;
shiftPressed = (e.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK ? 1 : 0;
if (e.getWheelRotation() > 0) {
......@@ -353,4 +361,26 @@ public class vtkInteractorForwarder implements MouseListener, MouseMotionListene
return;
}
}
public static int getDisplayScale() {
GraphicsDevice graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
return getGraphicDeviceScale(graphicsDevice);
}
public static int getGraphicDeviceScale(GraphicsDevice device) {
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
if (scale instanceof Integer) {
return ((Integer) scale).intValue();
}
System.out.println("Invalid scale type: " + scale);
}
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}
}
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