Commit 9833be98 authored by Andrey Filippov's avatar Andrey Filippov

working on dual-modal calibration

parent 7b892871
......@@ -6015,7 +6015,7 @@ if (MORE_BUTTONS) {
LASER_POINTERS, // MatchSimulatedPattern.LaserPointer laserPointer, // LaserPointer object that specifies actual laser poiners on the target
DISTORTION_PROCESS_CONFIGURATION.removeOutOfGridPointers, // boolean removeOutOfGridPointers,
(useHintTolerance?hintGridTolerance:0.0), //double hintGridTolerance, // alllowed mismatch (fraction of period) or 0 - orientation only
processAll, //boolean processAll, // if true - process all images, false - only disabeld
processAll, //boolean processAll, // if true - process all images, false - only disabled
ignoreLaserPointers,
processBlind,
imageNumber,
......@@ -9546,7 +9546,7 @@ if (MORE_BUTTONS) {
/* ======================================================================== */
if (label.equals("Grid offset")) {
DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
offsetGrids(0, 0, null);
offsetGrids(0, 0, null, null);
return;
}
/* ======================================================================== */
......@@ -9590,21 +9590,24 @@ if (MORE_BUTTONS) {
boolean use_lma = true;
GenericDialog gd = new GenericDialog("Initial alignment of the secondary camera to the reference one");
gd.addMessage("This command used Fitting Strategy[0] that should be set with all parameters but\n"+
"GXYZ0 and GXYZ1 are set to 'fixed', and GXYZ0 and GXYZ1 are set to 'individual'.\n"+
// gd.addMessage("This command used Fitting Strategy[last] that should be set with all parameters but\n"+
// "GXYZ0 and GXYZ1 are set to 'fixed', and GXYZ0 and GXYZ1 are set to 'individual'.\n"+
// "Each selected set should already have GXYZ set correctly (e.g. by reference cameras)");
gd.addMessage("This command uses Fitting Strategy[last] and set parameters but\n"+
"GXYZ0 and GXYZ1 to 'individual', all others - to 'fixed'.\n"+
"Each selected set should already have GXYZ set correctly (e.g. by reference cameras)");
gd.addNumericField("Image set start", min_set, 0);
gd.addNumericField("Image set last", max_set, 0);
gd.addCheckbox("Adjust EO (reference) sensors", adjust_eo);
gd.addCheckbox("Adjust LWIR (target) sensors", adjust_lwir);
gd.addCheckbox("Use LMA (unchecked - initial approximate grid setum by correlation)", use_lma);
gd.addCheckbox("Use LMA (unchecked - initial approximate grid set by correlation)", use_lma);
gd.showDialog();
if (gd.wasCanceled()) return false;
min_set = (int) gd.getNextNumber();
max_set = (int) gd.getNextNumber();
adjust_eo = gd.getNextBoolean();
adjust_lwir = gd.getNextBoolean();
use_lma = gd.getNextBoolean();
use_lma = gd.getNextBoolean();
if (!dcd.hasSmallSensors()) {
String msg="This system does not have any LWIR or other dependent sub-cameras";
IJ.showMessage("Error",msg);
......@@ -9626,10 +9629,14 @@ if (MORE_BUTTONS) {
continue;
}
}
double [] stats = new double [3];
int [] uvr = LENS_DISTORTIONS. findImageGridOffset(
num_img,
true, // boolean even, For first time - use parameter and parity of uv_rot
PATTERN_PARAMETERS);
num_img, // image num
-1, // use last series int ser_num, // number of series to reprogram
false, // boolean adjust_attitude, // true for eo, false for lwir (uses exact attitude from eo)
true, // boolean even, For first time - use parameter and parity of uv_rot
PATTERN_PARAMETERS,
stats); // rms, dU, dV
if ((uvr != null) && ((uvr[0] != 0) || (uvr[1] != 0))) {
int [] uv_shift_rot = {uvr[0],uvr[1],0};
// int [] new_uv_shift_rots =
......@@ -9639,6 +9646,8 @@ if (MORE_BUTTONS) {
PATTERN_PARAMETERS);
if (DEBUG_LEVEL > 0) {
System.out.println(num_img+ "("+num_set+"."+nc+"): uv_shift = "+uvr[0]+":"+uvr[1]);
System.out.println(num_img+ "("+num_set+"."+nc+"): errors: rms= "+stats[0]+", dU="+stats[1]+", dV="+stats[2]);
}
}
}
......@@ -9666,7 +9675,7 @@ if (MORE_BUTTONS) {
return true;
}
public boolean offsetGrids(int ichoice, int inum, int [] uv_shift_rot) {
public boolean offsetGrids(int ichoice, int inum, int [] uv_shift_rot, String msg) {
if (LENS_DISTORTIONS == null) {
System.out.println("LENS_DISTORTIONS is null");
return false;
......@@ -9695,8 +9704,16 @@ if (MORE_BUTTONS) {
String [] choices_nolwir = {"-- please select --","Image number","Image set number"};
String [] choices_lwir = {"-- please select --","Image number","Image set number (all images)", "Image set (EO only)","Image set (LWIR only)"};
String [] choices = has_lwir ? choices_lwir : choices_nolwir;
boolean readjust = true;
GenericDialog gd = new GenericDialog("Manually offset single grid or multiple grids in a set");
if (msg != null) {
gd.addMessage(msg);
}
if (auto) {
gd.addMessage("In 'auto' mode this command uses Fitting Strategy[last] and set parameters but\n"+
"GXYZ0, GXYZ1, goniometerHorizontal, and goniometerAxial to 'individual', all others - to 'fixed'.\n"+
"Each selected set should already have GXYZ set correctly (e.g. by reference cameras)");
}
gd. addChoice("Next number is: ",
choices,
choices[ichoice]);
......@@ -9705,6 +9722,10 @@ if (MORE_BUTTONS) {
if (has_lwir) {
gd.addCheckbox ("Auto from EO grid (calculatre from EO even if the requested image is LWIR)", false); //true
}
if (!auto) {
gd.addCheckbox("Run LMA to re-adjust goniometerHorizontal and goniometerAxial", readjust);
readjust = gd.getNextBoolean();
}
gd.addNumericField("Grid offset U", uv_shift_rot[0], 0);
gd.addNumericField("Grid offset V", uv_shift_rot[1], 0);
gd.addNumericField("Grid offset Rot", uv_shift_rot[2], 0);
......@@ -9712,17 +9733,24 @@ if (MORE_BUTTONS) {
if (gd.wasCanceled()) return false;
ichoice = gd.getNextChoiceIndex();
inum = (int) gd.getNextNumber();
boolean was_auto = auto;
auto = gd.getNextBoolean();
boolean auto_from_EO=false;
if (has_lwir) {
auto_from_EO = gd.getNextBoolean();
}
readjust = false;
if (!was_auto) {
readjust = gd.getNextBoolean();
}
uv_shift_rot[0] = (int) gd.getNextNumber();
uv_shift_rot[1] = (int) gd.getNextNumber();
uv_shift_rot[2] = (int) gd.getNextNumber();
if (ichoice == 0) {
return offsetGrids(ichoice, inum, uv_shift_rot);
return offsetGrids(ichoice, inum, uv_shift_rot, msg);
}
int ichoicemod = ichoice;
if (auto && auto_from_EO) {
......@@ -9766,20 +9794,23 @@ if (MORE_BUTTONS) {
// find first enabled image
for (int n:img_nums) {
if (n >= 0) {
double [] stats = new double[3]; // rms and 2 errors, null OK
int [] auto_uvr = LENS_DISTORTIONS.findImageGridOffset( // null for now
n,
true, // boolean even,
PATTERN_PARAMETERS); // PatternParameters patternParameters)
// int [] auto_uvr = dcd. suggestOffset (
// n, // int num_img,
// true, // boolean non_estimated,
// true, // boolean even,
// PATTERN_PARAMETERS); // PatternParameters patternParameters)
return offsetGrids(ichoice, inum, auto_uvr);
n, // image number to use for fitting (only one)
-1, // use last series int ser_num, // number of series to reprogram
true, // boolean adjust_attitude, // true for eo, false for lwir (uses exact attitude from eo)
true, // boolean even, For first time - use parameter and parity of uv_rot
PATTERN_PARAMETERS,
stats);
if (auto_uvr != null) {
String stats_msg = String.format("Fitting errors: LMA RMS = %7.4f, dU = %6.3f, dV = %6.3f", stats[0], stats[1], stats[2]);
return offsetGrids(ichoice, inum, auto_uvr, stats_msg);
} else {
System.out.println("**** LMA FAILED - trying next image");
}
}
}
return offsetGrids(ichoice, inum, null, "All images failed LMA !");
}
int [][] new_uv_shift_rots = new int [img_nums.length][];
......@@ -9798,6 +9829,20 @@ if (MORE_BUTTONS) {
System.out.println("<null>");
}
}
if (readjust) {
for (int n:img_nums) {
if (n >= 0) {
if (LENS_DISTORTIONS.adjustAttitudeAfterOffset(
n, // int num_img,
-1, // int ser_num, // number of series to reprogram
PATTERN_PARAMETERS)) {
break; // only one image
} else {
System.out.println("***** LMA FAILED - trying next image");
}
}
}
}
return true;
}
......@@ -9821,8 +9866,10 @@ if (MORE_BUTTONS) {
gd.showDialog();
if (gd.wasCanceled()) return false;
numStations= (int) gd.getNextNumber();
String [] grid_extensions={".tif",".tiff"};
String [] src_extensions={".tif",".tiff"};
// String [] grid_extensions={".tif",".tiff"};
// String [] src_extensions={".tif",".tiff"};
String [] grid_extensions={".tiff"};
String [] src_extensions={".tiff"};
MultipleExtensionsFileFilter gridFilter =
new MultipleExtensionsFileFilter("grid",grid_extensions,"Calibrated grid files");
MultipleExtensionsFileFilter sourceFilter =
......@@ -9859,6 +9906,13 @@ if (MORE_BUTTONS) {
int num_match = files[nFile].list(gridFilter).length;
if (num_match >= min_files) {
filelist.add(files[nFile]);
} else {
// System.out.println("nFile="+nFile+" files[nFile]="+files[nFile]+": num_match="+num_match);
// String[] matched=files[nFile].list(gridFilter);
// for (String s:matched) {
// System.out.println(s);
// }
// System.out.println("");
}
}
......@@ -1392,6 +1392,7 @@ import ij.text.TextWindow;
// suggest set grid offset by comparing with known (by mark) set.
// Wrong Grid UV should cause parallel shift - same Z, different XY
/*
public int [] suggestOffset (
int num_img,
boolean non_estimated,
......@@ -1409,14 +1410,16 @@ import ij.text.TextWindow;
num_img,
diff_xyz, // z is not used, may ne just[2]
even,
patternParameters);
patternParameters,
null);
}
*/
public int [] suggestOffset (
int num_img,
double [] diff_xyz, // This XYZ minus reference XYZ z is not used, may be just[2]
boolean even,
PatternParameters patternParameters) {
PatternParameters patternParameters,
double [] errs) { // will return errors, if not null (should be double[2]
int num_set = this.gIP[num_img].setNumber;
int station = this.gIS[num_set].stationNumber;
int [][] pixelsUV = this.gIP[num_img].pixelsUV ; // null; // for each image, each grid node - a pair of {gridU, gridV}
......@@ -1458,7 +1461,11 @@ import ij.text.TextWindow;
UV_err[0] = dUV[0] - idUV[0];
UV_err[1] = dUV[1] - idUV[1];
}
System.out.println(String.format("Errors U/V = %.3f:%.3f",UV_err[0],UV_err[1]));
System.out.println(String.format("idUV ="+idUV[0]+" / "+idUV[1]+", errors U/V = %.3f:%.3f",UV_err[0],UV_err[1]));
if (errs != null) {
errs[0] = UV_err[0];
errs[1] = UV_err[1];
}
return idUV;
}
......@@ -2244,7 +2251,9 @@ import ij.text.TextWindow;
int stationNumber=this.gIP[i].getStationNumber();
boolean enableNoLaser=this.eyesisCameraParameters.getEnableNoLaser(stationNumber,this.gIP[i].channel);
boolean wasEnabled=this.gIP[i].enabled;
if (resetHinted) this.gIP[i].hintedMatch=-1; // undefined
if (resetHinted) {
this.gIP[i].hintedMatch=-1; // undefined
}
/// if (Double.isNaN(this.gIP[i].getGridPeriod()) ||
/// ((minGridPeriodFraction>0) && ((this.gIP[i].getGridPeriod()<minGridPeriod[stationNumber]) || (this.gIP[i].getGridPeriod()>maxGridPeriod[stationNumber])))){
if (Double.isNaN(getEffectivePeriod(i)) ||
......@@ -2431,6 +2440,7 @@ import ij.text.TextWindow;
}
if (bestRating>0){
EyesisSubCameraParameters esp = this.eyesisCameraParameters.eyesisSubCameras[stationNumber][bestChannel];
System.out.println("Image number: "+this.gIS[i].imageSet[bestChannel].getImageNumber());
double [] uv_center = getGridUVfromXY(
esp.px0, // final double px,
esp.py0, // final double py,
......@@ -2486,18 +2496,40 @@ import ij.text.TextWindow;
Matrix mview_tilt = mtilt.times(mview_gon); // view point on the target from the tilted goniometer
double az = Math.atan2(mview_tilt.get(0, 0), mview_tilt.get(2, 0)); // x pointed right
double tilt_deg = tilt/Math.PI*180;
double tilt_deg = -tilt/Math.PI*180; // why "-" (experimentally)
double az_deg = az/Math.PI*180;
if (this.debugLevel>0) {
System.out.println("Tilt = "+tilt_deg+", az = "+az_deg);
System.out.print("");
}
if (overwriteAll || Double.isNaN(this.gIS[i].goniometerAxial)){
this.gIS[i].goniometerAxial=az_deg;
for (int j=0;j<this.gIS[i].imageSet.length;j++) if (this.gIS[i].imageSet[j]!=null) setGA(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerAxial);
this.gIS[i].orientationEstimated=true;
if (this.debugLevel>1) {
System.out.print(String.format("Setting goniometerAxial for the image set #%4d (%18.6f) to ", i, this.gIS[i].timeStamp));
System.out.println(""+this.gIS[i].goniometerAxial+" +++++ orientationEstimated==true +++++");
// System.out.println("Setting goniometerAxial for the image set #"+i+" ("+this.gIS[i].timeStamp+") to "+this.gIS[i].goniometerAxial+" +++++ orientationEstimated==true +++++");
}
}
if (overwriteAll || Double.isNaN(this.gIS[i].goniometerTilt )){
this.gIS[i].goniometerTilt= tilt_deg;
for (int j=0;j<this.gIS[i].imageSet.length;j++) if (this.gIS[i].imageSet[j]!=null) setGH(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerTilt);
this.gIS[i].orientationEstimated=true;
if (this.debugLevel>1) {
System.out.print(String.format("Setting goniometerTilt for the image set #%4d (%18.6f) to ", i, this.gIS[i].timeStamp));
System.out.println(""+this.gIS[i].goniometerTilt+" ===== orientationEstimated==true =====");
}
}
}
}
/*
* Remove old method completely
if (overwriteAll || Double.isNaN(this.gIS[i].goniometerAxial)){
// System.out.println("setInitialOrientation("+overwriteAll+"), Double.isNaN(this.gIS["+i+"].goniometerAxial)="+Double.isNaN(this.gIS[i].goniometerAxial));
double subcam_heading = (esp.heading + (esp.cartesian? 0: esp.azimuth));
this.gIS[i].goniometerAxial=-subcam_heading;
for (int j=0;j<this.gIS[i].imageSet.length;j++) if (this.gIS[i].imageSet[j]!=null) setGA(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerAxial);
......@@ -2505,11 +2537,9 @@ import ij.text.TextWindow;
if (this.debugLevel>1) {
System.out.print(String.format("Setting goniometerAxial for the image set #%4d (%18.6f) to ", i, this.gIS[i].timeStamp));
System.out.println(""+this.gIS[i].goniometerAxial+" +++++ orientationEstimated==true +++++");
// System.out.println("Setting goniometerAxial for the image set #"+i+" ("+this.gIS[i].timeStamp+") to "+this.gIS[i].goniometerAxial+" +++++ orientationEstimated==true +++++");
}
}
if (overwriteAll || Double.isNaN(this.gIS[i].goniometerTilt )){
// System.out.println("setInitialOrientation("+overwriteAll+"), Double.isNaN(this.gIS["+i+"].goniometerTilt)="+Double.isNaN(this.gIS[i].goniometerTilt));
this.gIS[i].goniometerTilt= -esp.theta;
for (int j=0;j<this.gIS[i].imageSet.length;j++) if (this.gIS[i].imageSet[j]!=null) setGH(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerTilt);
this.gIS[i].orientationEstimated=true;
......@@ -2518,6 +2548,9 @@ import ij.text.TextWindow;
System.out.println(""+this.gIS[i].goniometerTilt+" ===== orientationEstimated==true =====");
}
}
*/
}
}
}
......@@ -2531,6 +2564,9 @@ import ij.text.TextWindow;
* Updated version - only flag as orientationEstimated if no enabled images exist in the set or any of the angles is NaN
* Temporarily duplicate image parameters from those of the set (should not be needed)
* selectedImages will not be used
* Modified (selectedImages was not used) 2020: do not touch set if nothing is selected there
* was: if selectedImages[] is not null will set orientationEstimated for unselected images
* restored to how it was
*/
public void updateSetOrientation(boolean [] selectedImages){ // if selectedImages[] is not null will set orientationEstimated for unselected images
if (this.gIS==null){
......@@ -2564,6 +2600,50 @@ import ij.text.TextWindow;
}
}
public void updateSetOrientation1(boolean [] selectedImages){
if (this.gIS==null){
String msg="Image set is not initilaized";
System.out.println(msg);
IJ.showMessage(msg);
}
for (int i=0; i<this.gIS.length;i++){
if (!Double.isNaN(this.gIS[i].goniometerAxial) && !Double.isNaN(this.gIS[i].goniometerTilt)) {
boolean has_selected = false;
boolean has_enabled = false;
for (int j=0;j<this.gIS[i].imageSet.length;j++) {
if ((this.gIS[i].imageSet[j]!=null) && this.gIS[i].imageSet[j].enabled){
has_enabled = true;
break;
}
has_selected |= (selectedImages == null) || selectedImages[this.gIS[i].imageSet[j].imgNumber];
}
if (has_enabled) {
this.gIS[i].orientationEstimated=false;
this.gIS[i].goniometerAxial-=360.0*Math.floor((this.gIS[i].goniometerAxial+180.0)/360.0);
} else if (has_selected) { // nut none enabled!
this.gIS[i].orientationEstimated=true;
}
} else {
this.gIS[i].orientationEstimated=true;
}
if (!this.gIS[i].orientationEstimated){
// now fill that data to all disabled images of the same set (just for listing RMS errors and debugging)
for (int j=0;j<this.gIS[i].imageSet.length;j++) if (this.gIS[i].imageSet[j]!=null) { // fill even those that are enabled
setGA(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerAxial );
setGH(this.gIS[i].imageSet[j].imgNumber,this.gIS[i].goniometerTilt );
}
} else {
this.gIS[i].goniometerAxial=Double.NaN;
this.gIS[i].goniometerTilt= Double.NaN;
System.out.println("updateSetOrientation(): imageSet "+i+" orientationEstimated == true");
}
}
}
public void updateSetOrientationOld(boolean [] selectedImages){
if (this.gIS==null){
String msg="Image set is not initilaized";
......@@ -2751,6 +2831,11 @@ import ij.text.TextWindow;
public double [] getImagesetTiltAxial(double timeStamp){
int mAxial=1; // m2
int mHorizontal=2;// m3
double [] degree_per_step = new double[3];
degree_per_step[mAxial] = 1.0/goniometerParameters.goniometerMotors.stepsPerDegreeAxial;
degree_per_step[mHorizontal] = 1.0/goniometerParameters.goniometerMotors.stepsPerDegreeTilt;
// this is probably already set
for (int i=0;i<this.gIS.length;i++){
if ((this.gIS[i].imageSet!=null) && (this.gIS[i].imageSet.length>0) && (this.gIS[i].imageSet[0]!=null)) this.gIS[i].setStationNumber(this.gIS[i].imageSet[0].getStationNumber());
......@@ -2941,7 +3026,7 @@ import ij.text.TextWindow;
(this.gIS[indexSecond].motors[mAxial]-this.gIS[indexClosest].motors[mAxial]);
// 06/06/2015 Andrey: Was missing setting estimated orientation. Was it a bug?
this.gIS[i].orientationEstimated=true;
if (this.debugLevel>0) System.out.println("Orientation for set # "+i+" timestamp "+IJ.d2s(this.gIS[i].timeStamp,6)+
if (this.debugLevel>-1) System.out.println("Orientation for set # "+i+" timestamp "+IJ.d2s(this.gIS[i].timeStamp,6)+
") is not defined, using interpolated between sets # "+indexClosest+" (timestamp "+IJ.d2s(this.gIS[indexClosest].timeStamp,6)+") "+
"and # "+indexSecond+" (timestamp "+IJ.d2s(this.gIS[indexSecond].timeStamp,6)+")");
}
......@@ -2963,14 +3048,36 @@ import ij.text.TextWindow;
!Double.isNaN(this.gIS[j].interAxisAngle)) {
double d2=0;
for (int k=0;k<this.gIS[j].motors.length;k++){
d2+=1.0*(this.gIS[j].motors[k]-this.gIS[i].motors[k])*
(this.gIS[j].motors[k]-this.gIS[i].motors[k]);
double da = (this.gIS[j].motors[k]-this.gIS[i].motors[k]) * degree_per_step[k];
d2+=da * da;
}
if ((d2Min<0) || (d2Min>d2)) {
d2Min=d2;
iBest=j;
}
}
if (iBest < 0) {
// next try for the same station number only (any tilt):
d2Min=-1;
for (int j=0;j<this.gIS.length;j++) if ((j!=i) &&
(this.gIS[j].getStationNumber() == station_number) &&
(this.gIS[j].motors[mHorizontal] == this.gIS[i].motors[mHorizontal]) &&
!this.gIS[j].orientationEstimated &&
(this.gIS[j].motors!=null) &&
!Double.isNaN(this.gIS[j].goniometerTilt) &&
!Double.isNaN(this.gIS[j].goniometerAxial ) &&
!Double.isNaN(this.gIS[j].interAxisAngle)) {
double d2=0;
for (int k=0;k<this.gIS[j].motors.length;k++){
double da = (this.gIS[j].motors[k]-this.gIS[i].motors[k]) * degree_per_step[k];
d2+=da * da;
}
if ((d2Min<0) || (d2Min>d2)) {
d2Min=d2;
iBest=j;
}
}
}
if (iBest < 0) {
d2Min=-1;
for (int j=0;j<this.gIS.length;j++) if ((j!=i) &&
......@@ -2980,9 +3087,12 @@ import ij.text.TextWindow;
!Double.isNaN(this.gIS[j].goniometerAxial ) &&
!Double.isNaN(this.gIS[j].interAxisAngle)) {
double d2=0;
for (int k=0;k<this.gIS[j].motors.length;k++){
d2+=1.0*(this.gIS[j].motors[k]-this.gIS[i].motors[k])*
(this.gIS[j].motors[k]-this.gIS[i].motors[k]);
double da = (this.gIS[j].motors[k]-this.gIS[i].motors[k]) * degree_per_step[k];
d2 += da* da;
}
if ((d2Min<0) || (d2Min>d2)) {
d2Min=d2;
......@@ -2998,8 +3108,8 @@ import ij.text.TextWindow;
!Double.isNaN(this.gIS[j].interAxisAngle)) {
double d2=0;
for (int k=0;k<this.gIS[j].motors.length;k++){
d2+=1.0*(this.gIS[j].motors[k]-this.gIS[i].motors[k])*
(this.gIS[j].motors[k]-this.gIS[i].motors[k]);
double da = (this.gIS[j].motors[k]-this.gIS[i].motors[k]) * degree_per_step[k];
d2 += da* da;
}
if ((d2Min<0) || (d2Min>d2)) {
d2Min=d2;
......@@ -3024,6 +3134,7 @@ import ij.text.TextWindow;
// this.gIS[iBest].interAxisAngle
// };
if (iBest!=i){
boolean usable_tilt = (this.gIS[i].motors != null);
boolean usable_axial = usable_tilt && (this.gIS[i].getStationNumber() == this.gIS[iBest].getStationNumber());
double diff_axial = usable_axial? (this.gIS[i].motors[mAxial]-this.gIS[iBest].motors[mAxial])/
......@@ -3037,7 +3148,8 @@ import ij.text.TextWindow;
this.gIS[i].goniometerAxial-=360.0*Math.floor((this.gIS[i].goniometerAxial+180.0)/360.0);
if (this.debugLevel>0) System.out.println("Orientation for set # "+i+" timestamp "+IJ.d2s(this.gIS[i].timeStamp,6)+
") is not defined, estimating from # "+iBest+" (timestamp "+IJ.d2s(this.gIS[iBest].timeStamp,6)+")" );
") is not defined, estimating from # "+iBest+" (timestamp "+IJ.d2s(this.gIS[iBest].timeStamp,6)+"): "+
"tilt="+this.gIS[i].goniometerTilt+", axial = " + this.gIS[i].goniometerAxial);
this.gIS[i].orientationEstimated=true;
// this.gIS[i].goniometerTilt= this.gIS[iBest].goniometerTilt;
// this.gIS[i].goniometerAxial=this.gIS[iBest].goniometerAxial;
......
......@@ -270,9 +270,9 @@ public class Distortions {
@Override
public void run() {
for (int imgNum=imageNumberAtomic.getAndIncrement(); imgNum<numImg;imgNum=imageNumberAtomic.getAndIncrement()){
// if (imgNum == 443) {
// System.out.println("calculateGridImageMasks(), imgNum="+imgNum);
// }
if (imgNum == 488) {
System.out.println("calculateGridImageMasks(), imgNum="+imgNum);
}
distortionCalibrationData[imgNum].calculateMask(
minContrast,
shrinkBlurSigma,
......@@ -395,7 +395,7 @@ public class Distortions {
System.out.println("initFittingSeries("+justSelection+","+filter+","+numSeries+"), pass="+pass);
//TODO: ********* Implement comments above ************
// calculate total number of x/y pairs in the selected images
if (numSeries<0)justSelection=true;
if (numSeries<0) justSelection=true;
if ((pass==1) && (numSeries>=0)) fittingStrategy.invalidateSelectedImages(numSeries); // next selectedImages() will select all, including empty
if (!justSelection) {
fittingStrategy.buildParameterMap (numSeries); // also sets currentSeriesNumber
......@@ -598,7 +598,7 @@ public class Distortions {
this.weightFunction[2*index+1]=weight*weightScaleY;
this.sumWeights+= weight*weightSumXY;
this.fittingStrategy.distortionCalibrationData.gIS[setNumber].setWeight+=2.0*weight; // used for variances - proportional to the set weight
if (this.pixelCorrection==null){
if ((this.pixelCorrection==null) || (this.pixelCorrection[chnNum] == null)){
this.Y[2*index]= fittingStrategy.distortionCalibrationData.gIP[imgNum].pixelsXY[pointNumber][0];
this.Y[2*index+1]=fittingStrategy.distortionCalibrationData.gIP[imgNum].pixelsXY[pointNumber][1];
} else {
......@@ -2845,6 +2845,10 @@ For each point in the image
System.out.println("No goniometer orientation is available for image # "+numGridImage+" - "+dcd.gIP[numGridImage].path);
}
} else {
if ((numGridImage >= 234) && (numGridImage< 245)) {
System.out.println("debug numGridImage="+numGridImage);
System.out.println();
}
int station=dcd.getImageStation(numGridImage);
int setNumber=dcd.gIP[numGridImage].getSetNumber();
double [][][] hintGrid=estimateGridOnSensor(
......@@ -3613,7 +3617,7 @@ For each point in the image
"Hinted-All",
debugTitles);
}
if (this.debugLevel>1) {
if (this.debugLevel>0) {
System.out.println("Grid in the FOV of the subcamera "+subCamera+
" tilt="+goniometerHorizontal+" axial="+goniometerAxial+" has "+visibleCells+" cells");
}
......@@ -4183,6 +4187,9 @@ List calibration
this.seriesNumber=series;
}
if (!applyChannelFilter) selectedChannels=null;
if (recalculate) {
resetGridImageMasks(); // FIXME: move elsewhere?
}
// initFittingSeries(!recalculate,this.filterForAll,this.seriesNumber); // will set this.currentVector
initFittingSeries(!recalculate,this.filterForAll,this.seriesNumber); // will set this.currentVector
this.currentfX=calculateFxAndJacobian(this.currentVector, false); // is it always true here (this.jacobian==null)
......@@ -4294,13 +4301,24 @@ List calibration
// boolean [] oldSelection=this.fittingStrategy.selectAllImages(0); // enable all images in series 0
int filter=this.filterForAll;
if (this.askFilter) filter=selectFilter(filter);
initFittingSeries(true,filter, -1); // this.seriesNumber); // will set this.currentVector
this.currentfX=calculateFxAndJacobian(this.currentVector, false); // is it always true here (this.jacobian==null)
double [] errors=calcErrors(calcYminusFx(this.currentfX)); // for all images
double rms= calcError (calcYminusFx(this.currentfX));
int [] numPairs=calcNumPairs(); // for all images, not only selected
// re-init for the selected series
initFittingSeries(true,filter,this.seriesNumber); // will set this.currentVector
// initFittingSeries(true,this.filterForAll,this.seriesNumber); // will set this.currentVector
this.currentfX=calculateFxAndJacobian(this.currentVector, false); // is it always true here (this.jacobian==null)
double [] errors=calcErrors(calcYminusFx(this.currentfX));
double rms= calcError (calcYminusFx(this.currentfX));
// boolean [] selectedImages=fittingStrategy.selectedImages();
int [] numPairs=calcNumPairs();
// double [] errors=calcErrors(calcYminusFx(this.currentfX)); // error - always for -1?
rms= calcError (calcYminusFx(this.currentfX)); // for selected series
boolean [] selectedImages=fittingStrategy.selectedImages(this.seriesNumber);
// int [] numPairs=calcNumPairs();
int [][] imageSets=this.fittingStrategy.distortionCalibrationData.listImages(false); // true - only enabled images
int [] numSetPoints=new int [imageSets.length];
double [] rmsPerSet=new double[imageSets.length];
......@@ -4309,21 +4327,31 @@ List calibration
for (int setNum=0;setNum<imageSets.length;setNum++){
double error2=0.0;
int numInSet=0;
int numInSetOther=0; // not selected in this
hasNaNInSet[setNum]=false;
boolean has_selected = false; // remove selected with all nan in selected, and unselected with all nans
for (int imgInSet=0;imgInSet<imageSets[setNum].length;imgInSet++){
int imgNum=imageSets[setNum][imgInSet];
int num=numPairs[imgNum];
if (Double.isNaN(errors[imgNum])){
hasNaNInSet[setNum]=true;
} else {
error2+=errors[imgNum]*errors[imgNum]*num;
numInSet+=num;
int imgNum=imageSets[setNum][imgInSet];
int num=numPairs[imgNum];
if (selectedImages[imgNum]) {
has_selected = true;
if (Double.isNaN(errors[imgNum])){
hasNaNInSet[setNum]=true;
} else {
error2+=errors[imgNum]*errors[imgNum]*num;
numInSet+=num;
}
}
} else {
if (!Double.isNaN(errors[imgNum])){
numInSetOther += num;
}
}
}
allNaNInSet[setNum]=(numInSet==0);
// allNaNInSet[setNum]= hasNaNInSet[setNum] && (numInSet==0);
allNaNInSet[setNum]= has_selected? (numInSet == 0) : ((numInSet + numInSetOther) == 0);
numSetPoints[setNum]=numInSet;
rmsPerSet[setNum]=(numInSet>0)?Math.sqrt(error2/numInSet):Double.NaN;
rmsPerSet[setNum]=(numInSet>0)?Math.sqrt(error2/numInSet) : Double.NaN; // only count selected images (i.e. only eo, ignore lwir)
}
// int numSelectedNotNaNSets=0;
int numSelectedSets=0;
......@@ -4341,8 +4369,10 @@ List calibration
int [] indices=new int [numOutLiers];
boolean [] availableSets= new boolean [imageSets.length];
for (int i=0;i<imageSets.length;i++) availableSets[i]= !allNaNInSet[i]; //!Double.isNaN(rmsPerSet[i]);
/*
// Remove all empty, not just selected by strategy. Now errors are calculated for all images, not juet selected
if (removeEmptySets && (numNaN>0)){ //(this.debugLevel>0)
if (this.debugLevel>0) System.out.println("removeOutLierSets(): Number of empty (rms=NaN) sets="+numNaN+":");
if (this.debugLevel>-1) System.out.println("removeOutLierSets(): Number of empty (rms=NaN) sets="+numNaN+":");
// int n=0;
for (int setNum=0;setNum<imageSets.length;setNum++) if (!availableSets[setNum]){
// n++;
......@@ -4356,7 +4386,7 @@ List calibration
}
}
}
*/
System.out.println("removeOutLierSets(): availableSets.length="+availableSets.length+" numSelectedSets="+numSelectedSets);
for (int n=0;n<numOutLiers;n++){
double maxRMS=-1.0;
......@@ -4376,19 +4406,21 @@ List calibration
if (this.debugLevel>0) System.out.println("Listing "+numOutLiers+" worst image sets");
for (int n=0;n<indices.length;n++){
int numSet=indices[n];
double setWeight=this.fittingStrategy.distortionCalibrationData.gIS[numSet].setWeight;
if (this.debugLevel>0) System.out.println(n+" ("+numSet+"): "+(hasNaNInSet[numSet]?"* ":"")+IJ.d2s(rmsPerSet[numSet],3)+
" points: "+numSetPoints[numSet]+" weight:"+setWeight);
gd.addCheckbox(n+": "+numSet+": "+(hasNaNInSet[numSet]?"* ":"")+IJ.d2s(rmsPerSet[numSet],3)+" weight:"+setWeight, true);
for (int i=0;i<imageSets[numSet].length;i++){
int numImg=imageSets[numSet][i];
double diameter=this.fittingStrategy.distortionCalibrationData.gIP[numImg].getGridDiameter();
gd.addMessage(i+":"+numImg+": "+IJ.d2s(errors[numImg],3)+" "+
" ("+this.fittingStrategy.distortionCalibrationData.gIP[numImg].pixelsXY.length+" points, diameter="+diameter+") "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
if (this.debugLevel>0) System.out.println(" --- "+numImg+": "+IJ.d2s(errors[numImg],3)+" "+
" ("+this.fittingStrategy.distortionCalibrationData.gIP[numImg].pixelsXY.length+" points, diameter="+diameter+") "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
if (numSet >= 0) {
double setWeight=this.fittingStrategy.distortionCalibrationData.gIS[numSet].setWeight; //-1
if (this.debugLevel>0) System.out.println(n+" ("+numSet+"): "+(hasNaNInSet[numSet]?"* ":"")+IJ.d2s(rmsPerSet[numSet],3)+
" points: "+numSetPoints[numSet]+" weight:"+setWeight);
gd.addCheckbox(n+": "+numSet+": "+(hasNaNInSet[numSet]?"* ":"")+IJ.d2s(rmsPerSet[numSet],3)+" weight:"+setWeight, true);
for (int i=0;i<imageSets[numSet].length;i++){
int numImg=imageSets[numSet][i];
double diameter=this.fittingStrategy.distortionCalibrationData.gIP[numImg].getGridDiameter();
gd.addMessage(i+":"+numImg+": "+IJ.d2s(errors[numImg],3)+" "+
" ("+this.fittingStrategy.distortionCalibrationData.gIP[numImg].pixelsXY.length+" points, diameter="+diameter+") "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
if (this.debugLevel>0) System.out.println(" --- "+numImg+": "+IJ.d2s(errors[numImg],3)+" "+
" ("+this.fittingStrategy.distortionCalibrationData.gIP[numImg].pixelsXY.length+" points, diameter="+diameter+") "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
}
}
}
WindowTools.addScrollBars(gd);
......@@ -4399,20 +4431,41 @@ List calibration
}
if (this.debugLevel>0) System.out.println("Removing outliers:");
for (int n=0;n<indices.length;n++){
if (gd.getNextBoolean()) {
int numSet=indices[n];
if (this.debugLevel>0) System.out.println(" Removing imgages in image set "+numSet);
for (int i=0;i<imageSets[numSet].length;i++){
int numImg=imageSets[numSet][i];
if (this.debugLevel>0) System.out.println(n+":"+i+"("+numImg+")"+IJ.d2s(errors[numImg],3)+" "+
int numSet=indices[n];
if (numSet >= 0) {
if (gd.getNextBoolean()) {
if (this.debugLevel>0) System.out.println(" Removing imgages in image set "+numSet);
for (int i=0;i<imageSets[numSet].length;i++){
int numImg=imageSets[numSet][i];
if (this.debugLevel>0) System.out.println(n+":"+i+"("+numImg+")"+IJ.d2s(errors[numImg],3)+" "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
this.fittingStrategy.distortionCalibrationData.gIP[numImg].enabled=false;
this.fittingStrategy.distortionCalibrationData.gIP[numImg].hintedMatch=-1; // so can be re-calibrated again w/o others
}
}
}
}
// Remove all empty, not just selected by strategy. Now errors are calculated for all images, not juet selected
if (removeEmptySets && (numNaN>0)){ //(this.debugLevel>0)
if (this.debugLevel>-1) System.out.println("removeOutLierSets(): Number of empty (rms=NaN) sets="+numNaN+":");
// int n=0;
for (int setNum=0;setNum<imageSets.length;setNum++) if (!availableSets[setNum]){
// n++;
if (this.debugLevel>0) System.out.println("Set "+setNum);
for (int imgInSet=0;imgInSet<imageSets[setNum].length;imgInSet++){
int numImg=imageSets[setNum][imgInSet];
if (this.debugLevel>0) System.out.println(setNum+":"+imgInSet+" #"+ numImg+" "+IJ.d2s(errors[numImg],3)+" "+
this.fittingStrategy.distortionCalibrationData.gIP[numImg].path);
this.fittingStrategy.distortionCalibrationData.gIP[numImg].enabled=false;
this.fittingStrategy.distortionCalibrationData.gIP[numImg].hintedMatch=-1; // so can be re-calibrated again w/o others
}
}
}
}
// next is not needed
fittingStrategy.distortionCalibrationData.updateSetOrientation(null); // remove orientation information from the image set if none is enabled
fittingStrategy.distortionCalibrationData.updateSetOrientation(null); //selectedImages); // null); // remove orientation information from the image set if none is enabled
// this.fittingStrategy.setImageSelection(0, oldSelection); // restore original selection in series 0
return true;
}
......@@ -4700,12 +4753,19 @@ List calibration
*/
public double calcError(double [] diff){
double result=0;
double sumw = 0;
if (this.weightFunction!=null) {
for (int i=0;i<diff.length;i++) result+=diff[i]*diff[i]*this.weightFunction[i];
result/=this.sumWeights;
for (int i=0;i<diff.length;i++) if (!Double.isNaN(diff[i])){
result+=diff[i]*diff[i]*this.weightFunction[i];
sumw += this.weightFunction[i];
}
result/=sumw; // this.sumWeights;
} else {
for (int i=0;i<diff.length;i++) result+=diff[i]*diff[i];
result/=diff.length;
for (int i=0;i<diff.length;i++) if (!Double.isNaN(diff[i])){
result+=diff[i]*diff[i];
sumw += 1.0;
}
result/=sumw; // diff.length;
}
return Math.sqrt(result)*this.RMSscale;
}
......@@ -7497,22 +7557,52 @@ List calibration
// approximately in XY plane, so by freezing all other parameters but GXY0 and GXY1 it is possible to find
// the pattern grid match.
public int [] findImageGridOffset(
int num_img,
int num_img,
int ser_num, // number of series to reprogram (< 0 - from the last one)
boolean adjust_attitude, // true for eo, false for lwir (uses exact attitude from eo)
boolean even,
PatternParameters patternParameters) {
PatternParameters patternParameters,
double [] stats) { // result quality, null OK
if (ser_num < 0) {
ser_num = fittingStrategy.parameterMode.length + ser_num; // use from the last one
}
if (this.debugLevel > 0) {
System.out.println("Will use/modify fitting series "+ser_num+" to adjust image "+num_img);
if (adjust_attitude) {
System.out.println("Will adjust GXYZ0, GXYZ1, goniometerHorizontal, and goniometerAxial");
} else {
System.out.println("Will adjust only GXYZ0 and GXYZ1.");
}
}
// set series 0 to this set images
boolean [] selection = fittingStrategy.selectAllImages(0); // enable all images in series 0
int was_seriesNumber = seriesNumber;
// set series ser_num (was 0) to this set images
DistortionCalibrationData dcd = fittingStrategy.distortionCalibrationData;
int par_index_goniometerHorizontal = dcd.getParameterIndexByName("goniometerHorizontal");
int par_index_goniometerAxial = dcd.getParameterIndexByName("goniometerAxial");
int par_index_GXYZ0 = dcd.getParameterIndexByName("GXYZ0");
int par_index_GXYZ1 = dcd.getParameterIndexByName("GXYZ1");
for (int i = 0; i < fittingStrategy.parameterMode[ser_num].length; i++) {
fittingStrategy.parameterMode[ser_num][i] = FittingStrategy.modeFixed; // 0
}
fittingStrategy.parameterMode[ser_num][par_index_GXYZ0] = FittingStrategy.modeIndividual; // 3
fittingStrategy.parameterMode[ser_num][par_index_GXYZ1] = FittingStrategy.modeIndividual; // 3
if (adjust_attitude) {
fittingStrategy.parameterMode[ser_num][par_index_goniometerHorizontal] = FittingStrategy.modeIndividual; // 3
fittingStrategy.parameterMode[ser_num][par_index_goniometerAxial] = FittingStrategy.modeIndividual; // 3
}
boolean [] selection = fittingStrategy.selectAllImages(ser_num); // enable all images in series 0
for (int i=0;i<selection.length;i++) selection[i]=false;
selection[num_img]=true;
fittingStrategy.setImageSelection(0,selection);
seriesNumber= 0; // start from 0;
initFittingSeries(false, filterForAll,0); // will set this.currentVector
fittingStrategy.setImageSelection(ser_num,selection);
seriesNumber= ser_num; // start from 0;
initFittingSeries(false, filterForAll,ser_num); // will set this.currentVector, will build parameter map too
//this.stopAfterThis[numSeries]
fittingStrategy.stopAfterThis[0]=true;
fittingStrategy.stopAfterThis[ser_num]=true;
stopEachStep= false;
stopEachSeries= false; // will not ask for confirmation after done
lambda = fittingStrategy.lambdas[0];
lambda = fittingStrategy.lambdas[ser_num];
boolean LMA_OK = false;
try {
LMA_OK = LevenbergMarquardt (false, true); // skip dialog, dry run (no updates)
......@@ -7522,8 +7612,13 @@ List calibration
if (!LMA_OK) {
return null; // LMA did not converge
}
double [] new_XY = {this.currentVector[0],this.currentVector[1]};
DistortionCalibrationData dcd = this.fittingStrategy.distortionCalibrationData;
// DistortionCalibrationData dcd = this.fittingStrategy.distortionCalibrationData;
// find indices of GXYZ0 and GXYZ1 in the vector
int index_GXYZ0 = this.fittingStrategy.reverseParameterMap[num_img][par_index_GXYZ0];
int index_GXYZ1 = this.fittingStrategy.reverseParameterMap[num_img][par_index_GXYZ1];
double [] new_XY = {this.currentVector[index_GXYZ0],this.currentVector[index_GXYZ1]};
// DistortionCalibrationData dcd = this.fittingStrategy.distortionCalibrationData;
// int num_set = dcd.gIP[num_img].getSetNumber();
double [] ref_XYZ = dcd.getXYZ(num_img);
double [] diff_XY = {
......@@ -7531,36 +7626,74 @@ List calibration
new_XY[1] -ref_XYZ[1]};
//save safe settings to run LMA manually (or save what was set)
seriesNumber= 0; // start from 0;
initFittingSeries (false,filterForAll,0); // will set this.currentVector
seriesNumber= was_seriesNumber; // start from 0;
initFittingSeries (false,filterForAll,seriesNumber); // will set this.currentVector
stopEachSeries= true; // will not ask for confirmation after done
stopOnFailure= true;
lambda= fittingStrategy.lambdas[0];
lambda= fittingStrategy.lambdas[seriesNumber];
double [] errs = new double[2];
int [] grid_offset = dcd.suggestOffset (
num_img,
diff_XY, // This XYZ minus reference XYZ z is not used, may be just[2]
even,
patternParameters);
patternParameters,
errs);
if (stats != null) {
stats[0] = this.currentRMS;
stats[1] = errs[0]; // dU
stats[2] = errs[1]; // dV
}
return grid_offset;
}
/*
*
this.currentVector[0] - GXYZ[0]
this.currentVector[1] - GXYZ[1]
dcd. public int [] suggestOffset (
int num_img,
double [] diff_xyz, // This XYZ minus reference XYZ z is not used, may be just[2]
boolean even,
PatternParameters patternParameters) {
*/
public boolean adjustAttitudeAfterOffset(
int num_img,
int ser_num, // number of series to reprogram
PatternParameters patternParameters) {
if (ser_num < 0) {
ser_num = fittingStrategy.parameterMode.length + ser_num; // use from the last one
}
if (this.debugLevel > 0) {
System.out.println("Will use/modify fitting series "+ser_num+" for to adjust az, tilt of image "+num_img);
System.out.println("Will adjust goniometerHorizontal, and goniometerAxial");
}
int was_seriesNumber = seriesNumber;
// set series ser_num (was 0) to this set images
DistortionCalibrationData dcd = fittingStrategy.distortionCalibrationData;
int par_index_goniometerHorizontal = dcd.getParameterIndexByName("goniometerHorizontal");
int par_index_goniometerAxial = dcd.getParameterIndexByName("goniometerAxial");
for (int i = 0; i < fittingStrategy.parameterMode[ser_num].length; i++) {
fittingStrategy.parameterMode[ser_num][i] = FittingStrategy.modeFixed; // 0
}
fittingStrategy.parameterMode[ser_num][par_index_goniometerHorizontal] = FittingStrategy.modeIndividual; // 3
fittingStrategy.parameterMode[ser_num][par_index_goniometerAxial] = FittingStrategy.modeIndividual; // 3
boolean [] selection = fittingStrategy.selectAllImages(ser_num); // enable all images in series 0
for (int i=0;i<selection.length;i++) selection[i]=false;
selection[num_img]=true;
fittingStrategy.setImageSelection(ser_num,selection);
seriesNumber= ser_num; // start from 0;
initFittingSeries(false, filterForAll,ser_num); // will set this.currentVector, will build parameter map too
fittingStrategy.stopAfterThis[ser_num]=true;
stopEachStep= false;
stopEachSeries= false; // will not ask for confirmation after done
lambda = fittingStrategy.lambdas[ser_num];
boolean LMA_OK = false;
try {
LMA_OK = LevenbergMarquardt (false, false); // true); // skip dialog, dry run (no updates)
} catch (Exception e) {
// LMA failed - e.g. not enough points (Singular Matrix)
}
if (!LMA_OK) {
return false; // LMA did not converge
}
//save safe settings to run LMA manually (or save what was set)
seriesNumber= was_seriesNumber; // start from 0;
initFittingSeries (false,filterForAll,seriesNumber); // will set this.currentVector
stopEachSeries= true; // will not ask for confirmation after done
stopOnFailure= true;
lambda= fittingStrategy.lambdas[seriesNumber];
return true;
}
......
......@@ -2470,10 +2470,23 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
if (useImages) {
fromToImages[0]= (int) gd.getNextNumber();
fromToImages[1]= (int) gd.getNextNumber();
for (int i =0; i<this.distortionCalibrationData.getNumImages();i++)
if ((allImages || this.distortionCalibrationData.gIP[i].enabled) && (i>=fromToImages[0]) && (i<=fromToImages[1])){
this.selectedImages[numSeries][i]=gd.getNextBoolean();
for (int i =0; i<this.distortionCalibrationData.getNumImages();i++) {
// if ((allImages || this.distortionCalibrationData.gIP[i].enabled) && (i>=fromToImages[0]) && (i<=fromToImages[1])){
// this.selectedImages[numSeries][i]=gd.getNextBoolean();
// }
if ((i>=fromToImages[0]) && (i<=fromToImages[1])){
if (allImages || this.distortionCalibrationData.gIP[i].enabled) {
this.selectedImages[numSeries][i]=gd.getNextBoolean();
} else {
this.selectedImages[numSeries][i]=false; // unselect stray non-shown images
}
}
}
if (allImages) enableDisableSelected=gd.getNextBoolean();
this.masterImages[numSeries]=(int) gd.getNextNumber();
if (this.masterImages[numSeries]<0)this.masterImages[numSeries]=0;
......
......@@ -7074,6 +7074,10 @@ public class MatchSimulatedPattern {
coeff[0][2]=SMU;
coeff[1][2]=SMV;
} else {
if (this.debugLevel>0) {
System.out.println("coeff == null");
}
}
return coeff;
}
......@@ -7589,7 +7593,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
double [][] pointersXYUV,
boolean removeOutOfGridPointers, //
double [][][] hintGrid, // predicted grid array (or null)
double hintGridTolerance, // alllowed mismatch (fraction of period) or 0 - orientation only
double hintGridTolerance, // allowed mismatch (fraction of period) or 0 - orientation only
int global_debug_level, // DEBUG_LEVEL
boolean noMessageBoxes
){
......@@ -7602,7 +7606,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
}
int acalibrated=0;
double [][] gridMatchCoeff=null;
double searchAround=20.0; // how far to look for the grid node
double searchAround=50; // 20.0; // how far to look for the grid node
int gridRotation=-1; //undefined
int [] iGridTranslateUV=null; // translate UV grid by these integer numbers
if (hintGrid!=null){
......@@ -7612,7 +7616,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
gridRotation=matrixToRot(gridMatchCoeff);
this.debugLevel=global_debug_level;
int [][] iGridMatchCoeff=gridMatrixApproximate(gridMatchCoeff);
if (global_debug_level>1){
if (global_debug_level > 0){
System.out.println("gridMatchCoeff[0]={"+IJ.d2s(gridMatchCoeff[0][0],5)+", "+IJ.d2s(gridMatchCoeff[0][1],5)+", "+IJ.d2s(gridMatchCoeff[0][2],5)+"}");
System.out.println("gridMatchCoeff[1]={"+IJ.d2s(gridMatchCoeff[1][0],5)+", "+IJ.d2s(gridMatchCoeff[1][1],5)+", "+IJ.d2s(gridMatchCoeff[1][2],5)+"}");
System.out.println("gridRotation="+gridRotation);
......@@ -7624,12 +7628,13 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
// hintGridTolerance==0 - do not try to determine shift from the hint (not reliable yet)
if (hintGridTolerance>0) {
if (worstGridMatchTranslate(gridMatchCoeff)<=hintGridTolerance){ // convert to pixels from halfperiods (or just chnage definition of hintGridTolerance)
if (global_debug_level>1) System.out.println("worstGridMatchTranslate(gridMatchCoeff)= "+worstGridMatchTranslate(gridMatchCoeff)+", hintGridTolerance="+hintGridTolerance);
if (global_debug_level>0) System.out.println("worstGridMatchTranslate(gridMatchCoeff)= "+worstGridMatchTranslate(gridMatchCoeff)+", hintGridTolerance="+hintGridTolerance);
iGridTranslateUV=new int[2];
iGridTranslateUV[0]=iGridMatchCoeff[0][2];
iGridTranslateUV[1]=iGridMatchCoeff[1][2];
} else {
if (global_debug_level>1) System.out.println("*** Warning: combineGridCalibration() failed, worstGridMatchTranslate(gridMatchCoeff)= "+worstGridMatchTranslate(gridMatchCoeff)+", hintGridTolerance="+hintGridTolerance);
if (global_debug_level>0) System.out.println("*** Warning: combineGridCalibration() failed, worstGridMatchTranslate(gridMatchCoeff)= "+
worstGridMatchTranslate(gridMatchCoeff)+", hintGridTolerance="+hintGridTolerance);
return -1;
}
}
......@@ -8720,7 +8725,7 @@ y=xy0[1] + dU*deltaUV[0]*(xy1[1]-xy0[1])+dV*deltaUV[1]*(xy2[1]-xy0[1])
distUV[0]=reReMap[0][0]*uv[i][0]+reReMap[0][1]*uv[i][1]+reReMap[0][2]-xyuv[i][2];
distUV[1]=reReMap[1][0]*uv[i][0]+reReMap[1][1]*uv[i][1]+reReMap[1][2]-xyuv[i][3];
dist=Math.sqrt(distUV[0]*distUV[0]+distUV[1]*distUV[1]);
if (debugLevel>1){
if (debugLevel > 0){ // 1) {
System.out.println("Laser spot #"+i+", distance from predicted ="+ IJ.d2s(dist,3)+" ("+IJ.d2s(200*dist,3)+
"% of cell radius), du="+IJ.d2s(distUV[0],3)+", dv="+IJ.d2s(distUV[1],3));
}
......
......@@ -776,7 +776,7 @@ import ij.io.Opener;
corn[2] = getXYZM(iu, iv + 1, verbose, station);
corn[3] = getXYZM(iu + 1, iv + 1, verbose, station);
if ((corn[0] == null) || (corn[1] == null) || (corn[2] == null) || (corn[3] == null)) {
System.out.println("Optical axis outside of te grid: TODO: modify getXYZM() to handle!");
System.out.println("Optical axis outside of the grid: TODO: modify getXYZM() to handle!");
return null;
}
double [] rslt_xyz = new double[3];
......
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