Commit f62718b1 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Before Java 1.8

parent 3f43f2ac
Loading
Loading
Loading
Loading
+80 −0
Original line number Original line Diff line number Diff line
@@ -702,6 +702,7 @@ private Panel panel1,
			addButton("Inter Test",                 panelClt5, color_stop);
			addButton("Inter Test",                 panelClt5, color_stop);
			addButton("Inter Pairs",                panelClt5, color_process);
			addButton("Inter Pairs",                panelClt5, color_process);
			addButton("Inter LMA",                  panelClt5, color_stop);
			addButton("Inter LMA",                  panelClt5, color_stop);
			addButton("Inter Series",               panelClt5, color_process);
			plugInFrame.add(panelClt5);
			plugInFrame.add(panelClt5);
		}
		}


@@ -5116,6 +5117,14 @@ private Panel panel1,
        CLT_PARAMETERS.batch_run = true;
        CLT_PARAMETERS.batch_run = true;
        interPairsLMA();
        interPairsLMA();
    	return;
    	return;
/* ======================================================================== */
    } else if (label.equals("Inter Series")) {
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
        CLT_PARAMETERS.batch_run = true;
        interSeriesLMA();
    	return;
    	
/* ======================================================================== */
/* ======================================================================== */
    } else if (label.equals("Inter LMA")) {
    } else if (label.equals("Inter LMA")) {
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
@@ -6636,6 +6645,77 @@ private Panel panel1,
	}
	}
	
	
	
	
	public boolean interSeriesLMA() {
		long startTime=System.nanoTime();
		// load needed sensor and kernels files
		if (!prepareRigImages()) return false;
		String configPath=getSaveCongigPath();
		if (configPath.equals("ABORT")) return false;
		setAllProperties(PROPERTIES); // batchRig may save properties with the model. Extrinsics will be updated, others should be set here
		if (DEBUG_LEVEL > -2){
			System.out.println("++++++++++++++ Testing Interscene processing ++++++++++++++");
		}
		
		if (CLT_PARAMETERS.useGPU()) { // only init GPU instances if it is used
			if (GPU_TILE_PROCESSOR == null) {
				try {
					GPU_TILE_PROCESSOR = new GPUTileProcessor(CORRECTION_PARAMETERS.tile_processor_gpu);
				} catch (Exception e) {
					System.out.println("Failed to initialize GPU class");
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} //final int        debugLevel);
			}
			if (CLT_PARAMETERS.useGPU(false) && (QUAD_CLT != null) && (GPU_QUAD == null)) { // if GPU main is needed
				try {
					GPU_QUAD = GPU_TILE_PROCESSOR.new GpuQuad(
							QUAD_CLT,
							4,
							3);
				} catch (Exception e) {
					System.out.println("Failed to initialize GpuQuad class");
					// TODO Auto-generated catch block
					e.printStackTrace();
					return false;
				} //final int        debugLevel);
				QUAD_CLT.setGPU(GPU_QUAD);
			}
		}
		
		try {
			TWO_QUAD_CLT.interSeriesLMA(
					QUAD_CLT, // QuadCLT quadCLT_main,
//					QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
					CLT_PARAMETERS,  // EyesisCorrectionParameters.DCTParameters           dct_parameters,
					DEBAYER_PARAMETERS, //EyesisCorrectionParameters.DebayerParameters     debayerParameters,
					COLOR_PROC_PARAMETERS, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters,
					COLOR_PROC_PARAMETERS_AUX, //EyesisCorrectionParameters.ColorProcParameters colorProcParameters_aux,
					CHANNEL_GAINS_PARAMETERS, //CorrectionColorProc.ColorGainsParameters     channelGainParameters,
					RGB_PARAMETERS, //EyesisCorrectionParameters.RGBParameters             rgbParameters,
					EQUIRECTANGULAR_PARAMETERS, // EyesisCorrectionParameters.EquirectangularParameters equirectangularParameters,
					PROPERTIES,  // Properties                                           properties,
					true, // false, // boolean                                              reset_from_extrinsics,
					THREADS_MAX, //final int          threadsMax,  // maximal number of threads to launch
					UPDATE_STATUS, //final boolean    updateStatus,
					DEBUG_LEVEL);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} //final int        debugLevel);
		if (configPath!=null) {
			saveTimestampedProperties( // save config again
					configPath,      // full path or null
					null, // use as default directory if path==null
					true,
					PROPERTIES);
		}
		System.out.println("batchRig(): Processing finished at "+
				IJ.d2s(0.000000001*(System.nanoTime()-startTime),3)+" sec, --- Free memory="+
				Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
		return true;
	}
	
	
	
	
	


+39 −12
Original line number Original line Diff line number Diff line
@@ -233,6 +233,19 @@ public class ErsCorrection extends GeometryCorrection {
		return ers_watr_center_d2t;
		return ers_watr_center_d2t;
	}
	}


	public void setErsDt(
			double []    ers_xyz_dt,
			double []    ers_atr_dt) {
		this.ers_wxyz_center_dt = ers_xyz_dt;
		this.ers_watr_center_dt = ers_atr_dt;
	}
	public void setErsD2t(
			double []    ers_xyz_d2t,
			double []    ers_atr_d2t) {
		this.ers_wxyz_center_d2t = ers_xyz_d2t;
		this.ers_watr_center_d2t = ers_atr_d2t;
	}

	
	
	
	
	
	
