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

working on dual-modal calibration

parent 7b892871
Loading
Loading
Loading
Loading
+79 −25
Original line number Original line Diff line number Diff line
@@ -6015,7 +6015,7 @@ if (MORE_BUTTONS) {
    				LASER_POINTERS, // MatchSimulatedPattern.LaserPointer laserPointer, // LaserPointer object that specifies actual laser poiners on the target
    				LASER_POINTERS, // MatchSimulatedPattern.LaserPointer laserPointer, // LaserPointer object that specifies actual laser poiners on the target
    				DISTORTION_PROCESS_CONFIGURATION.removeOutOfGridPointers, // boolean removeOutOfGridPointers,
    				DISTORTION_PROCESS_CONFIGURATION.removeOutOfGridPointers, // boolean removeOutOfGridPointers,
    				(useHintTolerance?hintGridTolerance:0.0),                   //double  hintGridTolerance, // alllowed mismatch (fraction of period) or 0 - orientation only
    				(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,
    				ignoreLaserPointers,
    				processBlind,
    				processBlind,
    				imageNumber,
    				imageNumber,
@@ -9546,7 +9546,7 @@ if (MORE_BUTTONS) {
/* ======================================================================== */
/* ======================================================================== */
	if       (label.equals("Grid offset")) {
	if       (label.equals("Grid offset")) {
		DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
		DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
		offsetGrids(0, 0, null);
		offsetGrids(0, 0, null, null);
		return;
		return;
	}
	}
/* ======================================================================== */
/* ======================================================================== */
@@ -9590,14 +9590,17 @@ if (MORE_BUTTONS) {
		boolean use_lma =     true;
		boolean use_lma =     true;
		GenericDialog gd = new GenericDialog("Initial alignment of the secondary camera to the reference one");
		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"+
//		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"+
//		"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)");
				"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 start", min_set, 0);
		gd.addNumericField("Image set last",  max_set, 0);
		gd.addNumericField("Image set last",  max_set, 0);
		gd.addCheckbox("Adjust EO (reference) sensors", adjust_eo);
		gd.addCheckbox("Adjust EO (reference) sensors", adjust_eo);
		gd.addCheckbox("Adjust LWIR (target) sensors", adjust_lwir);
		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();
		gd.showDialog();
		if (gd.wasCanceled()) return false;
		if (gd.wasCanceled()) return false;
		min_set = (int) gd.getNextNumber();
		min_set = (int) gd.getNextNumber();
@@ -9626,10 +9629,14 @@ if (MORE_BUTTONS) {
       							continue;
       							continue;
       						}
       						}
       					}
       					}
       					double [] stats = new double [3];
       					int [] uvr = LENS_DISTORTIONS. findImageGridOffset(
       					int [] uvr = LENS_DISTORTIONS. findImageGridOffset(
       							num_img,
       							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
       							true,     // boolean even, For first time - use parameter and parity of uv_rot
       							PATTERN_PARAMETERS);
       							PATTERN_PARAMETERS,
       							stats); // rms, dU, dV
       					if ((uvr != null) && ((uvr[0] != 0) || (uvr[1] != 0))) {
       					if ((uvr != null) && ((uvr[0] != 0) || (uvr[1] != 0))) {
       						int [] uv_shift_rot = {uvr[0],uvr[1],0};
       						int [] uv_shift_rot = {uvr[0],uvr[1],0};
       						//						int [] new_uv_shift_rots =
       						//						int [] new_uv_shift_rots =
@@ -9639,6 +9646,8 @@ if (MORE_BUTTONS) {
       								PATTERN_PARAMETERS);
       								PATTERN_PARAMETERS);
       						if (DEBUG_LEVEL > 0) {
       						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+"): 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;
       	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) {
		if (LENS_DISTORTIONS == null) {
			System.out.println("LENS_DISTORTIONS is null");
			System.out.println("LENS_DISTORTIONS is null");
			return false;
			return false;
@@ -9695,8 +9704,16 @@ if (MORE_BUTTONS) {
		String [] choices_nolwir = {"-- please select --","Image number","Image set number"};
		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_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;
		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");
		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: ",
		gd. addChoice("Next number is: ",
				choices,
				choices,
				choices[ichoice]);
				choices[ichoice]);
@@ -9705,6 +9722,10 @@ if (MORE_BUTTONS) {
		if (has_lwir) {
		if (has_lwir) {
			gd.addCheckbox    ("Auto from EO grid (calculatre from EO even if the requested image is LWIR)", false); //true
			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 U",     uv_shift_rot[0], 0);
		gd.addNumericField("Grid offset V",     uv_shift_rot[1], 0);
		gd.addNumericField("Grid offset V",     uv_shift_rot[1], 0);
		gd.addNumericField("Grid offset Rot",   uv_shift_rot[2], 0);
		gd.addNumericField("Grid offset Rot",   uv_shift_rot[2], 0);
@@ -9712,17 +9733,24 @@ if (MORE_BUTTONS) {
		if (gd.wasCanceled()) return false;
		if (gd.wasCanceled()) return false;
		ichoice = gd.getNextChoiceIndex();
		ichoice = gd.getNextChoiceIndex();
		inum = (int) gd.getNextNumber();
		inum = (int) gd.getNextNumber();
		boolean was_auto = auto;
		auto = gd.getNextBoolean();
		auto = gd.getNextBoolean();
		boolean auto_from_EO=false;
		boolean auto_from_EO=false;
		if (has_lwir) {
		if (has_lwir) {
			auto_from_EO = gd.getNextBoolean();
			auto_from_EO = gd.getNextBoolean();
		}
		}
		readjust =  false;
		if (!was_auto) {
			readjust =      gd.getNextBoolean();
		}
		uv_shift_rot[0] =  (int) gd.getNextNumber();
		uv_shift_rot[0] =  (int) gd.getNextNumber();
		uv_shift_rot[1] =  (int) gd.getNextNumber();
		uv_shift_rot[1] =  (int) gd.getNextNumber();
		uv_shift_rot[2] =  (int) gd.getNextNumber();
		uv_shift_rot[2] =  (int) gd.getNextNumber();
		if (ichoice == 0) {
		if (ichoice == 0) {
			return offsetGrids(ichoice, inum, uv_shift_rot);
			return offsetGrids(ichoice, inum, uv_shift_rot, msg);
		}
		}
		int ichoicemod = ichoice;
		int ichoicemod = ichoice;
		if (auto && auto_from_EO) {
		if (auto && auto_from_EO) {
@@ -9766,21 +9794,24 @@ if (MORE_BUTTONS) {
			// find first enabled image
			// find first enabled image
			for (int n:img_nums) {
			for (int n:img_nums) {
				if (n >= 0) {
				if (n >= 0) {
					double [] stats = new double[3]; // rms and 2 errors, null OK
					int [] auto_uvr = LENS_DISTORTIONS.findImageGridOffset( // null for now
					int [] auto_uvr = LENS_DISTORTIONS.findImageGridOffset( // null for now
							n,
   							n,  // image number to use for fitting (only one)
							true, // boolean even,
   				    		-1,       // use last series int     ser_num, // number of series to reprogram
							PATTERN_PARAMETERS); // PatternParameters patternParameters)
   				    		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
//					int [] auto_uvr = dcd. suggestOffset (
   							PATTERN_PARAMETERS,
//			        		n,    // int num_img,
   							stats);
//			        		true, // boolean non_estimated,
					if (auto_uvr != null) {
//			        		true, // boolean even,
						String stats_msg = String.format("Fitting errors: LMA RMS = %7.4f, dU = %6.3f, dV = %6.3f", stats[0], stats[1], stats[2]);
//			        		PATTERN_PARAMETERS); // PatternParameters patternParameters)
						return offsetGrids(ichoice, inum, auto_uvr, stats_msg);
					return offsetGrids(ichoice, inum, auto_uvr);
					} 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][];
		int [][] new_uv_shift_rots = new int [img_nums.length][];
		for (int i = 0; i < img_nums.length; i++) if (img_nums[i] >=0) {
		for (int i = 0; i < img_nums.length; i++) if (img_nums[i] >=0) {
@@ -9798,6 +9829,20 @@ if (MORE_BUTTONS) {
				System.out.println("<null>");
				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;
		return true;
	}
	}
@@ -9821,8 +9866,10 @@ if (MORE_BUTTONS) {
	    gd.showDialog();
	    gd.showDialog();
	    if (gd.wasCanceled()) return false;
	    if (gd.wasCanceled()) return false;
	    numStations= (int) gd.getNextNumber();
	    numStations= (int) gd.getNextNumber();
		String [] grid_extensions={".tif",".tiff"};
//		String [] grid_extensions={".tif",".tiff"};
		String [] src_extensions={".tif",".tiff"};
//		String [] src_extensions={".tif",".tiff"};
		String [] grid_extensions={".tiff"};
		String [] src_extensions={".tiff"};
		MultipleExtensionsFileFilter gridFilter =
		MultipleExtensionsFileFilter gridFilter =
			new MultipleExtensionsFileFilter("grid",grid_extensions,"Calibrated grid files");
			new MultipleExtensionsFileFilter("grid",grid_extensions,"Calibrated grid files");
		MultipleExtensionsFileFilter sourceFilter =
		MultipleExtensionsFileFilter sourceFilter =
@@ -9859,6 +9906,13 @@ if (MORE_BUTTONS) {
	    		int num_match = files[nFile].list(gridFilter).length;
	    		int num_match = files[nFile].list(gridFilter).length;
	    		if (num_match >= min_files) {
	    		if (num_match >= min_files) {
	    			filelist.add(files[nFile]);
	    			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("");
	    		}
	    		}
	    	}
	    	}
+131 −19
Original line number Original line Diff line number Diff line
@@ -1392,6 +1392,7 @@ import ij.text.TextWindow;


        // suggest set grid offset by comparing with known (by mark) set.
        // suggest set grid offset by comparing with known (by mark) set.
        // Wrong Grid UV should cause parallel shift - same Z, different XY
        // Wrong Grid UV should cause parallel shift - same Z, different XY
/*
        public int [] suggestOffset (
        public int [] suggestOffset (
        		int num_img,
        		int num_img,
        		boolean non_estimated,
        		boolean non_estimated,
@@ -1409,14 +1410,16 @@ import ij.text.TextWindow;
        			num_img,
        			num_img,
        			diff_xyz, // z is not used, may ne just[2]
        			diff_xyz, // z is not used, may ne just[2]
        			even,
        			even,
        			patternParameters);
        			patternParameters,
        			null);
        }
        }

*/
        public int [] suggestOffset (
        public int [] suggestOffset (
        		int num_img,
        		int num_img,
        		double [] diff_xyz, // This XYZ minus reference XYZ  z is not used, may be just[2]
        		double [] diff_xyz, // This XYZ minus reference XYZ  z is not used, may be just[2]
        		boolean even,
        		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 num_set = this.gIP[num_img].setNumber;
        	int station = this.gIS[num_set].stationNumber;
        	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}
        	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[0] = dUV[0] - idUV[0];
        		UV_err[1] = dUV[1] - idUV[1];
        		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;
        	return idUV;
        }
        }


@@ -2244,7 +2251,9 @@ import ij.text.TextWindow;
        		int stationNumber=this.gIP[i].getStationNumber();
        		int stationNumber=this.gIP[i].getStationNumber();
        		boolean enableNoLaser=this.eyesisCameraParameters.getEnableNoLaser(stationNumber,this.gIP[i].channel);
        		boolean enableNoLaser=this.eyesisCameraParameters.getEnableNoLaser(stationNumber,this.gIP[i].channel);
        		boolean wasEnabled=this.gIP[i].enabled;
        		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()) ||
///        		if (Double.isNaN(this.gIP[i].getGridPeriod()) ||
///        				((minGridPeriodFraction>0) && ((this.gIP[i].getGridPeriod()<minGridPeriod[stationNumber]) || (this.gIP[i].getGridPeriod()>maxGridPeriod[stationNumber])))){
///        				((minGridPeriodFraction>0) && ((this.gIP[i].getGridPeriod()<minGridPeriod[stationNumber]) || (this.gIP[i].getGridPeriod()>maxGridPeriod[stationNumber])))){
           		if (Double.isNaN(getEffectivePeriod(i)) ||
           		if (Double.isNaN(getEffectivePeriod(i)) ||
@@ -2431,6 +2440,7 @@ import ij.text.TextWindow;
        		}
        		}
        		if (bestRating>0){
        		if (bestRating>0){
        			EyesisSubCameraParameters esp = this.eyesisCameraParameters.eyesisSubCameras[stationNumber][bestChannel];
        			EyesisSubCameraParameters esp = this.eyesisCameraParameters.eyesisSubCameras[stationNumber][bestChannel];
        			System.out.println("Image number: "+this.gIS[i].imageSet[bestChannel].getImageNumber());
        			double [] uv_center = getGridUVfromXY(
        			double [] uv_center = getGridUVfromXY(
        	        		esp.px0, // final double px,
        	        		esp.px0, // final double px,
        	        		esp.py0, // final double py,
        	        		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
            				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 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;
            				double az_deg =   az/Math.PI*180;
            				if (this.debugLevel>0) {
            				if (this.debugLevel>0) {
            					System.out.println("Tilt = "+tilt_deg+", az = "+az_deg);
            					System.out.println("Tilt = "+tilt_deg+", az = "+az_deg);
            					System.out.print("");
            					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 =====");
            					}
            					}
            				}
            				}


        			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));



            			}
        			}
/*
 * Remove old method completely
        			if (overwriteAll || Double.isNaN(this.gIS[i].goniometerAxial)){
        				double subcam_heading = (esp.heading + (esp.cartesian? 0: esp.azimuth));
        				double subcam_heading = (esp.heading + (esp.cartesian? 0: esp.azimuth));
        				this.gIS[i].goniometerAxial=-subcam_heading;
        				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);
        				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) {
            			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.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(""+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 )){
        			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;
        				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);
        				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;
            			this.gIS[i].orientationEstimated=true;
@@ -2518,6 +2548,9 @@ import ij.text.TextWindow;
            				System.out.println(""+this.gIS[i].goniometerTilt+" ===== orientationEstimated==true =====");
            				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
         * 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)
         * Temporarily duplicate  image parameters from those of the set (should not be needed)
         * selectedImages will not be used
         * 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
        public void updateSetOrientation(boolean [] selectedImages){ // if selectedImages[] is not null will set orientationEstimated for unselected images
        	if (this.gIS==null){
        	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){
        public void updateSetOrientationOld(boolean [] selectedImages){
        	if (this.gIS==null){
        	if (this.gIS==null){
        		String msg="Image set is not initilaized";
        		String msg="Image set is not initilaized";
@@ -2751,6 +2831,11 @@ import ij.text.TextWindow;
        public double [] getImagesetTiltAxial(double timeStamp){
        public double [] getImagesetTiltAxial(double timeStamp){
        	int mAxial=1;     // m2
        	int mAxial=1;     // m2
        	int mHorizontal=2;// m3
        	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
        	// this is probably already set
        	for (int i=0;i<this.gIS.length;i++){
        	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());
        		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]);
            						(this.gIS[indexSecond].motors[mAxial]-this.gIS[indexClosest].motors[mAxial]);
            					// 06/06/2015 Andrey: Was missing setting estimated orientation. Was it a bug?
            					// 06/06/2015 Andrey: Was missing setting estimated orientation. Was it a bug?
                    			this.gIS[i].orientationEstimated=true;
                    			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)+") "+
                    					") 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)+")");
                    					"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.isNaN(this.gIS[j].interAxisAngle)) {
            					double d2=0;
            					double d2=0;
            					for (int k=0;k<this.gIS[j].motors.length;k++){
            					for (int k=0;k<this.gIS[j].motors.length;k++){
            						d2+=1.0*(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];
            						(this.gIS[j].motors[k]-this.gIS[i].motors[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)) {
            						if ((d2Min<0) || (d2Min>d2)) {
            							d2Min=d2;
            							d2Min=d2;
            							iBest=j;
            							iBest=j;
            						}
            						}
            					}
            					}
            				}
            				if (iBest < 0) {
            				if (iBest < 0) {
                				d2Min=-1;
                				d2Min=-1;
                				for (int j=0;j<this.gIS.length;j++) if ((j!=i) &&
                				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].goniometerAxial )  &&
                						!Double.isNaN(this.gIS[j].interAxisAngle)) {
                						!Double.isNaN(this.gIS[j].interAxisAngle)) {
                					double d2=0;
                					double d2=0;



                					for (int k=0;k<this.gIS[j].motors.length;k++){
                					for (int k=0;k<this.gIS[j].motors.length;k++){
                						d2+=1.0*(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];
                						(this.gIS[j].motors[k]-this.gIS[i].motors[k]);
                						d2 += da* da;
                					}
                					}
                					if ((d2Min<0) || (d2Min>d2)) {
                					if ((d2Min<0) || (d2Min>d2)) {
                						d2Min=d2;
                						d2Min=d2;
@@ -2998,8 +3108,8 @@ import ij.text.TextWindow;
                    						!Double.isNaN(this.gIS[j].interAxisAngle)) {
                    						!Double.isNaN(this.gIS[j].interAxisAngle)) {
                    					double d2=0;
                    					double d2=0;
                    					for (int k=0;k<this.gIS[j].motors.length;k++){
                    					for (int k=0;k<this.gIS[j].motors.length;k++){
                    						d2+=1.0*(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];
                    						(this.gIS[j].motors[k]-this.gIS[i].motors[k]);
                    						d2 += da* da;
                    					}
                    					}
                    					if ((d2Min<0) || (d2Min>d2)) {
                    					if ((d2Min<0) || (d2Min>d2)) {
                    						d2Min=d2;
                    						d2Min=d2;
@@ -3024,6 +3134,7 @@ import ij.text.TextWindow;
//        					this.gIS[iBest].interAxisAngle
//        					this.gIS[iBest].interAxisAngle
//        			};
//        			};
        			if (iBest!=i){
        			if (iBest!=i){

        				boolean usable_tilt  = (this.gIS[i].motors != null);
        				boolean usable_tilt  = (this.gIS[i].motors != null);
        				boolean usable_axial = usable_tilt && (this.gIS[i].getStationNumber() == this.gIS[iBest].getStationNumber());
        				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])/
        				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);
        				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)+
            			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].orientationEstimated=true;
//    					this.gIS[i].goniometerTilt= this.gIS[iBest].goniometerTilt;
//    					this.gIS[i].goniometerTilt= this.gIS[iBest].goniometerTilt;
//    					this.gIS[i].goniometerAxial=this.gIS[iBest].goniometerAxial;
//    					this.gIS[i].goniometerAxial=this.gIS[iBest].goniometerAxial;
+212 −79

File changed.

Preview size limit exceeded, changes collapsed.

+16 −3
Original line number Original line Diff line number Diff line
@@ -2470,9 +2470,22 @@ I* - special case when the subcamera is being adjusted/replaced. How to deal wit
			if (useImages) {
			if (useImages) {
				fromToImages[0]=    (int) gd.getNextNumber();
				fromToImages[0]=    (int) gd.getNextNumber();
				fromToImages[1]=    (int) gd.getNextNumber();
				fromToImages[1]=    (int) gd.getNextNumber();
				for (int i =0; i<this.distortionCalibrationData.getNumImages();i++)
				for (int i =0; i<this.distortionCalibrationData.getNumImages();i++) {
					if ((allImages || this.distortionCalibrationData.gIP[i].enabled) && (i>=fromToImages[0]) && (i<=fromToImages[1])){
//					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();
							this.selectedImages[numSeries][i]=gd.getNextBoolean();
						} else {
							this.selectedImages[numSeries][i]=false; // unselect stray non-shown images
						}



					}


				}
				}
				if (allImages) enableDisableSelected=gd.getNextBoolean();
				if (allImages) enableDisableSelected=gd.getNextBoolean();
				this.masterImages[numSeries]=(int) gd.getNextNumber();
				this.masterImages[numSeries]=(int) gd.getNextNumber();
+11 −6

File changed.

Preview size limit exceeded, changes collapsed.

Loading