This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch visual-test
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/visual-test by this push:
new bac36a6 Add visual comparison of isolines computed sequentially and
in parallel.
bac36a6 is described below
commit bac36a69bab5dae422a1739e524d67a2f4415bf0
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri Jan 22 22:56:25 2021 +0100
Add visual comparison of isolines computed sequentially and in parallel.
---
.../org/apache/sis/test/visual/DesktopPane.java | 53 +++++++++++++++------
.../org/apache/sis/test/visual/IsolinesView.java | 54 +++++++++++++++-------
.../org/apache/sis/test/visual/Visualization.java | 16 +++++++
3 files changed, 92 insertions(+), 31 deletions(-)
diff --git a/src/main/java/org/apache/sis/test/visual/DesktopPane.java
b/src/main/java/org/apache/sis/test/visual/DesktopPane.java
index 708019b..3daec90 100644
--- a/src/main/java/org/apache/sis/test/visual/DesktopPane.java
+++ b/src/main/java/org/apache/sis/test/visual/DesktopPane.java
@@ -29,6 +29,7 @@ import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import javax.swing.AbstractAction;
+import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
@@ -75,6 +76,11 @@ final class DesktopPane extends JDesktopPane {
private JComponent active;
/**
+ * Whether all previous windows should be closed before new windows are
created.
+ */
+ private final JCheckBoxMenuItem autoClose;
+
+ /**
* Creates the desktop, creates its frame and makes it visible.
*/
private DesktopPane() {
@@ -96,6 +102,10 @@ final class DesktopPane extends JDesktopPane {
menu.add(new AbstractAction("List") {
@Override public void actionPerformed(final ActionEvent event)
{listWindows();}
});
+ menu.add(new AbstractAction("Close all") {
+ @Override public void actionPerformed(final ActionEvent event)
{closeAllWindows();}
+ });
+ menu.add(autoClose = new JCheckBoxMenuItem("Auto close"));
menuBar.add(menu);
}
final JFrame frame = new JFrame("Widget tests");
@@ -126,10 +136,12 @@ final class DesktopPane extends JDesktopPane {
* Shows the widget created by the given test case.
*/
private void show(final Visualization testCase) {
+ if (autoClose.isSelected()) {
+ closeAllWindows();
+ }
try {
- final int n = testCase.numTests;
- for (int i=0; i<n; i++) {
- show(testCase.create(i), i, n);
+ for (int i=0; i<testCase.numTests; i++) {
+ show(testCase, testCase.create(i), i);
}
} catch (Exception e) {
// Not acceptable for a real application, but this widget is only
for testing purpose.
@@ -142,12 +154,8 @@ final class DesktopPane extends JDesktopPane {
*
* @param component the component to show.
*/
- private void show(final JComponent component, final int index, final int
numTests) {
- String title = Classes.getShortClassName(component);
- if (numTests != 1) {
- title = title + " (" + index + ')';
- }
- final JInternalFrame frame = new JInternalFrame(title, true, true,
true, true);
+ private void show(final Visualization testCase, final JComponent
component, final int index) {
+ final JInternalFrame frame = new JInternalFrame(testCase.title(index),
true, true, true, true);
frame.addInternalFrameListener(new InternalFrameAdapter() {
@Override public void internalFrameActivated(final
InternalFrameEvent event) {
active = component;
@@ -166,8 +174,8 @@ final class DesktopPane extends JDesktopPane {
frame.setSize(Math.max(frame.getWidth(), size.width),
Math.max(frame.getHeight(), size.height));
}
- final int numCols = (int) Math.ceil(Math.sqrt(numTests));
- final int numRows = (numTests + numCols - 1) / numCols;
+ final int numCols = (int) Math.ceil(Math.sqrt(testCase.numTests));
+ final int numRows = (testCase.numTests + numCols - 1) / numCols;
final int deltaX = getWidth() / numCols;
final int deltaY = getHeight() / numRows;
frame.setLocation(Math.max(0, deltaX * (index % numCols) + (deltaX -
frame.getWidth()) / 2),
@@ -182,7 +190,7 @@ final class DesktopPane extends JDesktopPane {
}
/**
- * List windows known to this desktop.
+ * Lists windows known to this desktop.
*/
private void listWindows() {
final Component[] components = getComponents();
@@ -191,9 +199,9 @@ final class DesktopPane extends JDesktopPane {
Component c = components[i];
String title = String.valueOf(c.getName());
if (c instanceof JInternalFrame) {
- final JInternalFrame ci = (JInternalFrame) c;
- title = String.valueOf(ci.getTitle());
- c = ci.getRootPane().getComponent(0);
+ final JInternalFrame frame = (JInternalFrame) c;
+ title = String.valueOf(frame.getTitle());
+ c = frame.getRootPane().getComponent(0);
}
final Dimension size = c.getSize();
titles[i] = title + " : " + c.getClass().getSimpleName() +
@@ -207,6 +215,21 @@ final class DesktopPane extends JDesktopPane {
}
/**
+ * Closes all windows known to this desktop.
+ */
+ private void closeAllWindows() {
+ final Component[] components = getComponents();
+ for (final Component c : components) {
+ if (c instanceof JInternalFrame) {
+ final JInternalFrame frame = (JInternalFrame) c;
+ frame.dispose();
+ remove(frame);
+ }
+ }
+ active = null;
+ }
+
+ /**
* Popups a dialog box for setting the preferences.
*/
private void preferences() {
diff --git a/src/main/java/org/apache/sis/test/visual/IsolinesView.java
b/src/main/java/org/apache/sis/test/visual/IsolinesView.java
index 35d1c73..9261764 100644
--- a/src/main/java/org/apache/sis/test/visual/IsolinesView.java
+++ b/src/main/java/org/apache/sis/test/visual/IsolinesView.java
@@ -33,17 +33,21 @@ import java.awt.image.WritableRaster;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import javax.swing.JComponent;
-import org.opengis.referencing.operation.TransformException;
import org.apache.sis.referencing.operation.matrix.AffineTransforms2D;
import org.apache.sis.internal.coverage.j2d.RasterFactory;
import org.apache.sis.internal.processing.image.Isolines;
import org.apache.sis.swing.ZoomPane;
+import org.apache.sis.util.Classes;
/**
* Generate an image with synthetic mounts and draw isolines on that image.
* This allows a visual check of {@link Isolines} results.
*
+ * <p><b>Note:</b> for useful test of parallel computation, the
+ * {@link org.apache.sis.internal.processing.image.TiledProcess#MIN_TILE_SIZE}
+ * constant may been to be temporarily set to a small value such as 100.</p>
+ *
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
* @since 1.1
@@ -70,7 +74,12 @@ public final class IsolinesView extends Visualization {
private final Color[] colors;
/**
- * The image with data as as integer numbers. Created together with
floating-point version of same image,
+ * The image with data as floating point numbers.
+ */
+ private BufferedImage dataAsFloats;
+
+ /**
+ * The image with data as integer numbers. Created together with
floating-point version of same image,
* and restored to {@code null} after {@code dataAsIntegers} has been
assigned to a {@link ZoomPane}.
*/
private BufferedImage dataAsIntegers;
@@ -85,7 +94,7 @@ public final class IsolinesView extends Visualization {
* Creates a new viewer for {@link Isolines}.
*/
public IsolinesView() {
- super(Isolines.class, 2);
+ super(Isolines.class, 4);
width = 800;
height = 600;
colors = new Color[] {
@@ -94,23 +103,39 @@ public final class IsolinesView extends Visualization {
}
/**
+ * Returns a title for a window created by {@link #create(int)}.
+ */
+ @Override
+ protected String title(int index) {
+ return new StringBuilder(Classes.getShortName(testing)).append(" (")
+ .append((index & 2) == 0 ? "sequential" : "parallel").append("
on ")
+ .append((index & 1) == 0 ? "floats" : "integers").append(')')
+ .toString();
+ }
+
+ /**
* Creates a widget showing a random image with isolines on it.
* The widget uses {@link ZoomPane}.
*
* @param index a sequence number for the isoline window. Shall be 0 or
1.
* @return a widget showing isolines.
- * @throws TransformException if an error occurred while computing
isolines.
+ * @throws Exception if an error occurred while computing isolines.
*/
@Override
- protected JComponent create(final int index) throws TransformException {
- final BufferedImage image;
- switch (index) {
- case 0: image = createImages(); break;
- case 1: image = dataAsIntegers; dataAsIntegers = null; break;
- default: throw new AssertionError(index);
+ protected JComponent create(final int index) throws Exception {
+ if (index == 0) {
+ createImages();
+ }
+ final BufferedImage image = ((index & 1) == 0) ? dataAsFloats :
dataAsIntegers;
+ final double[][] levels = {{0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0}};
+ final Isolines[] result;
+ if ((index & 2) == 0) {
+ result = Isolines.generate(image, levels, null);
+ } else {
+ result = Isolines.parallelGenerate(image, levels, null).get();
}
final List<Shape> shapes = new ArrayList<>();
- for (final Isolines isolines : Isolines.generate(image, new double[][]
{{0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0}}, null)) {
+ for (final Isolines isolines : result) {
shapes.addAll(isolines.polylines().values());
}
final ZoomPane pane = new ZoomPane() {
@@ -196,11 +221,9 @@ public final class IsolinesView extends Visualization {
/**
* Creates grayscale images (floating and integer versions) with random
mounts.
- * This method returns the floating point version and stores the integer
version
- * in {@link #dataAsIntegers} for future use.
+ * This method stores the images in {@link #dataAsFloats} and {@link
#dataAsIntegers}.
*/
- private BufferedImage createImages() {
- final BufferedImage dataAsFloats;
+ private void createImages() {
dataAsFloats =
RasterFactory.createGrayScaleImage(DataBuffer.TYPE_FLOAT, width, height, 1, 0,
0, 255);
dataAsIntegers = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_GRAY);
final WritableRaster rasterAsFloats = dataAsFloats.getRaster();
@@ -225,6 +248,5 @@ public final class IsolinesView extends Visualization {
}
}
}
- return dataAsFloats;
}
}
diff --git a/src/main/java/org/apache/sis/test/visual/Visualization.java
b/src/main/java/org/apache/sis/test/visual/Visualization.java
index 63ccb82..9d81247 100644
--- a/src/main/java/org/apache/sis/test/visual/Visualization.java
+++ b/src/main/java/org/apache/sis/test/visual/Visualization.java
@@ -18,6 +18,7 @@ package org.apache.sis.test.visual;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
+import org.apache.sis.util.Classes;
/**
@@ -59,6 +60,21 @@ public abstract class Visualization {
}
/**
+ * Returns a title for a window created by {@link #create(int)}.
+ * Default implementation returns testing class name followed by {@code
index} value.
+ *
+ * @param index index of test occurrence, from 0 inclusive to the value
given at construction time, exclusive.
+ * @return title for the window.
+ */
+ protected String title(int index) {
+ String title = Classes.getShortName(testing);
+ if (numTests != 1) {
+ title = title + " (" + index + ')';
+ }
+ return title;
+ }
+
+ /**
* Creates a widget showing the object to test.
*
* @param index index of test occurrence, from 0 inclusive to the value
given at construction time, exclusive.