From 721762dbc19a91a6f71fb772000fd8b7e37c0766 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 15 Sep 2016 17:15:01 +0200 Subject: [PATCH] Startup --- devices/CurrentCamera.properties | 18 ++-- plugins/ScreenPanel.form | 18 +++- plugins/ScreenPanel.java | 169 +++++++++++++++---------------- 3 files changed, 107 insertions(+), 98 deletions(-) diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index aaf4cb8..e4bd815 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,13 +1,13 @@ -#Thu Sep 15 09:19:12 CEST 2016 -colormap=Rainbow +#Thu Sep 15 15:24:56 CEST 2016 +colormap=Temperature colormapAutomatic=true colormapMax=0.0 colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=2160 -imageWidth=2560 +imageHeight=1024 +imageWidth=1280 invert=false rescaleFactor=1.0 rescaleOffset=0.0 @@ -15,12 +15,12 @@ roiHeight=-1 roiWidth=-1 roiX=0 roiY=0 -rotation=1.0 +rotation=0.0 rotationCrop=true scale=1.0 -spatialCalOffsetX=-1057.0 -spatialCalOffsetY=-1420.0 -spatialCalScaleX=8.51063829787234 -spatialCalScaleY=8.559201141226819 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN spatialCalUnits=mm transpose=false diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form index 1bc42e7..68ab795 100644 --- a/plugins/ScreenPanel.form +++ b/plugins/ScreenPanel.form @@ -11,6 +11,11 @@ + + + + + @@ -39,8 +44,8 @@ - + @@ -100,7 +105,7 @@ - + @@ -215,6 +220,11 @@ + + + + + @@ -223,7 +233,7 @@ - + @@ -429,7 +439,7 @@ - + diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java index 1e45319..93f1a95 100644 --- a/plugins/ScreenPanel.java +++ b/plugins/ScreenPanel.java @@ -38,13 +38,11 @@ import ch.psi.pshell.imaging.Renderer.Profile; import static ch.psi.pshell.imaging.RendererMenu.PEN_MARKER; 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.utils.Arr; import ch.psi.utils.ArrayProperties; import ch.psi.utils.Convert; -import ch.psi.utils.Str; import ch.psi.utils.swing.Editor.EditorDialog; import java.awt.Color; import java.awt.Component; @@ -73,7 +71,6 @@ public class ScreenPanel extends Panel { public ScreenPanel() { initComponents(); renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin")); - renderer.setProfileFactor(4); setPersistedComponents(new Component[]{buttonCamtool, buttonDirect}); comboCameras.setEnabled(false); if (App.hasArgument("poll")) { @@ -91,6 +88,7 @@ public class ScreenPanel extends Panel { ex.printStackTrace(); } } + showFit=buttonFit.isSelected(); } @Override @@ -114,6 +112,7 @@ public class ScreenPanel extends Panel { JDialog histogramDialog; DiscretePositioner screen; DiscretePositioner filter; + boolean showFit; //Overridable callbacks @Override @@ -125,13 +124,12 @@ public class ScreenPanel extends Panel { ((Source)getDevice("image")).addListener(new ImageListener() { @Override public void onImage(Object o, BufferedImage bi, Data data) { - if (bi == null) { + if ((bi == null)||(!showFit)) { fitOv = null; } else { - Overlay[] profile = renderer.getProfileOverlays(); - profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null; - renderer.updateOverlays(profile, fitOv); - fitOv = profile; + Overlay[] fo = getFitOverlays(data); + renderer.updateOverlays(fo, fitOv); + fitOv = fo; } } @Override @@ -374,16 +372,14 @@ public class ScreenPanel extends Panel { camera.addListener(new ImageListener() { @Override public void onImage(Object o, BufferedImage bi, Data data) { - if (bi == null) { + if ((bi == null)|| (!showFit)) { renderer.removeOverlays(fitOv); fitOv = null; } else { - //System.out.println(bi.getWidth() + " - " + bi.getHeight()); - if (!renderer.isPaused() && buttonFit.isSelected()){ - Overlay[] profile = renderer.getProfileOverlays(); - profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null; - renderer.updateOverlays(profile, fitOv); - fitOv = profile; + if (!renderer.isPaused()){ + Overlay[] fo = getFitOverlays(data); + renderer.updateOverlays(fo, fitOv); + fitOv = fo; } } } @@ -538,76 +534,75 @@ public class ScreenPanel extends Panel { Pen fitPen = new Pen(new Color(192, 105, 0), 1); Pen crossPen = new Pen(new Color(192, 105, 0), 1); - Overlay[] getFitOverlays(BufferedImage img){ + Overlay[] getFitOverlays(Data data){ Overlays.Polyline hpoly = null; Overlays.Polyline vpoly = null; Double xMean = null; Double xSigma = null; Double yMean = null; Double ySigma = null; - Profile profile = renderer.getProfile(); - if ((profile != Profile.None) && (img != null)) { - img = Utils.grayscale(img); - if (profile.hasVertical()) { - try { - double[] sum = (double[]) Convert.toDouble(Utils.integrateVertically(img)); - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i=0; i< sum.length; i++){ - sum[i] = sum[i] - min; - } - double[] gaussian = fitGaussian(sum, x); - if (gaussian!=null){ -// System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]+ " Min: " + min); - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ - xMean = gaussian[1]; - xSigma = gaussian[2]; - gaussian[0]+=min; - double[] fit = getFitFunction(gaussian, x); - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / renderer.getProfileFactor())); - } - vpoly = new Overlays.Polyline(fitPen, x, y); - } - } else { - //System.out.println("Fit failure"); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - if (profile.hasHorizontal()) { - try { - double[] sum = (double[]) Convert.toDouble(Utils.integrateHorizontally(img)); - int[] x = Arr.indexesInt(sum.length); - DescriptiveStatistics stats = new DescriptiveStatistics(sum); - double min = stats.getMin(); - for (int i=0; i< sum.length; i++){ - sum[i] = sum[i] - min; - } - double[] gaussian = fitGaussian(sum, x); - if (gaussian!=null){ - //Only aknowledge beam fully inside the image and peak over 3% of min - if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ - yMean = gaussian[1]; - ySigma = gaussian[2]; - gaussian[0]+=min; - double[] fit = getFitFunction(gaussian, x); + if (data != null) { + //img = Utils.grayscale(img); + double maxPlot = 255.0; + + try { + double[] sum = (double[]) Convert.toDouble(data.integrateVertically()); + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i=0; i< sum.length; i++){ + sum[i] = sum[i] - min; + } + + maxPlot = 4 * stats.getMax() /data.getHeight() ; - int[] y = new int[x.length]; - for (int i = 0; i < x.length; i++) { - y[i] = (int) (((double) fit[i]) / 255 / renderer.getProfileFactor()); - } - hpoly = new Overlays.Polyline(fitPen, y, x); - } + double[] gaussian = fitGaussian(sum, x); + if (gaussian!=null){ + if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ + xMean = gaussian[1]; + xSigma = gaussian[2]; + gaussian[0]+=min; + 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] / maxPlot)); + } + vpoly = new Overlays.Polyline(fitPen, x, y); } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + try { + double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally()); + int[] x = Arr.indexesInt(sum.length); + DescriptiveStatistics stats = new DescriptiveStatistics(sum); + double min = stats.getMin(); + for (int i=0; i< sum.length; i++){ + sum[i] = sum[i] - min; + } + maxPlot = 4 * stats.getMax() /data.getWidth() ; + + double[] gaussian = fitGaussian(sum, x); + if (gaussian!=null){ + //Only aknowledge beam fully inside the image and peak over 3% of min + if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){ + yMean = gaussian[1]; + ySigma = gaussian[2]; + gaussian[0]+=min; + double[] fit = getFitFunction(gaussian, x); + + int[] y = new int[x.length]; + for (int i = 0; i < x.length; i++) { + y[i] = (int) (fit[i] / maxPlot); + } + hpoly = new Overlays.Polyline(fitPen, y, x); + } + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + Overlays.Crosshairs cross= null; if ((xMean!=null) && (yMean!=null)){ cross = new Overlays.Crosshairs(crossPen, @@ -935,6 +930,8 @@ public class Camtool extends ArraySource { valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); comboFilter = new javax.swing.JComboBox(); + setPreferredSize(new java.awt.Dimension(873, 150)); + buttonGrabBackground.setText("Grab Background"); buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -1062,7 +1059,7 @@ public class Camtool extends ArraySource { .addComponent(buttonConfig) .addComponent(buttonSetup)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE) .addGap(12, 12, 12) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonPause) @@ -1076,6 +1073,8 @@ public class Camtool extends ArraySource { jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState}); + jPanel4.setPreferredSize(new java.awt.Dimension(235, 128)); + jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom")); buttonGroup1.add(buttonZoomFit); @@ -1282,7 +1281,7 @@ public class Camtool extends ArraySource { .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonHistogram) .addContainerGap()) ); @@ -1395,7 +1394,7 @@ public class Camtool extends ArraySource { .addContainerGap() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE) + .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(panelScreen1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) @@ -1432,8 +1431,8 @@ public class Camtool extends ArraySource { .addGroup(layout.createSequentialGroup() .addGap(0, 0, 0) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) ); }// //GEN-END:initComponents @@ -1519,7 +1518,7 @@ public class Camtool extends ArraySource { private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed try { - renderer.setProfile(buttonFit.isSelected() ? Profile.Both :Profile.None); + showFit=buttonFit.isSelected(); if (!buttonFit.isSelected()){ renderer.removeOverlays(fitOv); fitOv = null;