From 9111b9a8158afaebcd69ea240bb65f05470702d8 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 29 Sep 2016 15:16:37 +0200 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 14 +-- devices/cam1.properties | 6 +- devices/cam2.properties | 6 +- plugins/Correlation.java | 8 ++ plugins/ScreenPanel.form | 19 +++- plugins/ScreenPanel.java | 172 ++++++++++++++++++++++++------- 6 files changed, 168 insertions(+), 57 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 07bde24..94dd96d 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,10 +1,10 @@ -#Wed Sep 28 09:24:26 CEST 2016 -colormap=Grayscale +#Thu Sep 29 15:13:32 CEST 2016 +colormap=Temperature colormapAutomatic=true colormapMax=0.0 colormapMin=0.0 flipHorizontally=false -flipVertically=false +flipVertically=true grayscale=false imageHeight=1200 imageWidth=1246 @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=true scale=1.0 -spatialCalOffsetX=NaN -spatialCalOffsetY=NaN -spatialCalScaleX=NaN -spatialCalScaleY=NaN +spatialCalOffsetX=-630.0 +spatialCalOffsetY=-612.0 +spatialCalScaleX=26.761819803746654 +spatialCalScaleY=-26.595744680851062 spatialCalUnits=mm transpose=false diff --git a/devices/cam1.properties b/devices/cam1.properties index e42c29e..09cd72e 100644 --- a/devices/cam1.properties +++ b/devices/cam1.properties @@ -1,4 +1,4 @@ -#Thu Sep 08 08:33:51 CEST 2016 +#Thu Sep 29 08:47:56 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=30000.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1628 -imageWidth=1280 +imageHeight=0 +imageWidth=0 invert=false offsetX=0.0 offsetY=0.0 diff --git a/devices/cam2.properties b/devices/cam2.properties index 8beced8..54d94bd 100644 --- a/devices/cam2.properties +++ b/devices/cam2.properties @@ -1,4 +1,4 @@ -#Thu Sep 08 08:33:52 CEST 2016 +#Thu Sep 29 08:47:56 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=255.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1680 -imageWidth=1744 +imageHeight=0 +imageWidth=0 invert=false offsetX=0.0 offsetY=0.0 diff --git a/plugins/Correlation.java b/plugins/Correlation.java index 5ea899a..5dd2adc 100644 --- a/plugins/Correlation.java +++ b/plugins/Correlation.java @@ -2,6 +2,7 @@ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ +import ch.psi.pshell.ui.App; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.awt.Component; @@ -20,7 +21,14 @@ public class Correlation extends Panel { //Overridable callbacks @Override public void onInitialize(int runCount) { + super.onInitialize(runCount); this.startTimer(100, 10); + if (App.hasArgument("dx")) { + textDevX.setText(App.getArgumentValue("dx")); + } + if (App.hasArgument("dy")) { + textDevY.setText(App.getArgumentValue("dy")); + } } @Override diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form index 3246f7b..3e8dea2 100644 --- a/plugins/ScreenPanel.form +++ b/plugins/ScreenPanel.form @@ -75,7 +75,7 @@ - + @@ -272,14 +272,18 @@ - + + + + + - + @@ -296,7 +300,9 @@ - + + + @@ -773,6 +779,11 @@ + + + + + diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index f0fc455..006a89f 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -11,6 +11,7 @@ import ch.psi.pshell.ui.Panel; import ch.psi.pshell.imaging.ImageListener; import ch.psi.utils.State; import ch.psi.utils.IO; +import ch.psi.utils.Chrono; import ch.psi.utils.swing.SwingUtils; import ch.psi.utils.swing.TextEditor; import ch.psi.pshell.epics.PsiCamera; @@ -18,10 +19,7 @@ import ch.psi.pshell.epics.Camtool; import ch.psi.pshell.core.JsonSerializer; import ch.psi.pshell.device.Device; import ch.psi.pshell.epics.ArraySource; -import ch.psi.pshell.epics.ChannelDouble; -import ch.psi.pshell.epics.ChannelDoubleArray; import ch.psi.pshell.epics.ChannelInteger; -import ch.psi.pshell.epics.ChannelIntegerArray; import ch.psi.pshell.epics.DiscretePositioner; import ch.psi.pshell.epics.Epics; import ch.psi.pshell.imaging.Colormap; @@ -34,10 +32,14 @@ import ch.psi.pshell.imaging.Overlay; import ch.psi.pshell.imaging.Overlays; import ch.psi.pshell.imaging.Overlays.Text; import ch.psi.pshell.imaging.Pen; +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.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; +import ch.psi.pshell.swing.ValueSelection; +import ch.psi.pshell.swing.ValueSelection.ValueSelectionListener; import ch.psi.utils.Arr; import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; @@ -70,6 +72,23 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; */ public class ScreenPanel extends Panel { + final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; + File[] cameraConfigFiles = new File[0]; + ArraySource camera; + String cameraName; + String cameraConfigJson; + CameraConfig config; + int polling = 1000; + Overlay marker = null; + JDialog histogramDialog; + DiscretePositioner screen; + DiscretePositioner filter; + boolean showFit; + + final ArrayList imageBuffer = new ArrayList(); + int imageBufferLenght = 0; + Text imageBufferOverlay; + public ScreenPanel() { initComponents(); renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin")); @@ -90,9 +109,46 @@ public class ScreenPanel extends Panel { ex.printStackTrace(); } } + if (App.hasArgument("buf")) { + try { + imageBufferLenght = Integer.valueOf(App.getArgumentValue("buf")); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + renderer.setProfileNormalized(true); renderer.setShowProfileLimits(true); showFit = buttonFit.isSelected(); + + if (imageBufferLenght>1){ + renderer.addListener(new RendererListener() { + @Override + public void onImage(Renderer renderer, Object origin, BufferedImage image, Data data) { + if (data!=null){ + synchronized(imageBuffer){ + imageBuffer.add(data); + if (imageBuffer.size() > imageBufferLenght){ + imageBuffer.remove(0); + } + } + } + } + }); + } + pauseSelection.setVisible(false); + pauseSelection.setMinValue(1); + pauseSelection.addListener(new ValueSelectionListener() { + @Override + public void onValueChanged(ValueSelection origin, double value, boolean editing){ + if (editing && (value>=1) && (value<=imageBuffer.size())){ + updatePause(); + } + } + }); + imageBufferOverlay = new Text(renderer.getPenErrorText(), "", new Font("Verdana", Font.PLAIN, 12), new Point(-100, 20)); + imageBufferOverlay.setFixed(true); + imageBufferOverlay.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_RIGHT); } @Override @@ -105,19 +161,6 @@ public class ScreenPanel extends Panel { } } - final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; - File[] cameraConfigFiles = new File[0]; - ArraySource camera; - String cameraName; - String cameraConfigJson; - CameraConfig config; - int polling = 1000; - Overlay marker = null; - JDialog histogramDialog; - DiscretePositioner screen; - DiscretePositioner filter; - boolean showFit; - //Overridable callbacks @Override public void onInitialize(int runCount) { @@ -128,13 +171,7 @@ public class ScreenPanel extends Panel { ((Source) getDevice("image")).addListener(new ImageListener() { @Override public void onImage(Object o, BufferedImage bi, Data data) { - if ((bi == null) || (!showFit)) { - fitOv = null; - } else { - Overlay[] fo = getFitOverlays(data); - renderer.updateOverlays(fo, fitOv); - fitOv = fo; - } + manageFit(bi, data); } @Override @@ -169,6 +206,12 @@ public class ScreenPanel extends Panel { startTimer(1000); } + void manageFit(BufferedImage bi, Data data){ + Overlay[] fo = ((bi == null) || (!showFit)) ? null : getFitOverlays(data); + renderer.updateOverlays(fo, fitOv); + fitOv = fo; + } + @Override public void onStateChange(State state, State former) { @@ -325,7 +368,7 @@ public class ScreenPanel extends Panel { camera.getConfig().spatialCalOffsetX = config.getCalOffsetX(); camera.getConfig().spatialCalOffsetY = config.getCalOffsetY(); camera.getConfig().spatialCalScaleX = config.getScaleX(); - camera.getConfig().spatialCalScaleY = config.getScaleY(); + camera.getConfig().spatialCalScaleY = - config.getScaleY(); } catch (Exception ex) { camera.getConfig().spatialCalOffsetX = Double.NaN; camera.getConfig().spatialCalOffsetY = Double.NaN; @@ -343,7 +386,7 @@ public class ScreenPanel extends Panel { camera.getConfig().spatialCalOffsetX = ((Camtool) camera).calOffX.read(); camera.getConfig().spatialCalOffsetY = ((Camtool) camera).calOffY.read(); camera.getConfig().spatialCalScaleX = ((Camtool) camera).calScaleX.read(); - camera.getConfig().spatialCalScaleY = ((Camtool) camera).calScaleY.read(); + camera.getConfig().spatialCalScaleY = - ((Camtool) camera).calScaleY.read(); } catch (Exception ex) { System.err.println(ex.getMessage()); camera.getConfig().spatialCalOffsetX = 0.0; @@ -368,7 +411,7 @@ public class ScreenPanel extends Panel { camera.addListener(new ImageListener() { @Override - public void onImage(Object o, BufferedImage bi, Data data) { + public void onImage(Object o, BufferedImage bi, Data data) { if (firstImage && (bi!=null)){ if ((renderer.getMode()==RendererMode.Zoom) || (renderer.getMode()==RendererMode.Fixed)){ SwingUtilities.invokeLater(new Runnable() { @@ -551,6 +594,16 @@ public class ScreenPanel extends Panel { Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex); } } + if (renderer.isPaused() != buttonPause.isSelected()){ + buttonPause.setSelected(renderer.isPaused()); + buttonPauseActionPerformed(null); + } + if (renderer.getShowReticle()!= buttonReticle.isSelected()){ + buttonReticle.setSelected(renderer.getShowReticle()); + } + if ((renderer.getMarker()==null) && buttonMarker.isSelected()){ + buttonMarker.setSelected(false); + } updateZoom(); updateColormap(); buttonSave.setSelected(renderer.isSnapshotDialogVisible()); @@ -640,6 +693,8 @@ public class ScreenPanel extends Panel { text = new Overlays.Text(fitPen, String.format("x = %f \n y = %f" , data.getX((int) Math.round(xMean)), data.getY((int) Math.round(yMean))), new Font(Font.MONOSPACED, 0, 14), new Point(20,20)); + text.setFixed(true); + text.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT); } return new Overlay[]{hpoly, vpoly, cross, text}; @@ -990,6 +1045,20 @@ public class ScreenPanel extends Panel { renderer.setViewPosition(topleft); } } + + void updatePause(){ + int index = ((int)pauseSelection.getValue())-1; + synchronized(imageBuffer){ + if (index0)); + if (pauseSelection.isVisible()){ + renderer.addOverlay(imageBufferOverlay); + pauseSelection.setMaxValue(imageBuffer.size()); + pauseSelection.setValue(imageBuffer.size());; + } } } } catch (Exception ex) { + ex.printStackTrace(); showException(ex); } }//GEN-LAST:event_buttonPauseActionPerformed @@ -1775,6 +1863,9 @@ public class ScreenPanel extends Panel { source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer) spinnerMax.getValue(); source.getConfig().save(); source.refresh(); + if (buttonPause.isSelected()){ + updatePause(); + } } } catch (Exception ex) { showException(ex); @@ -1905,6 +1996,7 @@ public class ScreenPanel extends Panel { private javax.swing.JProgressBar jProgressBar1; private javax.swing.JPanel panelScreen; private javax.swing.JPanel panelScreen1; + private ch.psi.pshell.swing.ValueSelection pauseSelection; private ch.psi.pshell.imaging.Renderer renderer; private javax.swing.JSpinner spinnerMax; private javax.swing.JSpinner spinnerMin;