Commit 53924b9e authored by Andrey Filippov's avatar Andrey Filippov

modified save/restore calibration state, bug fixes

parent 7a838c63
......@@ -606,6 +606,7 @@ public static MatchSimulatedPattern.DistortionParameters DISTORTION =new MatchSi
addButton("Select source directory", panelDirs);
addButton("Select intermediate directory",panelDirs);
addButton("Select results directory", panelDirs);
addButton("View CSV file", panelDirs, color_report);
add(panelDirs);
......@@ -1092,13 +1093,15 @@ if (MORE_BUTTONS) {
selectedProperties.setProperty("selected", "true");
saveProperties(null,PROCESS_PARAMETERS.kernelsDirectory, PROCESS_PARAMETERS.useXML, selectedProperties);
return;
/* ======================================================================== */
} else if (label.equals("View CSV file")) {
viewCSVFile();
return;
/* ======================================================================== */
} else if (label.equals("Restore") || label.equals("Restore no autoload")) {
boolean noAuto=label.equals("Restore no autoload");
ABERRATIONS_PARAMETERS.autoRestore=false;
loadProperties(null,PROCESS_PARAMETERS.kernelsDirectory,PROCESS_PARAMETERS.useXML, PROPERTIES);
String confPath=loadProperties(null,PROCESS_PARAMETERS.kernelsDirectory,PROCESS_PARAMETERS.useXML, PROPERTIES);
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
if (ABERRATIONS_PARAMETERS.autoRestore && !noAuto){
if (DEBUG_LEVEL>0)System.out.println("Auto-loading configuration files");
......@@ -1114,6 +1117,13 @@ if (MORE_BUTTONS) {
UPDATE_STATUS,
DEBUG_LEVEL
);
/*// Not needed, controlled by parameters
if (ABERRATIONS_PARAMETERS.autoLoadPaths()[3]!=null) {
// Re-read configuration file to overwrite camera parameters restored with calibration files
if (DEBUG_LEVEL>0) System.out.println("Re-reading configuration to overwrite camera parameters restored from the sensor calibration files");
loadProperties(confPath,PROCESS_PARAMETERS.kernelsDirectory,PROCESS_PARAMETERS.useXML, PROPERTIES);
}
*/
if (dcdUpdated) DISTORTION_CALIBRATION_DATA=LENS_DISTORTIONS.fittingStrategy.distortionCalibrationData;
if (ABERRATIONS_PARAMETERS.autoReCalibrate){
if (LENS_DISTORTIONS.fittingStrategy==null) {
......@@ -1169,6 +1179,7 @@ if (MORE_BUTTONS) {
}
}
restoreFocusingHistory(false);
}
return;
......@@ -2407,6 +2418,7 @@ if (MORE_BUTTONS) {
defaultPath,
PATTERN_PARAMETERS,
EYESIS_CAMERA_PARAMETERS,
ABERRATIONS_PARAMETERS,
null); // gridImages null - use specified files
if (DISTORTION_CALIBRATION_DATA.pathName== null){ // failed to select/open the file
DISTORTION_CALIBRATION_DATA=oldDISTORTION_CALIBRATION_DATA;
......@@ -3171,15 +3183,17 @@ if (MORE_BUTTONS) {
GenericDialog gd = new GenericDialog("Select sensor number");
gd.addCheckbox("Restore all sensors", true);
gd.addNumericField("Number of sensor/channel to apply calibration (if \"all\" is not selected)", 0,0);
gd.addCheckbox("Overwrite SFE position/orientation from the sensor calibration data", true);
gd.addCheckbox("Overwrite all SFE position/orientation from the sensor calibration data", true);
gd.addCheckbox("Overwrite SFE distortion from the sensor calibration data", true);
gd.showDialog();
if (gd.wasCanceled()) return;
boolean allFiles=gd.getNextBoolean();
int numSensor= (int) gd.getNextNumber();
if (allFiles) numSensor=-1;
boolean overwriteExtrinsic=gd.getNextBoolean();
if (numSensor<0) LENS_DISTORTIONS.setDistortionFromImageStack(pathname,overwriteExtrinsic); // requires fitting strategy to be set?
else LENS_DISTORTIONS.setDistortionFromImageStack(pathname, numSensor,true,overwriteExtrinsic); // report missing files
boolean overwriteDistortion=gd.getNextBoolean();
if (numSensor<0) LENS_DISTORTIONS.setDistortionFromImageStack(pathname,overwriteExtrinsic,overwriteDistortion); // requires fitting strategy to be set?
else LENS_DISTORTIONS.setDistortionFromImageStack(pathname, numSensor,true,overwriteExtrinsic,overwriteDistortion); // report missing files
return;
}
/* ======================================================================== */
......@@ -3830,6 +3844,7 @@ if (MORE_BUTTONS) {
FOCUS_MEASUREMENT_PARAMETERS.initialCalibrationFile,
PATTERN_PARAMETERS,
EYESIS_CAMERA_PARAMETERS, // is it null or 1?
ABERRATIONS_PARAMETERS,
imp_calibrated); // gridImages null - use specified files - single image
if (DISTORTION_CALIBRATION_DATA.pathName== null){ // failed to select/open the file
DISTORTION_CALIBRATION_DATA=null;
......@@ -9549,6 +9564,49 @@ if (MORE_BUTTONS) {
}
/* ===== Other methods ==================================================== */
public void viewCSVFile(){
String [] extensions={".csv","CSV"};
CalibrationFileManagement.MultipleExtensionsFileFilter parFilter = new CalibrationFileManagement.MultipleExtensionsFileFilter("",extensions,"CSV table *.csv files");
String pathname=CalibrationFileManagement.selectFile(
true, // smart,
false,
"Restore CSV file (table)",
"Restore",
parFilter,
""); // (defaultPath==null)?this.pathName:defaultPath); //String defaultPath
if (pathname==null) return;
BufferedReader reader=null;
try {
reader = new BufferedReader( new FileReader (pathname));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Error opening "+pathname+" for reading");
return;
}
String header=null;
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
try {
header = reader.readLine();
} catch (IOException e) {
System.out.println("Failed to read a header from "+pathname);
try {reader.close();} catch (IOException e1) {}
return;
}
try {
while( ( line = reader.readLine() ) != null ) {
stringBuilder.append( line );
stringBuilder.append( ls );
}
} catch (IOException e) {
System.out.println("Error reading from "+pathname);
try {reader.close();} catch (IOException e1) {}
}
new TextWindow(pathname, header, stringBuilder.toString(), 500,900);
try {reader.close();} catch (IOException e1) {}
}
public void checkDefects(){
imp_sel = WindowManager.getCurrentImage();
if (imp_sel==null){
......@@ -10195,6 +10253,7 @@ if (MORE_BUTTONS) {
configPaths[0],
patternParameters,
eyesisCameraParameters,
aberrationParameters,
null); // gridImages null - use specified files
if (distortions.fittingStrategy!=null) {
distortions.fittingStrategy.distortionCalibrationData=dcd;
......@@ -10227,7 +10286,11 @@ if (MORE_BUTTONS) {
if (configPaths[3] !=null){ // load sensor
if (distortions.fittingStrategy==null) return false;
if (DEBUG_LEVEL>0) System.out.println("Autoloading sensor calibration files "+configPaths[3]);
distortions.setDistortionFromImageStack(configPaths[3],aberrationParameters.autoRestoreSensorOverwriteOrientation);
distortions.setDistortionFromImageStack(
configPaths[3],
aberrationParameters.autoRestoreSensorOverwriteOrientation,
aberrationParameters.autoRestoreSensorOverwriteDistortion
);
}
return true;
}
......@@ -14424,7 +14487,7 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
}
/* ======================================================================== */
public void loadProperties(
public String loadProperties(
String path,
String directory,
boolean useXML,
......@@ -14445,13 +14508,13 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
path+=patterns[0];
}
}
if (path==null) return;
if (path==null) return path;
InputStream is;
try {
is = new FileInputStream(path);
} catch (FileNotFoundException e) {
IJ.showMessage("Error","Failed to open configuration file: "+path);
return;
return path;
}
if (useXML) {
......@@ -14460,14 +14523,14 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
} catch (IOException e) {
IJ.showMessage("Error","Failed to read XML configuration file: "+path);
return;
return path;
}
} else {
try {
properties.load(is);
} catch (IOException e) {
IJ.showMessage("Error","Failed to read configuration file: "+path);
return;
return path;
}
}
try {
......@@ -14478,6 +14541,8 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
}
getAllProperties(properties);
if (DEBUG_LEVEL>0) System.out.println("Configuration parameters are restored from "+path);
return path;
}
/* ======================================================================== */
public void setAllProperties(Properties properties){
......@@ -16218,7 +16283,13 @@ private double [][] jacobianByJacobian(double [][] jacobian, boolean [] mask) {
double over;
// individual per-thread - will be needed when converted to doubleFHT
// MatchSimulatedPattern matchSimulatedPattern=new MatchSimulatedPattern(FFT_SIZE);
MatchSimulatedPattern matchSimulatedPattern=commonMatchSimulatedPattern.clone();
MatchSimulatedPattern matchSimulatedPattern=commonMatchSimulatedPattern.cloneDeep(
false, // boolean clonePATTERN_GRID,
false, // boolean cloneTargetUV,
false, // boolean clonePixelsUV,
false, // boolean cloneFlatFieldForGrid,
false // boolean cloneFocusMask
);
matchSimulatedPattern.debugLevel=DEBUG_LEVEL;
SimulationPattern simulationPattern= new SimulationPattern(bitmaskPattern);
simulationPattern.debugLevel=DEBUG_LEVEL;
......
This diff is collapsed.
......@@ -2304,7 +2304,14 @@ public class EyesisAberrations {
// double [] sum_kern_el=new double[6]; // just testing
int x0,y0,nTX,nTY,nChn;
double [][] kernels;
MatchSimulatedPattern matchSimulatedPattern=commonMatchSimulatedPattern.clone();
// change to true (first 2 only?) to separate memory arrays for threads
MatchSimulatedPattern matchSimulatedPattern=commonMatchSimulatedPattern.cloneDeep(
false, // boolean clonePATTERN_GRID,
false, // boolean cloneTargetUV,
false, // boolean clonePixelsUV,
false, // boolean cloneFlatFieldForGrid,
false // boolean cloneFocusMask
);
matchSimulatedPattern.debugLevel=globalDebugLevel;
SimulationPattern simulationPattern= new SimulationPattern(bitmaskPattern);
simulationPattern.debugLevel=globalDebugLevel;
......@@ -4478,10 +4485,12 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
public String strategyPath="";
public String gridPath="";
public String sensorsPath="";
public boolean autoRestoreSensorOverwriteOrientation=true; // overwrite camera parameters from sensor calibration files
public boolean autoRestoreSensorOverwriteOrientation=false; // dangerous! true; // overwrite camera parameters from sensor calibration files
public boolean autoRestoreSensorOverwriteDistortion= false; // dangerous! true; // overwrite camera parameters from sensor calibration files
public boolean autoReCalibrate=true; // Re-calibrate grids on autoload
public boolean autoReCalibrateIgnoreLaser=false; // "Ignore laser pointers on recalibrate"
public boolean autoFilter=true;
public boolean autoFilter=false; // true;
public boolean trustEnabled= true; // mark all enabled images as hintedMatch=2 on Read Calibration
public boolean noMessageBoxes=true;
public boolean overwriteResultFiles=false;
public boolean partialToReprojected=true; // Use reprojected grid for partial kernel calculation (false - use extracted)
......@@ -4514,9 +4523,11 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
properties.setProperty(prefix+"gridPath",this.gridPath);
properties.setProperty(prefix+"sensorsPath",this.sensorsPath);
properties.setProperty(prefix+"autoRestoreSensorOverwriteOrientation",this.autoRestoreSensorOverwriteOrientation+"");
properties.setProperty(prefix+"autoRestoreSensorOverwriteDistortion",this.autoRestoreSensorOverwriteDistortion+"");
properties.setProperty(prefix+"autoReCalibrate",this.autoReCalibrate+"");
properties.setProperty(prefix+"autoReCalibrateIgnoreLaser",this.autoReCalibrateIgnoreLaser+"");
properties.setProperty(prefix+"autoFilter",this.autoFilter+"");
properties.setProperty(prefix+"trustEnabled",this.trustEnabled+"");
properties.setProperty(prefix+"noMessageBoxes",this.noMessageBoxes+"");
properties.setProperty(prefix+"overwriteResultFiles",this.overwriteResultFiles+"");
properties.setProperty(prefix+"partialToReprojected",this.partialToReprojected+"");
......@@ -4557,11 +4568,13 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
if (properties.getProperty(prefix+"sensorsPath")!=null) this.sensorsPath=properties.getProperty(prefix+"sensorsPath");
if (properties.getProperty(prefix+"autoRestoreSensorOverwriteOrientation")!=null)
this.autoRestoreSensorOverwriteOrientation=Boolean.parseBoolean(properties.getProperty(prefix+"autoRestoreSensorOverwriteOrientation"));
if (properties.getProperty(prefix+"autoRestoreSensorOverwriteDistortion")!=null)
this.autoRestoreSensorOverwriteDistortion=Boolean.parseBoolean(properties.getProperty(prefix+"autoRestoreSensorOverwriteDistortion"));
if (properties.getProperty(prefix+"autoReCalibrate")!=null) this.autoReCalibrate=Boolean.parseBoolean(properties.getProperty(prefix+"autoReCalibrate"));
if (properties.getProperty(prefix+"autoReCalibrateIgnoreLaser")!=null) this.autoReCalibrateIgnoreLaser=Boolean.parseBoolean(properties.getProperty(prefix+"autoReCalibrateIgnoreLaser"));
if (properties.getProperty(prefix+"autoFilter")!=null) this.autoFilter=Boolean.parseBoolean(properties.getProperty(prefix+"autoFilter"));
if (properties.getProperty(prefix+"trustEnabled")!=null) this.trustEnabled=Boolean.parseBoolean(properties.getProperty(prefix+"trustEnabled"));
if (properties.getProperty(prefix+"noMessageBoxes")!=null) this.noMessageBoxes=Boolean.parseBoolean(properties.getProperty(prefix+"noMessageBoxes"));
if (properties.getProperty(prefix+"overwriteResultFiles")!=null) this.overwriteResultFiles=Boolean.parseBoolean(properties.getProperty(prefix+"overwriteResultFiles"));
if (properties.getProperty(prefix+"partialToReprojected")!=null) this.partialToReprojected=Boolean.parseBoolean(properties.getProperty(prefix+"partialToReprojected"));
......@@ -4706,10 +4719,13 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
gd.addCheckbox("Process all enabled image files (false - use selected fitting series)", this.allImages);
gd.addMessage("===== Autoload options (when restoring configuration) =====");
gd.addCheckbox("Autoload additional files on \"Restore\"", this.autoRestore);
gd.addCheckbox("Overwrite SFE parameters from the sensor calibration files (at auto-load)", this.autoRestoreSensorOverwriteOrientation);
gd.addCheckbox("Overwrite all (including position/orientation) SFE parameters from the sensor calibration files (at auto-load) DANGEROUS!", this.autoRestoreSensorOverwriteOrientation);
gd.addCheckbox("Overwrite SFE distortion parameters from the sensor calibration files (at auto-load) DANGEROUS!", this.autoRestoreSensorOverwriteDistortion);
gd.addCheckbox("Re-calibrate grids on autoload", this.autoReCalibrate);
gd.addCheckbox("Ignore laser pointers on recalibrate", this.autoReCalibrateIgnoreLaser);
gd.addCheckbox("Filter grids after restore", this.autoFilter);
gd.addCheckbox("Trust enabled images on input (mark as hintedGrid=2)", this.trustEnabled);
gd.addMessage("Calibration: "+(((this.calibrationPath==null) || (this.calibrationPath.length()==0))?"not configured ":(this.calibrationPath+" "))+
((currentConfigs[0]!=null)?("(current: "+currentConfigs[0]+")"):("") ));
......@@ -4753,9 +4769,11 @@ if (globalDebugLevel>2)globalDebugLevel=0; //***********************************
this.allImages= gd.getNextBoolean();
this.autoRestore= gd.getNextBoolean();
this.autoRestoreSensorOverwriteOrientation= gd.getNextBoolean();
this.autoRestoreSensorOverwriteDistortion= gd.getNextBoolean();
this.autoReCalibrate= gd.getNextBoolean();
this.autoReCalibrateIgnoreLaser=gd.getNextBoolean();
this.autoFilter= gd.getNextBoolean();
this.trustEnabled= gd.getNextBoolean();
if (gd.getNextBoolean()) {
if (currentConfigs[0]!=null) this.calibrationPath=currentConfigs[0];
......
......@@ -1588,15 +1588,17 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
if (numEstimated>0) selectEstimated=gd.getNextBoolean();
boolean selectNewEnabled=false;
if (numNewEnabled>0) selectNewEnabled=gd.getNextBoolean();
if (selectNewEnabled) {
this.selectedImages[numSeries]=this.distortionCalibrationData.selectNewEnabled();
return numSeries; // caller will repeat with the same series
}
if (this.distortionCalibrationData.eyesisCameraParameters.numStations>1){
// boolean removeUnselectedStations=gd.getNextBoolean();
for (int i=0;i<constrainByStation.length; i++) constrainByStation[i]=gd.getNextBoolean();
}
if (selectNewEnabled) {
this.selectedImages[numSeries]=this.distortionCalibrationData.selectNewEnabled();
for (int i =0; i<this.distortionCalibrationData.getNumImages();i++){
this.selectedImages[numSeries][i]&=constrainByStation[this.distortionCalibrationData.gIP[i].getStationNumber()];
}
return numSeries; // caller will repeat with the same series
}
if (selectEstimated) {
this.selectedImages[numSeries]=this.distortionCalibrationData.selectEstimated(true); //(boolean enabledOnly
......@@ -1612,6 +1614,9 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
copySeries(sourceSeries, numSeries);
} else {
System.out.println("Could not copy from invalid series "+sourceSeries);
}
for (int i =0; i<this.distortionCalibrationData.getNumImages();i++){
this.selectedImages[numSeries][i]&=constrainByStation[this.distortionCalibrationData.gIP[i].getStationNumber()];
}
return numSeries; // caller will repeat with the same series
}
......
......@@ -923,6 +923,7 @@ dPXmmc/dphi=
double zp, // target point horizontal, positive - away from camera, mm
boolean calculateAll){ // calculate derivatives, false - values only
// this.cummulativeCorrection=false; // just debugging
final double maxRelativeRadius=2.0; // make configurable?
// TODO - add reduced calculations for less terms?
// final int numDerivatives=44; // 18+6*2+7*2; // 18 for radial and 26 more for non-radial
......@@ -1190,9 +1191,9 @@ dPXmmc/dphi=
partDeriv[0][0]= 1000.0/this.pixelSize*xyDist[0] + this.px0;
partDeriv[0][1]= -1000.0/this.pixelSize*xyDist[1] + this.py0;
if (!calculateAll) {
if (!calculateAll) { // TODO: how to deal with it when calculating Jacobian???
// TODO: Looking away from the target, trying only with no dervatives. Do the same for derivatives too?
if (XeYeZe[2]<0.0) {
if ((XeYeZe[2]<0.0) || ((xmmc*xmmc+ymmc*ymmc)>maxRelativeRadius*maxRelativeRadius)){ // non-distorted too far from the axis
partDeriv[0][0]=Double.NaN;
partDeriv[0][1]=Double.NaN;
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment