diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties
index 2454a8e..31c4cac 100644
--- a/devices/CurrentCamera.properties
+++ b/devices/CurrentCamera.properties
@@ -1,12 +1,12 @@
-#Mon Sep 12 10:50:08 CEST 2016
+#Mon Sep 12 15:37:13 CEST 2016
colormap=Temperature
colormapAutomatic=true
-colormapMax=NaN
-colormapMin=NaN
-flipHorizontally=true
-flipVertically=true
+colormapMax=1.0
+colormapMin=0.0
+flipHorizontally=false
+flipVertically=false
grayscale=false
-imageHeight=1628
+imageHeight=1024
imageWidth=1280
invert=true
rescaleFactor=1.0
@@ -18,9 +18,9 @@ roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
-spatialCalOffsetX=-685.0
-spatialCalOffsetY=-874.0
-spatialCalScaleX=14.146772767462423
-spatialCalScaleY=12.708498808578236
+spatialCalOffsetX=NaN
+spatialCalOffsetY=NaN
+spatialCalScaleX=NaN
+spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false
diff --git a/plugins/Cameras.form b/plugins/Cameras.form
index 28ac2d5..7993cd6 100644
--- a/plugins/Cameras.form
+++ b/plugins/Cameras.form
@@ -1,6 +1,14 @@
diff --git a/plugins/Cameras.java b/plugins/Cameras.java
index f1c9a7b..38748e0 100644
--- a/plugins/Cameras.java
+++ b/plugins/Cameras.java
@@ -22,6 +22,9 @@ import ch.psi.pshell.epics.ChannelDouble;
import ch.psi.pshell.epics.ChannelDoubleArray;
import ch.psi.pshell.epics.ChannelInteger;
import ch.psi.pshell.epics.ChannelIntegerArray;
+import ch.psi.pshell.imaging.Colormap;
+import ch.psi.pshell.imaging.ColormapSource;
+import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig;
import ch.psi.pshell.ui.App;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.Overlay;
@@ -31,6 +34,7 @@ import ch.psi.pshell.imaging.Pen;
import static ch.psi.pshell.imaging.Renderer.PEN_ERROR_TEXT;
import ch.psi.pshell.imaging.Renderer.Profile;
import static ch.psi.pshell.imaging.RendererMenu.PEN_MARKER;
+import ch.psi.pshell.imaging.RendererMode;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.imaging.Utils;
import ch.psi.pshell.scripting.InterpreterResult;
@@ -182,7 +186,7 @@ public class Cameras extends Panel {
public ArrayList getCalibration() {
return (ArrayList) state.get("calibration");
}
-
+
public double getCalOffsetX(){
ArrayList calibration = getCalibration();
double ret = - (calibration.get(0) + calibration.get(2))/2;
@@ -393,7 +397,40 @@ public class Cameras extends Panel {
}
renderer.refresh();
}
+
+ void updateZoom(){
+ try{
+ buttonZoomStretch.setSelected(renderer.getMode() == RendererMode.Stretch);
+ buttonZoomFit.setSelected(renderer.getMode() == RendererMode.Fit);
+ buttonZoomNormal.setSelected( (renderer.getMode() == RendererMode.Fixed) || ((renderer.getMode() == RendererMode.Zoom) && (renderer.getZoom()==1.0)));
+ buttonZoom05.setSelected((renderer.getMode() == RendererMode.Zoom) && (renderer.getZoom()==0.5));
+ buttonZoom025.setSelected((renderer.getMode() == RendererMode.Zoom) && (renderer.getZoom()==0.25));
+ }catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ void updateColormap(){
+ try{
+ if ((camera!=null) && (camera instanceof ColormapSource)){
+ ColormapSourceConfig config = ((ColormapSource)camera).getConfig();
+ buttonGrayscale.setSelected(config.colormap == Colormap.Grayscale);
+ buttonRainbow.setSelected(config.colormap == Colormap.Rainbow);
+ buttonTemperature.setSelected(config.colormap == Colormap.Temperature);
+
+ buttonFullRange.setSelected(config.isDefaultColormap());
+ buttonAutomatic.setSelected(config.colormapAutomatic);
+ buttonManual.setSelected((!buttonFullRange.isSelected()) && (!buttonAutomatic.isSelected()));
+ spinnerMin.setEnabled(buttonManual.isSelected());
+ spinnerMax.setEnabled(buttonManual.isSelected());
+ spinnerMin.setValue(Double.isNaN(config.colormapMin) ? 0 : Math.min(Math.max((int)config.colormapMin, 0), 65535));
+ spinnerMax.setValue(Double.isNaN(config.colormapMax) ? 0 : Math.min(Math.max((int)config.colormapMax, 0), 65535));
+ }
+ }catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
@Override
protected void onTimer() {
textState.setText((camera == null) ? "" : camera.getState().toString());
@@ -407,6 +444,8 @@ public class Cameras extends Panel {
Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex);
}
}
+ updateZoom();
+ updateColormap();
}
Pen fitPen = new Pen(new Color(192, 105, 0), 1);
@@ -761,59 +800,58 @@ public class Camtool extends ArraySource {
// //GEN-BEGIN:initComponents
private void initComponents() {
- renderer = new ch.psi.pshell.imaging.Renderer();
- jLabel1 = new javax.swing.JLabel();
- comboCameras = new javax.swing.JComboBox();
- jLabel2 = new javax.swing.JLabel();
- textState = new javax.swing.JTextField();
- buttonConfig = new javax.swing.JButton();
- buttonSetup = new javax.swing.JButton();
- checkCamtool = new javax.swing.JCheckBox();
- buttonFit = new javax.swing.JToggleButton();
- buttonPause = new javax.swing.JToggleButton();
- buttonMarker = new javax.swing.JToggleButton();
- buttonSave = new javax.swing.JToggleButton();
- buttonReticle = new javax.swing.JToggleButton();
+ buttonGroup1 = new javax.swing.ButtonGroup();
+ buttonGroup2 = new javax.swing.ButtonGroup();
+ buttonGroup3 = new javax.swing.ButtonGroup();
+ jPanel1 = new javax.swing.JPanel();
buttonGrabBackground = new javax.swing.JButton();
+ renderer = new ch.psi.pshell.imaging.Renderer();
+ textState = new javax.swing.JTextField();
+ buttonSave = new javax.swing.JToggleButton();
+ buttonPause = new javax.swing.JToggleButton();
+ jLabel2 = new javax.swing.JLabel();
+ buttonFit = new javax.swing.JToggleButton();
+ comboCameras = new javax.swing.JComboBox();
+ buttonSetup = new javax.swing.JButton();
+ buttonMarker = new javax.swing.JToggleButton();
+ jLabel1 = new javax.swing.JLabel();
+ buttonConfig = new javax.swing.JButton();
+ buttonReticle = new javax.swing.JToggleButton();
+ jPanel2 = new javax.swing.JPanel();
+ buttonGrayscale = new javax.swing.JRadioButton();
+ buttonRainbow = new javax.swing.JRadioButton();
+ buttonTemperature = new javax.swing.JRadioButton();
+ buttonFullRange = new javax.swing.JRadioButton();
+ buttonManual = new javax.swing.JRadioButton();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+ spinnerMin = new javax.swing.JSpinner();
+ spinnerMax = new javax.swing.JSpinner();
+ buttonAutomatic = new javax.swing.JRadioButton();
+ jPanel3 = new javax.swing.JPanel();
+ buttonZoomFit = new javax.swing.JRadioButton();
+ buttonZoomStretch = new javax.swing.JRadioButton();
+ buttonZoomNormal = new javax.swing.JRadioButton();
+ buttonZoom025 = new javax.swing.JRadioButton();
+ buttonZoom05 = new javax.swing.JRadioButton();
+ checkCamtool = new javax.swing.JCheckBox();
- jLabel1.setText("Camera:");
-
- comboCameras.setMaximumRowCount(30);
- comboCameras.addActionListener(new java.awt.event.ActionListener() {
+ buttonGrabBackground.setText("Grab Background");
+ buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
- comboCamerasActionPerformed(evt);
+ buttonGrabBackgroundActionPerformed(evt);
}
});
- jLabel2.setText("State:");
-
textState.setEditable(false);
textState.setHorizontalAlignment(javax.swing.JTextField.CENTER);
textState.setDisabledTextColor(new java.awt.Color(0, 0, 0));
textState.setEnabled(false);
- buttonConfig.setText("Config");
- buttonConfig.addActionListener(new java.awt.event.ActionListener() {
+ buttonSave.setText("Save Snapshot");
+ buttonSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonConfigActionPerformed(evt);
- }
- });
-
- buttonSetup.setText("Setup");
- buttonSetup.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonSetupActionPerformed(evt);
- }
- });
-
- checkCamtool.setSelected(true);
- checkCamtool.setText("Camtool");
-
- buttonFit.setSelected(true);
- buttonFit.setText("Fit");
- buttonFit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonFitActionPerformed(evt);
+ buttonSaveActionPerformed(evt);
}
});
@@ -824,6 +862,30 @@ public class Camtool extends ArraySource {
}
});
+ jLabel2.setText("State:");
+
+ buttonFit.setSelected(true);
+ buttonFit.setText("Fit");
+ buttonFit.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonFitActionPerformed(evt);
+ }
+ });
+
+ comboCameras.setMaximumRowCount(30);
+ comboCameras.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ comboCamerasActionPerformed(evt);
+ }
+ });
+
+ buttonSetup.setText("Setup");
+ buttonSetup.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonSetupActionPerformed(evt);
+ }
+ });
+
buttonMarker.setText("Marker");
buttonMarker.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -831,10 +893,12 @@ public class Camtool extends ArraySource {
}
});
- buttonSave.setText("Save Snapshot");
- buttonSave.addActionListener(new java.awt.event.ActionListener() {
+ jLabel1.setText("Camera:");
+
+ buttonConfig.setText("Config");
+ buttonConfig.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonSaveActionPerformed(evt);
+ buttonConfigActionPerformed(evt);
}
});
@@ -846,36 +910,27 @@ public class Camtool extends ArraySource {
}
});
- buttonGrabBackground.setText("Grab Background");
- buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonGrabBackgroundActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
- this.setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
+ javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
+ jPanel1.setLayout(jPanel1Layout);
+ jPanel1Layout.setHorizontalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(renderer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(checkCamtool)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(comboCameras, 0, 170, Short.MAX_VALUE)
+ .addComponent(comboCameras, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonConfig)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSetup)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGap(50, 50, 50)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(buttonPause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonMarker)
@@ -890,28 +945,27 @@ public class Camtool extends ArraySource {
.addContainerGap())
);
- layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup});
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup});
- layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
- layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ jPanel1Layout.setVerticalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(buttonConfig)
- .addComponent(buttonSetup)
- .addComponent(checkCamtool))
+ .addComponent(buttonSetup))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
+ .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)
.addGap(12, 12, 12)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonPause)
.addComponent(buttonFit)
.addComponent(buttonMarker)
@@ -921,8 +975,237 @@ public class Camtool extends ArraySource {
.addContainerGap())
);
- layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
+ jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Colormap"));
+
+ buttonGroup2.add(buttonGrayscale);
+ buttonGrayscale.setText("Grayscale");
+ buttonGrayscale.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ buttonGroup2.add(buttonRainbow);
+ buttonRainbow.setText("Rainbow");
+ buttonRainbow.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ buttonGroup2.add(buttonTemperature);
+ buttonTemperature.setText("Temperature");
+ buttonTemperature.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ buttonGroup3.add(buttonFullRange);
+ buttonFullRange.setText("Full range");
+ buttonFullRange.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ buttonGroup3.add(buttonManual);
+ buttonManual.setText("Manual");
+ buttonManual.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ jLabel3.setText("min:");
+
+ jLabel4.setText("max:");
+
+ spinnerMin.setModel(new javax.swing.SpinnerNumberModel(0, 0, 65535, 1));
+ spinnerMin.setEnabled(false);
+ spinnerMin.setPreferredSize(new java.awt.Dimension(60, 20));
+ spinnerMin.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ onChangeColormapRange(evt);
+ }
+ });
+
+ spinnerMax.setModel(new javax.swing.SpinnerNumberModel(255, 0, 65535, 1));
+ spinnerMax.setEnabled(false);
+ spinnerMax.setPreferredSize(new java.awt.Dimension(60, 20));
+ spinnerMax.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ onChangeColormapRange(evt);
+ }
+ });
+
+ buttonGroup3.add(buttonAutomatic);
+ buttonAutomatic.setText("Automatic");
+ buttonAutomatic.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ onChangeColormap(evt);
+ }
+ });
+
+ javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
+ jPanel2.setLayout(jPanel2Layout);
+ jPanel2Layout.setHorizontalGroup(
+ jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(buttonFullRange)
+ .addComponent(buttonManual))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel4)
+ .addComponent(jLabel3))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap())
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(buttonGrayscale)
+ .addComponent(buttonRainbow)
+ .addComponent(buttonTemperature)
+ .addComponent(buttonAutomatic))
+ .addGap(0, 0, Short.MAX_VALUE))))
+ );
+ jPanel2Layout.setVerticalGroup(
+ jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addComponent(buttonGrayscale)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonRainbow)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonTemperature)
+ .addGap(18, 18, 18)
+ .addComponent(buttonAutomatic)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(jPanel2Layout.createSequentialGroup()
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(buttonFullRange)
+ .addComponent(jLabel3)
+ .addComponent(spinnerMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonManual))
+ .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel4)
+ .addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+
+ jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom"));
+
+ buttonGroup1.add(buttonZoomFit);
+ buttonZoomFit.setText("Fit");
+ buttonZoomFit.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonZoomFitActionPerformed(evt);
+ }
+ });
+
+ buttonGroup1.add(buttonZoomStretch);
+ buttonZoomStretch.setText("Stretch");
+ buttonZoomStretch.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonZoomStretchActionPerformed(evt);
+ }
+ });
+
+ buttonGroup1.add(buttonZoomNormal);
+ buttonZoomNormal.setText("Normal");
+ buttonZoomNormal.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonZoomNormalActionPerformed(evt);
+ }
+ });
+
+ buttonGroup1.add(buttonZoom025);
+ buttonZoom025.setText("0.25");
+ buttonZoom025.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonZoom025ActionPerformed(evt);
+ }
+ });
+
+ buttonGroup1.add(buttonZoom05);
+ buttonZoom05.setText("0.5");
+ buttonZoom05.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonZoom05ActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
+ jPanel3.setLayout(jPanel3Layout);
+ jPanel3Layout.setHorizontalGroup(
+ jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel3Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(buttonZoomFit)
+ .addComponent(buttonZoomStretch)
+ .addComponent(buttonZoomNormal)
+ .addComponent(buttonZoom025)
+ .addComponent(buttonZoom05))
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ );
+ jPanel3Layout.setVerticalGroup(
+ jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel3Layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(buttonZoomFit)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonZoomStretch)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonZoom025)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(buttonZoom05)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonZoomNormal)
+ .addContainerGap())
+ );
+
+ checkCamtool.setSelected(true);
+ checkCamtool.setText("Use Camtool");
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(checkCamtool)
+ .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGap(0, 0, 0))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(checkCamtool)
+ .addGap(61, 61, 61)
+ .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(0, 0, Short.MAX_VALUE))
+ .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGap(0, 0, 0))
+ );
}// //GEN-END:initComponents
private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
@@ -1043,20 +1326,97 @@ public class Camtool extends ArraySource {
}
}//GEN-LAST:event_buttonGrabBackgroundActionPerformed
+ private void buttonZoomFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomFitActionPerformed
+ try {
+ renderer.setMode(RendererMode.Fit);
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonZoomFitActionPerformed
+
+ private void buttonZoomStretchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomStretchActionPerformed
+ try {
+ renderer.setMode(RendererMode.Stretch);
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonZoomStretchActionPerformed
+
+ private void buttonZoomNormalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoomNormalActionPerformed
+ try {
+ renderer.setMode(RendererMode.Fixed);
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonZoomNormalActionPerformed
+
+ private void onChangeColormap(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onChangeColormap
+ try {
+ if ((camera != null) && (camera instanceof ColormapSource)){
+ ColormapSource source = (ColormapSource)camera;
+ if (buttonGrayscale.isSelected()) source.getConfig().colormap = Colormap.Grayscale;
+ if (buttonTemperature.isSelected()) source.getConfig().colormap = Colormap.Temperature;
+ if (buttonRainbow.isSelected()) source.getConfig().colormap = Colormap.Rainbow;
+ source.getConfig().colormapAutomatic = buttonAutomatic.isSelected();
+ source.getConfig().colormapMin = buttonFullRange.isSelected() ? Double.NaN : (Integer)spinnerMin.getValue();
+ source.getConfig().colormapMax = buttonFullRange.isSelected() ? Double.NaN : (Integer)spinnerMax.getValue();
+ source.getConfig().save();
+ source.refresh();
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_onChangeColormap
+
+ private void onChangeColormapRange(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_onChangeColormapRange
+ onChangeColormap(null);
+ }//GEN-LAST:event_onChangeColormapRange
+
+ private void buttonZoom025ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom025ActionPerformed
+ renderer.setZoom(0.25);
+ renderer.setMode(RendererMode.Zoom);
+ }//GEN-LAST:event_buttonZoom025ActionPerformed
+
+ private void buttonZoom05ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonZoom05ActionPerformed
+ renderer.setZoom(0.5);
+ renderer.setMode(RendererMode.Zoom);
+ }//GEN-LAST:event_buttonZoom05ActionPerformed
+
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JRadioButton buttonAutomatic;
private javax.swing.JButton buttonConfig;
private javax.swing.JToggleButton buttonFit;
+ private javax.swing.JRadioButton buttonFullRange;
private javax.swing.JButton buttonGrabBackground;
+ private javax.swing.JRadioButton buttonGrayscale;
+ private javax.swing.ButtonGroup buttonGroup1;
+ private javax.swing.ButtonGroup buttonGroup2;
+ private javax.swing.ButtonGroup buttonGroup3;
+ private javax.swing.JRadioButton buttonManual;
private javax.swing.JToggleButton buttonMarker;
private javax.swing.JToggleButton buttonPause;
+ private javax.swing.JRadioButton buttonRainbow;
private javax.swing.JToggleButton buttonReticle;
private javax.swing.JToggleButton buttonSave;
private javax.swing.JButton buttonSetup;
+ private javax.swing.JRadioButton buttonTemperature;
+ private javax.swing.JRadioButton buttonZoom025;
+ private javax.swing.JRadioButton buttonZoom05;
+ private javax.swing.JRadioButton buttonZoomFit;
+ private javax.swing.JRadioButton buttonZoomNormal;
+ private javax.swing.JRadioButton buttonZoomStretch;
private javax.swing.JCheckBox checkCamtool;
private javax.swing.JComboBox comboCameras;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JPanel jPanel1;
+ private javax.swing.JPanel jPanel2;
+ private javax.swing.JPanel jPanel3;
private ch.psi.pshell.imaging.Renderer renderer;
+ private javax.swing.JSpinner spinnerMax;
+ private javax.swing.JSpinner spinnerMin;
private javax.swing.JTextField textState;
// End of variables declaration//GEN-END:variables
}
diff --git a/plugins/CamerasSimple.form b/plugins/CamerasSimple.form
new file mode 100644
index 0000000..28ac2d5
--- /dev/null
+++ b/plugins/CamerasSimple.form
@@ -0,0 +1,189 @@
+
+
+
diff --git a/plugins/CamerasSimple.java b/plugins/CamerasSimple.java
new file mode 100644
index 0000000..ff4b5a4
--- /dev/null
+++ b/plugins/CamerasSimple.java
@@ -0,0 +1,1062 @@
+/*
+ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
+ */
+
+import ch.psi.pshell.core.Controller;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Paths;
+import javax.swing.DefaultComboBoxModel;
+import ch.psi.pshell.ui.Panel;
+import ch.psi.pshell.imaging.ImageListener;
+import ch.psi.utils.State;
+import ch.psi.utils.IO;
+import ch.psi.utils.swing.SwingUtils;
+import ch.psi.utils.swing.TextEditor;
+import ch.psi.pshell.epics.PsiCamera;
+//import ch.psi.pshell.epics.Camtool;
+import ch.psi.pshell.core.JsonSerializer;
+import ch.psi.pshell.device.Device;
+import ch.psi.pshell.epics.ArraySource;
+import ch.psi.pshell.epics.ChannelDouble;
+import ch.psi.pshell.epics.ChannelDoubleArray;
+import ch.psi.pshell.epics.ChannelInteger;
+import ch.psi.pshell.epics.ChannelIntegerArray;
+import ch.psi.pshell.ui.App;
+import ch.psi.pshell.imaging.Data;
+import ch.psi.pshell.imaging.Overlay;
+import ch.psi.pshell.imaging.Overlays;
+import ch.psi.pshell.imaging.Overlays.Text;
+import ch.psi.pshell.imaging.Pen;
+import static ch.psi.pshell.imaging.Renderer.PEN_ERROR_TEXT;
+import ch.psi.pshell.imaging.Renderer.Profile;
+import static ch.psi.pshell.imaging.RendererMenu.PEN_MARKER;
+import ch.psi.pshell.imaging.Source;
+import ch.psi.pshell.imaging.Utils;
+import ch.psi.pshell.scripting.InterpreterResult;
+import ch.psi.pshell.scripting.ScriptManager;
+import ch.psi.utils.Arr;
+import ch.psi.utils.ArrayProperties;
+import ch.psi.utils.Convert;
+import ch.psi.utils.Str;
+import ch.psi.utils.swing.Editor.EditorDialog;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Point;
+import java.awt.image.BufferedImage;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.math3.analysis.function.Gaussian;
+import org.apache.commons.math3.fitting.GaussianCurveFitter;
+import org.apache.commons.math3.fitting.WeightedObservedPoint;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+/**
+ *
+ */
+public class CamerasSimple extends Panel {
+
+ public CamerasSimple() {
+ initComponents();
+ renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin"));
+ renderer.setProfileFactor(4);
+ setPersistedComponents(new Component[]{checkCamtool});
+ comboCameras.setEnabled(false);
+ if (App.hasArgument("poll")) {
+ try{
+ polling = Integer.valueOf(App.getArgumentValue("poll"));
+ } catch (Exception ex){
+ ex.printStackTrace();
+ }
+ }
+ if (App.hasArgument("zoom")) {
+ try{
+ renderer.setDefaultZoom(Double.valueOf(App.getArgumentValue("zoom")));
+ renderer.resetZoom();
+ } catch (Exception ex){
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ if (App.hasArgument("ct")) {
+ checkCamtool.setSelected(!App.getArgumentValue("ct").equals("0") && !App.getArgumentValue("ct").equalsIgnoreCase("false"));
+ }
+ }
+
+ final String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool";
+ File[] cameraConfigFiles = new File[0];
+ ArraySource camera;
+ String cameraName;
+ String cameraConfigJson;
+ CameraConfig config;
+ int polling = 1000;
+ Overlay marker = null;
+
+ //Overridable callbacks
+ @Override
+ public void onInitialize(int runCount) {
+ comboCameras.setEnabled(false);
+ if (App.hasArgument("s")){
+ renderer.setDevice((Source)getDevice("image"));
+ renderer.setAutoScroll(true);
+ ((Source)getDevice("image")).addListener(new ImageListener() {
+ @Override
+ public void onImage(Object o, BufferedImage bi, Data data) {
+ if (bi == null) {
+ fitOv = null;
+ } else {
+ Overlay[] profile = renderer.getProfileOverlays();
+ profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
+ renderer.updateOverlays(profile, fitOv);
+ fitOv = profile;
+ }
+ }
+ @Override
+ public void onError(Object o, Exception excptn) {
+ }
+ }
+ );
+
+ } 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);
+ }
+ }
+ comboCameras.setModel(model);
+ comboCameras.setEnabled(true);
+ comboCameras.setSelectedItem(-1);
+ if (model.getSize() > 0) {
+ try {
+ //setCamera((String)comboCameras.getSelectedItem());
+ if (App.hasArgument("cam")) {
+ comboCameras.setSelectedItem(App.getArgumentValue("cam"));
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ startTimer(1000);
+ }
+
+ @Override
+ public void onStateChange(State state, State former) {
+
+ }
+
+ @Override
+ public void onExecutedFile(String fileName, Object result) {
+ }
+
+ //Callback to perform update - in event thread
+ @Override
+ protected void doUpdate() {
+ }
+
+ public static class CameraConfig {
+
+ public HashMap kwargs;
+ public ArrayList args;
+ public ArrayList links;
+ public String type;
+ public HashMap state;
+ public CameraConfig image_source;
+ public HashMap subcomponents;
+
+ public ArrayList getCalibration() {
+ return (ArrayList) state.get("calibration");
+ }
+
+ public double getCalOffsetX(){
+ ArrayList calibration = getCalibration();
+ double ret = - (calibration.get(0) + calibration.get(2))/2;
+ return ret;
+ }
+
+ public double getCalOffsetY(){
+ ArrayList calibration = getCalibration();
+ double ret = - (calibration.get(1) + calibration.get(3))/2;
+ return ret;
+ }
+
+ public double getScaleX(){
+ ArrayList calibration = getCalibration();
+ double width = Math.abs( calibration.get(2) - calibration.get(0));
+ return getCalibrationWidth()/width;
+ //return getCalibrationWidth()/1000;
+ }
+
+ public double getScaleY(){
+ ArrayList calibration = getCalibration();
+ double height = Math.abs( calibration.get(3) - calibration.get(1));
+ return getCalibrationHeight()/height;
+ }
+
+
+ public Double getCalibrationHeight() {
+ return (Double) state.get("calibration_height");
+ }
+
+ public Double getCalibrationWidth() {
+ return (Double) state.get("calibration_width");
+ }
+
+ public Double getCalibrationHorizontalAngle() {
+ return (Double) state.get("calibration_horizontal_angle");
+ }
+
+ public Double getCalibrationVerticalAngle() {
+ return (Double) state.get("calibration_vertical_angle");
+ }
+
+ public Boolean getMirrorX() {
+ return (Boolean) state.get("mirror_x");
+ }
+
+ public Boolean getMirrorY() {
+ return (Boolean) state.get("mirror_y");
+ }
+
+ public Integer getRotate() {
+ return (Integer) state.get("rotate");
+ }
+
+ public ArrayList getOrigin() {
+ return (ArrayList) state.get("origin");
+ }
+
+ public ArrayList getRoi() {
+ return (ArrayList) state.get("roi");
+ }
+
+ public Boolean getRoiEnable() {
+ if ((state.get("roi_enable") == null) || (state.get("roi") == null)) {
+ return false;
+ }
+ return (Boolean) state.get("roi_enable");
+ }
+
+ public ArrayList getUnitSize() {
+ return (ArrayList) state.get("unit_size");
+ }
+
+ public Integer getRun() {
+ return (Integer) state.get("run");
+ }
+ }
+
+ Overlay[] fitOv;
+
+ void setCamera(String cameraName) throws IOException, InterruptedException {
+ System.out.println("Setting camera: " + cameraName);
+ if (camera != null) {
+ camera.close();
+ camera = null;
+ renderer.setDevice(null);
+ renderer.setShowReticle(false);
+ renderer.removeOverlays(fitOv);
+ renderer.clear();
+ renderer.resetZoom();
+ }
+ try {
+ Path configFile = Paths.get(configFolder, cameraName + ".json");
+ cameraConfigJson = new String(Files.readAllBytes(configFile));
+ this.cameraName = cameraName;
+ //SwingUtils.showMessage(null, "", json);
+ try {
+ if (checkCamtool.isSelected()) {
+ camera = new Camtool("CurrentCamera", cameraName, false);
+ camera.getConfig().flipHorizontally = false;
+ camera.getConfig().flipVertically = false;
+ camera.getConfig().rotation = 0.0;
+ camera.getConfig().roiX = 0;
+ camera.getConfig().roiY = 0;
+ camera.getConfig().roiWidth = -1;
+ camera.getConfig().roiHeight = -1;
+ } else {
+ camera = new PsiCamera("CurrentCamera", cameraName);
+ config = (CameraConfig) JsonSerializer.decode(cameraConfigJson, CameraConfig.class);
+ camera.getConfig().flipHorizontally = config.getMirrorX();
+ camera.getConfig().flipVertically = config.getMirrorY();
+ camera.getConfig().rotation = config.getRotate();
+ camera.getConfig().rotationCrop = true;
+ camera.getConfig().roiX = config.getRoiEnable() ? config.getRoi().get(0) : 0;
+ camera.getConfig().roiY = config.getRoiEnable() ? config.getRoi().get(1) : 0;
+ camera.getConfig().roiWidth = config.getRoiEnable() ? config.getRoi().get(2) : -1;
+ camera.getConfig().roiHeight = config.getRoiEnable() ? config.getRoi().get(3) : -1;
+ try{
+ camera.getConfig().spatialCalOffsetX = config.getCalOffsetX();
+ camera.getConfig().spatialCalOffsetY = config.getCalOffsetY();
+ camera.getConfig().spatialCalScaleX = config.getScaleX();
+ camera.getConfig().spatialCalScaleY = config.getScaleY();
+ } catch (Exception ex){
+ camera.getConfig().spatialCalOffsetX = Double.NaN;
+ camera.getConfig().spatialCalOffsetY = Double.NaN;
+ camera.getConfig().spatialCalScaleX = Double.NaN;
+ camera.getConfig().spatialCalScaleY = Double.NaN;
+ }
+ }
+ } catch (Exception ex) {
+ config = null;
+ showException(ex);
+ }
+ camera.initialize();
+ if (camera instanceof Camtool){
+ try{
+ camera.getConfig().spatialCalOffsetX = ((Camtool)camera).calOffX.read();
+ camera.getConfig().spatialCalOffsetY = ((Camtool)camera).calOffY.read();
+ camera.getConfig().spatialCalScaleX = ((Camtool)camera).calScaleX.read();
+ camera.getConfig().spatialCalScaleY = ((Camtool)camera).calScaleY.read();
+ } catch (Exception ex){
+ ex.printStackTrace();
+ camera.getConfig().spatialCalOffsetX = 0.0;
+ camera.getConfig().spatialCalOffsetY = 0.0;
+ camera.getConfig().spatialCalScaleX = 1.0;
+ camera.getConfig().spatialCalScaleY = 1.0;
+ }
+ /*
+ double[] origin = ((Camtool)camera).origin.read();
+ if (origin.length>=2){
+ camera.getConfig().spatialCalOffsetX = origin[0];
+ camera.getConfig().spatialCalOffsetY = origin[1];
+ }
+ */
+ }
+ buttonReticle.setEnabled(camera.getConfig().isCalibrated());
+ buttonGrabBackground.setEnabled(camera instanceof Camtool);
+ camera.getConfig().save();
+
+ if (polling<=0){
+ camera.setMonitored(true);
+ } else {
+ camera.setPolling(-polling);
+ }
+ renderer.setDevice(camera);
+ renderer.setAutoScroll(true);
+ renderer.setMarker(marker);
+
+ camera.addListener(new ImageListener() {
+ @Override
+ public void onImage(Object o, BufferedImage bi, Data data) {
+ if (bi == null) {
+ renderer.removeOverlays(fitOv);
+ fitOv = null;
+ } else {
+ //System.out.println(bi.getWidth() + " - " + bi.getHeight());
+ if (!renderer.isPaused() && buttonFit.isSelected()){
+ Overlay[] profile = renderer.getProfileOverlays();
+ profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
+ renderer.updateOverlays(profile, fitOv);
+ fitOv = profile;
+ }
+ }
+ }
+
+ @Override
+ public void onError(Object o, Exception excptn) {
+ }
+ });
+ } catch (Exception ex) {
+ if (renderer.getDevice()==null){
+ renderer.setZoom(1.0);
+ renderer.addOverlay(new Text(PEN_ERROR_TEXT, ex.toString(), new Font("Verdana", Font.PLAIN, 12), new Point(20, 20)));
+ }
+ } finally {
+ checkReticle();
+ onTimer();
+ }
+ }
+
+ void checkReticle(){
+ if ((renderer.getDevice()!=null) && (camera!=null) && (camera.getConfig().isCalibrated()) && buttonReticle.isSelected()){
+ renderer.setCalibration(camera.getCalibration());
+ renderer.configureReticle(new Dimension(800,800), 200);
+ renderer.setShowReticle(true);
+ } else {
+ renderer.setShowReticle(false);
+ }
+ renderer.refresh();
+ }
+
+ @Override
+ protected void onTimer() {
+ textState.setText((camera == null) ? "" : camera.getState().toString());
+ buttonConfig.setEnabled(camera != null);
+ if (App.hasArgument("s")){
+ try {
+ ((Source)getDevice("image")).initialize();
+ } catch (IOException ex) {
+ Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+
+ Pen fitPen = new Pen(new Color(192, 105, 0), 1);
+ Pen crossPen = new Pen(new Color(192, 105, 0), 1);
+ Overlay[] getFitOverlays(BufferedImage img){
+ Overlays.Polyline hpoly = null;
+ Overlays.Polyline vpoly = null;
+ Double xMean = null; Double xSigma = null;
+ Double yMean = null; Double ySigma = null;
+ Profile profile = renderer.getProfile();
+ if ((profile != Profile.None) && (img != null)) {
+ img = Utils.grayscale(img);
+ if (profile.hasVertical()) {
+ try {
+ double[] sum = (double[]) Convert.toDouble(Utils.integrateVertically(img));
+ int[] x = Arr.indexesInt(sum.length);
+ DescriptiveStatistics stats = new DescriptiveStatistics(sum);
+ double min = stats.getMin();
+ for (int i=0; i< sum.length; i++){
+ sum[i] = sum[i] - min;
+ }
+ double[] gaussian = fitGaussian(sum, x);
+ if (gaussian!=null){
+// System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]+ " Min: " + min);
+ //Only aknowledge beam fully inside the image and peak over 3% of min
+ if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
+ xMean = gaussian[1];
+ xSigma = gaussian[2];
+ gaussian[0]+=min;
+ double[] fit = getFitFunction(gaussian, x);
+ int[] y = new int[x.length];
+ for (int i = 0; i < x.length; i++) {
+ y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / renderer.getProfileFactor()));
+ }
+ vpoly = new Overlays.Polyline(fitPen, x, y);
+ }
+ } else {
+ //System.out.println("Fit failure");
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ if (profile.hasHorizontal()) {
+ try {
+ double[] sum = (double[]) Convert.toDouble(Utils.integrateHorizontally(img));
+ int[] x = Arr.indexesInt(sum.length);
+ DescriptiveStatistics stats = new DescriptiveStatistics(sum);
+ double min = stats.getMin();
+ for (int i=0; i< sum.length; i++){
+ sum[i] = sum[i] - min;
+ }
+ double[] gaussian = fitGaussian(sum, x);
+ if (gaussian!=null){
+ //Only aknowledge beam fully inside the image and peak over 3% of min
+ if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
+ yMean = gaussian[1];
+ ySigma = gaussian[2];
+ gaussian[0]+=min;
+ double[] fit = getFitFunction(gaussian, x);
+
+ int[] y = new int[x.length];
+ for (int i = 0; i < x.length; i++) {
+ y[i] = (int) (((double) fit[i]) / 255 / renderer.getProfileFactor());
+ }
+ hpoly = new Overlays.Polyline(fitPen, y, x);
+ }
+ }
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ Overlays.Crosshairs cross= null;
+ if ((xMean!=null) && (yMean!=null)){
+ cross = new Overlays.Crosshairs(crossPen,
+ new Point(xMean.intValue(), yMean.intValue()),
+ new Dimension(2*xSigma.intValue(),2*ySigma.intValue()));
+ }
+ return new Overlay[]{hpoly, vpoly, cross};
+ }
+ return null;
+ }
+
+
+double[] fitGaussianScript(int[] y, int[] x){
+ ScriptManager sm = Controller.getInstance().getScriptManager();
+ ArrayProperties pY = ArrayProperties.get(y);
+ sm.setVar("y", y);
+ sm.setVar("x", x);
+ InterpreterResult r = sm.eval("r = fit_gaussians(y, x, [" + pY.maxIndex+ ",])");
+ if (r.exception != null){
+ r.exception .printStackTrace();
+ } else {
+ List ret = (List) sm.getVar("r");
+ if ((ret!=null) && (ret.size()==1)&& (ret.get(0) instanceof List) && (((List)(ret.get(0))).size()==3)){
+ double norm = (Double) ((List)ret.get(0)).get(0);
+ double mean = (Double) ((List)ret.get(0)).get(1);
+ double sigma = (Double) ((List)ret.get(0)).get(2);
+ return new double[]{norm, mean, sigma};
+ }
+ }
+ return null;
+ }
+
+double[]fitGaussian(double[] y, int[] x){
+ try{
+ ArrayProperties pY = ArrayProperties.get(y);
+ GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max-pY.min)/2,x[pY.maxIndex],1.0}).withMaxIterations(1000);
+ ArrayListvalues = new ArrayList<>();
+ for (int i=0; i< y.length; i++){
+ values.add(new WeightedObservedPoint(1.0, x[i], y[i]));
+ }
+ return fitter.fit(values);
+ } catch (Exception ex){
+ return null;
+ }
+
+ }
+
+
+
+ double[] getFitFunction(double[] pars, int[] x){
+ double[] fit = new double[x.length];
+ Gaussian g = new Gaussian(pars[0], pars[1], pars[2]);
+ for (int i=0; i< x.length; i++){
+ fit[i] = g.value(x[i]);
+ }
+ return fit;
+ }
+
+public class Camtool extends ArraySource {
+
+ final String prefix;
+ final String dataPrefix;
+ final boolean latch;
+
+ final public ChannelInteger channelRun;
+ final public ChannelInteger channelLatch;
+ final public ChannelDouble channelTimestamp;
+ final public ChannelDoubleArray origin;
+ final public ChannelDouble posX, posY;
+ final public ChannelDoubleArray profileX, profileY;
+ final public ChannelIntegerArray shape;
+ final public ChannelInteger roiEnabled;
+ final public ChannelIntegerArray roiShape;
+ final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain;
+ final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY;
+
+ public Camtool(String name, String prefix) {
+ this(name, prefix, false);
+ }
+
+ public Camtool(String name, String prefix, boolean latch) {
+ //super(name, prefix + (latch ? ":latch" : ":pipeline") + (roi ? ".roi.output" : ".image"));
+ super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output");
+ this.prefix = prefix + ":";
+ this.latch = latch;
+ dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + ".";
+
+ channelRun = new ChannelInteger(name + " run", this.prefix + "camera.run");
+ channelLatch = new ChannelInteger(name + " latch", this.prefix + "latch.capture");
+ channelTimestamp = new ChannelDouble(name + " timestamp", dataPrefix + "timestamp");
+ channelTimestamp.setMonitored(true);
+ //posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com");
+ //posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com");
+ posX = new ChannelDouble(name + " com x", dataPrefix + "x_stats.com_egu");
+ posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu");
+ profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x");
+ profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y");
+ //shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape" : "image.shape"));
+ shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("image.shape"));
+ roiShape = new ChannelIntegerArray(name + " roi shape", dataPrefix + "roi.roi");
+ roiEnabled = new ChannelInteger(name + " roi enabled", dataPrefix + "roi.enabled");
+ //origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin"));
+ origin = new ChannelDoubleArray(name + " origin X", dataPrefix + "roi.origin_out");
+ bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled");
+ bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture");
+ bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain");
+ calOffX = new ChannelDouble(name + " cal off x", this.prefix + "pipeline.egu.eoff_x");
+ calOffY = new ChannelDouble(name + " cal off y", this.prefix + "pipeline.egu.eoff_y");
+ calScaleX = new ChannelDouble(name + " cal scale x", this.prefix + "pipeline.egu.eslo_x");
+ calScaleY = new ChannelDouble(name + " cal scale y", this.prefix + "pipeline.egu.eslo_y");
+ }
+
+ @Override
+ public void doSetMonitored(boolean value) {
+ super.doSetMonitored(value);
+ getDevice().setMonitored(value);
+ }
+
+ @Override
+ public void doUpdate() throws IOException, InterruptedException {
+ super.doUpdate();
+ getDevice().update();
+ }
+
+ void safeInitialize(Device dev, int timeout) throws IOException, InterruptedException {
+ for (int retries = 0; retries < 10; retries++) {
+ try {
+ dev.initialize();
+ break;
+ } catch (IOException ex) {
+ if (retries == 9) {
+ throw ex;
+ }
+ Thread.sleep(timeout / 10);
+ }
+ }
+ }
+
+
+ @Override
+ protected void doInitialize() throws IOException, InterruptedException {
+ try {
+ channelRun.initialize();
+ channelLatch.initialize();
+ if (latch) {
+ start();
+ latch();
+ }
+ safeInitialize(channelTimestamp, 2000);
+ posX.initialize();
+ posY.initialize();
+ profileX.initialize();
+ profileY.initialize();
+ shape.initialize();
+ roiShape.initialize();
+ roiEnabled.initialize();
+ origin.initialize();
+ bgEnable.initialize();
+ bgCapture.initialize();
+ bgCaptureRemain.initialize();
+ try {
+ calOffX.initialize();
+ calOffY.initialize();
+ calScaleX.initialize();
+ calScaleY.initialize();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ if (roiEnabled.read()>0){
+ int[] s = roiShape.read();
+ //for (int x : s) System.out.println(x);
+ getConfig().imageHeight = s[3];
+ getConfig().imageWidth = s[2];
+ } else {
+ int[] s = shape.read();
+ //for (int x : s){ System.out.println(x);}
+ getConfig().imageHeight = s[0];
+ getConfig().imageWidth = s[1];
+ }
+
+ getConfig().save();
+ getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth);
+ super.doInitialize();
+ //System.out.println(((int[])(getDevice().read())).length);
+ } catch (InterruptedException ex) {
+ throw ex;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new IOException(ex);
+ }
+ }
+
+ int numImages = 1;
+
+ public int getNumImages() {
+ return numImages;
+ }
+
+ public void setNumImages(int value) {
+ numImages = value;
+ }
+
+ double grabTimeout = 3.0;
+
+ public double getGrabTimeout() {
+ return grabTimeout;
+ }
+
+ public void setGrabTimeou(double value) {
+ grabTimeout = value;
+ }
+
+ public void capture() throws IOException, InterruptedException {
+ int retries = 3;
+ while (true) {
+ try {
+ double timestamp = channelTimestamp.read();
+ if (latch) {
+ channelLatch.write(1);
+ } else {
+ channelRun.write(1);
+ }
+ long start = System.currentTimeMillis();
+ while (true) {
+ double val = channelTimestamp.read();
+ if (timestamp != val) {
+ return;
+ }
+ if ((System.currentTimeMillis() - start) > grabTimeout) {
+ throw new IOException("Frame timeout");
+ }
+ Thread.sleep(5);
+ }
+ } catch (IOException ex) {
+ retries--;
+ if (--retries <= 0) {
+ throw ex;
+ }
+ }
+ }
+ }
+
+ public void start() throws IOException, InterruptedException {
+ channelRun.write(-1);
+ }
+
+ public void stop() throws IOException, InterruptedException {
+ channelRun.write(0);
+ }
+
+ public void grabSingle() throws IOException, InterruptedException {
+ channelRun.write(1);
+ }
+
+ public void latch() throws IOException, InterruptedException {
+ channelLatch.write(1);
+ }
+
+ public void enableBackground(boolean value) throws IOException, InterruptedException {
+ bgEnable.write(value ? 1 : 0);
+ }
+
+ public void captureBackground(int images) throws IOException, InterruptedException {
+ start();
+ bgCapture.write(images);
+ Thread.sleep(200);
+ while (bgCaptureRemain.read() > 0) {
+ Thread.sleep(10);
+ }
+ }
+
+}
+
+
+ ////////
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ renderer = new ch.psi.pshell.imaging.Renderer();
+ jLabel1 = new javax.swing.JLabel();
+ comboCameras = new javax.swing.JComboBox();
+ jLabel2 = new javax.swing.JLabel();
+ textState = new javax.swing.JTextField();
+ buttonConfig = new javax.swing.JButton();
+ buttonSetup = new javax.swing.JButton();
+ checkCamtool = new javax.swing.JCheckBox();
+ buttonFit = new javax.swing.JToggleButton();
+ buttonPause = new javax.swing.JToggleButton();
+ buttonMarker = new javax.swing.JToggleButton();
+ buttonSave = new javax.swing.JToggleButton();
+ buttonReticle = new javax.swing.JToggleButton();
+ buttonGrabBackground = new javax.swing.JButton();
+
+ jLabel1.setText("Camera:");
+
+ comboCameras.setMaximumRowCount(30);
+ comboCameras.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ comboCamerasActionPerformed(evt);
+ }
+ });
+
+ jLabel2.setText("State:");
+
+ textState.setEditable(false);
+ textState.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+ textState.setDisabledTextColor(new java.awt.Color(0, 0, 0));
+ textState.setEnabled(false);
+
+ buttonConfig.setText("Config");
+ buttonConfig.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonConfigActionPerformed(evt);
+ }
+ });
+
+ buttonSetup.setText("Setup");
+ buttonSetup.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonSetupActionPerformed(evt);
+ }
+ });
+
+ checkCamtool.setSelected(true);
+ checkCamtool.setText("Camtool");
+
+ buttonFit.setSelected(true);
+ buttonFit.setText("Fit");
+ buttonFit.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonFitActionPerformed(evt);
+ }
+ });
+
+ buttonPause.setText("Pause");
+ buttonPause.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonPauseActionPerformed(evt);
+ }
+ });
+
+ buttonMarker.setText("Marker");
+ buttonMarker.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonMarkerActionPerformed(evt);
+ }
+ });
+
+ buttonSave.setText("Save Snapshot");
+ buttonSave.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonSaveActionPerformed(evt);
+ }
+ });
+
+ buttonReticle.setSelected(true);
+ buttonReticle.setText("Reticle");
+ buttonReticle.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonReticleActionPerformed(evt);
+ }
+ });
+
+ buttonGrabBackground.setText("Grab Background");
+ buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonGrabBackgroundActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(renderer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(checkCamtool)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jLabel1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(comboCameras, 0, 170, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonConfig)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonSetup)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jLabel2)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(buttonPause)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonMarker)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonFit)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonReticle)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(buttonGrabBackground)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonSave)))
+ .addContainerGap())
+ );
+
+ layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup});
+
+ layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
+
+ layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
+
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel1)
+ .addComponent(comboCameras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel2)
+ .addComponent(textState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(buttonConfig)
+ .addComponent(buttonSetup)
+ .addComponent(checkCamtool))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
+ .addGap(12, 12, 12)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(buttonPause)
+ .addComponent(buttonFit)
+ .addComponent(buttonMarker)
+ .addComponent(buttonSave)
+ .addComponent(buttonReticle)
+ .addComponent(buttonGrabBackground))
+ .addContainerGap())
+ );
+
+ layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
+
+ }// //GEN-END:initComponents
+
+ private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
+ try {
+ comboCameras.setEnabled(false);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try{
+ setCamera((String) comboCameras.getSelectedItem());
+ } catch(Exception ex){
+ ex.printStackTrace();
+ } finally{
+ comboCameras.setEnabled(true);
+ }
+ }
+ }).start();
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_comboCamerasActionPerformed
+
+ private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed
+ try {
+ if (camera != null) {
+ TextEditor editor = new TextEditor();
+ editor.setText(cameraConfigJson);
+ editor.setReadOnly(true);
+ editor.setTitle(cameraName);
+ EditorDialog dlg = editor.getDialog(getTopLevel(), false);
+ dlg.setSize(480, 640);
+ dlg.setVisible(true);
+ SwingUtils.centerComponent(this, dlg);
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonConfigActionPerformed
+
+ private void buttonSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSetupActionPerformed
+ try {
+ if (camera != null) {
+ this.showDeviceConfigDialog(camera, false);
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonSetupActionPerformed
+
+ private void buttonPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPauseActionPerformed
+ try {
+ if (camera != null) {
+ if (buttonPause.isSelected()){
+ renderer.pause();
+ } else {
+ renderer.resume();
+ }
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonPauseActionPerformed
+
+ private void buttonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMarkerActionPerformed
+ try {
+ if (camera != null) {
+ if (buttonMarker.isSelected()){
+ Dimension d = renderer.getImageSize();
+ Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2);
+ Overlay ov = null;
+ marker = new Overlays.Crosshairs(PEN_MARKER, p, new Dimension(100, 100));
+ marker.setMovable(true);
+ } else {
+ marker = null;
+ }
+ renderer.setMarker(marker);
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonMarkerActionPerformed
+
+ private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed
+ try {
+ renderer.setProfile(buttonFit.isSelected() ? Profile.Both :Profile.None);
+ if (!buttonFit.isSelected()){
+ renderer.removeOverlays(fitOv);
+ fitOv = null;
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonFitActionPerformed
+
+ private void buttonReticleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReticleActionPerformed
+ try {
+ checkReticle();
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonReticleActionPerformed
+
+ private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
+ try {
+ renderer.setSnapshotDialogVisible(buttonSave.isSelected());
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonSaveActionPerformed
+
+ private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed
+ try {
+ if (camera instanceof Camtool){
+ ((Camtool)camera).captureBackground(5);
+ }
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonGrabBackgroundActionPerformed
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton buttonConfig;
+ private javax.swing.JToggleButton buttonFit;
+ private javax.swing.JButton buttonGrabBackground;
+ private javax.swing.JToggleButton buttonMarker;
+ private javax.swing.JToggleButton buttonPause;
+ private javax.swing.JToggleButton buttonReticle;
+ private javax.swing.JToggleButton buttonSave;
+ private javax.swing.JButton buttonSetup;
+ private javax.swing.JCheckBox checkCamtool;
+ private javax.swing.JComboBox comboCameras;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private ch.psi.pshell.imaging.Renderer renderer;
+ private javax.swing.JTextField textState;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/plugins/Camtool.java b/plugins/Camtool.java
index 89839c8..2347ade 100644
--- a/plugins/Camtool.java
+++ b/plugins/Camtool.java
@@ -18,12 +18,14 @@ public class Camtool extends ArraySource {
final boolean latch;
final public ChannelInteger channelRun;
- final public ChannelInteger channelLatch;
+ final public ChannelInteger channelLatch;
final public ChannelDouble channelTimestamp;
final public ChannelDoubleArray origin;
final public ChannelDouble posX, posY;
final public ChannelDoubleArray profileX, profileY;
final public ChannelIntegerArray shape;
+ final public ChannelInteger roiEnabled;
+ final public ChannelIntegerArray roiShape;
final public ChannelInteger bgEnable, bgCapture, bgCaptureRemain;
final public ChannelDouble calOffX, calOffY, calScaleX, calScaleY;
final public CamToolPosX posMeanX;
@@ -32,11 +34,12 @@ public class Camtool extends ArraySource {
final public CamToolVarY posVarY;
public Camtool(String name, String prefix) {
- this(name, prefix, false, true);
+ this(name, prefix, false);
}
- public Camtool(String name, String prefix, boolean latch, boolean roi) {
- super(name, prefix + (latch ? ":latch" : ":pipeline") + (roi ? ".roi.output" : ".image"));
+ public Camtool(String name, String prefix, boolean latch) {
+ //super(name, prefix + (latch ? ":latch" : ":pipeline") + (roi ? ".roi.output" : ".image"));
+ super(name, prefix + (latch ? ":latch" : ":pipeline") + ".roi.output");
this.prefix = prefix + ":";
this.latch = latch;
dataPrefix = this.prefix + (latch ? "latch" : "pipeline") + ".";
@@ -51,8 +54,12 @@ public class Camtool extends ArraySource {
posY = new ChannelDouble(name + " com y", dataPrefix + "y_stats.com_egu");
profileX = new ChannelDoubleArray(name + " profile x", dataPrefix + "profile.x");
profileY = new ChannelDoubleArray(name + " profile y", dataPrefix + "profile.y");
- shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape" : "image.shape"));
- origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin"));
+ //shape = new ChannelIntegerArray(name + " shape", dataPrefix + (roi ? "roi.output.shape" : "image.shape"));
+ shape = new ChannelIntegerArray(name + " shape", dataPrefix + ("image.shape"));
+ roiShape = new ChannelIntegerArray(name + " roi shape", dataPrefix + "roi.roi");
+ roiEnabled = new ChannelInteger(name + " roi enabled", dataPrefix + "roi.enabled");
+ //origin = new ChannelDoubleArray(name + " origin X", roi ? (dataPrefix + "roi.origin_out") : (prefix + "origin"));
+ origin = new ChannelDoubleArray(name + " origin X", dataPrefix + "roi.origin_out");
bgEnable = new ChannelInteger(name + " bg enable", this.prefix + "pipeline.bg.enabled");
bgCapture = new ChannelInteger(name + " bg capture", this.prefix + "pipeline.bg.capture");
bgCaptureRemain = new ChannelInteger(name + " bg capture remain", this.prefix + "pipeline.bg.capture_remain");
@@ -92,11 +99,12 @@ public class Camtool extends ArraySource {
}
}
}
+
@Override
protected void doInitialize() throws IOException, InterruptedException {
try {
- safeInitialize(channelRun, 3000);
+ channelRun.initialize();
channelLatch.initialize();
if (latch) {
start();
@@ -108,6 +116,8 @@ public class Camtool extends ArraySource {
profileX.initialize();
profileY.initialize();
shape.initialize();
+ roiShape.initialize();
+ roiEnabled.initialize();
origin.initialize();
bgEnable.initialize();
bgCapture.initialize();
@@ -120,13 +130,23 @@ public class Camtool extends ArraySource {
} catch (Exception ex) {
ex.printStackTrace();
}
-
- int[] s = shape.read();
- getConfig().imageHeight = s[0];
- getConfig().imageWidth = s[1];
+
+ if (roiEnabled.read()>0){
+ int[] s = roiShape.read();
+ //for (int x : s) System.out.println(x);
+ getConfig().imageHeight = s[3];
+ getConfig().imageWidth = s[2];
+ } else {
+ int[] s = shape.read();
+ //for (int x : s){ System.out.println(x);}
+ getConfig().imageHeight = s[0];
+ getConfig().imageWidth = s[1];
+ }
+
getConfig().save();
- getDevice().setSize(s[0] * s[1]);
- super.doInitialize();
+ getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth);
+ super.doInitialize();
+ //System.out.println(((int[])(getDevice().read())).length);
} catch (InterruptedException ex) {
throw ex;
} catch (Exception ex) {