Startup
This commit is contained in:
@@ -57,6 +57,8 @@ 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;
|
||||
import java.net.ServerSocket;
|
||||
@@ -72,6 +74,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
@@ -206,6 +209,15 @@ public class ScreenPanel extends Panel {
|
||||
|
||||
renderer.setProfileNormalized(true);
|
||||
renderer.setShowProfileLimits(false);
|
||||
|
||||
JMenuItem menuCalibrate = new JMenuItem("Calibrate...");
|
||||
menuCalibrate.addActionListener((ActionEvent e) -> {
|
||||
try {
|
||||
calibrate();
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem menuSaveStack = new JMenuItem("Save Stack");
|
||||
menuSaveStack.addActionListener((ActionEvent e) -> {
|
||||
@@ -263,16 +275,18 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
renderer.getPopupMenu().add(menuCalibrate);
|
||||
renderer.getPopupMenu().add(menuSaveStack);
|
||||
renderer.getPopupMenu().addSeparator();
|
||||
renderer.getPopupMenu().add(menuSetROI);
|
||||
renderer.getPopupMenu().add(menuResetROI);
|
||||
renderer.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
menuResetROI.setEnabled(camera instanceof Camtool);
|
||||
menuSetROI.setEnabled(camera instanceof Camtool);
|
||||
menuCalibrate.setVisible(camera instanceof Camtool);
|
||||
menuCalibrate.setEnabled(calibrationOverlays==null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -608,6 +622,11 @@ public class ScreenPanel extends Panel {
|
||||
spinnerThreshold.setEnabled(false);
|
||||
|
||||
checkThreshold.setEnabled(false);
|
||||
|
||||
if (calibrationDialolg!=null){
|
||||
calibrationDialolg.dispose();
|
||||
calibrationDialolg = null;
|
||||
}
|
||||
|
||||
if (camera != null) {
|
||||
//camera.removeAllListeners();
|
||||
@@ -712,12 +731,14 @@ public class ScreenPanel extends Panel {
|
||||
|
||||
((Camtool) camera).startReceiver();
|
||||
} else {
|
||||
/*
|
||||
if (camera.getConfig() instanceof PsiCamera.PsiCameraConfig){
|
||||
if (camera.getConfig().isCalibrated()){
|
||||
camera.getConfig().spatialCalOffsetX += ((PsiCamera.PsiCameraConfig)camera.getConfig()).regionStartX;
|
||||
camera.getConfig().spatialCalOffsetY += ((PsiCamera.PsiCameraConfig)camera.getConfig()).regionStartY;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
if (polling <= 0) {
|
||||
camera.setMonitored(true);
|
||||
} else {
|
||||
@@ -1104,7 +1125,7 @@ public class ScreenPanel extends Panel {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
double[] sum = (double[]) Convert.toDouble(data.integrateVertically(true));
|
||||
double[] sum = data.integrateVertically(true);
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
//xCom = getCom(sum);
|
||||
@@ -1138,7 +1159,7 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
|
||||
try {
|
||||
double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally(true));
|
||||
double[] sum = data.integrateHorizontally(true);
|
||||
double[] saux = new double[sum.length];
|
||||
int[] p = new int[sum.length];
|
||||
//yCom = getCom(sum);
|
||||
@@ -1535,9 +1556,73 @@ public class ScreenPanel extends Panel {
|
||||
getContext().getDataManager().setAttribute(path, "y_sigma", ys.getStdev());
|
||||
getContext().getDataManager().closeOutput();
|
||||
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)) {
|
||||
((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);
|
||||
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);
|
||||
calibrationDialolg = calibrationMessage.createDialog(getTopLevel(), "Calibration");
|
||||
calibrationDialolg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
calibrationDialolg.setModal(false);
|
||||
calibrationDialolg.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (calibrationOverlays!=null){
|
||||
try {
|
||||
renderer.removeOverlays(calibrationOverlays);
|
||||
calibrationOverlays = null;
|
||||
calibrationDialolg = null;
|
||||
if (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 camera calibration: " + x1 + ", "+ + x2 + ", " + + y1 + ", " + + y2);
|
||||
HashMap c = new HashMap();
|
||||
c.put("reference_marker", Arrays.asList(new Integer[]{x1, y1, x2, y2}));
|
||||
((Camtool) camera).setCalibration(cameraName, c);
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
calibrationDialolg.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
////////
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
|
||||
Reference in New Issue
Block a user