This commit is contained in:
sfop
2017-07-14 11:03:17 +02:00
parent c74d5661f5
commit 54c3592384
31 changed files with 1939 additions and 266 deletions

View File

@@ -27,6 +27,7 @@ import ch.psi.pshell.ui.App;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.DimensionDouble;
import ch.psi.pshell.imaging.Histogram;
import ch.psi.pshell.imaging.ImageBuffer;
import ch.psi.pshell.imaging.Overlay;
import ch.psi.pshell.imaging.Overlays;
import ch.psi.pshell.imaging.Overlays.Text;
@@ -47,6 +48,7 @@ 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.StandardDialog.StandardDialogListener;
import ch.psi.utils.swing.SwingUtils.OptionResult;
import ch.psi.utils.swing.SwingUtils.OptionType;
import java.awt.BorderLayout;
@@ -281,6 +283,7 @@ public class ScreenPanel extends Panel {
try {
calibrate();
} catch (Exception ex) {
ex.printStackTrace();
showException(ex);
}
});
@@ -363,7 +366,7 @@ public class ScreenPanel extends Panel {
menuSetROI.setEnabled(camera instanceof Camtool);
menuShowImageData.setVisible(camera instanceof Camtool);
menuCalibrate.setVisible(camera instanceof Camtool);
menuCalibrate.setEnabled(calibrationOverlays==null);
menuCalibrate.setEnabled((calibrationDialolg==null) || (!calibrationDialolg.isShowing()) );
}
@Override
@@ -1020,8 +1023,8 @@ public class ScreenPanel extends Panel {
checkHistogram.setSelected((histogramDialog != null) && (histogramDialog.isShowing()));
}
Pen penFit = new Pen(new Color(192, 105, 0), 1);
Pen penCross = new Pen(new Color(192, 105, 0), 1);
Pen penFit = new Pen(new Color(192, 105, 0), 0);
Pen penCross = new Pen(new Color(192, 105, 0), 0);
Frame getCurrentFrame(){
@@ -1626,7 +1629,9 @@ public class ScreenPanel extends Panel {
//Enforce the same timestamp to data & image files.
//snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart());
snapshotFile = getContext().getExecutionPars().getPath() + ".png";
renderer.saveSnapshot(snapshotFile, "png", true);
//renderer.saveSnapshot(snapshotFile, "png", true);
ImageBuffer.saveImage(SwingUtils.createImage(renderer), snapshotFile, "png");
}
JPanel panel = new JPanel();
@@ -1691,112 +1696,23 @@ public class ScreenPanel extends Panel {
SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000);
}
JDialog calibrationDialolg;
Overlay[] calibrationOverlays;
void calibrate() throws IOException{
if ( (camera instanceof Camtool) && (calibrationOverlays==null)) {
Map<String, Object> calibration = ((Camtool) camera).getCalibration(cameraName);
//Map<String, Object> calibration = (Map<String, Object>) ((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);
Overlays.Crosshairs top = new Overlays.Crosshairs(pen, new Dimension(-1, 1));
Overlays.Crosshairs bottom = new Overlays.Crosshairs(pen, new Dimension(-1, 1));
Overlays.Crosshairs left = new Overlays.Crosshairs(pen, new Dimension(1, -1));
Overlays.Crosshairs right = new Overlays.Crosshairs(pen, new Dimension(1, -1));
calibrationOverlays = new Overlay[]{top, bottom, left, right};
for (Overlay ov : calibrationOverlays){
ov.setMovable(true);
}
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 (um): "), 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(um): "), 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 java.awt.event.WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (calibrationOverlays!=null){
try {
renderer.removeOverlays(calibrationOverlays);
calibrationOverlays = null;
calibrationDialolg = null;
if ((calibrationMessage.getValue()!=null) && calibrationMessage.getValue().equals(0)){ //If pressed OK
int x1 = Math.min(left.getPosition().x, right.getPosition().x);
int x2 = Math.max(left.getPosition().x, right.getPosition().x);
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 " + 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", Double.valueOf(textWidth.getText()));
}
if (textHeight.getText().trim().length() > 0){
c.put("reference_marker_height", Double.valueOf(textHeight.getText()));
}
((Camtool) camera).setCalibration(cameraName, c);
Logger.getLogger(ScreenPanel.class.getName()).warning("Updated " + cameraName + " calibration: " + x1 + ", "+ x2 + ", " + y1 + ", " + y2);
}
}
} catch (IOException ex) {
Logger.getLogger(ScreenPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
public void windowDeactivated(java.awt.event.WindowEvent e) {
if (!calibrationDialolg.isShowing()){ //windowClosed is not called if window closed with ok/cancel
windowClosed(e);
}
}
});
StandardDialog calibrationDialolg;
void calibrate() throws Exception{
if (camera instanceof Camtool){
calibrationDialolg = (StandardDialog) getContext().getClassByName("CameraConfigDialog").getConstructors()[0].newInstance(new Object[]{getTopLevel(), camera, renderer});
SwingUtils.centerComponent(this, calibrationDialolg);
calibrationDialolg.setVisible(true);
calibrationDialolg.setListener(new StandardDialogListener() {
@Override
public void onWindowOpened(StandardDialog dlg) {
}
@Override
public void onWindowClosed(StandardDialog dlg, boolean accepted) {
if (accepted){
comboCamerasActionPerformed(null);
}
}
});
}
}