Merge pull request #241 from jzy3d/bug/swingChartBlack_238

Swing chart display correctly and have an ITTest to verify screenshots
This commit is contained in:
jzy3d 2022-02-22 12:21:35 +01:00 committed by GitHub
commit 93db3fa4e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 97 additions and 8 deletions

View File

@ -543,8 +543,6 @@ public abstract class Geometry extends Wireframeable implements ISingleColorable
protected void drawWireframe(IPainter painter) {
if (wireframeDisplayed) {
painter.glPolygonMode(polygonMode, PolygonFill.LINE);
if (polygonWireframeDepthTrick)
applyDepthRangeForOverlying(painter); // OVER - enable range
@ -589,6 +587,9 @@ public abstract class Geometry extends Wireframeable implements ISingleColorable
}
else {
painter.glPolygonMode(polygonMode, PolygonFill.LINE);
// default Draw geometry
begin(painter);

View File

@ -38,7 +38,7 @@ public class CanvasSwing extends GLJPanel implements IScreenCanvas, INativeCanva
protected Renderer3d renderer;
protected IAnimator animator;
protected List<ICanvasListener> canvasListeners = new ArrayList<>();
protected ScheduledExecutorService exec = new ScheduledThreadPoolExecutor(1);
/**
@ -72,24 +72,26 @@ public class CanvasSwing extends GLJPanel implements IScreenCanvas, INativeCanva
if (quality.isAnimated()) {
animator.start();
}
if(ALLOW_WATCH_PIXEL_SCALE)
if (ALLOW_WATCH_PIXEL_SCALE)
watchPixelScale();
if (quality.isPreserveViewportSize())
setPixelScale(newPixelScaleIdentity());
}
protected void watchPixelScale() {
exec.schedule(new PixelScaleWatch() {
@Override
public double getPixelScaleY() {
return CanvasSwing.this.getPixelScaleY();
}
@Override
public double getPixelScaleX() {
return CanvasSwing.this.getPixelScaleX();
}
@Override
protected void firePixelScaleChanged(double pixelScaleX, double pixelScaleY) {
CanvasSwing.this.firePixelScaleChanged(pixelScaleX, pixelScaleY);
@ -196,9 +198,26 @@ public class CanvasSwing extends GLJPanel implements IScreenCanvas, INativeCanva
@Override
public TextureData screenshot() {
// setupPrint(1, 1, 1, getRendererWidth(), getRendererHeight());
if (!isVisible() || !isRealized()) {
throw new RuntimeException(
"Can't make a screenshot out of a Swing canvas without making it visible. "
+ "Either call chart.open(), add chart.getCanvas() to an application, or use an OffscreenChartFactory");
// because the display() method of GLJPanel skip invocation of renderer.display() if
// the panel is not visible.s
}
renderer.nextDisplayUpdateScreenshot();
display();
return renderer.getLastScreenshot();
TextureData screenshot = renderer.getLastScreenshot();
// releasePrint();
return screenshot;
}
/* */

View File

@ -40,7 +40,7 @@ public class SurfaceDemoSwing extends AbstractAnalysis {
final Shape surface = new SurfaceBuilder().orthonormal(new OrthonormalGrid(range, steps), func);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface, new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
surface.setWireframeDisplayed(true);
// Create a chart
chart = new SwingChartFactory().newChart(Quality.Advanced());

View File

@ -0,0 +1,69 @@
package org.jzy3d.tests.integration;
import org.junit.Test;
import org.jzy3d.bridge.swing.FrameSwing;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.chart.factories.SwingChartFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.junit.ChartTester;
import org.jzy3d.junit.NativeChartTester;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Func3D;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.SurfaceBuilder;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.CanvasSwing;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class ITTestNativeSurfaceChart_Swing {
@Test
public void surfaceTest() {
IChartFactory factory = new SwingChartFactory();
Chart chart = factory.newChart(Quality.Advanced());
chart.add(surface());
FrameSwing f = (FrameSwing)chart.open(800,600);
// We want to ensure that we won't start baseline image
// comparison before the canvas is (1) displayed
// and (2) having the good image size.
CanvasSwing canvas = (CanvasSwing)chart.getCanvas();
while(!f.isVisible() || !canvas.isRealized()) {
int waitTimeMs = 1500;
System.out.println("Waiting " + waitTimeMs);
chart.sleep(waitTimeMs);
//canvas.forceRepaint();
}
// Then
ChartTester tester = new NativeChartTester();
tester.assertSimilar(chart,
ChartTester.EXPECTED_IMAGE_FOLDER + this.getClass().getSimpleName() + ".png");
}
private static Shape surface() {
Func3D func = new Func3D((x, y) -> x * Math.sin(x * y));
Range range = new Range(-3, 3);
int steps = 80;
// Create the object to represent the function over the given range.
final Shape surface = new SurfaceBuilder().orthonormal(new OrthonormalGrid(range, steps), func);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface, new Color(1, 1, 1, .5f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(true);
return surface;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB