Painter interface integration in progress.

This commit is contained in:
Martin Pernollet 2020-10-30 13:40:19 +01:00
parent a56fb13c7c
commit 163d77333a
80 changed files with 339 additions and 260 deletions

3
.gitignore vendored
View File

@ -11,6 +11,9 @@ target
*~/
*~
*.obj
*/.classpath
*/.project
*/.settings

View File

@ -13,7 +13,6 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.canvas.CanvasAWT;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.Renderer2d;
@ -46,10 +45,7 @@ public class TextOverlay implements Renderer2d{
}
protected void init(ICanvas canvas) {
if(canvas instanceof CanvasAWT)
initComponent((Component)canvas);
else
throw new RuntimeException("TextRenderer not implemented for this Canvas implementation");
initComponent((Component)canvas);
}
protected void initComponent(Component c){
@ -65,8 +61,7 @@ public class TextOverlay implements Renderer2d{
target.removeComponentListener(resizeListener);
}
/**
* @param painter TODO**************************************************************/
/****************************************************************/
public void appendText(Painter painter, Camera cam, String s, Coord3d position, Halign halign, Valign valign, Color color){
Coord3d posScreen = cam.modelToScreen(painter, position);

View File

@ -67,7 +67,7 @@ GL.CONST
IGLLoader
Move
- Drawable texture to NATIVE because it uses an internal
- Drawable texture to NATIVE because it uses an internal texture
Dive in
- AWTImageViewport
@ -104,7 +104,7 @@ Ajouter un test U
Tous les utilisateur de getCurrentContext ne devraient pas le faire explicitement, idéalement c'est à l'intérieur du Painter
AbstractCameraController -> Mouse pickers
Demo with
FINAL CLEANUP ===========

View File

@ -206,6 +206,10 @@ public class Chart {
/* FRAME */
public IFrame open() {
return open("Jzy3d", new Rectangle(0, 0, 600, 600));
}
public IFrame open(String title, int width, int height) {
return open(title, new Rectangle(0, 0, width, height));
}

View File

@ -86,22 +86,19 @@ public class PickingSupport {
protected TicToc perf = new TicToc();
public void pickObjects(Painter painter, GL gl, GLU glu, View view, Graph graph, IntegerCoord2d pickPoint) {
public void pickObjects(Painter painter, GL gll, GLU gluu, View view, Graph graph, IntegerCoord2d pickPoint) {
perf.tic();
int viewport[] = new int[4];
int selectBuf[] = new int[bufferSize]; // TODO: move @ construction
IntBuffer selectBuffer = Buffers.newDirectIntBuffer(bufferSize);
if (!gl.isGL2()) throw new UnsupportedOperationException();
// Prepare selection data
gl.getGL2().glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
gl.getGL2().glSelectBuffer(bufferSize, selectBuffer);
gl.getGL2().glRenderMode(GL2.GL_SELECT);
gl.getGL2().glInitNames();
gl.getGL2().glPushName(0);
painter.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
painter.glSelectBuffer(bufferSize, selectBuffer);
painter.glRenderMode(GL2.GL_SELECT);
painter.glInitNames();
painter.glPushName(0);
// Retrieve view settings
Camera camera = view.getCamera();
@ -112,33 +109,35 @@ public class PickingSupport {
double ypick = pickPoint.y;
// Setup projection matrix
gl.getGL2().glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.getGL2().glPushMatrix();
painter.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
painter.glPushMatrix();
{
gl.getGL2().glLoadIdentity();
painter.glLoadIdentity();
// Setup picking matrix, and update view frustrum
glu.gluPickMatrix(xpick, ypick, brushSize, brushSize, viewport, 0);
painter.gluPickMatrix(xpick, ypick, brushSize, brushSize, viewport, 0);
camera.doShoot(painter, cMode);
// Draw each pickable element in select buffer
gl.getGL2().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
painter.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
synchronized(this){
for(Pickable pickable: pickables.values()){
setCurrentName(gl, pickable);
setCurrentName(painter, pickable);
pickable.setTransform(viewTransform);
pickable.draw(painter, gl, glu, camera);
releaseCurrentName(gl);
pickable.draw(painter, gll, gluu, camera);
releaseCurrentName(painter);
}
}
// Back to projection matrix
gl.getGL2().glMatrixMode(GLMatrixFunc.GL_PROJECTION);
painter.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
}
gl.getGL2().glPopMatrix();
gl.glFlush();
painter.glPopMatrix();
painter.glFlush();
// Process hits
int hits = gl.getGL2().glRenderMode(GL2.GL_RENDER);
int hits = painter.glRenderMode(GL2.GL_RENDER);
selectBuffer.get(selectBuf);
List<Pickable> picked = processHits(hits, selectBuf);
@ -157,18 +156,18 @@ public class PickingSupport {
return perf.elapsedMilisecond();
}
protected void setCurrentName(GL gl, Pickable pickable){
protected void setCurrentName(Painter painter, Pickable pickable){
if(method==0)
gl.getGL2().glLoadName(pickable.getPickingId());
painter.glLoadName(pickable.getPickingId());
else
gl.getGL2().glPushName(pickable.getPickingId());
painter.glPushName(pickable.getPickingId());
}
protected void releaseCurrentName(GL gl){
protected void releaseCurrentName(Painter painter){
if(method==0)
;
else
gl.getGL2().glPopName();
painter.glPopName();
}
protected static int method = 0;

View File

@ -27,7 +27,6 @@ import org.jzy3d.plot3d.rendering.ordering.BarycentreOrderingStrategy;
import org.jzy3d.plot3d.rendering.scene.Graph;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
@ -112,15 +111,7 @@ public abstract class ChartComponentFactory implements IChartComponentFactory {
return axe;
}
@Override
public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL) {
return new Renderer3d(view, traceGL, debugGL);
}
@Override
public Renderer3d newRenderer(View view) {
return newRenderer(view, false, false);
}
@Override
public AbstractOrderingStrategy newOrderingStrategy() {

View File

@ -20,7 +20,6 @@ import org.jzy3d.plot3d.rendering.ordering.AbstractOrderingStrategy;
import org.jzy3d.plot3d.rendering.scene.Graph;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.rendering.view.layout.IViewportLayout;
@ -37,8 +36,8 @@ public interface IChartComponentFactory {
public View newView(IChartComponentFactory factory, Scene scene, ICanvas canvas, Quality quality);
public Camera newCamera(Coord3d center);
public IAxe newAxe(BoundingBox3d box, View view);
public Renderer3d newRenderer(View view);
public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
//public Renderer3d newRenderer(View view);
//public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
public AbstractOrderingStrategy newOrderingStrategy();
public ICanvas newCanvas(Scene scene, Quality quality);

View File

@ -24,7 +24,9 @@ public class StringGraphGenerator {
public static DefaultGraphLayout2d<String> getRandomLayout(IGraph<String,String> graph, float size){
DefaultGraphLayout2d<String> layout = new DefaultGraphLayout2d<String>();
Random rng = new Random();
Random rng = new Random();
rng.setSeed(0);
for (String v: graph.getVertices()) {
float x = rng.nextFloat()*size-size/2;
float y = rng.nextFloat()*size-size/2;

View File

@ -2,6 +2,7 @@ package org.jzy3d.painters;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
@ -233,9 +234,28 @@ public class NativeDesktopPainter extends AbstractPainter implements Painter {
public void glPixelZoom(float xfactor, float yfactor) {
gl.getGL2().glPixelZoom(xfactor, yfactor);
}
@Override
public void glPixelStorei(int pname, int param) {
gl.glPixelStorei(pname, param);
}
@Override
public void glBitmap(int width, int height, float xorig, float yorig, float xmove, float ymove, byte[] bitmap, int bitmap_offset) {
gl.getGL2().glBitmap(width, height, xorig, yorig, xmove, ymove, bitmap, bitmap_offset);
}
@Override
public void glutBitmapString(int font, String string) {
glut.glutBitmapString(font, string);
}
// GL LISTS
@Override
public int glGenLists(int range) {
return gl.getGL2().glGenLists(range);
@ -407,6 +427,7 @@ public class NativeDesktopPainter extends AbstractPainter implements Painter {
}
// GL OTHER
@Override
public void glClearColor(float red, float green, float blue, float alpha) {
gl.glClearColor(red, green, blue, alpha);
@ -421,7 +442,44 @@ public class NativeDesktopPainter extends AbstractPainter implements Painter {
public void glClear(int mask) {
gl.glClear(mask);
}
// GL PICKING
@Override
public void glInitNames() {
gl.getGL2().glInitNames();
}
@Override
public void glLoadName(int name) {
gl.getGL2().glLoadName(name);
}
@Override
public void glPushName(int name) {
gl.getGL2().glPushName(name);
}
@Override
public void glPopName() {
gl.getGL2().glPopName();
}
@Override
public void glSelectBuffer(int size, IntBuffer buffer) {
gl.getGL2().glSelectBuffer(size, buffer);
}
@Override
public void gluPickMatrix(double x, double y, double delX, double delY, int[] viewport, int viewport_offset) {
glu.gluPickMatrix(x, y, delX, delY, viewport, viewport_offset);
}
@Override
public void glFlush() {
gl.glFlush();
}
}

View File

@ -2,6 +2,7 @@ package org.jzy3d.painters;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.jzy3d.plot3d.pipelines.NotImplementedException;
import org.jzy3d.plot3d.primitives.axes.IAxe;
@ -228,7 +229,22 @@ public class NativeEmbeddedPainter extends AbstractPainter implements Painter{
GLES2CompatUtils.glPixelZoom(xfactor, yfactor);
}
@Override
public void glPixelStorei(int pname, int param) {
throw new NotImplementedException();
//GLES2CompatUtils.glPixelStorei(pname, param);
}
@Override
public void glBitmap(int width, int height, float xorig, float yorig, float xmove, float ymove, byte[] bitmap,
int bitmap_offset) {
GLES2CompatUtils.glBitmap(width, height, xorig, yorig, xmove, ymove, bitmap, bitmap_offset);
}
@Override
public void glutBitmapString(int font, String string) {
glut.glutBitmapString(font, string);
}
// GL LISTS
@ -428,4 +444,47 @@ public class NativeEmbeddedPainter extends AbstractPainter implements Painter{
gl.glClear(mask);
}
// GL PICKING
@Override
public void glInitNames() {
throw new NotImplementedException();
//gl.getGL2().glInitNames();
}
@Override
public void glLoadName(int name) {
throw new NotImplementedException();
//gl.getGL2().glLoadName(name);
}
@Override
public void glPushName(int name) {
throw new NotImplementedException();
//gl.getGL2().glPushName(name);
}
@Override
public void glPopName() {
throw new NotImplementedException();
//gl.getGL2().glPopName();
}
@Override
public void glSelectBuffer(int size, IntBuffer buffer) {
throw new NotImplementedException();
//gl.getGL2().glSelectBuffer(size, buffer);
}
@Override
public void gluPickMatrix(double x, double y, double delX, double delY, int[] viewport, int viewport_offset) {
throw new NotImplementedException();
//glu.gluPickMatrix(x, y, delX, delY, viewport, viewport_offset);
}
@Override
public void glFlush() {
throw new NotImplementedException();
//gl.glFlush();
}
}

View File

@ -2,6 +2,7 @@ package org.jzy3d.painters;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
@ -134,8 +135,12 @@ public interface Painter {
public void glDrawPixels(int width, int height, int format, int type, Buffer pixels);
public void glPixelZoom(float xfactor, float yfactor);
public void glPixelStorei(int pname, int param);
public void glRasterPos3f(float x, float y, float z);
public void glBitmap(int width, int height, float xorig, float yorig, float xmove, float ymove, byte[] bitmap, int bitmap_offset);
public void glutBitmapString(final int font, final String string);
// GL VIEWPOINT
public void glOrtho(double left, double right, double bottom, double top, double near_val, double far_val);
@ -181,5 +186,15 @@ public interface Painter {
public void glClearColor(float red, float green, float blue, float alpha);
public void glClearDepth(double d);
public void glClear(int mask);
// GL PICKING
public void glInitNames();
public void glLoadName(int name);
public void glPushName(int name);
public void glPopName();
public void glSelectBuffer(int size, IntBuffer buffer);
public void gluPickMatrix(double x, double y, double delX, double delY, int[] viewport, int viewport_offset);
public void glFlush();
}

View File

@ -9,7 +9,6 @@ import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Utils;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.symbols.MaskImageSymbolHandler;
import org.jzy3d.plot3d.primitives.symbols.SymbolHandler;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.transform.Transform;
@ -42,7 +41,7 @@ public class LineStrip extends AbstractWireframeable {
public LineStrip(int n) {
points = new ArrayList<Point>(n);
bbox = new BoundingBox3d();
symbolHandler = new MaskImageSymbolHandler(n);
//symbolHandler = new MaskImageSymbolHandler(n);
setWireframeColor(null);
}
@ -264,7 +263,8 @@ public class LineStrip extends AbstractWireframeable {
public void setShowSymbols(boolean showSymbols) {
if (!showSymbols){
symbolHandler.clear();
if(symbolHandler!=null)
symbolHandler.clear();
}
else {
if(symbolHandler!=null){

View File

@ -8,7 +8,6 @@ import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.GLES2CompatUtils;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.graphs.AbstractDrawableGraph2d;
import org.jzy3d.plot3d.primitives.textured.DrawableTexture;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.text.align.Halign;
import org.jzy3d.plot3d.text.align.Valign;
@ -104,12 +103,12 @@ public class DefaultDrawableGraph2d<V, E> extends AbstractDrawableGraph2d<V, E>
@Override
public void applyGeometryTransform(Transform transform) {
Logger.getLogger(DrawableTexture.class).warn("not implemented");
Logger.getLogger(DefaultDrawableGraph2d.class).warn("not implemented");
}
@Override
public void updateBounds() {
Logger.getLogger(DrawableTexture.class).warn("not implemented");
Logger.getLogger(DefaultDrawableGraph2d.class).warn("not implemented");
}
}

View File

@ -5,7 +5,6 @@ import java.io.IOException;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View;
import com.jogamp.nativewindow.ScalableSurface;
@ -36,7 +35,7 @@ public interface ICanvas {
/** Returns the renderer's height, i.e. the display height. */
public int getRendererHeight();
public Renderer3d getRenderer();
//public Renderer3d getRenderer();
/**
* Invoked when a user requires the Canvas to be repainted (e.g. a non 3d

View File

@ -241,8 +241,7 @@ public class Graph {
return monotypes;
}
/** Update all interactive {@link AbstractDrawable} projections
* @param painter TODO*/
/** Update all interactive {@link AbstractDrawable} projections */
public synchronized void project(Painter painter, Camera camera) {
for (AbstractDrawable d : components) {
if (d instanceof Selectable)

View File

@ -9,7 +9,6 @@ import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.lights.Light;
import org.jzy3d.plot3d.rendering.lights.LightSet;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2011, Martin Pernollet
* Copyright (c) Since 2010, Martin Pernollet
* All rights reserved.
*
* Redistribution in binary form, with or without modification, is permitted.

View File

@ -17,10 +17,10 @@ import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Rectangle;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.axes.AxeBox;
import org.jzy3d.plot3d.primitives.axes.IAxe;
import org.jzy3d.plot3d.primitives.selectable.Selectable;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.lights.LightSet;
@ -64,10 +64,8 @@ import com.jogamp.opengl.glu.GLU;
public class View {
protected static Logger LOGGER = Logger.getLogger(View.class);
/** A view may optionnaly know its parent chart. */
protected Chart chart;
public static float STRETCH_RATIO = 0.25f;
/**
@ -79,30 +77,21 @@ public class View {
protected boolean DISPLAY_AXE_WHOLE_BOUNDS = false;
protected boolean axeBoxDisplayed = true;
protected boolean squared = true;
protected Camera cam;
protected IAxe axe;
protected Quality quality;
protected Scene scene;
protected ICanvas canvas;
protected Painter painter;
protected Scene annotations;
protected Coord3d viewpoint;
protected Coord3d center;
protected Coord3d scaling;
protected BoundingBox3d viewbounds;
protected CameraMode cameraMode;
protected ViewPositionMode viewmode;
protected ViewBoundMode boundmode;
// protected BoundingBox3d targetBox;
protected Color bgColor = Color.BLACK;
protected List<IViewPointChangedListener> viewPointChangedListeners;
protected List<IViewIsVerticalEventListener> viewOnTopListeners;
protected List<IViewLifecycleEventListener> viewLifecycleListeners;
@ -119,9 +108,7 @@ public class View {
* rendering due to a canvas size change
*/
protected boolean viewDirty = false;
protected static View current;
protected BoundingBox3d initBounds;
/**
@ -133,9 +120,7 @@ public class View {
/** A slave view won't clear its color and depth buffer before rendering */
protected boolean slave = false;
protected SpaceTransformer spaceTransformer = new SpaceTransformer();
private ISquarifier squarifier;
/**
@ -214,20 +199,26 @@ public class View {
canvas.forceRepaint();
}
/**
* Perform the 2d projection of all {@link Selectable} objects of the scene.
*
* The result of the projection can be retrieved on the objects's instances.
*/
public void project() {
((NativeDesktopPainter)painter).getCurrentGL(canvas);
//((NativeDesktopPainter)painter).getCurrentGL(canvas);
scene.getGraph().project(painter, cam);
((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
//((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
}
/** Perform the 3d projection of a 2d coordinate.*/
public Coord3d projectMouse(int x, int y) {
((NativeDesktopPainter)painter).getCurrentGL(canvas);
//((NativeDesktopPainter)painter).getCurrentGL(canvas);
Coord3d p = cam.screenToModel(painter, new Coord3d(x, y, 0));
((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
//((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
return p;
}

View File

@ -4,7 +4,6 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Utils;
import org.jzy3d.painters.GLES2CompatUtils;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.AbstractDrawable;
import org.jzy3d.plot3d.primitives.AbstractGeometry;
@ -44,7 +43,7 @@ public class CameraDistanceAnnotation extends Point {
computeCameraPosition();
doTransform(painter, cam);
doDrawCamera(gl, glu, cam);
doDrawCamera(painter, cam);
Halign h = Halign.RIGHT;
Valign v = Valign.CENTER;
@ -87,20 +86,12 @@ public class CameraDistanceAnnotation extends Point {
xyz = xyz.div(scaling);
}
public void doDrawCamera(GL gl, GLU glu, Camera cam) {
if (gl.isGL2()) {
gl.getGL2().glPointSize(width);
gl.getGL2().glBegin(GL.GL_POINTS);
gl.getGL2().glColor4f(rgb.r, rgb.g, rgb.b, rgb.a);
gl.getGL2().glVertex3f(xyz.x, xyz.y, xyz.z);
gl.getGL2().glEnd();
} else {
GLES2CompatUtils.glPointSize(width);
GLES2CompatUtils.glBegin(GL.GL_POINTS);
GLES2CompatUtils.glColor4f(rgb.r, rgb.g, rgb.b, rgb.a);
GLES2CompatUtils.glVertex3f(xyz.x, xyz.y, xyz.z);
GLES2CompatUtils.glEnd();
}
public void doDrawCamera(Painter painter, Camera cam) {
painter.glPointSize(width);
painter.glBegin(GL.GL_POINTS);
painter.glColor4f(rgb.r, rgb.g, rgb.b, rgb.a);
painter.glVertex3f(xyz.x, xyz.y, xyz.z);
painter.glEnd();
}
protected View view;

View File

@ -47,5 +47,11 @@ public abstract class AbstractTextRenderer implements ITextRenderer {
public void setSpaceTransformer(SpaceTransformer transformer) {
this.spaceTransformer = transformer;
}
protected void glRaster(Painter painter, Coord3d position, Color color) {
painter.glColor3f(color.r, color.g, color.b);
painter.raster(position, spaceTransformer);
}
}

View File

@ -19,7 +19,7 @@ public interface ITextRenderer {
public BoundingBox3d drawText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Halign halign, Valign valign, Color color, Coord2d screenOffset);
public BoundingBox3d drawText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Halign halign, Valign valign, Color color, Coord3d sceneOffset);
public void drawSimpleText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color);
public void drawSimpleText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color);
public SpaceTransformer getSpaceTransformer();
public void setSpaceTransformer(SpaceTransformer transformer);

View File

@ -4,7 +4,6 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.GLES2CompatUtils;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.text.AbstractTextRenderer;
@ -18,30 +17,29 @@ import com.jogamp.opengl.glu.GLU;
/**
* A {@link TextBillboardRenderer} allows writing 2d text always facing the
* Camera of a 3d Scene. <br>
*
* TextBillboard provides the pixel definition of all characters of the ASCII
* alphabet. A default bitmap (plain rectangle) is provided for unrecognized
* characters (those that do not have an ASCII code). The bitmap library is
* static, and thus no overhead is generated by the use of several instances of
* TextBillboard. <br>
* TextBillboard.
*
* It is however not necessary to have an instance of TextBillboard for each
* drawn string. <br>
* <code>
* String s = new String("2d text in 3d Scene");<br>
* TextBillboard txt = new TextBillboard();<br>
* BoundingBox3d box;<br>
* <br>
* txt.drawText(gl, s, Coord3d.ORIGIN, Halign.LEFT, Valign.GROUND, Color.BLACK);<br>
* box = txt.drawText(gl, glu, cam, s, Coord3d.ORIGIN, Halign.LEFT, Valign.GROUND, Color.BLACK);<br>
* </code> <br>
* <b>Layout constants</b> <br>
* drawn string.
*
* <pre><code>
* String s = new String("2d text in 3d Scene");
* TextBillboard txt = new TextBillboard();
* BoundingBox3d box;
*
* txt.drawText(gl, s, Coord3d.ORIGIN, Halign.LEFT, Valign.GROUND, Color.BLACK);
* box = txt.drawText(gl, glu, cam, s, Coord3d.ORIGIN, Halign.LEFT, Valign.GROUND, Color.BLACK);
* </code></pre>
*
* <b>Layout constants</b>
* As demonstrated in the previous example, the {@link TextBillboardRenderer}
* handles vertical and horizontal layout of text according to the given text
* coordinate. <br>
* The following picture illustrates the text layout when using the various
* layout constants <img
* src="plot3d/primitives/doc-files/TextBillboardBillboard-1.gif">
*
*
* coordinate.
*
* @author Martin Pernollet
*/
@ -54,10 +52,10 @@ public class TextBillboardRenderer extends AbstractTextRenderer implements IText
}
@Override
public void drawSimpleText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
glRaster(gl, position, color);
public void drawSimpleText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
glRaster(painter, position, color);
printString(gl, s, Halign.RIGHT, Valign.GROUND);
printString(painter, s, Halign.RIGHT, Valign.GROUND);
}
/** Draw a string at the specified position. */
@ -70,23 +68,15 @@ public class TextBillboardRenderer extends AbstractTextRenderer implements IText
*/
@Override
public BoundingBox3d drawText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Halign halign, Valign valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) {
glRaster(gl, position, color);
BillBoardSize dims = printString(gl, s, halign, valign);
BoundingBox3d txtBounds = computeTextBounds(painter, gl, glu, cam, position, dims);
glRaster(painter, position, color);
BillBoardSize dims = printString(painter, s, halign, valign);
BoundingBox3d txtBounds = computeTextBounds(painter, cam, position, dims);
return txtBounds;
}
public void glRaster(GL gl, Coord3d position, Color color) {
if (gl.isGL2()) {
gl.getGL2().glColor3f(color.r, color.g, color.b);
gl.getGL2().glRasterPos3f(position.x, position.y, position.z);
} else {
GLES2CompatUtils.glColor3f(color.r, color.g, color.b);
GLES2CompatUtils.glRasterPos3f(position.x, position.y, position.z);
}
}
public BoundingBox3d computeTextBounds(Painter painter, GL gl, GLU glu, Camera cam, Coord3d position, BillBoardSize dims) {
protected BoundingBox3d computeTextBounds(Painter painter, Camera cam, Coord3d position, BillBoardSize dims) {
Coord3d posScreen = cam.modelToScreen(painter, position);
Coord3d botLeft = new Coord3d();
Coord3d topRight = new Coord3d();
@ -108,20 +98,20 @@ public class TextBillboardRenderer extends AbstractTextRenderer implements IText
/**
* Performs actual display of the string.
*
* @param gl
* GL2 context.
* @param painter TODO
* @param s
* the String that must be displayed.
* @param halign
* the horizontal alignment constant.
* @param valign
* the vertical alignment constant.
* @param gl
* GL2 context.
* @throws an
* IllegalArgumentException if the vertical or horizontal
* alignment constant value is unknown.
*/
private BillBoardSize printString(GL gl, String s, Halign halign, Valign valign) {
protected BillBoardSize printString(Painter painter, String s, Halign halign, Valign valign) {
byte[] acodes = s.getBytes();
int nchar = s.length();
float xorig = 0.0f;
@ -152,31 +142,20 @@ public class TextBillboardRenderer extends AbstractTextRenderer implements IText
throw new IllegalArgumentException("Vertical alignement constant unknown: " + valign);
// Draw the bitmaps
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
painter.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
int idx;
for (int c = 0; c < acodes.length; c++) {
idx = acodes[c] - 32;
if (idx < 0 || idx > ascii.length)
glBitmap(gl, charWidth, charHeight, xorig, yorig, xmove, ymove, nonascii, 0);
painter.glBitmap(charWidth, charHeight, xorig, yorig, xmove, ymove, nonascii, 0);
else
glBitmap(gl, charWidth, charHeight, xorig, yorig, xmove, ymove, ascii[idx], 0);
painter.glBitmap(charWidth, charHeight, xorig, yorig, xmove, ymove, ascii[idx], 0);
}
// Compute occupied space
return new BillBoardSize(xmove * nchar, charHeight, -xorig, -yorig);
}
/********************************************************************/
private void glBitmap(GL gl, int charWidth2, int charHeight2, float xorig, float yorig, float xmove, float ymove, byte[] nonascii2, int i) {
if (gl.isGL2()) {
gl.getGL2().glBitmap(charWidth, charHeight, xorig, yorig, xmove, ymove, nonascii, 0);
} else {
GLES2CompatUtils.glBitmap(charWidth, charHeight, xorig, yorig, xmove, ymove, nonascii, 0);
}
}
/**
* Provides information on the 2d space occupied by a
* {@link TextBillboardRenderer}

View File

@ -5,7 +5,6 @@ import org.jzy3d.colors.Color;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.GLES2CompatUtils;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.text.AbstractTextRenderer;
@ -62,16 +61,10 @@ public class TextBitmapRenderer extends AbstractTextRenderer implements ITextRen
}
@Override
public void drawSimpleText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
if (gl.isGL2()) {
gl.getGL2().glColor3f(color.r, color.g, color.b);
gl.getGL2().glRasterPos3f(position.x, position.y, position.z);
} else {
GLES2CompatUtils.glColor3f(color.r, color.g, color.b);
GLES2CompatUtils.glRasterPos3f(position.x, position.y, position.z);
}
glut.glutBitmapString(font, s);
public void drawSimpleText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
glRaster(painter, position, color);
painter.glutBitmapString(font, s);
}
/**
@ -103,7 +96,7 @@ public class TextBitmapRenderer extends AbstractTextRenderer implements ITextRen
// Draws actual string
glRasterPos(painter, gl, sceneOffset, posReal);
glut.glutBitmapString(font, text);
painter.glutBitmapString(font, text);
return computeTextBounds(painter, cam, posScreenShifted, strlen);
}
@ -115,7 +108,7 @@ public class TextBitmapRenderer extends AbstractTextRenderer implements ITextRen
painter.raster(posReal.add(sceneOffset), null);
}
public BoundingBox3d computeTextBounds(Painter painter, Camera cam, Coord3d posScreenShifted, float strlen) {
protected BoundingBox3d computeTextBounds(Painter painter, Camera cam, Coord3d posScreenShifted, float strlen) {
Coord3d botLeft = new Coord3d();
Coord3d topRight = new Coord3d();
botLeft.x = posScreenShifted.x;

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jzy3d</groupId>
<artifactId>jzy3d-depthpeeling</artifactId>
<name>Jzy3d Depth Peeling Extension</name>
<parent>
<groupId>org.jzy3d</groupId>
<artifactId>jzy3d-master</artifactId>
<artifactId>jzy3d-all</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

View File

@ -0,0 +1 @@
http://download.jzy3d.org/objfiles/bunny.obj

View File

@ -0,0 +1 @@
http://download.jzy3d.org/objfiles/dragon.obj

View File

@ -129,8 +129,7 @@ public class AWTMousePickingController extends AbstractCameraController implemen
GL gl = ((NativeDesktopPainter)chart().getView().getPainter()).getCurrentGL(chart.getCanvas());
Graph graph = chart().getScene().getGraph();
// will trigger vertex selection event to those subscribing to
// PickingSupport.
// will trigger vertex selection event to those subscribing to PickingSupport
picking.pickObjects(chart.getView().getPainter(), gl, glu, view, graph, new IntegerCoord2d(e.getX(), yflip));
}

View File

@ -85,10 +85,10 @@ public class AWTChartComponentFactory extends NativeChartFactory {
boolean debugGL = false;
if(isOffscreen()) {
return newOffscreenCanvas(factory, scene, quality, traceGL, debugGL);
return newOffscreenCanvas((NativeChartFactory)factory, scene, quality, traceGL, debugGL);
}
else
return new CanvasAWT(factory, scene, quality, getCapabilities(), traceGL, debugGL);
return new CanvasAWT((NativeChartFactory) factory, scene, quality, getCapabilities(), traceGL, debugGL);
}

View File

@ -6,6 +6,8 @@ import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.OffscreenCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
import org.jzy3d.plot3d.rendering.view.View;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
@ -28,10 +30,20 @@ public abstract class NativeChartFactory extends ChartComponentFactory{
return new NativeDesktopPainter();
}
protected ICanvas newOffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, boolean traceGL,
protected ICanvas newOffscreenCanvas(NativeChartFactory factory, Scene scene, Quality quality, boolean traceGL,
boolean debugGL) {
return new OffscreenCanvas(factory, scene, quality, getCapabilities(), width, height, traceGL, debugGL);
}
//@Override
public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL) {
return new Renderer3d(view, traceGL, debugGL);
}
//@Override
public Renderer3d newRenderer(View view) {
return newRenderer(view, false, false);
}
/************ PROFILE AND CAPABILITIES HELPERS ************/

View File

@ -23,7 +23,7 @@ public class OffscreenChartComponentFactory extends AWTChartComponentFactory {
boolean traceGL = false;
boolean debugGL = false;
return new OffscreenCanvas(factory, scene, quality, getCapabilities(), width, height, traceGL, debugGL);
return new OffscreenCanvas((NativeChartFactory)factory, scene, quality, getCapabilities(), width, height, traceGL, debugGL);
}
}

View File

@ -5,7 +5,7 @@ import java.awt.event.MouseWheelListener;
import java.io.File;
import java.io.IOException;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.chart.factories.NativeChartFactory;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
@ -31,12 +31,12 @@ import com.jogamp.opengl.util.texture.TextureIO;
*
* @author Martin Pernollet
*/
public class CanvasAWT extends GLCanvas implements IScreenCanvas {
public CanvasAWT(IChartComponentFactory factory, Scene scene, Quality quality) {
public class CanvasAWT extends GLCanvas implements IScreenCanvas, INativeCanvas {
public CanvasAWT(NativeChartFactory factory, Scene scene, Quality quality) {
this(factory, scene, quality, org.jzy3d.chart.Settings.getInstance().getGLCapabilities());
}
public CanvasAWT(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
public CanvasAWT(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
this(factory, scene, quality, glci, false, false);
}
@ -44,7 +44,7 @@ public class CanvasAWT extends GLCanvas implements IScreenCanvas {
* Initialize a {@link CanvasAWT} attached to a {@link Scene}, with a given
* rendering {@link Quality}.
*/
public CanvasAWT(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
public CanvasAWT(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
super(glci);
view = scene.newView(this, quality);

View File

@ -6,7 +6,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.chart.factories.NativeChartFactory;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
@ -33,14 +33,14 @@ import com.jogamp.opengl.util.texture.TextureIO;
* If a non AWT panel where required, follow the guidelines given in
* {@link IScreenCanvas} documentation.
*/
public class CanvasNewtAwt extends Panel implements IScreenCanvas {
public class CanvasNewtAwt extends Panel implements IScreenCanvas, INativeCanvas {
static Logger LOGGER = Logger.getLogger(CanvasNewtAwt.class);
public CanvasNewtAwt(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
public CanvasNewtAwt(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
this(factory, scene, quality, glci, false, false);
}
public CanvasNewtAwt(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
public CanvasNewtAwt(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
window = GLWindow.create(glci);
canvas = new NewtCanvasAWT(window);
view = scene.newView(this, quality);

View File

@ -3,7 +3,7 @@ package org.jzy3d.plot3d.rendering.canvas;
import java.io.File;
import java.io.IOException;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.chart.factories.NativeChartFactory;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.pipelines.NotImplementedException;
import org.jzy3d.plot3d.rendering.scene.Scene;
@ -37,12 +37,12 @@ import com.jogamp.opengl.util.texture.TextureIO;
* @author Nils Hoffman
* @author Martin Pernollet
*/
public class OffscreenCanvas implements ICanvas {
public OffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height) {
public class OffscreenCanvas implements ICanvas, INativeCanvas {
public OffscreenCanvas(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height) {
this(factory, scene, quality, capabilities, width, height, false, false);
}
public OffscreenCanvas(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height, boolean traceGL, boolean debugGL) {
public OffscreenCanvas(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilities capabilities, int width, int height, boolean traceGL, boolean debugGL) {
this.view = scene.newView(this, quality);
this.renderer = factory.newRenderer(view, traceGL, debugGL);

View File

@ -12,6 +12,7 @@ import java.awt.image.DataBufferByte;
import java.awt.image.PixelGrabber;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -142,7 +143,7 @@ public class GLImage {
public static ByteBuffer allocBytes(byte[] bytearray) {
ByteBuffer bb = ByteBuffer.allocateDirect(bytearray.length * SIZE_BYTE)
.order(ByteOrder.nativeOrder());
bb.put(bytearray).flip();
((Buffer)bb.put(bytearray)).flip();
return bb;
}

View File

@ -45,6 +45,24 @@ public class AWTView extends ChartView {
super.dispose();
renderers.clear();
}
public void project() {
((NativeDesktopPainter)painter).getCurrentGL(canvas);
scene.getGraph().project(painter, cam);
((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
}
/** Perform the 3d projection of a 2d coordinate.*/
public Coord3d projectMouse(int x, int y) {
((NativeDesktopPainter)painter).getCurrentGL(canvas);
Coord3d p = cam.screenToModel(painter, new Coord3d(x, y, 0));
((NativeDesktopPainter)painter).getCurrentContext(canvas).release();
return p;
}
@Override
protected void renderAxeBox(IAxe axe, Scene scene, Camera camera, Coord3d scaling, boolean axeBoxDisplayed) {

View File

@ -1,36 +1,4 @@
Jzy3d - Core
Jzy3d - Native JOGL Core
================================
Project layout
--------------
Source folders organisation:
- api holds the API sources
- bridge holds classes to ease injection of components from a given windowing toolkit to another one (awt, swing, swt, newt)
- tests holds
- ChartTest, a tool to compare a chart with a previously saved screenshot
- Replay, a utility to record and validate a sequence of mouse and key interactions results on a chart (work in progress)
- awt and swing hold Windowing toolkit dependent classes.
- Will be moved soon to external module as jzy3d-swt.
Build files
--------------
- Maven: pom.xml, with dependency on parent artifact <a href="https://github.com/jzy3d/jzy3d-api">jzy3d-master</a>
- Eclipse: .project & .classpath files, generated by command "mvn eclipse:eclipse"
- Ant: build.xml
- Javadoc: javadoc.xml
Library dependencies
--------------
- <a href="http://jogamp.org/jogl/www/">jogl2</a>
- <a href="https://github.com/jzy3d/jzy3d-api/tree/master/jzy3d-jdt-core">jdt</a> (Java Delaunay Triangulation)
- opencsv
- log4j
- junit
License
--------------
New BSD
More information
--------------
http://www.jzy3d.org
The root of native rendering tools made with JOGL, without dependencies to a particular Windowing Toolkit (AWT, SWT, etc).

View File

@ -62,7 +62,7 @@ public class Settings {
}
/**
* Modifies the acceleration status for all {@link ICanvas.Canvas}
* Modifies the acceleration status for all {@link INativeCanvas.Canvas}
* instantiations. This doesn't modify the status of canvases that have
* already been instantiated.
*/

View File

@ -230,18 +230,7 @@ public class DrawableTexture extends AbstractDrawable implements ITranslucent {
protected void before(Painter painter, GL gl) {
painter.glPushMatrix();
// gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT,GL2.GL_NICEST);
painter.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
// gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
// gl.glPolygonOffset(1.0f, 1.0f);
// gl.glEnable(GL2.GL_BLEND);
// gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
// gl.glEnable(GL2.GL_ALPHA_TEST);
// gl.glAlphaFunc(GL2.GL_GREATER, 0);
painter.glEnable(GL.GL_TEXTURE_2D);
painter.glTexEnvf(GL.GL_TEXTURE_2D, GL2ES1.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
}
@ -249,8 +238,6 @@ public class DrawableTexture extends AbstractDrawable implements ITranslucent {
protected void after(Painter painter, GL gl) {
painter.glDisable(GL.GL_TEXTURE_2D);
painter.glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_MODULATE);
// gl.glDisable(GL2.GL_ALPHA);
// gl.glDisable(GL2.GL_BLEND);
painter.glPopMatrix();
}

View File

@ -26,9 +26,7 @@ public class TranslucentQuad extends Quad implements ITranslucent {
painter.glBegin(GL2GL3.GL_QUADS); // <<<
for (Point p : points) {
if (mapper != null) {
Color c = mapper.getColor(p.xyz); // TODO: should store
// result in the
// point color
Color c = mapper.getColor(p.xyz);
painter.colorAlphaFactor(c, alpha);
} else
painter.colorAlphaFactor(p.rgb, alpha);

View File

@ -82,8 +82,11 @@ public class DrawableVBO extends AbstractDrawable implements IGLBindedResource {
// @see
// http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/
@Override
public void draw(Painter painter, GL gl, GLU glu, Camera cam) {
if (hasMountedOnce) {
public void draw(Painter painter, GL gll, GLU gluu, Camera cam) {
if (hasMountedOnce) {
GL gl = ((NativeDesktopPainter)painter).getGL();
GLU glu = ((NativeDesktopPainter)painter).getGLU();
doTransform(painter, cam);
configure(painter, gl);
doDrawElements(gl);

View File

@ -0,0 +1,7 @@
package org.jzy3d.plot3d.rendering.canvas;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
public interface INativeCanvas {
public Renderer3d getRenderer();
}

View File

@ -30,7 +30,7 @@ public class JOGLTextRenderer extends AbstractTextRenderer implements ITextRende
}
@Override
public void drawSimpleText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
public void drawSimpleText(Painter painter, GL gl, GLU glu, Camera cam, String s, Coord3d position, Color color) {
renderer.begin3DRendering();
renderer.draw3D(s, position.x, position.y, position.z, 0.01f);
renderer.flush();

View File

@ -17,6 +17,7 @@ import org.jzy3d.javafx.controllers.keyboard.JavaFXCameraKeyController;
import org.jzy3d.javafx.controllers.mouse.JavaFXCameraMouseController;
import org.jzy3d.javafx.controllers.mouse.JavaFXMousePickingController;
import org.jzy3d.maths.Utils;
import org.jzy3d.plot3d.rendering.canvas.INativeCanvas;
import org.jzy3d.plot3d.rendering.canvas.OffscreenCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.view.AWTImageRenderer3d.DisplayListener;
@ -43,7 +44,7 @@ public class JavaFXChartFactory extends AWTChartComponentFactory {
public Image getScreenshotAsJavaFXImage(AWTChart chart) {
chart.screenshot();
AWTRenderer3d renderer = (AWTRenderer3d) chart.getCanvas().getRenderer();
AWTRenderer3d renderer = (AWTRenderer3d) ((INativeCanvas)chart.getCanvas()).getRenderer();
BufferedImage i = renderer.getLastScreenshotImage();
if (i != null) {
Image image = SwingFXUtils.toFXImage(i, null);
@ -94,13 +95,13 @@ public class JavaFXChartFactory extends AWTChartComponentFactory {
* Register for renderer notifications with a new JavaFX Image
*/
public void bind(final ImageView imageView, AWTChart chart) {
if (!(chart.getCanvas().getRenderer() instanceof JavaFXRenderer3d)) {
if (!(((INativeCanvas)chart.getCanvas()).getRenderer() instanceof JavaFXRenderer3d)) {
LOGGER.error("NOT BINDING IMAGE VIEW TO CHART AS NOT A JAVAFX RENDERER");
return;
}
// Set listener on renderer to update imageView
JavaFXRenderer3d renderer = (JavaFXRenderer3d) chart.getCanvas().getRenderer();
JavaFXRenderer3d renderer = (JavaFXRenderer3d) ((INativeCanvas)chart.getCanvas()).getRenderer();
renderer.addDisplayListener(new DisplayListener() {
@Override
public void onDisplay(Object image) {

View File

@ -95,7 +95,7 @@ public class NewtChartComponentFactory extends NativeChartFactory {
boolean traceGL = false;
boolean debugGL = false;
return new CanvasNewtAwt(factory, scene, quality, getCapabilities(), traceGL, debugGL);
return new CanvasNewtAwt((NativeChartFactory)factory, scene, quality, getCapabilities(), traceGL, debugGL);
}
@Override

View File

@ -19,7 +19,7 @@ public class SwingChartComponentFactory extends AWTChartComponentFactory {
boolean traceGL = false;
boolean debugGL = false;
return new CanvasSwing(factory, scene, quality, capabilities, traceGL, debugGL);
return new CanvasSwing((NativeChartFactory) factory, scene, quality, capabilities, traceGL, debugGL);
}
/* */

View File

@ -5,7 +5,7 @@ import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.chart.factories.NativeChartFactory;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Renderer3d;
@ -34,8 +34,8 @@ import com.jogamp.opengl.util.texture.TextureIO;
* @author Martin Pernollet
*/
@Deprecated
public class CanvasSwing extends GLJPanel implements IScreenCanvas {
public CanvasSwing(IChartComponentFactory factory, Scene scene,
public class CanvasSwing extends GLJPanel implements IScreenCanvas, INativeCanvas {
public CanvasSwing(NativeChartFactory factory, Scene scene,
Quality quality) {
this(factory, scene, quality, org.jzy3d.chart.Settings.getInstance()
.getGLCapabilities());
@ -45,7 +45,7 @@ public class CanvasSwing extends GLJPanel implements IScreenCanvas {
* Initialize a Canvas3d attached to a {@link Scene}, with a given rendering
* {@link Quality}.
*/
public CanvasSwing(IChartComponentFactory factory, Scene scene,
public CanvasSwing(NativeChartFactory factory, Scene scene,
Quality quality, GLCapabilitiesImmutable glci) {
this(factory, scene, quality, glci, false, false);
}
@ -54,7 +54,7 @@ public class CanvasSwing extends GLJPanel implements IScreenCanvas {
* Initialize a Canvas3d attached to a {@link Scene}, with a given rendering
* {@link Quality}.
*/
public CanvasSwing(IChartComponentFactory factory, Scene scene,
public CanvasSwing(NativeChartFactory factory, Scene scene,
Quality quality, GLCapabilitiesImmutable glci, boolean traceGL,
boolean debugGL) {
super(glci);

View File

@ -21,6 +21,7 @@ import javax.swing.border.Border;
import net.miginfocom.swing.MigLayout;
import org.jzy3d.chart.Chart;
import org.jzy3d.plot3d.rendering.canvas.INativeCanvas;
import org.jzy3d.plot3d.rendering.canvas.OffscreenCanvas;
import org.jzy3d.plot3d.rendering.view.AWTRenderer3d;
import org.jzy3d.ui.views.ImagePanel;
@ -192,7 +193,7 @@ public class MultiChartPanel extends JPanel {
} catch (IOException e) {
throw new RuntimeException(e);
}
AWTRenderer3d renderer = (AWTRenderer3d)chart.getCanvas().getRenderer();
AWTRenderer3d renderer = (AWTRenderer3d)((INativeCanvas)chart.getCanvas()).getRenderer();
BufferedImage i = renderer.getLastScreenshotImage();
JPanel component = new ImagePanel(i);
return component;

View File

@ -6,8 +6,9 @@ import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.chart.factories.NativeChartFactory;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.rendering.canvas.INativeCanvas;
import org.jzy3d.plot3d.rendering.canvas.IScreenCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
@ -33,13 +34,13 @@ import com.jogamp.opengl.util.texture.TextureIO;
* If a non AWT panel where required, follow the guidelines given in
* {@link IScreenCanvas} documentation.
*/
public class CanvasNewtSWT extends Composite implements IScreenCanvas {
public class CanvasNewtSWT extends Composite implements IScreenCanvas, INativeCanvas {
public CanvasNewtSWT(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
public CanvasNewtSWT(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci) {
this(factory, scene, quality, glci, false, false);
}
public CanvasNewtSWT(IChartComponentFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
public CanvasNewtSWT(NativeChartFactory factory, Scene scene, Quality quality, GLCapabilitiesImmutable glci, boolean traceGL, boolean debugGL) {
super(((SWTChartComponentFactory) factory).getComposite(), SWT.NONE);
this.setLayout(new FillLayout());
window = GLWindow.create(glci);

View File

@ -102,7 +102,7 @@ public class SWTChartComponentFactory extends NativeChartFactory {
boolean traceGL = false;
boolean debugGL = false;
return new CanvasNewtSWT(factory, scene, quality, getCapabilities(), traceGL, debugGL);
return new CanvasNewtSWT((NativeChartFactory)factory, scene, quality, getCapabilities(), traceGL, debugGL);
}
@Override

View File

@ -1,4 +1,4 @@
package org.jzy3d.analysis;
package org.jzy3d.demos;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;

View File

@ -18,6 +18,7 @@ import org.jzy3d.chart.factories.AWTChartComponentFactory;
import org.jzy3d.maths.IntegerCoord2d;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.primitives.AbstractDrawable;
import org.jzy3d.plot3d.rendering.canvas.INativeCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.view.AWTRenderer3d;
@ -176,9 +177,9 @@ public class ChartTester{
public void compare(Chart chart, String filename) throws IOException, ChartTestFailed {
// Will compare buffered image
if(chart.getCanvas().getRenderer() instanceof AWTRenderer3d){
if(((INativeCanvas)chart.getCanvas()).getRenderer() instanceof AWTRenderer3d){
chart.screenshot();
AWTRenderer3d awtR = (AWTRenderer3d)chart.getCanvas().getRenderer();
AWTRenderer3d awtR = (AWTRenderer3d)((INativeCanvas)chart.getCanvas()).getRenderer();
BufferedImage actual = awtR.getLastScreenshotImage();
BufferedImage expected = loadBufferedImage(filename);