This commit is contained in:
Martin Pernollet 2020-12-30 15:59:54 +01:00
parent bc82b6d898
commit 13b35a16f1
28 changed files with 379 additions and 159 deletions

View File

@ -22,6 +22,14 @@ import org.jzy3d.plot3d.rendering.view.modes.ViewPositionMode;
public class AWTView extends ChartView {
protected List<ITooltipRenderer> tooltips;
protected List<AWTRenderer2d> renderers;
protected AWTImageViewport backgroundViewport;
protected BufferedImage backgroundImage = null;
//protected java.awt.Color overlayBackground = new java.awt.Color(0, 0, 0, 0);
public AWTView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super(factory, scene, canvas, quality);
}
public void initInstance(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super.initInstance(factory, scene, canvas, quality);
@ -149,17 +157,11 @@ public class AWTView extends ChartView {
renderers.remove(renderer);
}
protected boolean hasOverlayStuffs() {
public List<AWTRenderer2d> getRenderers2d() {
return renderers;
}
public boolean hasOverlayStuffs() {
return tooltips.size() > 0 || renderers.size() > 0;
}
protected List<AWTRenderer2d> renderers;
protected AWTImageViewport backgroundViewport;
protected BufferedImage backgroundImage = null;
protected java.awt.Color overlayBackground = new java.awt.Color(0, 0, 0, 0);
public AWTView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super(factory, scene, canvas, quality);
}
}

View File

