Startup
This commit is contained in:
@@ -13,6 +13,7 @@ import ch.psi.utils.Chrono;
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
import ch.psi.utils.swing.TextEditor;
|
||||
import ch.psi.pshell.bs.Camtool;
|
||||
import ch.psi.pshell.bs.StreamValue;
|
||||
import ch.psi.pshell.device.DescStatsDouble;
|
||||
import ch.psi.pshell.device.Device;
|
||||
import ch.psi.pshell.epics.ChannelInteger;
|
||||
@@ -44,6 +45,7 @@ import ch.psi.utils.Convert;
|
||||
import ch.psi.utils.TcpClient;
|
||||
import ch.psi.utils.swing.Editor.EditorDialog;
|
||||
import ch.psi.utils.swing.MainFrame;
|
||||
import ch.psi.utils.swing.StandardDialog;
|
||||
import ch.psi.utils.swing.SwingUtils.OptionResult;
|
||||
import ch.psi.utils.swing.SwingUtils.OptionType;
|
||||
import java.awt.BorderLayout;
|
||||
@@ -56,6 +58,7 @@ import java.awt.GridBagLayout;
|
||||
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;
|
||||
@@ -77,10 +80,14 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import org.apache.commons.math3.analysis.function.Gaussian;
|
||||
import org.apache.commons.math3.fitting.GaussianCurveFitter;
|
||||
import org.apache.commons.math3.fitting.WeightedObservedPoint;
|
||||
@@ -230,10 +237,10 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem menuShowIdentifiers = new JMenuItem("Show Identifiers...");
|
||||
menuShowIdentifiers.addActionListener((ActionEvent e) -> {
|
||||
JMenuItem menuShowImageData = new JMenuItem("Show Image Data");
|
||||
menuShowImageData.addActionListener((ActionEvent e) -> {
|
||||
try {
|
||||
showIdentifiers();
|
||||
showImageData();
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
@@ -295,7 +302,7 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
renderer.getPopupMenu().add(menuShowIdentifiers);
|
||||
renderer.getPopupMenu().add(menuShowImageData);
|
||||
renderer.getPopupMenu().add(menuCalibrate);
|
||||
renderer.getPopupMenu().add(menuSaveStack);
|
||||
renderer.getPopupMenu().addSeparator();
|
||||
@@ -306,7 +313,7 @@ public class ScreenPanel extends Panel {
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
menuResetROI.setEnabled(camera instanceof Camtool);
|
||||
menuSetROI.setEnabled(camera instanceof Camtool);
|
||||
menuShowIdentifiers.setVisible(camera instanceof Camtool);
|
||||
menuShowImageData.setVisible(camera instanceof Camtool);
|
||||
menuCalibrate.setVisible(camera instanceof Camtool);
|
||||
menuCalibrate.setEnabled(calibrationOverlays==null);
|
||||
}
|
||||
@@ -563,9 +570,14 @@ public class ScreenPanel extends Panel {
|
||||
buttonGrabBackground.setEnabled(false);
|
||||
checkBackground.setEnabled(false);
|
||||
spinnerThreshold.setEnabled(false);
|
||||
|
||||
checkThreshold.setEnabled(false);
|
||||
|
||||
if (dataTableDialog!=null){
|
||||
dataTableDialog.dispose();
|
||||
dataTableDialog = null;
|
||||
}
|
||||
dataTableModel = null;
|
||||
|
||||
if (calibrationDialolg!=null){
|
||||
calibrationDialolg.dispose();
|
||||
calibrationDialolg = null;
|
||||
@@ -689,7 +701,7 @@ public class ScreenPanel extends Panel {
|
||||
manageFit(bi, data);
|
||||
manageUserOverlays(bi, data);
|
||||
}
|
||||
|
||||
//updateImageData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -928,6 +940,9 @@ public class ScreenPanel extends Panel {
|
||||
if ((renderer.getMarker() == null) && buttonMarker.isSelected()) {
|
||||
buttonMarker.setSelected(false);
|
||||
}
|
||||
if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){
|
||||
updateImageData();
|
||||
}
|
||||
updateZoom();
|
||||
updateColormap();
|
||||
updateStop();
|
||||
@@ -1045,7 +1060,9 @@ public class ScreenPanel extends Panel {
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
double[] x_egu = renderer.getCalibration().getAxisX(sum.length);
|
||||
xCom = getCom(sum, x_egu);
|
||||
double[] comRms = getComRms(sum, x_egu);
|
||||
xCom = comRms[0];
|
||||
xRms = comRms[1];
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
|
||||
double min = stats.getMin();
|
||||
@@ -1064,14 +1081,16 @@ 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) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
|
||||
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
|
||||
y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
|
||||
}
|
||||
vgaussian = new Overlays.Polyline(penFit, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showProfile){
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
|
||||
}
|
||||
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -1083,7 +1102,9 @@ public class ScreenPanel extends Panel {
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
double[] y_egu = renderer.getCalibration().getAxisY(sum.length);
|
||||
yCom = getCom(sum, y_egu);
|
||||
double[] comRms = getComRms(sum, y_egu);
|
||||
yCom = comRms[0];
|
||||
yRms = comRms[1];
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
|
||||
double min = stats.getMin();
|
||||
@@ -1105,14 +1126,16 @@ 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) / width - minPlot) / rangePlot) * profileSize);
|
||||
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
|
||||
y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize);
|
||||
}
|
||||
hgaussian = new Overlays.Polyline(penFit, y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showProfile){
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
|
||||
}
|
||||
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x);
|
||||
}
|
||||
|
||||
@@ -1141,9 +1164,7 @@ public class ScreenPanel extends Panel {
|
||||
Point textPosition = new Point(12, 20);
|
||||
if (showProfile){
|
||||
if ((xCom != null) && (yCom != null)) {
|
||||
String text = ((xRms != null) && (yRms != null)) ?
|
||||
String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms) :
|
||||
String.format("com x: m=" + fmt + "\ncom y: m=" + fmt ,xCom, yCom);
|
||||
String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms);
|
||||
textCom = new Overlays.Text(renderer.getPenProfile(), text, new Font(Font.MONOSPACED, 0, 14), textPosition);
|
||||
textCom.setFixed(true);
|
||||
textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
|
||||
@@ -1288,22 +1309,26 @@ public class ScreenPanel extends Panel {
|
||||
return ret.toArray(new Overlay[0]);
|
||||
}
|
||||
|
||||
double getCom(double[] arr, double[] x) {
|
||||
if (arr == null) {
|
||||
return Double.NaN;
|
||||
double[] getComRms(double[] arr, double[] x) {
|
||||
if (arr != null) {
|
||||
double xmd = 0;
|
||||
double xmd2 = 0;
|
||||
double total = 0;
|
||||
for (int i=0; i< arr.length; i++) {
|
||||
double v = (arr[i] * x[i]);
|
||||
xmd += v;
|
||||
xmd2 += (v * x[i]);
|
||||
total += arr[i];
|
||||
}
|
||||
if (total > 0) {
|
||||
double com = xmd / total;
|
||||
double com2 = xmd2 / total;
|
||||
double rms = Math.sqrt(Math.abs(com2 - com * com));
|
||||
return new double[] {com, rms};
|
||||
}
|
||||
}
|
||||
int index = 0;
|
||||
double ret = 0;
|
||||
double total = 0;
|
||||
for (double v : arr) {
|
||||
ret += (v * x[index++]);
|
||||
total += v;
|
||||
}
|
||||
if (total == 0) {
|
||||
return Double.NaN;
|
||||
}
|
||||
return ret / total;
|
||||
}
|
||||
return new double[]{Double.NaN, Double.NaN};
|
||||
}
|
||||
|
||||
double[] fitGaussianScript(int[] y, int[] x) {
|
||||
ScriptManager sm = Context.getInstance().getScriptManager();
|
||||
@@ -1633,12 +1658,74 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
void showIdentifiers(){
|
||||
StandardDialog dataTableDialog;
|
||||
DefaultTableModel dataTableModel;
|
||||
void showImageData(){
|
||||
dataTableModel = null;
|
||||
if (camera instanceof Camtool){
|
||||
List<String> ids = ((Camtool)camera).getValue().getIdentifiers();
|
||||
|
||||
if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){
|
||||
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
|
||||
dataTableDialog.requestFocus();
|
||||
return;
|
||||
}
|
||||
List<String> ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers());
|
||||
Collections.sort(ids);
|
||||
String msg = String.join("\n", ids);
|
||||
SwingUtils.showMessage(getTopLevel(), "Camtool Identifiers", msg);
|
||||
//String msg = String.join("\n", ids);
|
||||
//SwingUtils.showMessage(getTopLevel(), "Image Data", msg);
|
||||
dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) {
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
return String.class;
|
||||
}
|
||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
for (String id : ids){
|
||||
dataTableModel.addRow(new Object[]{id, ""});
|
||||
}
|
||||
updateImageData();
|
||||
StreamValue val = ((Camtool)camera).getStream().take();
|
||||
JTable dataTable = new JTable(dataTableModel);
|
||||
dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
||||
dataTable.getTableHeader().setReorderingAllowed(false);
|
||||
dataTable.getTableHeader().setResizingAllowed(true);
|
||||
dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false);
|
||||
dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE );
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(dataTable);
|
||||
scrollPane.setPreferredSize(new Dimension(300, 400));
|
||||
dataTableDialog.setContentPane(scrollPane);
|
||||
dataTableDialog.pack();
|
||||
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
|
||||
dataTableDialog.setVisible(true);
|
||||
dataTableDialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
dataTableModel = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void updateImageData(){
|
||||
if (dataTableModel!=null){
|
||||
if (camera instanceof Camtool){
|
||||
for (int i = 0 ; i< dataTableModel.getRowCount(); i++){
|
||||
String id = String.valueOf(dataTableModel.getValueAt(i, 0));
|
||||
Object obj = ((Camtool)camera).getValue(id);
|
||||
if (obj!=null){
|
||||
if (obj.getClass().isArray()){
|
||||
obj = obj.getClass().getName();
|
||||
} else if (obj instanceof Double){
|
||||
obj = Convert.roundDouble((Double) obj, 1);
|
||||
} else if (obj instanceof Float){
|
||||
obj = Convert.roundDouble((Float) obj, 1);
|
||||
}
|
||||
}
|
||||
dataTableModel.setValueAt(String.valueOf(obj), i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2467,6 +2554,7 @@ public class ScreenPanel extends Panel {
|
||||
pauseSelection.setValue(imageBuffer.size());;
|
||||
}
|
||||
}
|
||||
updateImageData();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user