This commit is contained in:
sfop
2016-08-26 15:33:23 +02:00
parent 3c4df207ff
commit 1a5be5de4f
15 changed files with 534 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
Cameras.java=enabled
LaserGunAlignment.java=disabled
test2.java=disabled
GunSolenoidAlignment.java=enabled
GunSolenoidAlignment.java=disabled
test.java=disabled

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:07:24 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:07:30 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=0.0
spatialCalOffsetY=0.0
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:07:27 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:08:31 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 12:30:16 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 12:52:45 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:09:04 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 12:53:52 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 12:52:53 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -0,0 +1,26 @@
#Fri Aug 26 13:08:36 CEST 2016
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=0
imageWidth=0
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=0.0
spatialCalOffsetY=0.0
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -1,4 +1,4 @@
#Fri Aug 26 10:58:13 CEST 2016
#Fri Aug 26 15:33:18 CEST 2016
colormap=Grayscale
colormapAutomatic=true
colormapMax=30000.0
@@ -6,8 +6,8 @@ colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=2160
imageWidth=2560
imageHeight=1628
imageWidth=1280
invert=false
offsetX=0.0
offsetY=0.0

View File

@@ -1,4 +1,4 @@
#Fri Aug 26 10:58:28 CEST 2016
#Fri Aug 26 15:33:18 CEST 2016
colormap=Grayscale
colormapAutomatic=true
colormapMax=255.0
@@ -6,8 +6,8 @@ colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=2160
imageWidth=2560
imageHeight=1680
imageWidth=1744
invert=false
offsetX=0.0
offsetY=0.0

View File

@@ -16,13 +16,68 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="449" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="renderer" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="comboCameras" pref="348" max="32767" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
<Component id="textState" pref="131" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="137" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="comboCameras" linkSize="2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="textState" linkSize="2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" min="-2" max="-2" attributes="0"/>
<Component id="renderer" pref="342" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="ch.psi.pshell.imaging.Renderer" name="renderer">
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Camera:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboCameras">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="comboCamerasActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="State:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="textState">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="disabledTextColor" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@@ -2,8 +2,24 @@
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
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.pshell.epics.PsiCamera;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.imaging.Data;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
/**
*
@@ -13,11 +29,31 @@ public class Cameras extends Panel {
public Cameras() {
initComponents();
}
final String configFolder= "/afs/psi.ch/intranet/SF/Applications/config/camtool";
File[] cameraConfigFiles = new File[0];
PsiCamera camera;
CameraConfig config;
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"});
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (File file:cameraConfigFiles) {
String prefix = IO.getPrefix(file);
if (!prefix.startsWith("#")){
model.addElement(prefix);
}
}
comboCameras.setModel(model);
if (model.getSize()>0){
try {
setCamera((String)comboCameras.getSelectedItem());
} catch (Exception ex) {
}
}
startTimer(1000);
}
@Override
@@ -35,22 +71,193 @@ public class Cameras extends Panel {
protected void doUpdate() {
}
public static class CameraConfig{
public HashMap kwargs;
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(){
return (ArrayList<Integer>) state.get("calibration");
}
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<Integer> getOrigin(){
return (ArrayList<Integer>) state.get("origin");
}
public ArrayList<Integer> getRoi(){
return (ArrayList<Integer>) 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<Double> getUnitSize(){
return (ArrayList<Double>) state.get("unit_size");
}
public Integer getRun(){
return (Integer) state.get("run");
}
}
void setCamera(String cameraName) throws IOException, InterruptedException{
if (camera!=null){
camera.close();
camera = null;
}
try{
Path configFile= Paths.get(configFolder, cameraName + ".json");
String json = new String(Files.readAllBytes(configFile));
//SwingUtils.showMessage(null, "", json);
camera = new PsiCamera(cameraName, cameraName);
try{
config = (CameraConfig) JsonSerializer.decode(json, 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;
camera.getConfig().spatialCalOffsetX = (config.getOrigin()!=null) ? config.getOrigin().get(0) : Double.NaN;
camera.getConfig().spatialCalOffsetY = (config.getOrigin()!=null) ? config.getOrigin().get(1) : Double.NaN;
camera.getConfig().spatialCalScaleX = (config.getUnitSize()!=null) && (config.getOrigin().get(0)!=0) ? 1.0/(config.getOrigin().get(0)*1000) : Double.NaN;
camera.getConfig().spatialCalScaleY= (config.getUnitSize()!=null) && (config.getOrigin().get(1)!=0) ? 1.0/(config.getOrigin().get(1)*1000) : Double.NaN;
} catch (Exception ex){
config = null;
showException(ex);
}
camera.getConfig().save();
camera.addListener(renderer);
camera.addListener(new ImageListener() {
@Override
public void onImage(Object o, BufferedImage bi, Data data) {
if ((renderer.getReticle()!=null) && (bi!=null)){
renderer.getReticle().setSize(new Dimension(bi.getWidth(), bi.getHeight()));
}
camera.removeListener(this);
}
@Override
public void onError(Object o, Exception excptn) {
}
});
renderer.setShowReticle(true);
camera.initialize();
} finally{
onTimer();
}
}
@Override
protected void onTimer() {
textState.setText((camera==null) ? "" : camera.getState().toString());
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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();
jLabel1.setText("Camera:");
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);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 449, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboCameras, 0, 348, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addGap(4, 4, 4)
.addComponent(textState, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)))
.addGap(26, 26, 26))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 137, Short.MAX_VALUE)
.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))
.addGap(18, 18, 18)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
.addGap(6, 6, 6))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
}// </editor-fold>//GEN-END:initComponents
private void comboCamerasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCamerasActionPerformed
try{
String camera = (String) comboCameras.getSelectedItem();
setCamera(camera);
} catch(Exception ex){
showException(ex);
}
}//GEN-LAST:event_comboCamerasActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
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
}