From ba32753be7ec14d6c3b6ab7945d7f41fbbc0a5b1 Mon Sep 17 00:00:00 2001 From: sfop Date: Fri, 24 Mar 2017 09:54:38 +0100 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 22 +++---- plugins/ScreenPanel.java | 102 ++++++++++++++++++++++--------- 2 files changed, 85 insertions(+), 39 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index c94ade2..d5da017 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,16 +1,16 @@ -#Thu Mar 23 16:56:40 CET 2017 +#Fri Mar 24 09:53:40 CET 2017 colormap=Flame -colormapAutomatic=true -colormapMax=0.0 +colormapAutomatic=false +colormapMax=4000.0 colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=0 -imageWidth=0 +imageHeight=1024 +imageWidth=1280 invert=false -regionStartX=129 -regionStartY=7 +regionStartX=1 +regionStartY=1 rescaleFactor=1.0 rescaleOffset=0.0 roiHeight=-1 @@ -21,9 +21,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=localhost\:10000 -spatialCalOffsetX=-1093.4812581603794 -spatialCalOffsetY=-1098.5114274849898 -spatialCalScaleX=-7.617446798629459 -spatialCalScaleY=-7.774538463917676 +spatialCalOffsetX=-861.4939970777481 +spatialCalOffsetY=-820.4883730911062 +spatialCalScaleX=-18.90359092620482 +spatialCalScaleY=-19.37984500632817 spatialCalUnits=mm transpose=false diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index fb64a0d..7583d33 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -38,6 +38,7 @@ import ch.psi.pshell.imaging.Renderer; import ch.psi.pshell.imaging.RendererListener; import ch.psi.pshell.imaging.RendererMode; import ch.psi.pshell.imaging.Source; +import ch.psi.pshell.imaging.Utils; import ch.psi.pshell.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; import ch.psi.pshell.swing.ValueSelection; @@ -50,6 +51,7 @@ import ch.psi.utils.swing.Editor.EditorDialog; import ch.psi.utils.swing.MainFrame; import ch.psi.utils.swing.SwingUtils.OptionResult; import ch.psi.utils.swing.SwingUtils.OptionType; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -57,7 +59,6 @@ import java.awt.Font; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.FileInputStream; @@ -69,12 +70,16 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JDialog; +import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; @@ -206,7 +211,7 @@ public class ScreenPanel extends Panel { if (App.hasArgument("calc")) { useCamtoolStats = false; } - + renderer.setProfileNormalized(true); renderer.setShowProfileLimits(false); @@ -1040,6 +1045,8 @@ public class ScreenPanel extends Panel { Double xMean = null, xSigma = null, xNorm = null; Double yMean = null, ySigma = null, yNorm = null; double[] pX = null, pY = null, gX = null, gY = null; + int height = data.getHeight(); + int width = data.getWidth(); //Double xCom=null, yCom=null; if (data != null) { int profileSize = renderer.getProfileSize(); @@ -1083,9 +1090,9 @@ public class ScreenPanel extends Panel { for (int i = 0; i < x.length; i++) { if (gX != null) { - y[i] = (int) (data.getHeight() - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); + y[i] = (int) (height - 1 - (((gX[i] - minPlot) / rangePlot) * profileSize)); } - p[i] = (int) (data.getHeight() - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); + p[i] = (int) (height - 1 - (((pX[i] - minPlot) / rangePlot) * profileSize)); } vgaussian = new Overlays.Polyline(penFit, x, y); vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); @@ -1147,9 +1154,9 @@ public class ScreenPanel extends Panel { double[] fit = getFitFunction(gaussian, x); int[] y = new int[x.length]; for (int i = 0; i < x.length; i++) { - y[i] = (int) (data.getHeight() - 1 - ((((fit[i] + min) / data.getHeight() - minPlot) / rangePlot) * profileSize)); - p[i] = (int) (data.getHeight() - 1 - (((sum[i] / data.getHeight() - minPlot) / rangePlot) * profileSize)); - } + y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize)); + p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize)); + } vgaussian = new Overlays.Polyline(penFit, x, y); vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p); } @@ -1183,8 +1190,8 @@ public class ScreenPanel extends Panel { int[] y = new int[x.length]; for (int i = 0; i < x.length; i++) { - y[i] = (int) ((((fit[i] + min) / data.getWidth() - minPlot) / rangePlot) * profileSize); - p[i] = (int) (((sum[i] / data.getWidth() - minPlot) / rangePlot) * profileSize); + y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize); + p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize); } hgaussian = new Overlays.Polyline(penFit, y, x); hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x); @@ -1207,8 +1214,6 @@ public class ScreenPanel extends Panel { if (yMean != null) { yMean = data.getY((int) Math.round(yMean)); } - //if (xCom!=null) xCom = data.getX((int) Math.round(xCom)); - //if (yCom!=null) yCom = data.getY((int) Math.round(yCom)); } } @@ -1216,9 +1221,6 @@ public class ScreenPanel extends Panel { Overlays.Text text = null; if ((xMean != null) && (yMean != null)) { text = new Overlays.Text(penFit, - //String.format("x: m=%1.3f \u03C3=%1.3f c=%1.3f\ny: m=%1.3f \u03C3=%1.3f c=%1.3f", - // xMean, xSigma, xCom, - // yMean, ySigma, yCom), String.format("x: m=%1.3f \u03C3=%1.3f\ny: m=%1.3f \u03C3=%1.3f", xMean, xSigma, yMean, ySigma), @@ -1561,7 +1563,9 @@ public class ScreenPanel extends Panel { JDialog calibrationDialolg; Overlay[] calibrationOverlays; void calibrate() throws IOException{ - if ( (camera instanceof Camtool) && (calibrationOverlays==null)) { + if ( (camera instanceof Camtool) && (calibrationOverlays==null)) { + Map calibration = ((Camtool) camera).getCalibration(cameraName); + //Map calibration = (Map) ((Camtool) camera).getConfig(cameraName).get("calibration"); ((Camtool) camera).resetRoi(); renderer.setMode(RendererMode.Fit); Pen pen = new Pen(new Color(128, 0, 128), 1, Pen.LineStyle.solid); @@ -1573,21 +1577,56 @@ public class ScreenPanel extends Panel { for (Overlay ov : calibrationOverlays){ ov.setMovable(true); } - renderer.addOverlays(calibrationOverlays); - SwingUtils.invokeDelayed(() -> { - Dimension size = renderer.getImageSize(); - top.update(new Point(0, size.height/8)); - bottom.update(new Point(0, 7*size.height/8)); - left.update(new Point(size.width/8, 0)); - right.update(new Point(7*size.width/8, 0)); - }, 500); - JOptionPane calibrationMessage = new JOptionPane("Move the lines to the reference marks \n" + - "and press 'OK' to update the calibration.", - JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,null, null); + renderer.addOverlays(calibrationOverlays); + + try{ + List refMarker = ((List)calibration.get("reference_marker")); + Rectangle r = new Rectangle(); + left.update(new Point(Math.max((Integer)refMarker.get(0), 0), 0)); + top.update(new Point(0, Math.max((Integer)refMarker.get(1), 0))); + right.update(new Point(Math.max((Integer)refMarker.get(2), 0), 0)); + bottom.update(new Point(0, Math.max((Integer)refMarker.get(3),0))); + } catch (Exception ex){ + SwingUtils.invokeDelayed(() -> { + Dimension size = renderer.getImageSize(); + top.update(new Point(0, size.height/8)); + bottom.update(new Point(0, 7*size.height/8)); + left.update(new Point(size.width/8, 0)); + right.update(new Point(7*size.width/8, 0)); + }, 500); + } + + JPanel panel = new JPanel(new BorderLayout()); + JTextField textWidth = new JTextField(); + JTextField textHeight= new JTextField(); + if (calibration!=null){ + textWidth.setText(String.valueOf(calibration.get("reference_marker_width"))); + textHeight.setText(String.valueOf(calibration.get("reference_marker_height"))); + } + ((BorderLayout) panel.getLayout()).setVgap(10); + JPanel p1 = new JPanel(new BorderLayout()); + ((BorderLayout) p1.getLayout()).setHgap(5); + p1.add(new JLabel("Move the lines to the reference marks"), BorderLayout.NORTH); + p1.add(new JLabel("and press 'OK' to update the calibration."), BorderLayout.SOUTH); + panel.add(p1, BorderLayout.NORTH); + JPanel p2 = new JPanel(new BorderLayout()); + ((BorderLayout) p2.getLayout()).setHgap(5); + p2.add(new JLabel("Reference marker width: "), BorderLayout.WEST); + p2.add(textWidth, BorderLayout.EAST); + panel.add(p2, BorderLayout.CENTER); + JPanel p3 = new JPanel(new BorderLayout()); + ((BorderLayout) p3.getLayout()).setHgap(5); + p3.add(new JLabel("Reference marker height: "), BorderLayout.WEST); + p3.add(textHeight, BorderLayout.EAST); + panel.add(p3, BorderLayout.SOUTH); + textWidth.setPreferredSize(new Dimension(70, textWidth.getPreferredSize().height)); + textHeight.setPreferredSize(new Dimension(70, textHeight.getPreferredSize().height)); + + JOptionPane calibrationMessage = new JOptionPane(panel,JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,null, null); calibrationDialolg = calibrationMessage.createDialog(getTopLevel(), "Calibration"); calibrationDialolg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); calibrationDialolg.setModal(false); - calibrationDialolg.addWindowListener(new WindowAdapter() { + calibrationDialolg.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosed(WindowEvent e) { if (calibrationOverlays!=null){ @@ -1601,10 +1640,17 @@ public class ScreenPanel extends Panel { int y1 = Math.min(top.getPosition().y, bottom.getPosition().y); int y2 = Math.max(top.getPosition().y, bottom.getPosition().y); if ((x1!=-1) && (x2!=-1) && (y1!=-1) && (y2!=-1)){ - System.out.println("Updating camera calibration: " + x1 + ", "+ + x2 + ", " + + y1 + ", " + + y2); + System.out.println("Updating " + cameraName + " calibration: " + x1 + ", "+ x2 + ", " + y1 + ", " + y2); HashMap c = new HashMap(); c.put("reference_marker", Arrays.asList(new Integer[]{x1, y1, x2, y2})); + if (textWidth.getText().trim().length() > 0){ + c.put("reference_marker_width", Integer.valueOf(textWidth.getText())); + } + if (textHeight.getText().trim().length() > 0){ + c.put("reference_marker_height", Integer.valueOf(textHeight.getText())); + } ((Camtool) camera).setCalibration(cameraName, c); + Logger.getLogger(ScreenPanel.class.getName()).warning("Updated " + cameraName + " calibration: " + x1 + ", "+ x2 + ", " + y1 + ", " + y2); } } } catch (IOException ex) {