This commit is contained in:
gobbo_a
2017-03-17 11:14:30 +01:00
parent 9a2bb56569
commit 6565e930be
2 changed files with 152 additions and 161 deletions
+9 -9
View File
@@ -1,13 +1,13 @@
#Thu Mar 16 17:34:07 CET 2017 #Fri Mar 17 11:09:48 CET 2017
colormap=Temperature colormap=Temperature
colormapAutomatic=false colormapAutomatic=false
colormapMax=0.0 colormapMax=NaN
colormapMin=0.0 colormapMin=NaN
flipHorizontally=false flipHorizontally=false
flipVertically=false flipVertically=false
grayscale=false grayscale=false
imageHeight=1200 imageHeight=1040
imageWidth=1246 imageWidth=1392
invert=false invert=false
rescaleFactor=1.0 rescaleFactor=1.0
rescaleOffset=0.0 rescaleOffset=0.0
@@ -19,9 +19,9 @@ rotation=0.0
rotationCrop=false rotationCrop=false
scale=1.0 scale=1.0
serverURL=localhost\:10000 serverURL=localhost\:10000
spatialCalOffsetX=16859.947265625 spatialCalOffsetX=-50.0
spatialCalOffsetY=16276.595703125 spatialCalOffsetY=-50.0
spatialCalScaleX=-26.761820720381525 spatialCalScaleX=-1.0
spatialCalScaleY=-26.595744663521685 spatialCalScaleY=-1.0
spatialCalUnits=mm spatialCalUnits=mm
transpose=false transpose=false
+97 -106
View File
@@ -83,7 +83,7 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
*/ */
public class ScreenPanel extends Panel { public class ScreenPanel extends Panel {
final String CONFIG_FOLDER = "/afs/psi.ch/intranet/SF/Applications/config/camtool"; final String CONFIG_FOLDER = "/afs/psi.ch/intranet/SF/Applications/config/camtool_n";
final String CAMERA_DEVICE_NAME = "CurrentCamera"; final String CAMERA_DEVICE_NAME = "CurrentCamera";
boolean useCamtoolStats = true; boolean useCamtoolStats = true;
@@ -124,7 +124,6 @@ public class ScreenPanel extends Panel {
x_fit_gauss_function = getCamtoolDoubleArray("x_fit_gauss_function"); x_fit_gauss_function = getCamtoolDoubleArray("x_fit_gauss_function");
y_profile = getCamtoolDoubleArray("y_profile"); y_profile = getCamtoolDoubleArray("y_profile");
y_fit_gauss_function = getCamtoolDoubleArray("y_fit_gauss_function"); y_fit_gauss_function = getCamtoolDoubleArray("y_fit_gauss_function");
} }
} }
Data data; Data data;
@@ -172,7 +171,7 @@ public class ScreenPanel extends Panel {
if (App.hasArgument("usr_ov")) { if (App.hasArgument("usr_ov")) {
try { try {
userOverlaysConfigFile =App.getArgumentValue("usr_ov"); userOverlaysConfigFile = App.getArgumentValue("usr_ov");
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@@ -340,53 +339,54 @@ public class ScreenPanel extends Panel {
startTimer(1000); startTimer(1000);
} }
DefaultComboBoxModel getCameraListFromFolder() {
DefaultComboBoxModel getCameraListFromFolder(){
File[] cameraConfigFiles = new File[0]; File[] cameraConfigFiles = new File[0];
cameraConfigFiles = IO.listFiles(CONFIG_FOLDER, new String[]{"json"}); cameraConfigFiles = IO.listFiles(CONFIG_FOLDER, new String[]{"json"});
Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b)); Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model = new DefaultComboBoxModel();
for (File file : cameraConfigFiles) { for (File file : cameraConfigFiles) {
String prefix = IO.getPrefix(file); String prefix = IO.getPrefix(file);
if (!prefix.startsWith("#")) { if (!prefix.startsWith("#") && !prefix.endsWith("_parameters")) {
model.addElement(prefix); model.addElement(prefix);
} }
} }
return model; return model;
} }
DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException{ DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException {
DefaultComboBoxModel model = new DefaultComboBoxModel(); DefaultComboBoxModel model = new DefaultComboBoxModel();
Camtool camtool = new Camtool(CAMERA_DEVICE_NAME); Camtool camtool = new Camtool(CAMERA_DEVICE_NAME);
try{ try {
camtool.initialize(); camtool.initialize();
List<String> cameras = camtool.getCameras(); List<String> cameras = camtool.getCameras();
Collections.sort(cameras); Collections.sort(cameras);
for (String camera:cameras){ for (String camera : cameras) {
model.addElement(camera); model.addElement(camera);
} }
//model.addElement(Camtool.SIMULATION); //model.addElement(Camtool.SIMULATION);
} finally{ } finally {
camtool.close(); camtool.close();
} }
return model; return model;
} }
boolean updatingCameraSelection; boolean updatingCameraSelection;
void setComboCameraSelection(Object selection){
void setComboCameraSelection(Object selection) {
updatingCameraSelection = true; updatingCameraSelection = true;
try{ try {
comboCameras.setSelectedItem(selection); comboCameras.setSelectedItem(selection);
} finally{ } finally {
updatingCameraSelection = false; updatingCameraSelection = false;
} }
} }
boolean usingCamtool; boolean usingCamtool;
void updateCameraList(){
void updateCameraList() {
try { try {
String selected = (String) comboCameras.getSelectedItem(); String selected = (String) comboCameras.getSelectedItem();
DefaultComboBoxModel model= usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder(); DefaultComboBoxModel model = usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder();
if (App.hasArgument("cam")) { if (App.hasArgument("cam")) {
String cam = App.getArgumentValue("cam"); String cam = App.getArgumentValue("cam");
if (model.getIndexOf(cam) < 0) { if (model.getIndexOf(cam) < 0) {
@@ -394,12 +394,12 @@ public class ScreenPanel extends Panel {
} }
} }
comboCameras.setModel(model); comboCameras.setModel(model);
if (selected!=null){ if (selected != null) {
setComboCameraSelection(selected); setComboCameraSelection(selected);
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally{ } finally {
updateStop(); updateStop();
} }
} }
@@ -432,91 +432,80 @@ public class ScreenPanel extends Panel {
public static class CameraConfig { public static class CameraConfig {
public HashMap kwargs; public HashMap camera;
public ArrayList args;
public ArrayList links;
public String type;
public HashMap<String, Object> state;
public CameraConfig image_source;
public HashMap<String, CameraConfig> subcomponents;
public ArrayList<Integer> getCalibration() { public HashMap getCalibration() {
return (ArrayList<Integer>) state.get("calibration"); return (HashMap) camera.get("calibration");
}
public ArrayList<Integer> getCalibrationRefMarker() {
return (ArrayList<Integer>) getCalibration().get("reference_marker");
} }
public double getCalOffsetX() { public double getCalOffsetX() {
ArrayList<Integer> calibration = getCalibration(); ArrayList<Integer> calibration = getCalibrationRefMarker();
double ret = -(calibration.get(0) + calibration.get(2)) / 2; double ret = -(calibration.get(0) + calibration.get(2)) / 2;
return ret; return ret;
} }
public double getCalOffsetY() { public double getCalOffsetY() {
ArrayList<Integer> calibration = getCalibration(); ArrayList<Integer> calibration = getCalibrationRefMarker();
double ret = -(calibration.get(1) + calibration.get(3)) / 2; double ret = -(calibration.get(1) + calibration.get(3)) / 2;
return ret; return ret;
} }
public double getScaleX() { public double getScaleX() {
ArrayList<Integer> calibration = getCalibration(); ArrayList<Integer> calibration = getCalibrationRefMarker();
double width = Math.abs(calibration.get(2) - calibration.get(0)); double width = Math.abs(calibration.get(2) - calibration.get(0));
return getCalibrationWidth() / width; return getCalibrationWidth() / width;
} }
public double getScaleY() { public double getScaleY() {
ArrayList<Integer> calibration = getCalibration(); ArrayList<Integer> calibration = getCalibrationRefMarker();
double height = Math.abs(calibration.get(3) - calibration.get(1)); double height = Math.abs(calibration.get(3) - calibration.get(1));
return getCalibrationHeight() / height; return getCalibrationHeight() / height;
} }
public Double getCalibrationHeight() { public Double getCalibrationHeight() {
return (Double) state.get("calibration_height"); return (Double) getCalibration().get("reference_marker_height");
} }
public Double getCalibrationWidth() { public Double getCalibrationWidth() {
return (Double) state.get("calibration_width"); return (Double) getCalibration().get("reference_marker_width");
} }
public Double getCalibrationHorizontalAngle() { public Double getCalibrationHorizontalAngle() {
return (Double) state.get("calibration_horizontal_angle"); return (Double) getCalibration().get("horizontal_camera_angle");
} }
public Double getCalibrationVerticalAngle() { public Double getCalibrationVerticalAngle() {
return (Double) state.get("calibration_vertical_angle"); return (Double) getCalibration().get("vertical_camera_angle");
} }
public Boolean getMirrorX() { public boolean getMirrorX() {
return (Boolean) state.get("mirror_x"); Boolean ret = (Boolean) camera.get("mirror_x");
return (ret == null) ? false : ret;
} }
public Boolean getMirrorY() { public boolean getMirrorY() {
return (Boolean) state.get("mirror_y"); Boolean ret = (Boolean) camera.get("mirror_y");
return (ret == null) ? false : ret;
} }
public Integer getRotate() { public int getRotate() {
return (Integer) state.get("rotate"); Integer ret = (Integer) camera.get("rotate");
} return (ret == null) ? 0 : ret;
public ArrayList<Integer> getOrigin() {
return (ArrayList<Integer>) state.get("origin");
} }
public ArrayList<Integer> getRoi() { public ArrayList<Integer> getRoi() {
return (ArrayList<Integer>) state.get("roi"); return (ArrayList<Integer>) camera.get("roi");
} }
public Boolean getRoiEnable() { public Boolean getRoiEnable() {
if ((state.get("roi_enable") == null) || (state.get("roi") == null)) { if ((camera.get("roi_enable") == null) || (camera.get("roi") == null)) {
return false; return false;
} }
return (Boolean) state.get("roi_enable"); return (Boolean) camera.get("roi_enable");
}
public ArrayList<Double> getUnitSize() {
return (ArrayList<Double>) state.get("unit_size");
}
public Integer getRun() {
return (Integer) state.get("run");
} }
} }
@@ -539,6 +528,7 @@ public class ScreenPanel extends Panel {
camera = null; camera = null;
} }
renderer.setDevice(null); renderer.setDevice(null);
renderer.setShowReticle(false); renderer.setShowReticle(false);
renderer.removeOverlays(fitOv); renderer.removeOverlays(fitOv);
renderer.removeOverlays(userOv); renderer.removeOverlays(userOv);
@@ -548,8 +538,8 @@ public class ScreenPanel extends Panel {
boolean changed = !String.valueOf(cameraName).equals(this.cameraName); boolean changed = !String.valueOf(cameraName).equals(this.cameraName);
this.cameraName = cameraName; this.cameraName = cameraName;
if (changed){ if (changed) {
if ( (devicesInitTask!=null) && (devicesInitTask.isAlive())){ if ((devicesInitTask != null) && (devicesInitTask.isAlive())) {
devicesInitTask.interrupt(); devicesInitTask.interrupt();
} }
if (screen != null) { if (screen != null) {
@@ -561,7 +551,7 @@ public class ScreenPanel extends Panel {
filter = null; filter = null;
} }
} }
if (cameraName==null){ if (cameraName == null) {
return; return;
} }
@@ -655,14 +645,15 @@ public class ScreenPanel extends Panel {
public void onImage(Object o, BufferedImage bi, Data data) { public void onImage(Object o, BufferedImage bi, Data data) {
if (bi != null) { if (bi != null) {
if (firstImage) { if (firstImage) {
if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) { SwingUtilities.invokeLater(new Runnable() {
SwingUtilities.invokeLater(new Runnable() { @Override
@Override public void run() {
public void run() { if ((renderer.getMode() == RendererMode.Zoom) || (renderer.getMode() == RendererMode.Fixed)) {
centralizeRenderer(); centralizeRenderer();
} }
}); checkReticle();
} }
});
firstImage = false; firstImage = false;
} }
renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight())); renderer.setProfileSize(Math.min(bi.getWidth(), bi.getHeight()));
@@ -705,11 +696,11 @@ public class ScreenPanel extends Panel {
renderer.addOverlay(errorOverlay); renderer.addOverlay(errorOverlay);
} }
} finally { } finally {
checkReticle(); //checkReticle();
onTimer(); onTimer();
} }
if (changed){ if (changed) {
comboScreen.setModel(new DefaultComboBoxModel()); comboScreen.setModel(new DefaultComboBoxModel());
comboFilter.setModel(new DefaultComboBoxModel()); comboFilter.setModel(new DefaultComboBoxModel());
@@ -750,11 +741,10 @@ public class ScreenPanel extends Panel {
} }
comboFilter.setEnabled(filter != null); comboFilter.setEnabled(filter != null);
valueFilter.setDevice(filter); valueFilter.setDevice(filter);
}); });
devicesInitTask.start(); devicesInitTask.start();
} }
} }
volatile Boolean firstImage; volatile Boolean firstImage;
@@ -851,12 +841,12 @@ public class ScreenPanel extends Panel {
updatingColormap = false; updatingColormap = false;
} }
boolean updatingCamtoolControls; boolean updatingCamtoolControls;
void updateCamtoolControls(){
if ((camera!=null) && (camera instanceof Camtool)) { void updateCamtoolControls() {
if ((camera != null) && (camera instanceof Camtool)) {
updatingCamtoolControls = true; updatingCamtoolControls = true;
try{ try {
checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction()); checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction());
Double threshold = ((Camtool) camera).getThreshold(); Double threshold = ((Camtool) camera).getThreshold();
checkThreshold.setSelected(threshold != null); checkThreshold.setSelected(threshold != null);
@@ -868,18 +858,18 @@ public class ScreenPanel extends Panel {
} }
} }
boolean isCameraStopped(){ boolean isCameraStopped() {
if ((camera!=null) && (camera instanceof Camtool)) { if ((camera != null) && (camera instanceof Camtool)) {
if (!((Camtool) camera).isPipelineStarted()){ if (!((Camtool) camera).isPipelineStarted()) {
return true; return true;
} }
} }
return ((camera == null) || (camera.isClosed()) || !buttonStop.isEnabled()); return ((camera == null) || (camera.isClosed()) || !buttonStop.isEnabled());
} }
void updateStop(){ void updateStop() {
buttonStop.setEnabled(comboCameras.getSelectedItem()!=null); buttonStop.setEnabled(comboCameras.getSelectedItem() != null);
buttonStop.setText(isCameraStopped() ? "Start": "Stop"); buttonStop.setText(isCameraStopped() ? "Start" : "Stop");
} }
@@ -1130,6 +1120,7 @@ public class ScreenPanel extends Panel {
} }
class UserOverlay { class UserOverlay {
String name; String name;
Overlay obj; Overlay obj;
String[] channels; String[] channels;
@@ -1139,7 +1130,7 @@ public class ScreenPanel extends Panel {
void parseUserOverlays() { void parseUserOverlays() {
Properties userOverlays = new Properties(); Properties userOverlays = new Properties();
userOverlayConfig = new ArrayList<>(); userOverlayConfig = new ArrayList<>();
if (userOverlaysConfigFile!=null){ if (userOverlaysConfigFile != null) {
try { try {
try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) { try (FileInputStream in = new FileInputStream(getContext().getSetup().expandPath(userOverlaysConfigFile))) {
userOverlays.load(in); userOverlays.load(in);
@@ -2128,7 +2119,7 @@ public class ScreenPanel extends Panel {
private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
try { try {
if (!updatingCameraSelection){ if (!updatingCameraSelection) {
if (!comboCameras.isEnabled()) { if (!comboCameras.isEnabled()) {
throw new Exception("Invalid state"); throw new Exception("Invalid state");
} }
@@ -2139,7 +2130,7 @@ public class ScreenPanel extends Panel {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
if (requestCameraListUpdate){ if (requestCameraListUpdate) {
requestCameraListUpdate = false; requestCameraListUpdate = false;
try { try {
updateCameraList(); updateCameraList();
@@ -2258,24 +2249,24 @@ public class ScreenPanel extends Panel {
private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed
try { try {
if ((camera!=null) && (camera instanceof Camtool)) { if ((camera != null) && (camera instanceof Camtool)) {
if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) { if (SwingUtils.showOption(getTopLevel(), "Background", "Do you want to capture background now?", OptionType.YesNo) == OptionResult.Yes) {
boolean laserOn = getLaserState(); boolean laserOn = getLaserState();
boolean rendering = (!camera.isClosed()); boolean rendering = (!camera.isClosed());
if (rendering){ if (rendering) {
camera.close(); camera.close();
} }
if (laserOn) { if (laserOn) {
setLaserState(false); setLaserState(false);
} }
try{ try {
System.out.println("Grabbing background for: " + cameraName); System.out.println("Grabbing background for: " + cameraName);
((Camtool) camera).grabBackground(cameraName, 5); ((Camtool) camera).grabBackground(cameraName, 5);
} finally { } finally {
if (laserOn) { if (laserOn) {
setLaserState(true); setLaserState(true);
} }
if (rendering){ if (rendering) {
comboCamerasActionPerformed(null); comboCamerasActionPerformed(null);
} }
updateStop(); updateStop();
@@ -2367,7 +2358,7 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_buttonZoom05ActionPerformed }//GEN-LAST:event_buttonZoom05ActionPerformed
private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed
if (!usingCamtool){ if (!usingCamtool) {
usingCamtool = true; usingCamtool = true;
requestCameraListUpdate = true; requestCameraListUpdate = true;
} }
@@ -2375,7 +2366,7 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_buttonCamtoolActionPerformed }//GEN-LAST:event_buttonCamtoolActionPerformed
private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed
if (usingCamtool){ if (usingCamtool) {
usingCamtool = false; usingCamtool = false;
requestCameraListUpdate = true; requestCameraListUpdate = true;
} }
@@ -2397,18 +2388,18 @@ public class ScreenPanel extends Panel {
setpoint.write(index); setpoint.write(index);
//Must be threaded to control the laser because of sleep in setLaserState //Must be threaded to control the laser because of sleep in setLaserState
/* /*
boolean laserOn = getLaserState(); boolean laserOn = getLaserState();
if (laserOn) { if (laserOn) {
setLaserState(false); setLaserState(false);
} }
try { try {
setpoint.write(index); setpoint.write(index);
} finally { } finally {
if (laserOn) { if (laserOn) {
setLaserState(true); setLaserState(true);
} }
} }
*/ */
} }
screen.read(); screen.read();
} catch (Exception ex) { } catch (Exception ex) {
@@ -2449,7 +2440,7 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_buttonZoom2ActionPerformed }//GEN-LAST:event_buttonZoom2ActionPerformed
private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange
if (updatingCamtoolControls){ if (updatingCamtoolControls) {
return; return;
} }
try { try {
@@ -2463,7 +2454,7 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_spinnerThresholdonChange }//GEN-LAST:event_spinnerThresholdonChange
private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed
if (updatingCamtoolControls){ if (updatingCamtoolControls) {
return; return;
} }
try { try {
@@ -2482,7 +2473,7 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_checkBackgroundActionPerformed }//GEN-LAST:event_checkBackgroundActionPerformed
private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed
if (updatingCamtoolControls){ if (updatingCamtoolControls) {
return; return;
} }
try { try {
@@ -2498,12 +2489,12 @@ public class ScreenPanel extends Panel {
private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed
try { try {
if (buttonStop.getText().equals("Stop")){ if (buttonStop.getText().equals("Stop")) {
if ((camera!=null) && !camera.isClosed()){ if ((camera != null) && !camera.isClosed()) {
camera.close(); camera.close();
} }
} else { } else {
if (isCameraStopped()){ if (isCameraStopped()) {
comboCamerasActionPerformed(null); comboCamerasActionPerformed(null);
} }
} }