@@ -286,7 +299,7 @@ public class ErsCorrection extends GeometryCorrection {
		String prefix = parent_prefix+SCENES_PREFIX+"_"; 
		String prefix = parent_prefix+SCENES_PREFIX+"_"; 
		for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
		for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
			String key = (String) e.nextElement();
			String key = (String) e.nextElement();
			if (key.startsWith(prefix)) {
			if (key.startsWith(prefix) && !key.endsWith("t")) { // _dt, _d2t
				timestamps.add(key.substring(prefix.length()));
				timestamps.add(key.substring(prefix.length()));
			}
			}
		}
		}
@@ -899,15 +912,6 @@ public class ErsCorrection extends GeometryCorrection {
			if (xyzw == null) {
			if (xyzw == null) {
				return null;
				return null;
			}
			}
			if (xyzw[3] == 0.0) { // infinity
			/*
				if (xyzw[2] > 0) {
					for (int i = 0; i < 3; i++) {
						xyzw[i] = -xyzw[i];	
					}
				}
				*/
			}
			if (xyzw[2] > 0) {
			if (xyzw[2] > 0) {
				return null; // can not match object behind the camera
				return null; // can not match object behind the camera
			}
			}
@@ -1914,6 +1918,23 @@ public class ErsCorrection extends GeometryCorrection {
		}
		}
	}
	}
	
	
	public static double [][] combineXYZATR(
			double [] reference_xyz,
			double [] reference_atr,
			double [] scene_xyz,
			double [] scene_atr)
	{
		Rotation   ref_rotation=   new Rotation(RotationOrder.YXZ, ROT_CONV, reference_atr[0],reference_atr[1],reference_atr[2]);
		Rotation   scene_rotation= new Rotation(RotationOrder.YXZ, ROT_CONV, scene_atr[0],    scene_atr[1],    scene_atr[2]);
		Vector3D   ref_offset =    new Vector3D(reference_xyz);
		Vector3D   scene_offset =  new Vector3D(scene_xyz);
		Vector3D   offset = ref_offset.add(ref_rotation.applyTo(scene_offset));
		Rotation   rotation = ref_rotation.applyTo(scene_rotation);
		double []  angles = rotation.getAngles(RotationOrder.YXZ, ROT_CONV);
		double []  xyz = offset.toArray();
		return new double[][] {xyz,angles};
		
	}
	
	
	public double [] getImageCoordinatesERS(
	public double [] getImageCoordinatesERS(
			double [] xyzw,
			double [] xyzw,
@@ -2155,6 +2176,9 @@ public class ErsCorrection extends GeometryCorrection {
		double[][] derivatives = new double[DP_NUM_PARS+1][]; // includes [0] - pXpYD vector
		double[][] derivatives = new double[DP_NUM_PARS+1][]; // includes [0] - pXpYD vector
		// scene pX, pY, Disparity
		// scene pX, pY, Disparity
		derivatives[0] = pXpYD_scene;
		derivatives[0] = pXpYD_scene;
		if (Double.isNaN(pXpYD_scene[0]) || Double.isNaN(pXpYD_scene[1]) || Double.isNaN(pXpYD_scene[2])) {
			return null;
		}
		// derivatives by the reference parameters, starting with /dpX, /dpY, /dd
		// derivatives by the reference parameters, starting with /dpX, /dpY, /dd
		for (int indx = DW_DPX; indx <= DW_DZ; indx++) {
		for (int indx = DW_DPX; indx <= DW_DZ; indx++) {
			int vindx = indx+1;
			int vindx = indx+1;
@@ -2167,6 +2191,9 @@ public class ErsCorrection extends GeometryCorrection {
			} else {
			} else {
				derivatives[vindx] = matrixTimesVector(dpscene_dxyz, reference_vectors[vindx]).toArray();
				derivatives[vindx] = matrixTimesVector(dpscene_dxyz, reference_vectors[vindx]).toArray();
			}
			}
			if (Double.isNaN(derivatives[vindx][0]) || Double.isNaN(derivatives[vindx][1]) || Double.isNaN(derivatives[vindx][2])) {
				return null;
			}
		}
		}
		for (int indx = DP_DSVAZ; indx < DP_NUM_PARS; indx++) { // 15,16, ...
		for (int indx = DP_DSVAZ; indx < DP_NUM_PARS; indx++) { // 15,16, ...
			int indx_out = indx+1; // 16, 17,
			int indx_out = indx+1; // 16, 17,
@@ -2216,7 +2243,7 @@ public class ErsCorrection extends GeometryCorrection {
		double pYcd = pXpYD[1] - 0.5 * this.pixelCorrectionHeight;
		double pYcd = pXpYD[1] - 0.5 * this.pixelCorrectionHeight;
		double r_scale = 0.001 * this.pixelSize / this.distortionRadius;
		double r_scale = 0.001 * this.pixelSize / this.distortionRadius;
		double rDn =    Math.sqrt(pXcd*pXcd + pYcd*pYcd) * r_scale; // relative to distortion radius
		double rDn =    Math.sqrt(pXcd*pXcd + pYcd*pYcd) * r_scale; // relative to distortion radius
		double rND2RD = correctDistortions?(getRByRDist(rDn, false)): 1.0;
		double rND2RD = correctDistortions?(getRByRDist(rDn, false)): 1.0; // NaN
		// rD - in mm
		// rD - in mm
//		double rD = rDn * this.distortionRadius; // Math.sqrt(pXcd*pXcd + pYcd*pYcd)*0.001*this.pixelSize; // distorted radius in a virtual center camera
//		double rD = rDn * this.distortionRadius; // Math.sqrt(pXcd*pXcd + pYcd*pYcd)*0.001*this.pixelSize; // distorted radius in a virtual center camera
		// pXc, pYc - in pixels
		// pXc, pYc - in pixels
+4 −2
Original line number Original line Diff line number Diff line
@@ -4403,13 +4403,15 @@ matrix([[-0.125, -0.125, 0.125, 0.125, -0.125, 0.125, -0. , -0. , -0.
		}
		}
		if (rDist < 0) { // not used in lwir
		if (rDist < 0) { // not used in lwir
			if (debug)System.out.println("getRByRDist("+IJ.d2s(rDist,3)+"): rDist < 0");
			if (debug)System.out.println("getRByRDist("+IJ.d2s(rDist,3)+"): rDist < 0");
			return Double.NaN;
			rDist=0.0; // Double.NaN;
		}
		}
		double findex = rDist/this.stepR;
		double findex = rDist/this.stepR;
		int index=(int) Math.floor(findex);
		int index=(int) Math.floor(findex);
		if (index>=(this.rByRDist.length-2)) { // not used in lwir
		if (index>=(this.rByRDist.length-2)) { // not used in lwir
			if (debug) System.out.println("getRByRDist("+IJ.d2s(rDist,3)+"): index="+index+">="+(this.rByRDist.length-2));
			if (debug) System.out.println("getRByRDist("+IJ.d2s(rDist,3)+"): index="+index+">="+(this.rByRDist.length-2));
			return Double.NaN;
			// happens for 3D points far offcenter, should be filtered out by FoV
			return this.rByRDist.length-1;
//			return Double.NaN;
		}
		}
		double mu = findex - index;
		double mu = findex - index;
		double mu2 = mu * mu;
		double mu2 = mu * mu;
+25 −9
Original line number Original line Diff line number Diff line
@@ -176,7 +176,7 @@ public class IntersceneLma {
				scenesCLT[1],      // final QuadCLT     scene_QuadClt,
				scenesCLT[1],      // final QuadCLT     scene_QuadClt,
				scenesCLT[0],      // final QuadCLT     reference_QuadClt,
				scenesCLT[0],      // final QuadCLT     reference_QuadClt,
				debug_level);      // final int         debug_level)
				debug_level);      // final int         debug_level)
		double [][] wjtj = getWJtJlambda( // USED in lwir
		double [][] wjtj = getWJtJlambda( // USED in lwir all NAN
				0.0,               // final double      lambda,
				0.0,               // final double      lambda,
				last_jt);               // final double [][] jt)
				last_jt);               // final double [][] jt)
		for (int i = 0; i < parameters_vector.length; i++) {
		for (int i = 0; i < parameters_vector.length; i++) {
@@ -252,7 +252,7 @@ public class IntersceneLma {
			}
			}


		} else { // improved over initial ?
		} else { // improved over initial ?
			if (last_rms[0] < initial_rms[0]) {
			if (last_rms[0] < initial_rms[0]) { // NaN
				rslt[0] = true;
				rslt[0] = true;
				if (debug_level > 0) System.out.println("Step "+iter+": Failed to converge, but result improved over initial");
				if (debug_level > 0) System.out.println("Step "+iter+": Failed to converge, but result improved over initial");
			} else {
			} else {
@@ -270,6 +270,16 @@ public class IntersceneLma {
				}
				}
			}
			}
		}
		}
		if ((debug_level > -2) && !rslt[0]) { // failed
			if ((debug_level > 1) || (iter == 1) || last_run) {
				System.out.println("LMA failed on iteration = "+iter);
				String [] lines = printOldNew(true); // boolean allvectors)
				for (String line : lines) {
					System.out.println(line);
				}
			}
			System.out.println();
		}


		return rslt[0]? iter : -1;
		return rslt[0]? iter : -1;
	}
	}
@@ -487,6 +497,9 @@ public class IntersceneLma {
		double full_weight = asum_weight.sum();
		double full_weight = asum_weight.sum();
		pure_weight = s_pure/full_weight;
		pure_weight = s_pure/full_weight;
		final double s = 1.0/asum_weight.sum();
		final double s = 1.0/asum_weight.sum();
		if (Double.isNaN(s)) {
			System.out.println("normalizeWeights(): s == NaN");
		}
		ai.set(0);
		ai.set(0);
		for (int ithread = 0; ithread < threads.length; ithread++) {
		for (int ithread = 0; ithread < threads.length; ithread++) {
			threads[ithread] = new Thread() {
			threads[ithread] = new Thread() {
@@ -578,6 +591,8 @@ public class IntersceneLma {
									scene_rot_matrix,            // Matrix    scene_rot_matrix,        // single rotation (direct) matrix for the scene
									scene_rot_matrix,            // Matrix    scene_rot_matrix,        // single rotation (direct) matrix for the scene
									debug_level);                // int debug_level);
									debug_level);                // int debug_level);
							if (deriv_params!= null) {
							if (deriv_params!= null) {
								boolean bad_tile = false;
								if (!bad_tile) {
									fx[2 * iMTile + 0] = deriv_params[0][0]; // pX
									fx[2 * iMTile + 0] = deriv_params[0][0]; // pX
									fx[2 * iMTile + 1] = deriv_params[0][1]; // pY
									fx[2 * iMTile + 1] = deriv_params[0][1]; // pY
									if (jt != null) {
									if (jt != null) {
@@ -591,6 +606,7 @@ public class IntersceneLma {
							}
							}
						}
						}
					}
					}
				}
			};
			};
		}		      
		}		      
		ImageDtt.startAndJoin(threads);
		ImageDtt.startAndJoin(threads);
Loading