Startup
This commit is contained in:
@@ -15,20 +15,29 @@ import javax.swing.DefaultComboBoxModel;
|
||||
|
||||
public class SfCamera extends PsiCamera{
|
||||
|
||||
final static String CONFIG_FOLDER = "/afs/psi.ch/intranet/SF/Applications/config/camtool_n";
|
||||
static String configFolder = "/afs/psi.ch/intranet/SF/Applications/config/camtool_n";
|
||||
|
||||
public static DefaultComboBoxModel getCameras() {
|
||||
public static String getConfigFolder() {
|
||||
return configFolder;
|
||||
}
|
||||
|
||||
public static void setConfigFolder(String value) {
|
||||
configFolder = value;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getCameras() {
|
||||
ArrayList<String> ret = new ArrayList<>();
|
||||
File[] cameraConfigFiles = new File[0];
|
||||
cameraConfigFiles = IO.listFiles(CONFIG_FOLDER, new String[]{"json"});
|
||||
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("#") && !prefix.endsWith("_parameters")) {
|
||||
model.addElement(prefix);
|
||||
ret.add(prefix);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static class CameraConfig {
|
||||
@@ -67,12 +76,14 @@ public class SfCamera extends PsiCamera{
|
||||
return getCalibrationHeight() / height;
|
||||
}
|
||||
|
||||
public Double getCalibrationHeight() {
|
||||
return (Double) getCalibration().get("reference_marker_height");
|
||||
public Double getCalibrationHeight() {
|
||||
Double ret = (Double) getCalibration().get("reference_marker_height");
|
||||
return (ret == null) ? 100.0 : ret;
|
||||
}
|
||||
|
||||
public Double getCalibrationWidth() {
|
||||
return (Double) getCalibration().get("reference_marker_width");
|
||||
Double ret = (Double) getCalibration().get("reference_marker_width");
|
||||
return (ret == null) ? 100.0 : ret;
|
||||
}
|
||||
|
||||
public Double getCalibrationHorizontalAngle() {
|
||||
@@ -142,21 +153,39 @@ public class SfCamera extends PsiCamera{
|
||||
}
|
||||
|
||||
|
||||
public final CameraConfig cameraConfig;
|
||||
public final String cameraJson;
|
||||
CameraConfig setup;
|
||||
String json;
|
||||
public final String prefix;
|
||||
|
||||
public SfCamera(String name, String prefix) throws Exception {
|
||||
public SfCamera(String name, String prefix) {
|
||||
super(name, prefix);
|
||||
Path configFile = Paths.get(CONFIG_FOLDER, prefix + ".json");
|
||||
cameraJson = configFile.toFile().exists() ? new String(Files.readAllBytes(configFile)) : null;
|
||||
cameraConfig = (CameraConfig) JsonSerializer.decode(cameraJson, CameraConfig.class);
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getJson(){
|
||||
return json;
|
||||
}
|
||||
|
||||
public CameraConfig getSetup(){
|
||||
return setup;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInitialize() throws IOException, InterruptedException{
|
||||
super.doInitialize();
|
||||
Path configFile = Paths.get(configFolder, prefix + ".json");
|
||||
if (!configFile.toFile().exists()) {
|
||||
throw new IOException("Cannot open camera config file: " + configFile.toFile());
|
||||
}
|
||||
json = new String(Files.readAllBytes(configFile));
|
||||
setup = (CameraConfig) JsonSerializer.decode(json, CameraConfig.class);
|
||||
|
||||
CameraPars cameraPars = null;
|
||||
getConfig().roiX = 0; getConfig().roiY = 0;
|
||||
getConfig().roiWidth = -1; getConfig().roiHeight =-1;
|
||||
|
||||
try{
|
||||
Path parsFile = Paths.get(CONFIG_FOLDER, prefix + "_parameters.json");
|
||||
Path parsFile = Paths.get(configFolder, prefix + "_parameters.json");
|
||||
if (parsFile.toFile().exists()){
|
||||
String cameraParsJson = new String(Files.readAllBytes(parsFile));
|
||||
cameraPars = (CameraPars) JsonSerializer.decode(cameraParsJson, CameraPars.class);
|
||||
@@ -172,11 +201,11 @@ public class SfCamera extends PsiCamera{
|
||||
getLogger().log(Level.WARNING, null, ex);
|
||||
}
|
||||
|
||||
getConfig().flipHorizontally = cameraConfig.getMirrorX();
|
||||
getConfig().flipVertically = cameraConfig.getMirrorY();
|
||||
getConfig().flipHorizontally = setup.getMirrorX();
|
||||
getConfig().flipVertically = setup.getMirrorY();
|
||||
//getConfig().rotation = config.getRotate();
|
||||
//getConfig().rotationCrop = true;
|
||||
switch (cameraConfig.getRotate()) {
|
||||
switch (setup.getRotate()) {
|
||||
case 1:
|
||||
getConfig().rotation = 270;
|
||||
break;
|
||||
@@ -189,26 +218,20 @@ public class SfCamera extends PsiCamera{
|
||||
}
|
||||
getConfig().rotationCrop = false;
|
||||
try {
|
||||
getConfig().spatialCalOffsetX = cameraConfig.getCalOffsetX();
|
||||
getConfig().spatialCalOffsetY = cameraConfig.getCalOffsetY();
|
||||
getConfig().spatialCalOffsetX = setup.getCalOffsetX();
|
||||
getConfig().spatialCalOffsetY = setup.getCalOffsetY();
|
||||
} catch (Exception ex) {
|
||||
getConfig().spatialCalOffsetX = 0.0;
|
||||
getConfig().spatialCalOffsetY = 0.0;
|
||||
}
|
||||
try {
|
||||
getConfig().spatialCalScaleX = -cameraConfig.getScaleX();
|
||||
getConfig().spatialCalScaleY = -cameraConfig.getScaleY();
|
||||
} catch (Exception ex) {
|
||||
getLogger().log(Level.WARNING, null, ex);
|
||||
getConfig().spatialCalScaleX = -setup.getScaleX();
|
||||
getConfig().spatialCalScaleY = -setup.getScaleY();
|
||||
} catch (Exception ex) {
|
||||
getConfig().spatialCalScaleX = 1.0;
|
||||
getConfig().spatialCalScaleY = 1.0;
|
||||
}
|
||||
getConfig().save();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInitialize() throws IOException, InterruptedException{
|
||||
super.doInitialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user