diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties
index 855495b..a048a5f 100644
--- a/devices/CurrentCamera.properties
+++ b/devices/CurrentCamera.properties
@@ -1,13 +1,13 @@
-#Mon Feb 13 10:18:52 CET 2017
+#Mon Feb 13 16:27:34 CET 2017
colormap=Temperature
colormapAutomatic=true
colormapMax=0.0
colormapMin=0.0
flipHorizontally=false
-flipVertically=true
+flipVertically=false
grayscale=false
-imageHeight=1200
-imageWidth=1246
+imageHeight=1040
+imageWidth=1392
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
@@ -18,10 +18,10 @@ roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
-serverURL=sflca\:10000
-spatialCalOffsetX=-630.0
-spatialCalOffsetY=-612.0
-spatialCalScaleX=-26.761819803746654
-spatialCalScaleY=-26.595744680851062
+serverURL=sf-cons-01\:10000
+spatialCalOffsetX=16859.947265625
+spatialCalOffsetY=16276.595703125
+spatialCalScaleX=-26.761820720381525
+spatialCalScaleY=-26.595744663521685
spatialCalUnits=mm
transpose=false
diff --git a/plugins/ScreenPanel.form b/plugins/ScreenPanel.form
index 56c6a62..0da7c7a 100644
--- a/plugins/ScreenPanel.form
+++ b/plugins/ScreenPanel.form
@@ -662,6 +662,7 @@
+
diff --git a/plugins/ScreenPanel.java b/plugins/ScreenPanel.java
index 353bdcc..7bcdba8 100644
--- a/plugins/ScreenPanel.java
+++ b/plugins/ScreenPanel.java
@@ -82,11 +82,12 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
*
*/
public class ScreenPanel extends Panel {
-
+
+ final String CONFIG_FOLDER = "/afs/psi.ch/intranet/SF/Applications/config/camtool";
+ final String CAMERA_DEVICE_NAME = "CurrentCamera";
boolean useCamtoolStats = true;
- final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool";
- String userOverlaysConfigFile;
- File[] cameraConfigFiles = new File[0];
+
+ String userOverlaysConfigFile;
ColormapSource camera;
String cameraName;
String cameraConfigJson;
@@ -287,7 +288,7 @@ public class ScreenPanel extends Panel {
boolean direct = App.getArgumentValue("ct").equals("0") || App.getArgumentValue("ct").equalsIgnoreCase("false");
buttonCamtool.setSelected(!direct);
buttonDirect.setSelected(direct);
- }
+ }
}
@Override
@@ -320,30 +321,15 @@ public class ScreenPanel extends Panel {
);
} else {
- cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"});
- Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
- DefaultComboBoxModel model = new DefaultComboBoxModel();
- for (File file : cameraConfigFiles) {
- String prefix = IO.getPrefix(file);
- if (!prefix.startsWith("#")) {
- model.addElement(prefix);
- }
- }
- if (App.hasArgument("cam")) {
- String cam = App.getArgumentValue("cam");
- if (model.getIndexOf(cam) < 0) {
- model.addElement(cam);
- }
- }
- model.addElement(Camtool.SIMULATION);
-
- comboCameras.setModel(model);
+ usingCamtool = buttonCamtool.isSelected();
+ updateCameraList();
comboCameras.setEnabled(true);
- comboCameras.setSelectedItem(-1);
- if (model.getSize() > 0) {
+ setComboCameraSelection(-1);
+
+ if (comboCameras.getModel().getSize() > 0) {
try {
if (App.hasArgument("cam")) {
- comboCameras.setSelectedItem(App.getArgumentValue("cam"));
+ setComboCameraSelection(App.getArgumentValue("cam"));
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -352,6 +338,68 @@ public class ScreenPanel extends Panel {
}
startTimer(1000);
}
+
+
+ DefaultComboBoxModel getCameraListFromFolder(){
+ File[] cameraConfigFiles = new File[0];
+ cameraConfigFiles = IO.listFiles(CONFIG_FOLDER, new String[]{"json"});
+ Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
+ DefaultComboBoxModel model = new DefaultComboBoxModel();
+ for (File file : cameraConfigFiles) {
+ String prefix = IO.getPrefix(file);
+ if (!prefix.startsWith("#")) {
+ model.addElement(prefix);
+ }
+ }
+ return model;
+ }
+
+ DefaultComboBoxModel getCameraListFromCamtool() throws IOException, InterruptedException{
+ DefaultComboBoxModel model = new DefaultComboBoxModel();
+ Camtool camtool = new Camtool(CAMERA_DEVICE_NAME);
+ try{
+ camtool.initialize();
+ List cameras = camtool.getCameras();
+ Collections.sort(cameras);
+ for (String camera:cameras){
+ model.addElement(camera);
+ }
+ //model.addElement(Camtool.SIMULATION);
+ } finally{
+ camtool.close();
+ }
+ return model;
+ }
+
+ boolean updatingCameraSelection;
+ void setComboCameraSelection(Object selection){
+ updatingCameraSelection = true;
+ try{
+ comboCameras.setSelectedItem(selection);
+ } finally{
+ updatingCameraSelection = false;
+ }
+ }
+
+ boolean usingCamtool;
+ void updateCameraList(){
+ try {
+ String selected = (String) comboCameras.getSelectedItem();
+ DefaultComboBoxModel model= usingCamtool ? getCameraListFromCamtool() : getCameraListFromFolder();
+ if (App.hasArgument("cam")) {
+ String cam = App.getArgumentValue("cam");
+ if (model.getIndexOf(cam) < 0) {
+ model.addElement(cam);
+ }
+ }
+ comboCameras.setModel(model);
+ if (selected!=null){
+ setComboCameraSelection(selected);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
void manageFit(BufferedImage bi, Data data) {
Overlay[] fo = ((bi == null) || (!showFit)) ? null : getFitOverlays(data);
@@ -512,15 +560,12 @@ public class ScreenPanel extends Panel {
}
try {
- Path configFile = Paths.get(configFolder, cameraName + ".json");
+ Path configFile = Paths.get(CONFIG_FOLDER, cameraName + ".json");
cameraConfigJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null;
- if ((cameraConfigJson == null) && (buttonDirect.isSelected())) {
- throw new Exception("Cannot open camera config file: " + configFile.toFile());
- }
if (buttonCamtool.isSelected()) {
- //camera = new Camtool("CurrentCamera", "gfa-lc6-64:8080");
- camera = new Camtool("CurrentCamera");
+ //camera = new Camtool(CAMTOOL_DEVICE_NAME, "gfa-lc6-64:8080");
+ camera = new Camtool(CAMERA_DEVICE_NAME);
camera.getConfig().flipHorizontally = false;
camera.getConfig().flipVertically = false;
camera.getConfig().rotation = 0.0;
@@ -529,7 +574,11 @@ public class ScreenPanel extends Panel {
camera.getConfig().roiWidth = -1;
camera.getConfig().roiHeight = -1;
} else {
- camera = new PsiCamera("CurrentCamera", cameraName);
+ if ((cameraConfigJson == null) && (buttonDirect.isSelected())) {
+ throw new Exception("Cannot open camera config file: " + configFile.toFile());
+ }
+
+ camera = new PsiCamera(CAMERA_DEVICE_NAME, cameraName);
config = (CameraConfig) JsonSerializer.decode(cameraConfigJson, CameraConfig.class);
camera.getConfig().flipHorizontally = config.getMirrorX();
camera.getConfig().flipVertically = config.getMirrorY();
@@ -571,10 +620,7 @@ public class ScreenPanel extends Panel {
checkBackground.setEnabled(true);
if (changed) {
((Camtool) camera).startPipeline(cameraName, null);
- checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction());
- Double threshold = ((Camtool) camera).getThreshold();
- checkThreshold.setSelected(threshold != null);
- spinnerThreshold.setValue((threshold == null) ? 0 : threshold);
+ updateCamtoolControls();
} else {
((Camtool) camera).startPipeline(cameraName, null, checkBackground.isSelected(), null, null, null);
}
@@ -643,11 +689,7 @@ public class ScreenPanel extends Panel {
ex.printStackTrace();
showException(ex);
renderer.clearOverlays();
-
- //TODO: Find better way to manage no background exception
- if (ex.getMessage().toLowerCase().contains("no background image")) {
- checkBackground.setSelected(true);
- }
+ updateCamtoolControls();
if (renderer.getDevice() == null) {
//renderer.setZoom(1.0);
//renderer.setMode(RendererMode.Zoom);
@@ -800,6 +842,23 @@ public class ScreenPanel extends Panel {
}
updatingColormap = false;
}
+
+
+ boolean updatingCamtoolControls;
+ void updateCamtoolControls(){
+ if ((camera!=null) && (camera instanceof Camtool)) {
+ updatingCamtoolControls = true;
+ try{
+ checkBackground.setSelected(((Camtool) camera).getBackgroundSubtraction());
+ Double threshold = ((Camtool) camera).getThreshold();
+ checkThreshold.setSelected(threshold != null);
+ spinnerThreshold.setValue((threshold == null) ? 0 : threshold);
+
+ } catch (Exception ex) {
+ }
+ updatingCamtoolControls = false;
+ }
+ }
@Override
protected void onTimer() {
@@ -1826,6 +1885,7 @@ public class ScreenPanel extends Panel {
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Source"));
buttonGroup4.add(buttonCamtool);
+ buttonCamtool.setSelected(true);
buttonCamtool.setText("Camtool");
buttonCamtool.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -2032,28 +2092,30 @@ public class ScreenPanel extends Panel {
}// //GEN-END:initComponents
private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
- try {
- if (!comboCameras.isEnabled()) {
- throw new Exception("Invalid state");
- }
- comboCameras.setEnabled(false);
- buttonCamtool.setEnabled(false);
- buttonDirect.setEnabled(false);
- final String cameraName = (String) comboCameras.getSelectedItem();
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- setCamera(cameraName);
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- comboCameras.setEnabled(true);
- buttonCamtool.setEnabled(true);
- buttonDirect.setEnabled(true);
- }
+ try {
+ if (!updatingCameraSelection){
+ if (!comboCameras.isEnabled()) {
+ throw new Exception("Invalid state");
}
- }).start();
+ comboCameras.setEnabled(false);
+ buttonCamtool.setEnabled(false);
+ buttonDirect.setEnabled(false);
+ final String cameraName = (String) comboCameras.getSelectedItem();
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ setCamera(cameraName);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ comboCameras.setEnabled(true);
+ buttonCamtool.setEnabled(true);
+ buttonDirect.setEnabled(true);
+ }
+ }
+ }).start();
+ }
} catch (Exception ex) {
showException(ex);
}
@@ -2252,10 +2314,18 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_buttonZoom05ActionPerformed
private void buttonCamtoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCamtoolActionPerformed
+ if (!usingCamtool){
+ usingCamtool = true;
+ updateCameraList();
+ }
comboCamerasActionPerformed(null);
}//GEN-LAST:event_buttonCamtoolActionPerformed
private void buttonDirectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDirectActionPerformed
+ if (usingCamtool){
+ usingCamtool = false;
+ updateCameraList();
+ }
comboCamerasActionPerformed(null);
}//GEN-LAST:event_buttonDirectActionPerformed
@@ -2313,33 +2383,50 @@ public class ScreenPanel extends Panel {
}//GEN-LAST:event_buttonZoom2ActionPerformed
private void spinnerThresholdonChange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerThresholdonChange
+ if (updatingCamtoolControls){
+ return;
+ }
try {
if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) {
((Camtool) camera).setThreshold((Double) spinnerThreshold.getValue());
}
} catch (Exception ex) {
showException(ex);
+ updateCamtoolControls();
}
}//GEN-LAST:event_spinnerThresholdonChange
private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed
+ if (updatingCamtoolControls){
+ return;
+ }
try {
if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) {
((Camtool) camera).setBackgroundSubtraction(checkBackground.isSelected());
}
- } catch (Exception ex) {
- showException(ex);
+ } catch (Exception ex) {
+ showException(ex);
+ updateCamtoolControls();
+ //There is a bug in camtool: it will flag bg extraction as on:
+ updatingCamtoolControls = true;
+ checkBackground.setSelected(false);
+ updatingCamtoolControls = false;
+
}
}//GEN-LAST:event_checkBackgroundActionPerformed
private void checkThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkThresholdActionPerformed
+ if (updatingCamtoolControls){
+ return;
+ }
try {
if ((camera instanceof Camtool) && (((Camtool) camera).isPipelineStarted())) {
spinnerThreshold.setEnabled(checkThreshold.isSelected());
((Camtool) camera).setThreshold(checkThreshold.isSelected() ? (Double) spinnerThreshold.getValue() : null);
}
- } catch (Exception ex) {
+ } catch (Exception ex) {
showException(ex);
+ updateCamtoolControls();
}
}//GEN-LAST:event_checkThresholdActionPerformed