提交 0ea74468 编写于 作者: M Mathieu Bastian

Fix issues on visualization engine, updating to the latest JOGL version #1098...

Fix issues on visualization engine, updating to the latest JOGL version #1098 and fix HiDPI problems #961
上级 66ba514c
......@@ -75,7 +75,7 @@ import org.gephi.graph.api.Node;
* To provide a context menu item, a class has to implement this interface and
* have a
* <code>@ServiceProvider</code> annotation
* @author Eduardo Ramos <eduramiba@gmail.com>
* @author Eduardo Ramos
*/
public interface GraphContextMenuItem {
......
......@@ -75,12 +75,12 @@
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.1.3</version>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.1.3</version>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
......@@ -122,6 +122,14 @@
<build>
<plugins>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
......
......@@ -41,14 +41,24 @@
*/
package org.gephi.visualization;
import javax.media.opengl.GLProfile;
import com.jogamp.newt.NewtFactory;
import com.jogamp.opengl.GLProfile;
import org.openide.modules.ModuleInstall;
public class Installer extends ModuleInstall {
@Override
public void restored() {
// Workaround for bug jogl 1163
NewtFactory.setWindowIcons(null);
//Init JOGL, recommended
GLProfile.initSingleton();
}
@Override
public void close() {
// Destroy JOGL
VizController.getInstance().destroy();
}
}
......@@ -49,6 +49,7 @@ import org.gephi.project.api.Workspace;
import org.gephi.project.api.WorkspaceListener;
import org.gephi.visualization.api.VisualizationController;
import org.gephi.visualization.api.selection.SelectionManager;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.GraphIO;
import org.gephi.visualization.apiimpl.Scheduler;
import org.gephi.visualization.apiimpl.VizConfig;
......@@ -61,7 +62,7 @@ import org.gephi.visualization.opengl.AbstractEngine;
import org.gephi.visualization.opengl.CompatibilityEngine;
import org.gephi.visualization.scheduler.CompatibilityScheduler;
import org.gephi.visualization.screenshot.ScreenshotMaker;
import org.gephi.visualization.swing.GraphDrawableImpl;
import org.gephi.visualization.swing.GLAbstractListener;
import org.gephi.visualization.swing.StandardGraphIO;
import org.gephi.visualization.text.TextManager;
import org.openide.util.Lookup;
......@@ -88,7 +89,7 @@ public class VizController implements VisualizationController {
return instance;
}
//Architecture
private GraphDrawableImpl drawable;
private GLAbstractListener drawable;
private AbstractEngine engine;
private Scheduler scheduler;
private VizConfig vizConfig;
......@@ -122,8 +123,8 @@ public class VizController implements VisualizationController {
if (vizConfig.isUseGLJPanel()) {
drawable = commander.createPanel();
} else {
// drawable = commander.createCanvas();
drawable = commander.createNewtCanvas();
// drawable = commander.createCanvas();
}
drawable.initArchitecture();
engine.initArchitecture();
......@@ -249,7 +250,7 @@ public class VizController implements VisualizationController {
return currentModel;
}
public GraphDrawableImpl getDrawable() {
public GraphDrawable getDrawable() {
return drawable;
}
......
......@@ -41,9 +41,9 @@
*/
package org.gephi.visualization.api.initializer;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.VizConfig;
import org.gephi.visualization.model.Model;
......@@ -73,14 +73,4 @@ public abstract class Modeler {
public abstract void beforeDisplay(GL2 gl, GLU glu);
public abstract void afterDisplay(GL2 gl, GLU glu);
protected float cameraDistance(NodeModel object) {
float[] cameraLocation = controller.getDrawable().getCameraLocation();
double distance = Math.sqrt(Math.pow((double) object.getNode().x() - cameraLocation[0], 2d)
+ Math.pow((double) object.getNode().y() - cameraLocation[1], 2d)
+ Math.pow((double) object.getNode().z() - cameraLocation[2], 2d));
object.setCameraDistance((float) distance);
return (float) distance - object.getNode().size();
}
}
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.api.selection;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.model.node.NodeModel;
......
......@@ -41,10 +41,13 @@
*/
package org.gephi.visualization.apiimpl;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import java.awt.Component;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.gephi.lib.gleem.linalg.Vec3f;
import org.gephi.visualization.config.GraphicalConfiguration;
/**
*
......@@ -54,6 +57,8 @@ public interface GraphDrawable {
public Component getGraphComponent();
public float getGlobalScale();
public int getViewportHeight();
public int getViewportWidth();
......@@ -75,4 +80,18 @@ public interface GraphDrawable {
public FloatBuffer getProjectionMatrix();
public IntBuffer getViewport();
public double[] myGluProject(float x, float y);
public float[] myGluProject(float x, float y, float z);
public void display();
public void setCameraPosition(GL2 gl, GLU glu);
public void initConfig(GL2 gl);
public GraphicalConfiguration getGraphicalConfiguration();
public void destroy();
}
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.apiimpl;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
/**
*
......
......@@ -159,7 +159,6 @@ public class VizConfig {
public static final boolean DEFAULT_DISABLE_LOD = false;
public static final boolean DEFAULT_SHOW_HULLS = true;
public static final float DEFAULT_EDGE_SCALE = 2f;
public static final float DEFAULT_META_EDGE_SCALE = 2f;
//Default config - loaded in the VizModel
protected boolean defaultUse3d = NbPreferences.forModule(VizConfig.class).getBoolean(USE_3D, DEFAULT_USE_3D);
protected boolean defaultLighting = false; //Overriden by use3d
......
......@@ -47,6 +47,7 @@ import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
......@@ -54,14 +55,15 @@ import org.gephi.project.api.WorkspaceListener;
import org.gephi.tools.api.ToolController;
import org.gephi.ui.utils.UIUtils;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.opengl.AbstractEngine;
import org.gephi.visualization.swing.GraphDrawableImpl;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
@ConvertAsProperties(dtd = "-//org.gephi.visualization.component//Graph//EN",
autostore = false)
......@@ -77,7 +79,7 @@ public class GraphTopComponent extends TopComponent implements AWTEventListener
private AbstractEngine engine;
private VizBarController vizBarController;
// private Map<Integer, ContextMenuItemManipulator> keyActionMappings = new HashMap<Integer, ContextMenuItemManipulator>();
private final transient GraphDrawableImpl drawable;
private final transient GraphDrawable drawable;
public GraphTopComponent() {
initComponents();
......@@ -93,24 +95,24 @@ public class GraphTopComponent extends TopComponent implements AWTEventListener
drawable = VizController.getInstance().getDrawable();
//Request component activation and therefore initialize JOGL2 component
// WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
// @Override
// public void run() {
// open();
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// requestActive();
// add(drawable.getGraphComponent(), BorderLayout.CENTER);
// remove(waitingLabel);
// }
// });
// }
// });
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
@Override
public void run() {
open();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
requestActive();
add(drawable.getGraphComponent(), BorderLayout.CENTER);
remove(waitingLabel);
}
});
}
});
initKeyEventContextMenuActionMappings();
add(drawable.getGraphComponent(), BorderLayout.CENTER);
remove(waitingLabel);
// add(drawable.getGraphComponent(), BorderLayout.CENTER);
// remove(waitingLabel);
}
private void initCollapsePanel() {
......@@ -286,23 +288,6 @@ public class GraphTopComponent extends TopComponent implements AWTEventListener
private javax.swing.JLabel waitingLabel;
// End of variables declaration//GEN-END:variables
@Override
protected void componentShowing() {
super.componentShowing();
engine.startDisplay();
}
@Override
protected void componentHidden() {
super.componentHidden();
engine.stopDisplay();
}
@Override
public void componentOpened() {
}
@Override
protected void componentActivated() {
java.awt.Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
......@@ -313,11 +298,6 @@ public class GraphTopComponent extends TopComponent implements AWTEventListener
java.awt.Toolkit.getDefaultToolkit().removeAWTEventListener(this);
}
@Override
public void componentClosed() {
engine.stopDisplay();
}
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
......
......@@ -41,11 +41,11 @@
*/
package org.gephi.visualization.config;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.opengl.GL2;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLProfile;
import com.jogamp.nativewindow.AbstractGraphicsDevice;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLDrawableFactory;
import com.jogamp.opengl.GLProfile;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.openide.util.NbBundle;
......
package org.gephi.visualization.model;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.visualization.VizModel;
/**
......
......@@ -44,8 +44,8 @@ package org.gephi.visualization.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.visualization.VizController;
import org.gephi.visualization.api.initializer.Modeler;
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.edge;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vec2f;
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.edge;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vec3f;
......
......@@ -42,8 +42,8 @@
package org.gephi.visualization.model.edge;
import java.awt.geom.Rectangle2D;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.ElementProperties;
import org.gephi.visualization.VizModel;
......
......@@ -41,9 +41,9 @@
*/
package org.gephi.visualization.model.edge;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.graph.api.Edge;
import org.gephi.visualization.api.initializer.Modeler;
import org.gephi.visualization.model.Model;
......
......@@ -43,8 +43,8 @@ package org.gephi.visualization.model.edge;
import com.jogamp.common.nio.Buffers;
import java.nio.FloatBuffer;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vec3f;
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.edge;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vec3f;
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizModel;
......
......@@ -41,9 +41,9 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.graph.api.Node;
import org.gephi.visualization.model.Model;
import org.gephi.visualization.opengl.CompatibilityEngine;
......
......@@ -75,7 +75,6 @@ public abstract class NodeModel implements Model, TextModel {
//Edges
protected EdgeModel[] edges;
protected int edgeLength;
protected int edgeCount;
public NodeModel(Node node) {
this.node = node;
......@@ -266,7 +265,6 @@ public abstract class NodeModel implements Model, TextModel {
int id = edgeLength++;
growEdges(id);
edges[id] = model;
edgeCount++;
if (model.getSourceModel() == this) {
model.setOctantSourceId(id);
} else {
......@@ -282,7 +280,6 @@ public abstract class NodeModel implements Model, TextModel {
id = model.getOctantTargetId();
}
edges[id] = null;
edgeCount--;
}
public EdgeModel[] getEdges() {
......
......@@ -31,4 +31,14 @@ public abstract class NodeModeler extends Modeler {
float rad = Math.abs((float) res[0] - object.getViewportX());
object.setViewportRadius(rad);
}
protected float cameraDistance(NodeModel object) {
float[] cameraLocation = controller.getDrawable().getCameraLocation();
double distance = Math.sqrt(Math.pow((double) object.getNode().x() - cameraLocation[0], 2d)
+ Math.pow((double) object.getNode().y() - cameraLocation[1], 2d)
+ Math.pow((double) object.getNode().z() - cameraLocation[2], 2d));
object.setCameraDistance((float) distance);
return (float) distance - object.getNode().size();
}
}
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizController;
......
......@@ -41,9 +41,9 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.graph.api.Node;
import org.gephi.visualization.model.Model;
import org.gephi.visualization.opengl.CompatibilityEngine;
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizModel;
......
......@@ -41,9 +41,9 @@
*/
package org.gephi.visualization.model.node;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.graph.api.Node;
import org.gephi.visualization.model.Model;
import org.gephi.visualization.opengl.CompatibilityEngine;
......
package org.gephi.visualization.octree;
import com.jogamp.opengl.util.gl2.GLUT;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.visualization.model.node.NodeModel;
/**
......
......@@ -7,15 +7,15 @@ import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.graph.api.Node;
import org.gephi.lib.gleem.linalg.Vec3f;
import org.gephi.visualization.GraphLimits;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.model.edge.EdgeModel;
import org.gephi.visualization.model.node.NodeModel;
import org.gephi.visualization.swing.GraphDrawableImpl;
/**
*
......@@ -27,7 +27,7 @@ public class Octree {
protected static final int NULL_ID = -1;
//Architecture
protected GraphLimits limits;
private GraphDrawableImpl drawable;
private GraphDrawable drawable;
protected VizController vizController;
//Params
protected final int maxDepth;
......
......@@ -41,15 +41,16 @@
*/
package org.gephi.visualization.opengl;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
import org.gephi.visualization.api.selection.SelectionArea;
import org.gephi.visualization.apiimpl.Engine;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.GraphIO;
import org.gephi.visualization.apiimpl.Scheduler;
import org.gephi.visualization.apiimpl.VizConfig;
......@@ -59,7 +60,6 @@ import org.gephi.visualization.model.ModelClass;
import org.gephi.visualization.model.ModelClassLibrary;
import org.gephi.visualization.model.node.NodeModel;
import org.gephi.visualization.octree.Octree;
import org.gephi.visualization.swing.GraphDrawableImpl;
import org.gephi.visualization.text.TextManager;
/**
......@@ -76,7 +76,7 @@ public abstract class AbstractEngine implements Engine, VizArchitecture {
MIN_X, MAX_X, MIN_Y, MAX_Y, MIN_Z, MAX_Z
};
//Architecture
protected GraphDrawableImpl graphDrawable;
protected GraphDrawable graphDrawable;
protected GraphIO graphIO;
protected VizEventManager vizEventManager;
protected SelectionArea currentSelectionArea;
......
......@@ -45,9 +45,9 @@ import java.awt.Color;
import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.Iterator;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import org.gephi.visualization.VizController;
import org.gephi.visualization.VizModel;
import org.gephi.visualization.api.initializer.Modeler;
......
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.visualization.opengl;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import javax.swing.SwingUtilities;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.ModuleInstall;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
/**
* Manages the JOGL2 natives loading. Thanks to Michael Bien, Lilian Chamontin
* and Kenneth Russell.
*
* @author Mathieu Bastan
*/
public class JOGLNativesInstaller extends ModuleInstall {
private NativeLibInfo nativeLibInfo; //Compatible nativeLibInfo with OS/Arch
private boolean exitOnFatalError = true;
@Override
public void restored() {
if (System.getProperty("org.gephi.joGL2.init", "true").equals("true")) {
if (findCompatibleOsAndArch()) {
String nativeArch = nativeLibInfo.getSubDirectoryPath();
File joglDistFolder = InstalledFileLocator.getDefault().locate("modules/lib/" + nativeArch, "org-gephi-visualization-impl", false);
if (joglDistFolder != null) {
loadNatives(joglDistFolder);
} else {
fatalError(String.format(NbBundle.getMessage(JOGLNativesInstaller.class, "JOGLNativesInstaller_error1"), new Object[]{nativeArch}));
}
}
}
}
//=============================================================
//=============================================================
private boolean findCompatibleOsAndArch() {
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
if (checkOSAndArch(osName, osArch)) {
return true;
} else {
fatalError(String.format(NbBundle.getMessage(JOGLNativesInstaller.class, "JOGLNativesInstaller_error2"), new Object[]{osName, osArch}));
}
return false;
}
boolean checkOSAndArch(String osName, String osArch) {
for (int i = 0; i < allNativeLibInfo.length; i++) {
NativeLibInfo info = allNativeLibInfo[i];
if (info.matchesOSAndArch(osName, osArch)) {
nativeLibInfo = info;
return true;
}
}
return false;
}
private void loadNatives(final File nativeLibDir) {
try {
// back to the EDT
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
System.out.println("Loading native libraries");
// disable JOGL2 and GlueGen runtime library loading from elsewhere
// com.sun.openGL2.impl.NativeLibLoader.disableLoading();
// com.sun.gluegen.runtime.NativeLibLoader.disableLoading();
// Open GlueGen runtime library optimistically. Note that
// currently we do not need this on any platform except X11
// ones, because JOGL2 doesn't use the GlueGen NativeLibrary
// class anywhere except the DRIHack class, but if for
// example we add JOAL support then we will need this on
// every platform.
loadLibrary(nativeLibDir, "gluegen-rt");
Class driHackClass = null;
if (nativeLibInfo.mayNeedDRIHack()) {
// Run the DRI hack
try {
driHackClass = Class.forName("com.sun.openGL2.impl.x11.DRIHack");
driHackClass.getMethod("begin", new Class[]{}).invoke(null, new Object[]{});
} catch (Exception e) {
e.printStackTrace();
}
}
// Load core JOGL2 native library
loadLibrary(nativeLibDir, "jogl");
if (nativeLibInfo.mayNeedDRIHack()) {
// End DRI hack
try {
driHackClass.getMethod("end", new Class[]{}).invoke(null, new Object[]{});
} catch (Exception e) {
e.printStackTrace();
}
}
if (!nativeLibInfo.isMacOS()) {
// borrowed from NativeLibLoader
// Must pre-load JAWT on all non-Mac platforms to
// ensure references from jogl_awt shared object
// will succeed since JAWT shared object isn't in
// default library path
try {
System.loadLibrary("jawt");
} catch (UnsatisfiedLinkError ex) {
// Accessibility technologies load JAWT themselves; safe to continue
// as long as JAWT is loaded by any loader
if (ex.getMessage().indexOf("already loaded") == -1) {
fatalError(String.format(NbBundle.getMessage(JOGLNativesInstaller.class, "JOGLNativesInstaller_error3"), new Object[]{}));
}
}
} else {
//Make sure jawt is loaded on Mac Os X, Issue #542
//In Lion the symbolic link to the /Librarires might be missing is some JDK
//JAWT is a dependency of jogl_awt so it needs to be accessible
//We force to load the library at the default location
File defaultJdk = new File("/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK");
if (!defaultJdk.exists()) {
//Use the current JDK path and remove the /Home
String javaHome = System.getProperty("java.home");
javaHome = javaHome.substring(0, javaHome.lastIndexOf("Home"));
defaultJdk = new File(javaHome);
}
File libraryPath = new File(defaultJdk, "Libraries");
File jawtPath = new File(libraryPath, "libjawt.dylib");
if (libraryPath.exists() && jawtPath.exists()) {
//Load library file
loadLibrary(jawtPath);
} else {
System.out.println("Issue #452: Can't locate the default Libraries folder to load the"
+ "JAWT library. This library is needed as a dependency of jogl_awt and is"
+ "normally installed in the JDK. To fix that please make sure to have the"
+ "'/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK' path"
+ "points to the current Java installation.");
}
}
// Load AWT-specific native code
loadLibrary(nativeLibDir, "jogl_awt");
}
});
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
}
}
private void loadLibrary(File installDir, String libName) {
String nativeLibName = nativeLibInfo.getNativeLibName(libName);
loadLibrary(new File(installDir, nativeLibName));
}
private void loadLibrary(File file) {
try {
System.load(file.getPath());
} catch (UnsatisfiedLinkError ex) {
// should be safe to continue as long as the native is loaded by any loader
if (ex.getMessage().indexOf("already loaded") == -1) {
fatalError(String.format(NbBundle.getMessage(JOGLNativesInstaller.class, "JOGLNativesInstaller_error4"), new Object[]{file.getName()}));
}
}
}
private void fatalError(String error) {
Exception ex = new Exception(error);
NotifyDescriptor.Exception e = new NotifyDescriptor.Exception(ex);
DialogDisplayer.getDefault().notify(e);
if (exitOnFatalError) {
System.exit(1);
}
}
private static class NativeLibInfo {
private String osName;
private String osArch;
private String osNameAndArchPair;
private String nativePrefix;
private String nativeSuffix;
public NativeLibInfo(String osName, String osArch, String osNameAndArchPair, String nativePrefix, String nativeSuffix) {
this.osName = osName;
this.osArch = osArch;
this.osNameAndArchPair = osNameAndArchPair;
this.nativePrefix = nativePrefix;
this.nativeSuffix = nativeSuffix;
}
public boolean matchesOSAndArch(String osName, String osArch) {
if (osName.toLowerCase().startsWith(this.osName)) {
if ((this.osArch == null)
|| (osArch.toLowerCase().equals(this.osArch))) {
return true;
}
}
return false;
}
public boolean matchesNativeLib(String fileName) {
if (fileName.toLowerCase().endsWith(nativeSuffix)) {
return true;
}
return false;
}
public String formatNativeJarName(String nativeJarPattern) {
return MessageFormat.format(nativeJarPattern, new Object[]{osNameAndArchPair});
}
public String getNativeLibName(String baseName) {
return nativePrefix + baseName + nativeSuffix;
}
public boolean isMacOS() {
return (osName.equals("mac"));
}
public boolean mayNeedDRIHack() {
return (!isMacOS() && !osName.equals("win"));
}
public String getSubDirectoryPath() {
return osNameAndArchPair;
}
}
private static final NativeLibInfo[] allNativeLibInfo = {
new NativeLibInfo("win", "x86", "windows-i586", "", ".dll"),
new NativeLibInfo("win", "amd64", "windows-amd64", "", ".dll"),
new NativeLibInfo("win", "x86_64", "windows-amd64", "", ".dll"),
new NativeLibInfo("mac", "ppc", "macosx-ppc", "lib", ".jnilib"),
new NativeLibInfo("mac", "i386", "macosx-universal", "lib", ".jnilib"),
new NativeLibInfo("mac", "x86_64", "macosx-universal", "lib", ".jnilib"),
new NativeLibInfo("linux", "i386", "linux-i586", "lib", ".so"),
new NativeLibInfo("linux", "x86", "linux-i586", "lib", ".so"),
new NativeLibInfo("linux", "amd64", "linux-amd64", "lib", ".so"),
new NativeLibInfo("linux", "x86_64", "linux-amd64", "lib", ".so"),
new NativeLibInfo("sunos", "sparc", "solaris-sparc", "lib", ".so"),
new NativeLibInfo("sunos", "sparcv9", "solaris-sparcv9", "lib", ".so"),
new NativeLibInfo("sunos", "x86", "solaris-i586", "lib", ".so"),
new NativeLibInfo("sunos", "amd64", "solaris-amd64", "lib", ".so"),
new NativeLibInfo("sunos", "x86_64", "solaris-amd64", "lib", ".so")
};
}
......@@ -43,7 +43,7 @@ package org.gephi.visualization.opengl;
import java.util.ArrayList;
import java.util.List;
import javax.media.opengl.GL2;
import com.jogamp.opengl.GL2;
import org.gephi.ui.utils.PrefsUtils;
import org.openide.util.NbPreferences;
......
......@@ -42,14 +42,14 @@
package org.gephi.visualization.scheduler;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.Scheduler;
import org.gephi.visualization.apiimpl.VizConfig;
import org.gephi.visualization.opengl.CompatibilityEngine;
import org.gephi.visualization.swing.GraphDrawableImpl;
/**
*
......@@ -66,7 +66,7 @@ public class CompatibilityScheduler implements Scheduler, VizArchitecture {
AtomicBoolean stopDrag = new AtomicBoolean();
AtomicBoolean mouseClick = new AtomicBoolean();
//Architeture
private GraphDrawableImpl graphDrawable;
private GraphDrawable graphDrawable;
private CompatibilityEngine engine;
private VizConfig vizConfig;
//Animators
......
......@@ -41,36 +41,25 @@
*/
package org.gephi.visualization.screenshot;
import com.jogamp.opengl.util.awt.ImageUtil;
import java.awt.Cursor;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.imageio.ImageIO;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLPbuffer;
import javax.media.opengl.GLProfile;
import com.jogamp.opengl.GLAutoDrawable;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.gephi.ui.utils.DialogFileFilter;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.VizConfig;
import org.gephi.visualization.opengl.*;
import org.gephi.visualization.swing.GLAbstractListener;
import org.gephi.visualization.swing.GraphDrawableImpl;
import org.gephi.visualization.text.TextManager;
import org.netbeans.validation.api.ui.ValidationPanel;
import org.openide.util.NbBundle;
......@@ -93,7 +82,7 @@ public class ScreenshotMaker implements VizArchitecture {
private final String AUTOSAVE_DEFAULT = "ScreenshotMaker_Autosave_Default";
private final String SHOW_MESSAGE = "ScreenshotMaker_Show_Message";
//Architecture
private GraphDrawableImpl drawable;
private GraphDrawable drawable;
private AbstractEngine engine;
private TextManager textManager;
private VizConfig vizConfig;
......@@ -151,103 +140,104 @@ public class ScreenshotMaker implements VizArchitecture {
}
private void take(File file) throws Exception {
//System.out.println("Take Screenshot to " + file.getName());
// Fix the image size for now
int tileWidth = width / 16;
int tileHeight = height / 12;
int imageWidth = width;
int imageHeight = height;
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
AbstractGraphicsDevice device = GLDrawableFactory.getFactory(profile).getDefaultDevice();
//Caps
caps.setAlphaBits(8);
caps.setDoubleBuffered(false);
caps.setHardwareAccelerated(true);
caps.setSampleBuffers(true);
caps.setNumSamples(antiAliasing);
//Buffer
GLPbuffer pbuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(device, caps, null, tileWidth, tileHeight, null);
BufferedImage image = null;
if (transparentBackground) {
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
} else {
image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
}
ByteBuffer imageBuffer = ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData());
//Tile rendering
TileRenderer tileRenderer = new TileRenderer();
tileRenderer.setTileSize(tileWidth, tileHeight, 0);
tileRenderer.setImageSize(imageWidth, imageHeight);
if (transparentBackground) {
tileRenderer.setImageBuffer(GL2.GL_BGRA, GL2.GL_UNSIGNED_BYTE, imageBuffer);
} else {
tileRenderer.setImageBuffer(GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, imageBuffer);
}
tileRenderer.trPerspective(drawable.viewField, (float) imageWidth / (float) imageHeight, drawable.nearDistance, drawable.farDistance);
//Get gl
//GLContext oldContext = GLContext.getCurrent();
GLContext context = pbuffer.getContext();
if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
throw new RuntimeException("Error making pbuffer's context current");
}
System.out.println("Disabling snapshot");
GL2 gl = pbuffer.getGL().getGL2();
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
//Init
drawable.initConfig(gl);
vizConfig.setDisableLOD(true);
engine.initScreenshot(gl, GLAbstractListener.glu);
//Textrender - swap to 3D
textManager.setRenderer3d(true);
//Render in buffer
do {
tileRenderer.beginTile(gl);
drawable.renderScreenshot(pbuffer);
} while (tileRenderer.endTile(gl));
//Clean
context.release();
pbuffer.destroy();
//Textrender - back to 2D
textManager.setRenderer3d(false);
vizConfig.setDisableLOD(false);
//Write image
ImageUtil.flipImageVertically(image);
writeImage(image);
/*Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("png");
if (iter.hasNext()) {
ImageWriter writer = iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
//iwp.setCompressionType("DEFAULT");
//iwp.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
//iwp.setCompressionQuality((int)(9*pngCompresssion));
FileImageOutputStream output = new FileImageOutputStream(file);
writer.setOutput(output);
IIOImage img = new IIOImage(image, null, null);
writer.write(null, img, iwp);
writer.dispose();
}*/
//oldContext.makeCurrent();
//
// //System.out.println("Take Screenshot to " + file.getName());
//
// // Fix the image size for now
// int tileWidth = width / 16;
// int tileHeight = height / 12;
// int imageWidth = width;
// int imageHeight = height;
//
// GLProfile profile = GLProfile.get(GLProfile.GL2);
// GLCapabilities caps = new GLCapabilities(profile);
// AbstractGraphicsDevice device = GLDrawableFactory.getFactory(profile).getDefaultDevice();
// //Caps
//
// caps.setAlphaBits(8);
// caps.setDoubleBuffered(false);
// caps.setHardwareAccelerated(true);
// caps.setSampleBuffers(true);
// caps.setNumSamples(antiAliasing);
// caps.setPBuffer(true);
//
// //Buffer
//
// GLPbuffer pbuffer = GLDrawableFactory.getFactory(profile).createGLPbuffer(device, caps, null, tileWidth, tileHeight, null);
// BufferedImage image = null;
// if (transparentBackground) {
// image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
// } else {
// image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
// }
// ByteBuffer imageBuffer = ByteBuffer.wrap(((DataBufferByte) image.getRaster().getDataBuffer()).getData());
//
// //Tile rendering
// TileRenderer tileRenderer = new TileRenderer();
// tileRenderer.setTileSize(tileWidth, tileHeight, 0);
// tileRenderer.setImageSize(imageWidth, imageHeight);
// if (transparentBackground) {
// tileRenderer.setImageBuffer(GL2.GL_BGRA, GL2.GL_UNSIGNED_BYTE, imageBuffer);
// } else {
// tileRenderer.setImageBuffer(GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, imageBuffer);
// }
// tileRenderer.trPerspective(drawable.viewField, (float) imageWidth / (float) imageHeight, drawable.nearDistance, drawable.farDistance);
//
// //Get gl
// //GLContext oldContext = GLContext.getCurrent();
// GLContext context = pbuffer.getContext();
// if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) {
// throw new RuntimeException("Error making pbuffer's context current");
// }
//
// System.out.println("Disabling snapshot");
//
// GL2 gl = pbuffer.getGL().getGL2();
// gl.glMatrixMode(GL2.GL_MODELVIEW);
// gl.glLoadIdentity();
//
// //Init
// drawable.initConfig(gl);
// vizConfig.setDisableLOD(true);
// engine.initScreenshot(gl, GLAbstractListener.glu);
//
//
// //Textrender - swap to 3D
// textManager.setRenderer3d(true);
//
// //Render in buffer
// do {
// tileRenderer.beginTile(gl);
// drawable.renderScreenshot(pbuffer);
// } while (tileRenderer.endTile(gl));
//
// //Clean
// context.release();
// pbuffer.destroy();
//
//
// //Textrender - back to 2D
// textManager.setRenderer3d(false);
// vizConfig.setDisableLOD(false);
// //Write image
// ImageUtil.flipImageVertically(image);
// writeImage(image);
//
// /*Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("png");
// if (iter.hasNext()) {
// ImageWriter writer = iter.next();
// ImageWriteParam iwp = writer.getDefaultWriteParam();
// //iwp.setCompressionType("DEFAULT");
// //iwp.setCompressionMode(javax.imageio.ImageWriteParam.MODE_EXPLICIT);
// //iwp.setCompressionQuality((int)(9*pngCompresssion));
// FileImageOutputStream output = new FileImageOutputStream(file);
// writer.setOutput(output);
// IIOImage img = new IIOImage(image, null, null);
// writer.write(null, img, iwp);
// writer.dispose();
// }*/
//
// //oldContext.makeCurrent();
}
private void writeImage(BufferedImage image) throws Exception {
......
......@@ -3,8 +3,8 @@ package org.gephi.visualization.screenshot;
import java.awt.Dimension;
import java.nio.Buffer;
import javax.media.opengl.*;
import javax.media.opengl.glu.gl2.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.glu.gl2.*;
/**
* Note: Code copied from JOGL 2.0.2 sources http://jogamp.org/deployment/maven/org/jogamp/jogl/jogl/2.0.2/
......
......@@ -41,8 +41,8 @@
*/
package org.gephi.visualization.selection;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizController;
import org.gephi.visualization.VizModel;
......
......@@ -42,8 +42,8 @@
package org.gephi.visualization.selection;
import java.util.Arrays;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import org.gephi.lib.gleem.linalg.Vecf;
import org.gephi.visualization.VizController;
import org.gephi.visualization.api.selection.SelectionArea;
......
......@@ -42,17 +42,29 @@
package org.gephi.visualization.swing;
import com.jogamp.common.nio.Buffers;
import com.jogamp.newt.awt.NewtCanvasAWT;
import java.awt.Color;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.glu.GLU;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.nio.DoubleBuffer;
import org.gephi.lib.gleem.linalg.Vec3f;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
import org.gephi.visualization.VizModel;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.Scheduler;
import org.gephi.visualization.config.GraphicalConfiguration;
import org.gephi.visualization.opengl.AbstractEngine;
import org.gephi.visualization.opengl.Lighting;
import org.gephi.visualization.screenshot.ScreenshotMaker;
import org.openide.util.Exceptions;
......@@ -61,10 +73,11 @@ import org.openide.util.Exceptions;
*
* @author Mathieu Bastian
*/
public abstract class GLAbstractListener implements GLEventListener {
public abstract class GLAbstractListener implements GLEventListener, VizArchitecture, GraphDrawable {
protected GLAutoDrawable drawable;
protected VizController vizController;
protected VizModel vizModel;
public static final GLU glu = new GLU();
private static boolean DEBUG = true;
private long startTime = 0;
......@@ -76,26 +89,95 @@ public abstract class GLAbstractListener implements GLEventListener {
public final float nearDistance = 1.0f;
public final float farDistance = 100000f;
private double aspectRatio = 0;
protected float globalScale = 1f;
protected FloatBuffer projMatrix = Buffers.newDirectFloatBuffer(16);
protected FloatBuffer modelMatrix = Buffers.newDirectFloatBuffer(16);
protected IntBuffer viewport = Buffers.newDirectIntBuffer(4);
protected GraphicalConfiguration graphicalConfiguration;
protected Lighting lighting = new Lighting();
protected ScreenshotMaker screenshotMaker;
public Component graphComponent;
protected AbstractEngine engine;
protected Scheduler scheduler;
protected float[] cameraLocation;
protected float[] cameraTarget;
protected double[] draggingMarker = new double[2];//The drag mesure for a moving of 1 to the viewport
protected Vec3f cameraVector = new Vec3f();
protected MouseAdapter graphMouseAdapter;
public GLAbstractListener() {
this.vizController = VizController.getInstance();
}
protected void initDrawable(GLAutoDrawable drawable) {
this.drawable = drawable;
drawable.addGLEventListener(this);
}
@Override
public void initArchitecture() {
this.engine = VizController.getInstance().getEngine();
this.scheduler = VizController.getInstance().getScheduler();
this.screenshotMaker = VizController.getInstance().getScreenshotMaker();
cameraLocation = vizController.getVizConfig().getDefaultCameraPosition();
cameraTarget = vizController.getVizConfig().getDefaultCameraTarget();
//Mouse events
if (vizController.getVizConfig().isReduceFpsWhenMouseOut()) {
final int minVal = vizController.getVizConfig().getReduceFpsWhenMouseOutValue();
final int maxVal = 30;
graphMouseAdapter = new MouseAdapter() {
private float lastTarget = 0.1f;
@Override
public void mouseEntered(MouseEvent e) {
if (!scheduler.isAnimating()) {
engine.startDisplay();
}
scheduler.setFps(maxVal);
resetFpsAverage();
}
@Override
public void mouseExited(MouseEvent e) {
float fps = getFpsAverage();
float target = (float) (fps / (1. / Math.sqrt(getFpsAverage()) * 10.));
if (fps == 0f) {
target = lastTarget;
}
if (target <= 0.005f) {
engine.stopDisplay();
} else if (target > minVal) {
target = minVal;
}
lastTarget = target;
scheduler.setFps(target);
}
};
graphComponent.addMouseListener(graphMouseAdapter);
} else if (vizController.getVizConfig().isPauseLoopWhenMouseOut()) {
graphMouseAdapter = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
engine.startDisplay();
}
@Override
public void mouseExited(MouseEvent e) {
engine.stopDisplay();
}
};
graphComponent.addMouseListener(graphMouseAdapter);
}
}
protected abstract void init(GL2 gl);
protected abstract void render3DScene(GL2 gl, GLU glu);
protected abstract void reshape3DScene(GL2 gl);
protected abstract void setCameraPosition(GL2 gl, GLU glu);
protected GLCapabilities getCaps() {
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
......@@ -107,28 +189,36 @@ public abstract class GLAbstractListener implements GLEventListener {
//FSAA
int antialisaing = vizController.getVizConfig().getAntialiasing();
if (antialisaing == 0) {
caps.setSampleBuffers(false);
} else if (antialisaing == 2) {
caps.setSampleBuffers(true);
caps.setNumSamples(2);
} else if (antialisaing == 4) {
caps.setSampleBuffers(true);
caps.setNumSamples(4);
} else if (antialisaing == 8) {
caps.setSampleBuffers(true);
caps.setNumSamples(8);
} else if (antialisaing == 16) {
caps.setSampleBuffers(true);
caps.setNumSamples(16);
switch (antialisaing) {
case 0:
caps.setSampleBuffers(false);
break;
case 2:
caps.setSampleBuffers(true);
caps.setNumSamples(2);
break;
case 4:
caps.setSampleBuffers(true);
caps.setNumSamples(4);
break;
case 8:
caps.setSampleBuffers(true);
caps.setNumSamples(8);
break;
case 16:
caps.setSampleBuffers(true);
caps.setNumSamples(16);
break;
default:
}
} catch (javax.media.opengl.GLException ex) {
} catch (com.jogamp.opengl.GLException ex) {
Exceptions.printStackTrace(ex);
}
return caps;
}
@Override
public void initConfig(GL2 gl) {
//Disable Vertical synchro
gl.setSwapInterval(0);
......@@ -195,7 +285,6 @@ public abstract class GLAbstractListener implements GLEventListener {
}
}
//Material
if (vizController.getVizModel().isMaterial()) {
gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE);
......@@ -206,8 +295,8 @@ public abstract class GLAbstractListener implements GLEventListener {
gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
}
gl.glEnable(GL2.GL_TEXTURE_2D);
// Bug: Black faces when enabled
// gl.glEnable(GL2.GL_TEXTURE_2D);
}
protected void setLighting(GL2 gl) {
......@@ -227,9 +316,43 @@ public abstract class GLAbstractListener implements GLEventListener {
resizing = false;
initConfig(gl);
// graphComponent.setCursor(Cursor.getDefaultCursor());
engine.initEngine(gl, glu);
init(gl);
}
public void refreshDraggingMarker() {
//Refresh dragging marker
/*DoubleBuffer objPos = BufferUtil.newDoubleBuffer(3);
glu.gluProject(0, 0, 0, modelMatrix, projMatrix, viewport, objPos);
double dxx = objPos.get(0);
double dyy = objPos.get(1);
glu.gluProject(1, 1, 0, modelMatrix, projMatrix, viewport, objPos);
draggingMarker[0] = dxx - objPos.get(0);
draggingMarker[1] = dyy - objPos.get(1);
System.out.print(draggingMarker[0]);*/
float[] d = myGluProject(0, 0, 0);
float[] d2 = myGluProject(1, 1, 0);
draggingMarker[0] = d[0] - d2[0];
draggingMarker[1] = d[1] - d2[1];
}
@Override
public void setCameraPosition(GL2 gl, GLU glu) {
//Refresh rotation angle
gl.glLoadIdentity();
glu.gluLookAt(cameraLocation[0], cameraLocation[1], cameraLocation[2], cameraTarget[0], cameraTarget[1], cameraTarget[2], 0, 1, 0);
gl.glScalef(globalScale, globalScale, 0f);
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelMatrix);
cameraVector.set(cameraTarget[0] - cameraLocation[0], cameraTarget[1] - cameraLocation[1], cameraTarget[2] - cameraLocation[2]);
refreshDraggingMarker();
}
@Override
public void display(GLAutoDrawable drawable) {
......@@ -257,6 +380,13 @@ public abstract class GLAbstractListener implements GLEventListener {
}
render3DScene(gl, glu);
scheduler.display(gl, glu);
// renderTestCube(gl);
}
@Override
public void display() {
drawable.display();
}
@Override
......@@ -297,10 +427,10 @@ public abstract class GLAbstractListener implements GLEventListener {
glu.gluPerspective(viewField, aspectRatio, nearDistance, farDistance);
gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projMatrix);//Update projection buffer
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
setCameraPosition(gl, glu);
reshape3DScene(drawable.getGL().getGL2());
if (DEBUG) {
......@@ -308,12 +438,110 @@ public abstract class GLAbstractListener implements GLEventListener {
System.err.println("GL_VENDOR: " + gl.glGetString(GL2.GL_VENDOR));
System.err.println("GL_RENDERER: " + gl.glGetString(GL2.GL_RENDERER));
System.err.println("GL_VERSION: " + gl.glGetString(GL2.GL_VERSION));
System.err.println("GL_SURFACE_SCALE: " + globalScale);
}
resizing = false;
}
}
@Override
public void destroy() {
if (graphMouseAdapter != null) {
graphComponent.removeMouseListener(graphMouseAdapter);
}
drawable.destroy();
}
private static float rotateFactor = 15f;
private void renderTestCube(GL2 gl) {
float cubeSize = 1f;
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(cameraLocation[0], cameraLocation[1], cameraLocation[2], cameraTarget[0], cameraTarget[1], cameraTarget[2], 0, 1, 0);
gl.glColor3f(0f, 0f, 0f);
gl.glRotatef(rotateFactor++ % 360f, 0.0f, 1.0f, 0.0f); // Rotate The cube around the Y axis
gl.glRotatef(15.0f, 1.0f, 1.0f, 1.0f);
gl.glBegin(GL2.GL_QUADS); // Draw The Cube Using quads
gl.glColor3f(0.0f, 1.0f, 0.0f); // Color Green
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Top Right Of The Quad (Top)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Top Left Of The Quad (Top)
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Bottom Left Of The Quad (Top)
gl.glVertex3f(cubeSize, cubeSize, cubeSize); // Bottom Right Of The Quad (Top)
gl.glColor3f(1.0f, 0.5f, 0.0f); // Color Orange
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Top Right Of The Quad (Bottom)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Top Left Of The Quad (Bottom)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Bottom Left Of The Quad (Bottom)
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Bottom Right Of The Quad (Bottom)
gl.glColor3f(1.0f, 0.0f, 0.0f); // Color Red
gl.glVertex3f(cubeSize, cubeSize, cubeSize); // Top Right Of The Quad (Front)
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Top Left Of The Quad (Front)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Bottom Left Of The Quad (Front)
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Bottom Right Of The Quad (Front)
gl.glColor3f(1.0f, 1.0f, 0.0f); // Color Yellow
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Top Right Of The Quad (Back)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Top Left Of The Quad (Back)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Bottom Left Of The Quad (Back)
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Bottom Right Of The Quad (Back)
gl.glColor3f(0.0f, 0.0f, 1.0f); // Color Blue
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Top Right Of The Quad (Left)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Top Left Of The Quad (Left)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Bottom Left Of The Quad (Left)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Bottom Right Of The Quad (Left)
gl.glColor3f(1.0f, 0.0f, 1.0f); // Color Violet
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Top Right Of The Quad (Right)
gl.glVertex3f(cubeSize, cubeSize, cubeSize); // Top Left Of The Quad (Right)
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Bottom Left Of The Quad (Right)
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Bottom Right Of The Quad (Right)
gl.glEnd(); // End Drawing The Cube
}
//Utils
@Override
public double[] myGluProject(float x, float y) {
return myGluProject(x, y);
}
@Override
public float[] myGluProject(float x, float y, float z) {
float[] res = new float[2];
float o0 = modelMatrix.get(0) * x + modelMatrix.get(4) * y + modelMatrix.get(8) * z + modelMatrix.get(12) * 1f;
float o1 = modelMatrix.get(1) * x + modelMatrix.get(5) * y + modelMatrix.get(9) * z + modelMatrix.get(13) * 1f;
float o2 = modelMatrix.get(2) * x + modelMatrix.get(6) * y + modelMatrix.get(10) * z + modelMatrix.get(14) * 1f;
float o3 = modelMatrix.get(3) * x + modelMatrix.get(7) * y + modelMatrix.get(11) * z + modelMatrix.get(15) * 1f;
float p0 = projMatrix.get(0) * o0 + projMatrix.get(4) * o1 + projMatrix.get(8) * o2 + projMatrix.get(12) * o3;
float p1 = projMatrix.get(1) * o0 + projMatrix.get(5) * o1 + projMatrix.get(9) * o2 + projMatrix.get(13) * o3;
float p2 = projMatrix.get(2) * o0 + projMatrix.get(6) * o1 + projMatrix.get(10) * o2 + projMatrix.get(14) * o3;
float p3 = projMatrix.get(3) * o0 + projMatrix.get(7) * o1 + projMatrix.get(11) * o2 + projMatrix.get(15) * o3;
p0 /= p3;
p1 /= p3;
p2 /= p3;
res[0] = viewport.get(0) + (p0 + 1) * viewport.get(2) / 2;
res[1] = viewport.get(1) + viewport.get(3) * (p1 + 1) / 2;
return res;
}
private double[] transformVect(double[] in, DoubleBuffer m) {
double[] out = new double[4];
out[0] = m.get(0) * in[0] + m.get(4) * in[1] + m.get(8) * in[2] + m.get(12) * in[3];
out[1] = m.get(1) * in[0] + m.get(5) * in[1] + m.get(9) * in[2] + m.get(13) * in[3];
out[2] = m.get(2) * in[0] + m.get(6) * in[1] + m.get(10) * in[2] + m.get(14) * in[3];
out[3] = m.get(3) * in[0] + m.get(7) * in[1] + m.get(11) * in[2] + m.get(15) * in[3];
return out;
}
public GL2 getGL() {
return drawable.getGL().getGL2();
}
......@@ -330,6 +558,7 @@ public abstract class GLAbstractListener implements GLEventListener {
return lighting;
}
@Override
public GraphicalConfiguration getGraphicalConfiguration() {
return graphicalConfiguration;
}
......@@ -342,4 +571,79 @@ public abstract class GLAbstractListener implements GLEventListener {
protected float getFpsAverage() {
return fpsAvg;
}
@Override
public float[] getCameraLocation() {
return cameraLocation;
}
@Override
public void setCameraLocation(float[] cameraLocation) {
this.cameraLocation = cameraLocation;
}
@Override
public float[] getCameraTarget() {
return cameraTarget;
}
@Override
public void setCameraTarget(float[] cameraTarget) {
this.cameraTarget = cameraTarget;
}
@Override
public Component getGraphComponent() {
return graphComponent;
}
@Override
public Vec3f getCameraVector() {
return cameraVector;
}
@Override
public int getViewportHeight() {
return viewport.get(3);
}
@Override
public int getViewportWidth() {
return viewport.get(2);
}
@Override
public double getDraggingMarkerX() {
return draggingMarker[0];
}
@Override
public double getDraggingMarkerY() {
return draggingMarker[1];
}
@Override
public FloatBuffer getProjectionMatrix() {
return projMatrix;
}
public FloatBuffer getModelMatrix() {
return modelMatrix;
}
@Override
public IntBuffer getViewport() {
return viewport;
}
@Override
public float getGlobalScale() {
return globalScale;
}
@Override
public void dispose(GLAutoDrawable glad) {
engine.stopDisplay();
VizController.getInstance().getDataBridge().reset();
}
}
......@@ -41,12 +41,13 @@
*/
package org.gephi.visualization.swing;
import com.jogamp.nativewindow.ScalableSurface;
import com.jogamp.opengl.util.gl2.GLUT;
import java.awt.Component;
import java.awt.Dimension;
import javax.media.opengl.GL2;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import javax.swing.JPopupMenu;
import javax.swing.ToolTipManager;
......@@ -54,7 +55,7 @@ import javax.swing.ToolTipManager;
*
* @author Mathieu Bastian
*/
public class GraphCanvas extends GraphDrawableImpl {
public class GraphCanvas extends GLAbstractListener {
private final GLCanvas glCanvas;
private final GLUT glut = new GLUT();
......@@ -62,8 +63,10 @@ public class GraphCanvas extends GraphDrawableImpl {
public GraphCanvas() {
super();
glCanvas = new GLCanvas(getCaps());
// glCanvas.setSurfaceScale(new float[]{ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE});
super.initDrawable(glCanvas);
glCanvas.setMinimumSize(new Dimension(0, 0)); //Fix Canvas resize Issue
globalScale = glCanvas.getCurrentSurfaceScale(new float[2])[0];
//Basic init
graphComponent = (Component) glCanvas;
......@@ -74,6 +77,11 @@ public class GraphCanvas extends GraphDrawableImpl {
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
}
@Override
protected void init(GL2 gl) {
}
@Override
protected void render3DScene(GL2 gl, GLU glu) {
if (vizController.getVizConfig().isShowFPS()) {
......@@ -96,6 +104,10 @@ public class GraphCanvas extends GraphDrawableImpl {
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPopMatrix();
}
super.render3DScene(gl, glu);
}
@Override
protected void reshape3DScene(GL2 gl) {
}
}
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.visualization.swing;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;
import org.gephi.lib.gleem.linalg.Vec3f;
import org.gephi.visualization.VizArchitecture;
import org.gephi.visualization.VizController;
import org.gephi.visualization.apiimpl.GraphDrawable;
import org.gephi.visualization.apiimpl.Scheduler;
import org.gephi.visualization.opengl.AbstractEngine;
/**
*
* @author Mathieu Bastian
*/
public class GraphDrawableImpl extends GLAbstractListener implements VizArchitecture, GraphDrawable {
protected Component graphComponent;
protected AbstractEngine engine;
protected Scheduler scheduler;
protected float[] cameraLocation;
protected float[] cameraTarget;
protected double[] draggingMarker = new double[2];//The drag mesure for a moving of 1 to the viewport
protected Vec3f cameraVector = new Vec3f();
protected MouseAdapter graphMouseAdapter;
public GraphDrawableImpl() {
super();
this.vizController = VizController.getInstance();
}
@Override
public void initArchitecture() {
this.engine = VizController.getInstance().getEngine();
this.scheduler = VizController.getInstance().getScheduler();
this.screenshotMaker = VizController.getInstance().getScreenshotMaker();
cameraLocation = vizController.getVizConfig().getDefaultCameraPosition();
cameraTarget = vizController.getVizConfig().getDefaultCameraTarget();
//Mouse events
if (vizController.getVizConfig().isReduceFpsWhenMouseOut()) {
final int minVal = vizController.getVizConfig().getReduceFpsWhenMouseOutValue();
final int maxVal = 30;
graphMouseAdapter = new MouseAdapter() {
private float lastTarget = 0.1f;
@Override
public void mouseEntered(MouseEvent e) {
if (!scheduler.isAnimating()) {
engine.startDisplay();
}
scheduler.setFps(maxVal);
resetFpsAverage();
}
@Override
public void mouseExited(MouseEvent e) {
float fps = getFpsAverage();
float target = (float) (fps / (1. / Math.sqrt(getFpsAverage()) * 10.));
if (fps == 0f) {
target = lastTarget;
}
if (target <= 0.005f) {
engine.stopDisplay();
} else if (target > minVal) {
target = minVal;
}
lastTarget = target;
scheduler.setFps(target);
}
};
graphComponent.addMouseListener(graphMouseAdapter);
} else if (vizController.getVizConfig().isPauseLoopWhenMouseOut()) {
graphMouseAdapter = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
engine.startDisplay();
}
@Override
public void mouseExited(MouseEvent e) {
engine.stopDisplay();
}
};
graphComponent.addMouseListener(graphMouseAdapter);
}
}
@Override
protected void init(GL2 gl) {
//System.out.println("init");
// graphComponent.setCursor(Cursor.getDefaultCursor());
engine.initEngine(gl, glu);
}
public void destroy() {
if (graphMouseAdapter != null) {
graphComponent.removeMouseListener(graphMouseAdapter);
}
}
public void refreshDraggingMarker() {
//Refresh dragging marker
/*DoubleBuffer objPos = BufferUtil.newDoubleBuffer(3);
glu.gluProject(0, 0, 0, modelMatrix, projMatrix, viewport, objPos);
double dxx = objPos.get(0);
double dyy = objPos.get(1);
glu.gluProject(1, 1, 0, modelMatrix, projMatrix, viewport, objPos);
draggingMarker[0] = dxx - objPos.get(0);
draggingMarker[1] = dyy - objPos.get(1);
System.out.print(draggingMarker[0]);*/
float[] d = myGluProject(0, 0, 0);
float[] d2 = myGluProject(1, 1, 0);
draggingMarker[0] = d[0] - d2[0];
draggingMarker[1] = d[1] - d2[1];
}
@Override
public void setCameraPosition(GL2 gl, GLU glu) {
//Refresh rotation angle
gl.glLoadIdentity();
glu.gluLookAt(cameraLocation[0], cameraLocation[1], cameraLocation[2], cameraTarget[0], cameraTarget[1], cameraTarget[2], 0, 1, 0);
gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelMatrix);
cameraVector.set(cameraTarget[0] - cameraLocation[0], cameraTarget[1] - cameraLocation[1], cameraTarget[2] - cameraLocation[2]);
refreshDraggingMarker();
}
@Override
protected void reshape3DScene(GL2 gl) {
setCameraPosition(gl, glu);
}
@Override
protected void render3DScene(GL2 gl, GLU glu) {
scheduler.display(gl, glu);
//renderTestCube(gl);
}
private void renderTestCube(GL2 gl) {
float cubeSize = 100f;
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
glu.gluLookAt(cameraLocation[0], cameraLocation[1], cameraLocation[2], cameraTarget[0], cameraTarget[1], cameraTarget[2], 0, 1, 0);
gl.glColor3f(0f, 0f, 0f);
gl.glRotatef(15.0f, 0.0f, 1.0f, 0.0f); // Rotate The cube around the Y axis
gl.glRotatef(15.0f, 1.0f, 1.0f, 1.0f);
gl.glBegin(GL2.GL_QUADS); // Draw The Cube Using quads
gl.glColor3f(0.0f, 1.0f, 0.0f); // Color Blue
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Top Right Of The Quad (Top)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Top Left Of The Quad (Top)
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Bottom Left Of The Quad (Top)
gl.glVertex3f(cubeSize, cubeSize, 1.0f); // Bottom Right Of The Quad (Top)
gl.glColor3f(1.0f, 0.5f, 0.0f); // Color Orange
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Top Right Of The Quad (Bottom)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Top Left Of The Quad (Bottom)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Bottom Left Of The Quad (Bottom)
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Bottom Right Of The Quad (Bottom)
gl.glColor3f(1.0f, 0.0f, 0.0f); // Color Red
gl.glVertex3f(cubeSize, cubeSize, cubeSize); // Top Right Of The Quad (Front)
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Top Left Of The Quad (Front)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Bottom Left Of The Quad (Front)
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Bottom Right Of The Quad (Front)
gl.glColor3f(1.0f, 1.0f, 0.0f); // Color Yellow
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Top Right Of The Quad (Back)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Top Left Of The Quad (Back)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Bottom Left Of The Quad (Back)
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Bottom Right Of The Quad (Back)
gl.glColor3f(0.0f, 0.0f, 1.0f); // Color Blue
gl.glVertex3f(-cubeSize, cubeSize, cubeSize); // Top Right Of The Quad (Left)
gl.glVertex3f(-cubeSize, cubeSize, -cubeSize); // Top Left Of The Quad (Left)
gl.glVertex3f(-cubeSize, -cubeSize, -cubeSize); // Bottom Left Of The Quad (Left)
gl.glVertex3f(-cubeSize, -cubeSize, cubeSize); // Bottom Right Of The Quad (Left)
gl.glColor3f(1.0f, 0.0f, 1.0f); // Color Violet
gl.glVertex3f(cubeSize, cubeSize, -cubeSize); // Top Right Of The Quad (Right)
gl.glVertex3f(cubeSize, cubeSize, cubeSize); // Top Left Of The Quad (Right)
gl.glVertex3f(cubeSize, -cubeSize, cubeSize); // Bottom Left Of The Quad (Right)
gl.glVertex3f(cubeSize, -cubeSize, -cubeSize); // Bottom Right Of The Quad (Right)
gl.glEnd(); // End Drawing The Cube
}
public void renderScreenshot(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
if (vizController.getVizModel().isUse3d()) {
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
} else {
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
}
setCameraPosition(gl, glu);
engine.display(gl, glu);
}
public void display() {
drawable.display();
}
//Utils
public double[] myGluProject(float x, float y) {
return myGluProject(x, y);
}
public float[] myGluProject(float x, float y, float z) {
float[] res = new float[2];
float o0 = modelMatrix.get(0) * x + modelMatrix.get(4) * y + modelMatrix.get(8) * z + modelMatrix.get(12) * 1f;
float o1 = modelMatrix.get(1) * x + modelMatrix.get(5) * y + modelMatrix.get(9) * z + modelMatrix.get(13) * 1f;
float o2 = modelMatrix.get(2) * x + modelMatrix.get(6) * y + modelMatrix.get(10) * z + modelMatrix.get(14) * 1f;
float o3 = modelMatrix.get(3) * x + modelMatrix.get(7) * y + modelMatrix.get(11) * z + modelMatrix.get(15) * 1f;
float p0 = projMatrix.get(0) * o0 + projMatrix.get(4) * o1 + projMatrix.get(8) * o2 + projMatrix.get(12) * o3;
float p1 = projMatrix.get(1) * o0 + projMatrix.get(5) * o1 + projMatrix.get(9) * o2 + projMatrix.get(13) * o3;
float p2 = projMatrix.get(2) * o0 + projMatrix.get(6) * o1 + projMatrix.get(10) * o2 + projMatrix.get(14) * o3;
float p3 = projMatrix.get(3) * o0 + projMatrix.get(7) * o1 + projMatrix.get(11) * o2 + projMatrix.get(15) * o3;
p0 /= p3;
p1 /= p3;
p2 /= p3;
res[0] = viewport.get(0) + (p0 + 1) * viewport.get(2) / 2;
res[1] = viewport.get(1) + viewport.get(3) * (p1 + 1) / 2;
return res;
}
private double[] transformVect(double[] in, DoubleBuffer m) {
double[] out = new double[4];
out[0] = m.get(0) * in[0] + m.get(4) * in[1] + m.get(8) * in[2] + m.get(12) * in[3];
out[1] = m.get(1) * in[0] + m.get(5) * in[1] + m.get(9) * in[2] + m.get(13) * in[3];
out[2] = m.get(2) * in[0] + m.get(6) * in[1] + m.get(10) * in[2] + m.get(14) * in[3];
out[3] = m.get(3) * in[0] + m.get(7) * in[1] + m.get(11) * in[2] + m.get(15) * in[3];
return out;
}
@Override
public float[] getCameraLocation() {
return cameraLocation;
}
@Override
public void setCameraLocation(float[] cameraLocation) {
this.cameraLocation = cameraLocation;
}
@Override
public float[] getCameraTarget() {
return cameraTarget;
}
@Override
public void setCameraTarget(float[] cameraTarget) {
this.cameraTarget = cameraTarget;
}
@Override
public Component getGraphComponent() {
return graphComponent;
}
@Override
public Vec3f getCameraVector() {
return cameraVector;
}
@Override
public int getViewportHeight() {
return viewport.get(3);
}
@Override
public int getViewportWidth() {
return viewport.get(2);
}
@Override
public double getDraggingMarkerX() {
return draggingMarker[0];
}
@Override
public double getDraggingMarkerY() {
return draggingMarker[1];
}
@Override
public FloatBuffer getProjectionMatrix() {
return projMatrix;
}
public FloatBuffer getModelMatrix() {
return modelMatrix;
}
@Override
public IntBuffer getViewport() {
return viewport;
}
@Override
public void dispose(GLAutoDrawable glad) {
/* FIXME: jbilcke: what should it do? is it new in JOGL2? */
}
}
......@@ -41,12 +41,14 @@
*/
package org.gephi.visualization.swing;
import com.jogamp.opengl.GL2;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.text.NumberFormat;
import javax.media.opengl.awt.GLJPanel;
import com.jogamp.opengl.awt.GLJPanel;
import com.jogamp.opengl.glu.GLU;
import org.gephi.visualization.GraphLimits;
import org.gephi.visualization.VizController;
......@@ -54,7 +56,7 @@ import org.gephi.visualization.VizController;
*
* @author Mathieu Bastian
*/
public class GraphPanel extends GraphDrawableImpl {
public class GraphPanel extends GLAbstractListener {
private GLJPanel gljPanel;
private NumberFormat formatter;
......@@ -65,16 +67,16 @@ public class GraphPanel extends GraphDrawableImpl {
formatter.setMaximumFractionDigits(1);
//Init GLJPanel as the drawable
gljPanel = new GLJPanel(getCaps(), null, null) {
//@Override
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
render2DBackground(g2d);
super.paintComponent(g2d);
render2DForeground(g2d);
}
};
// gljPanel = new GLJPanel(getCaps(), null, null) {
// //@Override
// @Override
// public void paintComponent(Graphics g) {
// Graphics2D g2d = (Graphics2D) g;
// render2DBackground(g2d);
// super.paintComponent(g2d);
// render2DForeground(g2d);
// }
// };
//gljPanel.setOpaque(false);
graphComponent = gljPanel;
......@@ -114,4 +116,19 @@ public class GraphPanel extends GraphDrawableImpl {
g.setColor(Color.red);
g.drawPolygon(xP, yP, 4);
}
@Override
protected void init(GL2 gl) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
protected void render3DScene(GL2 gl, GLU glu) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
protected void reshape3DScene(GL2 gl) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
......@@ -45,8 +45,10 @@ import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.gl2.GLUT;
import java.awt.Component;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JPopupMenu;
import javax.swing.ToolTipManager;
......@@ -54,21 +56,23 @@ import javax.swing.ToolTipManager;
*
* @author Mathieu Bastian
*/
public class NewtGraphCanvas extends GraphDrawableImpl {
public class NewtGraphCanvas extends GLAbstractListener {
private NewtCanvasAWT glCanvas;
private final NewtCanvasAWT glCanvas;
private final GLWindow glWindow;
private final GLUT glut = new GLUT();
public NewtGraphCanvas() {
super();
GLWindow glWindow1 = GLWindow.create(getCaps());
glCanvas = new NewtCanvasAWT(glWindow1);
glWindow = GLWindow.create(getCaps());
// glWindow.setSurfaceScale(new float[]{ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE});
glCanvas = new NewtCanvasAWT(glWindow);
super.initDrawable(glWindow);
glCanvas.setFocusable(true);
glCanvas.setIgnoreRepaint(true);
glCanvas.setMinimumSize(new Dimension(0, 0)); //Fix Canvas resize Issue
super.initDrawable(glWindow1);
// glCanvas.setMinimumSize(new Dimension(0, 0)); //Fix Canvas resize Issue
//Basic init
graphComponent = (Component) glCanvas;
// graphComponent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
......@@ -78,6 +82,15 @@ public class NewtGraphCanvas extends GraphDrawableImpl {
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
}
public GLWindow getWindow() {
return glWindow;
}
@Override
protected void init(GL2 gl) {
globalScale = glWindow.getCurrentSurfaceScale(new float[2])[0];
}
@Override
protected void render3DScene(GL2 gl, GLU glu) {
if (vizController.getVizConfig().isShowFPS()) {
......@@ -91,15 +104,29 @@ public class NewtGraphCanvas extends GraphDrawableImpl {
glu.gluOrtho2D(0, viewport.get(2), viewport.get(3), 0);
gl.glDepthFunc(GL2.GL_ALWAYS);
gl.glColor3i(192, 192, 192);
gl.glRasterPos2f(10, 15);
gl.glRasterPos2f(10, 15 + (getGlobalScale() > 1f ? 8 : 0));
String fpsRound = String.valueOf((int) fps);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_10, fpsRound);
if (getGlobalScale() > 1f) {
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, fpsRound);
} else {
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_10, fpsRound);
}
gl.glDepthFunc(GL2.GL_LESS);
gl.glPopMatrix();
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPopMatrix();
}
super.render3DScene(gl, glu);
}
@Override
protected void reshape3DScene(GL2 gl) {
}
@Override
public void destroy() {
super.destroy();
glCanvas.getNEWTChild().destroy();
}
}
......@@ -66,7 +66,7 @@ import org.gephi.visualization.selection.Rectangle;
public class StandardGraphIO implements GraphIO, VizArchitecture {
//Architecture
protected GraphDrawableImpl graphDrawable;
protected GLAbstractListener graphDrawable;
protected AbstractEngine engine;
protected VizEventManager vizEventManager;
protected VizController vizController;
......@@ -86,7 +86,7 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
@Override
public void initArchitecture() {
this.graphDrawable = VizController.getInstance().getDrawable();
this.graphDrawable = (GLAbstractListener) VizController.getInstance().getDrawable();
this.engine = VizController.getInstance().getEngine();
this.vizEventManager = VizController.getInstance().getVizEventManager();
this.vizController = VizController.getInstance();
......@@ -104,7 +104,6 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
if (vizController.getVizConfig().isSelectionEnable()) {
graphDrawable.graphComponent.addMouseMotionListener(this);
}
}
@Override
......@@ -121,8 +120,8 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
return;
}
float x = e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x;
float y = e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y;
float x = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x);
float y = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y);
if (SwingUtilities.isRightMouseButton(e)) {
//Save the coordinate of the start
......@@ -153,8 +152,8 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
//Update mouse position because the movement during dragging
if (graphDrawable.getGraphComponent().isShowing()) {
float x = e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x;
float y = e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y;
float x = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x);
float y = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y);
mousePosition[0] = x;
mousePosition[1] = graphDrawable.viewport.get(3) - y;
}
......@@ -195,8 +194,8 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
return;
}
float x = e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x;
float y = e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y;
float x = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x);
float y = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y);
mousePosition[0] = x;
mousePosition[1] = graphDrawable.viewport.get(3) - y;
......@@ -235,8 +234,8 @@ public class StandardGraphIO implements GraphIO, VizArchitecture {
return;
}
float x = e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x;//TODO Pourqoui ce osnt des float et pas des int
float y = e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y;
float x = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().x - graphDrawable.graphComponent.getLocationOnScreen().x);//TODO Pourqoui ce osnt des float et pas des int
float y = graphDrawable.getGlobalScale() * (e.getLocationOnScreen().y - graphDrawable.graphComponent.getLocationOnScreen().y);
if (rightButtonMoving[0] != -1) {
//The right button is pressed
......
......@@ -407,14 +407,14 @@ public class TextManager implements VizArchitecture {
String txt = textData.getText();
if (nodeRefresh) {
txt = buildText(node, objectModel, model.getNodeTextColumns());
if (txt == null || txt.isEmpty()) {
return;
}
Rectangle2D r = renderer.getBounds(txt);
objectModel.setTextBounds(r);
}
if (txt == null || txt.isEmpty()) {
return;
}
model.colorMode.textNodeColor(this, objectModel);
float sizeFactor = textData.getSize() * model.sizeMode.getSizeFactor2d(model.nodeSizeFactor, objectModel);
float sizeFactor = drawable.getGlobalScale() * textData.getSize() * model.sizeMode.getSizeFactor2d(model.nodeSizeFactor, objectModel);
if (sizeFactor * renderer.getCharWidth('a') < PIXEL_LIMIT) {
return;
}
......@@ -436,12 +436,12 @@ public class TextManager implements VizArchitecture {
String txt = textData.getText();
if (edgeRefresh) {
txt = buildText(edge, objectModel, model.getEdgeTextColumns());
if (txt == null || txt.isEmpty()) {
return;
}
Rectangle2D r = renderer.getBounds(txt);
objectModel.setTextBounds(r);
}
if (txt == null || txt.isEmpty()) {
return;
}
model.colorMode.textEdgeColor(this, objectModel);
// float sizeFactor = textData.getSize() * model.sizeMode.getSizeFactor2d(model.nodeSizeFactor, objectModel);
float sizeFactor = 1f;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册