@ -13,8 +13,6 @@ public class AnalysisLauncher {
}
public static void open(IAnalysis demo, Rectangle rectangle) throws Exception {
//Settings.getInstance().setHardwareAccelerated(true);
demo.init();
Chart chart = demo.getChart();
@ -23,8 +21,6 @@ public class AnalysisLauncher {
ChartLauncher.instructions();
ChartLauncher.openChart(chart, rectangle, demo.getName());
// ChartLauncher.screenshot(demo.getChart(),
// "./data/screenshots/"+demo.getName()+".png");
}
/**

View File

@ -36,12 +36,6 @@ public abstract class ChartFactory implements IChartFactory {
static Logger logger = Logger.getLogger(ChartFactory.class);
//public abstract ICameraMouseController newMouseCameraController(Chart chart);
//public abstract IMousePickingController newMousePickingController(Chart chart, int clickWidth);
//public abstract IScreenshotKeyController newKeyboardScreenshotController(Chart chart);
//public abstract ICameraKeyController newKeyboardCameraController(Chart chart);
//public abstract IFrame newFrame(Chart chart, Rectangle bounds, String title);
//public abstract ICanvas newCanvas(IChartFactory factory, Scene scene, Quality quality);
public abstract IViewportLayout newViewportLayout();
boolean offscreen = false;
@ -55,7 +49,7 @@ public abstract class ChartFactory implements IChartFactory {
}
public ChartFactory(IPainterFactory painterFactory) {
this.painterFactory = painterFactory;
setPainterFactory(painterFactory);
}
@Override
@ -66,6 +60,9 @@ public abstract class ChartFactory implements IChartFactory {
@Override
public void setPainterFactory(IPainterFactory painterFactory) {
this.painterFactory = painterFactory;
if(painterFactory!=null)
this.painterFactory.setChartFactory(this);
}

View File

@ -22,16 +22,21 @@ public interface IChartFactory {
public IPainterFactory getPainterFactory();
public void setPainterFactory(IPainterFactory painterFactory);
public View newView(Scene scene, ICanvas canvas, Quality quality);
public View newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality);
public Camera newCamera(Coord3d center);
public Chart newChart();
public Chart newChart(Quality quality);
public Chart newChart(IChartFactory factory, Quality quality);
public ChartScene newScene(boolean sort);
public Graph newGraph(Scene scene, AbstractOrderingStrategy strategy, boolean sort);
public View newView(Scene scene, ICanvas canvas, Quality quality);
public View newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality);
public Camera newCamera(Coord3d center);
public IAxis newAxe(BoundingBox3d box, View view);
//public Renderer3d newRenderer(View view);
//public Renderer3d newRenderer(View view, boolean traceGL, boolean debugGL);
public AbstractOrderingStrategy newOrderingStrategy();

View File

@ -0,0 +1,7 @@
package org.jzy3d.chart.factories;
import org.jzy3d.plot3d.primitives.symbols.SymbolHandler;
public interface IDrawableFactory {
public SymbolHandler newSymbolHandler();
}

View File

@ -11,6 +11,7 @@ import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.IViewOverlay;
/**
* An {@link IPainterFactory} provides all Windowing toolkit dependent objects.
@ -23,7 +24,7 @@ import org.jzy3d.plot3d.rendering.scene.Scene;
* SWT, Swing, JavaFX:
* <ul>
* <li>The {@link ICanvas}
* <li> And so does the {@link IFrame},
* <li>And so does the {@link IFrame},
* <li>Controllers : {@link IMousePickingController},
* {@link ICameraKeyController}, {@link IScreenshotKeyController}.
* </ul>
@ -31,8 +32,11 @@ import org.jzy3d.plot3d.rendering.scene.Scene;
* @author Martin Pernollet
*/
public interface IPainterFactory {
public Painter newPainter();
public IViewOverlay newViewOverlay();
public ICanvas newCanvas(IChartFactory factory, Scene scene, Quality quality);
public Animator newAnimator(ICanvas canvas);
@ -48,4 +52,9 @@ public interface IPainterFactory {
public IFrame newFrame(Chart chart);
public IFrame newFrame(Chart chart, Rectangle bounds, String title);
public void setChartFactory(IChartFactory factory);
public IChartFactory getChartFactory();
}

View File

@ -2,9 +2,6 @@ package org.jzy3d.painters;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.axis.IAxis;
import org.jzy3d.plot3d.rendering.canvas.IScreenCanvas;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.transform.Transform;

View File

@ -10,7 +10,7 @@ import org.jzy3d.plot3d.primitives.Point;
import org.jzy3d.plot3d.transform.space.SpaceTransformer;
/**
* SymbolHandlers are used to configure a symbol when rendering a {@link LineStrip}.
* {@link SymbolHandler}s are used to configure a symbol when rendering a {@link LineStrip}.
*
* @author martin
*

View File

@ -0,0 +1,7 @@
package org.jzy3d.plot3d.rendering.view;
import org.jzy3d.painters.Painter;
public interface IViewBackground {
public void render(Painter painter);
}

View File

@ -0,0 +1,7 @@
package org.jzy3d.plot3d.rendering.view;
import org.jzy3d.painters.Painter;
public interface IViewOverlay {
public void render(View view, ViewportConfiguration viewport, Painter painter);
}

View File

@ -151,6 +151,9 @@ public class View {
protected SpaceTransformer spaceTransformer = new SpaceTransformer();
private ISquarifier squarifier;
protected IViewOverlay viewOverlay;
protected IViewBackground viewBackground;
/**
* Create a view attached to a Scene, with its own Camera and Axe. The initial
* view point is set at {@link View.DEFAULT_VIEW}.
@ -188,6 +191,7 @@ public class View {
this.cam = factory.newCamera(center);
this.painter = factory.getPainterFactory().newPainter();
this.painter.setCamera(cam);
this.viewOverlay = factory.getPainterFactory().newViewOverlay();
this.scene = scene;
this.canvas = canvas;
@ -1171,6 +1175,7 @@ public class View {
}
public void renderOverlay(ViewportConfiguration viewportConfiguration) {
viewOverlay.render(this, viewportConfiguration, painter);
}
public void renderAnnotations(Camera camera) {

View File

@ -17,7 +17,6 @@ import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode;
/**
* TODO : stop my Animator properly

View File

@ -3,11 +3,13 @@ package org.jzy3d.chart.factories;
import org.jzy3d.chart.AWTChart;
import org.jzy3d.chart.Chart;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.axes.EmulGLAxisBox;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.EmulGLView;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.rendering.view.layout.EmulGLViewAndColorbarsLayout;
import org.jzy3d.plot3d.rendering.view.layout.ViewAndColorbarsLayout;
@ -33,8 +35,18 @@ public class EmulGLChartFactory extends ChartFactory {
}
@Override
public EmulGLView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
return new EmulGLView(factory, scene, canvas, quality);
public AWTView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
return new AWTView(factory, scene, canvas, quality);
}
@Override
public View newView(Scene scene, ICanvas canvas, Quality quality) {
return newView(getFactory(), scene, canvas, quality);
}
@Override
public Camera newCamera(Coord3d center) {
return new Camera(center);
}
@Override

View File

@ -13,8 +13,12 @@ import org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.EmulGLViewOverlay;
import org.jzy3d.plot3d.rendering.view.IViewOverlay;
public class EmulGLPainterFactory implements IPainterFactory{
IChartFactory chartFactory;
EmulGLCanvas internalCanvas;
EmulGLPainter internalPainter;
@ -27,6 +31,12 @@ public class EmulGLPainterFactory implements IPainterFactory{
return internalPainter;
}
@Override
public IViewOverlay newViewOverlay() {
return new EmulGLViewOverlay();
}
@Override
public EmulGLAnimator newAnimator(ICanvas canvas) {
return new EmulGLAnimator((EmulGLCanvas)canvas);
@ -96,4 +106,13 @@ public class EmulGLPainterFactory implements IPainterFactory{
return null;
}
public IChartFactory getChartFactory() {
return chartFactory;
}
public void setChartFactory(IChartFactory chartFactory) {
this.chartFactory = chartFactory;
}
}

View File

@ -0,0 +1,60 @@
package org.jzy3d.plot3d.primitives.axes.symbols;
import java.awt.image.BufferedImage;
import org.apache.log4j.Logger;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.EmulGLPainter;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.Drawable;
import org.jzy3d.plot3d.transform.Transform;
/**
* Renders an image at the specified 3d position.
*
* The equivalent of {@link DrawableTexture}.
*/
public class EmulGLDrawableImage extends Drawable{
protected BufferedImage image;
protected Coord3d position;
public EmulGLDrawableImage(BufferedImage image) {
this.image = image;
this.position = Coord3d.ORIGIN.clone();
}
public EmulGLDrawableImage(BufferedImage image, Coord3d position) {
this.image = image;
this.position = position;
}
@Override
public void draw(Painter painter) {
if(painter instanceof EmulGLPainter) {
EmulGLPainter emulgl = (EmulGLPainter) painter;
Coord3d screenPosition = painter.getCamera().modelToScreen(painter, position);
emulgl.getGL().appendImageToDraw(image, (int)screenPosition.x-image.getWidth()/2, (int)screenPosition.y-image.getHeight()/2);
}
}
@Override
public void applyGeometryTransform(Transform transform) {
Logger.getLogger(EmulGLDrawableImage.class).warn("not implemented");
}
@Override
public void updateBounds() {
Logger.getLogger(EmulGLDrawableImage.class).warn("not implemented");
}
public Coord3d getPosition() {
return position;
}
public void setPosition(Coord3d position) {
this.position = position;
}
}

View File

@ -0,0 +1,53 @@
package org.jzy3d.plot3d.primitives.axes.symbols;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.image.BufferedImage;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Point;
import org.jzy3d.plot3d.primitives.symbols.SymbolHandler;
/**
* Create {@link DrawableTexture} symbols based on an {@link java.awt.Shape}
*
* @author martin
*/
public class EmulGLSymbolHandler extends SymbolHandler{
protected Shape awtShape;
public EmulGLSymbolHandler(int n, Shape awtShape) {
super(n);
this.awtShape = awtShape;
}
@Override
public void addSymbolOn(Point point) {
Color face = point.rgb;
float size = 1;
Coord3d position = point.xyz;
/*List<Coord2d> zmapping = TexturedCube.makeZPlaneTextureMapping(position, size);
// TODO : let the SAME buffered image instance be used by all DrawableTextures
BufferedImage image = getImage(awtShape, 100, 100);
BufferedImageTexture t = new BufferedImageTexture(image);
DrawableTexture dt = new DrawableTexture(t, PlaneAxis.Z, position.z, zmapping, face);*/
//symbols.add(dt);
}
public static BufferedImage getImage(Shape shape, int width, int height) {
return getImage(shape, width, height, BufferedImage.TYPE_4BYTE_ABGR);
}
public static BufferedImage getImage(Shape shape, int width, int height, int imageType) {
BufferedImage bimage = new BufferedImage(width, height, imageType);
Graphics2D g2d = bimage.createGraphics();
g2d.fill(shape);
g2d.dispose();
return bimage;
}
}

View File

@ -3,13 +3,11 @@ package org.jzy3d.plot3d.rendering.view;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import org.jzy3d.chart.factories.IChartFactory;
import org.apache.log4j.Logger;
import org.jzy3d.painters.EmulGLPainter;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.tooltips.ITooltipRenderer;
import org.jzy3d.plot3d.rendering.tooltips.Tooltip;
/**
* An EmulGL view implementation that is able to handle overlay and tooltip
@ -20,18 +18,17 @@ import org.jzy3d.plot3d.rendering.tooltips.Tooltip;
* @author Martin Pernollet
*
*/
public class EmulGLView extends AWTView {
public EmulGLView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super(factory, scene, canvas, quality);
}
public class EmulGLViewOverlay implements IViewOverlay {
protected static Logger LOGGER = Logger.getLogger(EmulGLViewOverlay.class);
protected java.awt.Color overlayBackground = new java.awt.Color(0, 0, 0, 0);
/**
* Renders all provided {@link Tooltip}s and {@link AWTRenderer2d}s on top of
* the scene.
*/
@Override
public void renderOverlay(ViewportConfiguration viewport) {
if (!hasOverlayStuffs())
public void render(View view, ViewportConfiguration viewport, Painter painter) {
AWTView awtView = ((AWTView)view);
ICanvas canvas = view.getCanvas();
if (!awtView.hasOverlayStuffs())
return;
if (viewport.getWidth() > 0 && viewport.getHeight() > 0) {
@ -46,11 +43,11 @@ public class EmulGLView extends AWTView {
g2d.clearRect(0, 0, canvas.getRendererWidth(), canvas.getRendererHeight());
// Tooltips
for (ITooltipRenderer t : tooltips)
for (ITooltipRenderer t : awtView.getTooltips())
t.render(g2d);
// Renderers
for (AWTRenderer2d renderer : renderers)
for (AWTRenderer2d renderer : awtView.getRenderers2d())
renderer.paint(g2d, canvas.getRendererWidth(), canvas.getRendererHeight());
g2d.dispose();

View File

@ -5,7 +5,7 @@ import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.EmulGLView;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.mockito.Mockito;
public class SpyEmulGLChartFactory extends EmulGLChartFactory{
@ -14,9 +14,9 @@ public class SpyEmulGLChartFactory extends EmulGLChartFactory{
}
@Override
public EmulGLView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
public AWTView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
//return Mockito.spy((ChartView) super.newView(factory, scene, canvas, quality));
EmulGLView view = Mockito.spy((EmulGLView) super.newView(factory, scene, canvas, quality));
AWTView view = Mockito.spy((AWTView) super.newView(factory, scene, canvas, quality));
view.initInstance(factory, scene, canvas, quality);
return view;

View File

@ -27,8 +27,8 @@ import org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.EmulGLView;
import org.mockito.Mockito;
/**
@ -47,8 +47,8 @@ public class TestContinuousAndOnDemandRendering {
EmulGLChartFactory factory = new EmulGLChartFactory() {
@Override
public EmulGLView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
EmulGLView view = Mockito.spy((EmulGLView) super.newView(factory, scene, canvas, quality));
public AWTView newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
AWTView view = Mockito.spy((AWTView) super.newView(factory, scene, canvas, quality));
view.initInstance(factory, scene, canvas, quality);
return view;

View File

@ -35,6 +35,15 @@ public class AWTChartFactory extends NativeChartFactory {
super(painterFactory);
}
/**
* The AWTView support Java2d defined components (tooltips, background
* images)
*/
@Override
public View newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
return new AWTNativeView(factory, scene, canvas, quality);
}
@Override
public AWTNativeChart newChart(IChartFactory factory, Quality quality) {
return new AWTNativeChart(factory, quality);
@ -45,14 +54,6 @@ public class AWTChartFactory extends NativeChartFactory {
return new ViewAndColorbarsLayout();
}
/**
* The AWTView support Java2d defined components (tooltips, background
* images)
*/
@Override
public View newView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
return new AWTNativeView(factory, scene, canvas, quality);
}
/** Provide AWT Texture loading for screenshots */
@Override

View File

@ -22,6 +22,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.AWTNativeViewOverlay;
import org.jzy3d.plot3d.rendering.view.IViewOverlay;
public class AWTPainterFactory extends NativePainterFactory implements IPainterFactory{
@ -29,9 +31,12 @@ public class AWTPainterFactory extends NativePainterFactory implements IPainterF
static Logger logger = Logger.getLogger(AWTPainterFactory.class);
public AWTPainterFactory() {
@Override
public IViewOverlay newViewOverlay() {
return new AWTNativeViewOverlay();
}
@Override
public ICanvas newCanvas(IChartFactory factory, Scene scene, Quality quality) {
boolean traceGL = false;

View File

@ -19,10 +19,10 @@ import org.jzy3d.plot3d.rendering.textures.BufferedImageTexture;
*
* @author martin
*/
public class AWTShapeSymbolHandler extends SymbolHandler{
public class AWTShapeNativeSymbolHandler extends SymbolHandler{
protected Shape awtShape;
public AWTShapeSymbolHandler(int n, Shape awtShape) {
public AWTShapeNativeSymbolHandler(int n, Shape awtShape) {
super(n);
this.awtShape = awtShape;
}
@ -43,12 +43,21 @@ public class AWTShapeSymbolHandler extends SymbolHandler{
}
public static BufferedImage getImage(Shape shape, int width, int height) {
return getImage(shape, width, height, BufferedImage.TYPE_4BYTE_ABGR);
return getImage(shape, width, height, null);
}
public static BufferedImage getImage(Shape shape, int width, int height, int imageType) {
public static BufferedImage getImage(Shape shape, int width, int height, java.awt.Color color) {
return getImage(shape, width, height, BufferedImage.TYPE_4BYTE_ABGR, color);
}
public static BufferedImage getImage(Shape shape, int width, int height, int imageType, java.awt.Color color) {
BufferedImage bimage = new BufferedImage(width, height, imageType);
Graphics2D g2d = bimage.createGraphics();
if(color!=null) {
g2d.setColor(color);
}
g2d.fill(shape);
g2d.dispose();
return bimage;

View File

@ -1,22 +1,11 @@
package org.jzy3d.plot3d.rendering.view;
import java.awt.Graphics2D;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.painters.NativeDesktopPainter;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
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;
import org.jzy3d.plot3d.rendering.tooltips.ITooltipRenderer;
import org.jzy3d.plot3d.rendering.tooltips.Tooltip;
import com.jogamp.opengl.util.awt.Overlay;
/**
* This view is named {@link AWTNativeView} because it uses AWT to handle
@ -27,8 +16,6 @@ import com.jogamp.opengl.util.awt.Overlay;
*
*/
public class AWTNativeView extends AWTView {
protected Overlay overlay;
public AWTNativeView(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super(factory, scene, canvas, quality);
}
@ -50,72 +37,4 @@ public class AWTNativeView extends AWTView {
((NativeDesktopPainter) painter).getCurrentContext(canvas).release();
return p;
}
/**
* Renders all provided {@link Tooltip}s and {@link AWTRenderer2d}s on top of the
* scene.
*
* Due to the behaviour of the {@link Overlay} implementation, Java2d geometries
* must be drawn relative to the {@link Chart}'s {@link IScreenCanvas}, BUT will
* then be stretched to fit in the {@link Camera}'s viewport. This bug is very
* important to consider, since the Camera's viewport may not occupy the full
* {@link IScreenCanvas}. Indeed, when View is not maximized (like the default
* behaviour), the viewport remains square and centered in the canvas, meaning
* the Overlay won't cover the full canvas area.
*
* In other words, the following piece of code draws a border around the
* {@link View}, and not around the complete chart canvas, although queried to
* occupy chart canvas dimensions:
*
* g2d.drawRect(1, 1, chart.getCanvas().getRendererWidth()-2,
* chart.getCanvas().getRendererHeight()-2);
*
* {@link renderOverlay()} must be called while the OpenGL2 context for the
* drawable is current, and after the OpenGL2 scene has been rendered.
*/
@Override
public void renderOverlay(ViewportConfiguration viewport) {
if (!hasOverlayStuffs())
return;
INativeCanvas nCanvas = (INativeCanvas) canvas;
if (overlay == null)
this.overlay = new Overlay(nCanvas.getDrawable());
// TODO: don't know why needed to allow working with Overlay!!!????
painter.glPolygonMode(PolygonMode.FRONT_AND_BACK, PolygonFill.FILL);
painter.glViewport(viewport.x, viewport.y, viewport.width, viewport.height);
if (overlay != null && viewport.width > 0 && viewport.height > 0) {
try {
if (nCanvas.getDrawable().getSurfaceWidth() > 0 && nCanvas.getDrawable().getSurfaceHeight() > 0) {
Graphics2D g2d = overlay.createGraphics();
g2d.setBackground(overlayBackground);
g2d.clearRect(0, 0, canvas.getRendererWidth(), canvas.getRendererHeight());
// Tooltips
for (ITooltipRenderer t : tooltips)
t.render(g2d);
// Renderers
for (AWTRenderer2d renderer : renderers)
renderer.paint(g2d, canvas.getRendererWidth(), canvas.getRendererHeight());
overlay.markDirty(0, 0, canvas.getRendererWidth(), canvas.getRendererHeight());
overlay.drawAll();
g2d.dispose();
}
} catch (Exception e) {
LOGGER.error(e, e);
}
}
}
}

View File

@ -0,0 +1,93 @@
package org.jzy3d.plot3d.rendering.view;
import java.awt.Graphics2D;
import org.apache.log4j.Logger;
import org.jzy3d.chart.Chart;
import org.jzy3d.painters.Painter;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.INativeCanvas;
import org.jzy3d.plot3d.rendering.canvas.IScreenCanvas;
import org.jzy3d.plot3d.rendering.tooltips.ITooltipRenderer;
import org.jzy3d.plot3d.rendering.tooltips.Tooltip;
import com.jogamp.opengl.util.awt.Overlay;
public class AWTNativeViewOverlay implements IViewOverlay {
protected static Logger LOGGER = Logger.getLogger(AWTNativeViewOverlay.class);
protected Overlay overlay;
protected java.awt.Color overlayBackground = new java.awt.Color(0, 0, 0, 0);
/**
* Renders all provided {@link Tooltip}s and {@link AWTRenderer2d}s on top of the
* scene.
*
* Due to the behaviour of the {@link Overlay} implementation, Java2d geometries
* must be drawn relative to the {@link Chart}'s {@link IScreenCanvas}, BUT will
* then be stretched to fit in the {@link Camera}'s viewport. This bug is very
* important to consider, since the Camera's viewport may not occupy the full
* {@link IScreenCanvas}. Indeed, when View is not maximized (like the default
* behaviour), the viewport remains square and centered in the canvas, meaning
* the Overlay won't cover the full canvas area.
*
* In other words, the following piece of code draws a border around the
* {@link View}, and not around the complete chart canvas, although queried to
* occupy chart canvas dimensions:
*
* g2d.drawRect(1, 1, chart.getCanvas().getRendererWidth()-2,
* chart.getCanvas().getRendererHeight()-2);
*
* {@link renderOverlay()} must be called while the OpenGL2 context for the
* drawable is current, and after the OpenGL2 scene has been rendered.
*/
@Override
public void render(View view, ViewportConfiguration viewport, Painter painter) {
AWTView awtView = ((AWTView)view);
ICanvas canvas = view.getCanvas();
INativeCanvas nCanvas = (INativeCanvas) canvas;
if (!awtView.hasOverlayStuffs())
return;
if (overlay == null)
this.overlay = new Overlay(nCanvas.getDrawable());
// TODO: don't know why needed to allow working with Overlay!!!????
painter.glPolygonMode(PolygonMode.FRONT_AND_BACK, PolygonFill.FILL);
painter.glViewport(viewport.x, viewport.y, viewport.width, viewport.height);
if (overlay != null && viewport.width > 0 && viewport.height > 0) {
try {
if (nCanvas.getDrawable().getSurfaceWidth() > 0 && nCanvas.getDrawable().getSurfaceHeight() > 0) {
Graphics2D g2d = overlay.createGraphics();
g2d.setBackground(overlayBackground);
g2d.clearRect(0, 0, canvas.getRendererWidth(), canvas.getRendererHeight());
// Tooltips
for (ITooltipRenderer t : awtView.getTooltips())
t.render(g2d);
// Renderers
for (AWTRenderer2d renderer : awtView.getRenderers2d())
renderer.paint(g2d, canvas.getRendererWidth(), canvas.getRendererHeight());
overlay.markDirty(0, 0, canvas.getRendererWidth(), canvas.getRendererHeight());
overlay.drawAll();
g2d.dispose();
}
} catch (Exception e) {
LOGGER.error(e, e);
}
}
}
}

View File

@ -8,6 +8,7 @@ import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import com.jogamp.opengl.GLAutoDrawable;
public abstract class NativePainterFactory implements IPainterFactory{
IChartFactory chartFactory;
@Override
public Painter newPainter() {
@ -19,4 +20,13 @@ public abstract class NativePainterFactory implements IPainterFactory{
return new NativeAnimator((GLAutoDrawable)canvas);
}
public IChartFactory getChartFactory() {
return chartFactory;
}
public void setChartFactory(IChartFactory chartFactory) {
this.chartFactory = chartFactory;
}
}

View File

@ -9,12 +9,9 @@ import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.pipelines.NotImplementedException;
import org.jzy3d.plot3d.primitives.PolygonFill;
import org.jzy3d.plot3d.primitives.PolygonMode;
import org.jzy3d.plot3d.primitives.axis.IAxis;
import org.jzy3d.plot3d.rendering.canvas.IScreenCanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.lights.LightModel;
import org.jzy3d.plot3d.rendering.lights.MaterialProperty;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.View;

View File

@ -20,11 +20,18 @@ import org.jzy3d.plot3d.rendering.canvas.CanvasNewtAwt;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTNativeViewOverlay;
import org.jzy3d.plot3d.rendering.view.IViewOverlay;
public class NewtPainterFactory extends NativePainterFactory implements IPainterFactory{
public static String SCREENSHOT_FOLDER = "./data/screenshots/";
static Logger logger = Logger.getLogger(NewtPainterFactory.class);
@Override
public IViewOverlay newViewOverlay() {
return new AWTNativeViewOverlay();
}
@Override
public ICanvas newCanvas(IChartFactory factory, Scene scene, Quality quality) {
boolean traceGL = false;

View File

@ -23,11 +23,18 @@ import org.jzy3d.maths.Utils;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTNativeViewOverlay;
import org.jzy3d.plot3d.rendering.view.IViewOverlay;
public class SWTPainterFactory extends NativePainterFactory implements IPainterFactory{
public static String SCREENSHOT_FOLDER = "./data/screenshots/";
static Logger logger = Logger.getLogger(SWTPainterFactory.class);
@Override
public IViewOverlay newViewOverlay() {
return new AWTNativeViewOverlay();
}
@Override
public ICanvas newCanvas(IChartFactory factory, Scene scene, Quality quality) {