Commit 99fcbcc4 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Debugging, IMU-ERS

parent bc3b706a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -763,7 +763,7 @@ public class CalibrationIllustration {
					try {
					try {
					    Files.createSymbolicLink(newLink, target);
					    Files.createSymbolicLink(newLink, target);
					} catch (IOException x) {
					} catch (IOException x) {
					    System.err.println(x);
					    System.out.println(x);
					} catch (UnsupportedOperationException x) {
					} catch (UnsupportedOperationException x) {
					    // Some file systems do not support symbolic links.
					    // Some file systems do not support symbolic links.
					    System.err.println(x);
					    System.err.println(x);
@@ -775,7 +775,7 @@ public class CalibrationIllustration {
		return true;
		return true;
	}
	}
	
	
	public int [] getStartEndTS(String p) {
	public static int [] getStartEndTS(String p) {
		int istart = p.lastIndexOf(Prefs.getFileSeparator());
		int istart = p.lastIndexOf(Prefs.getFileSeparator());
		if (istart < 0) {
		if (istart < 0) {
			istart = 0;
			istart = 0;
+5 −0
Original line number Original line Diff line number Diff line
@@ -267,6 +267,7 @@ public class EventLogger {
			byte [][] payload,
			byte [][] payload,
			int       debug_level) throws IOException // initialize to [2][] - will return a pair of byte arrays
			int       debug_level) throws IOException // initialize to [2][] - will return a pair of byte arrays
	{
	{
		int min_debug = 1; //-1 to enable
		// 1 find file with the first subpacket
		// 1 find file with the first subpacket
		int type = (EventLoggerFileInfo.REC_TYPE_GPS << 4) | EventLoggerFileInfo.REC_SUBTYPE_IMX5; // 0x18 - first subpacket
		int type = (EventLoggerFileInfo.REC_TYPE_GPS << 4) | EventLoggerFileInfo.REC_SUBTYPE_IMX5; // 0x18 - first subpacket
		int file_index_below = 0; // if ts_master is between the two files? use last of previous
		int file_index_below = 0; // if ts_master is between the two files? use last of previous
@@ -327,6 +328,10 @@ public class EventLogger {
		double ts_below = logger_files[file_index_below].getMasterTS(nrec_below); 
		double ts_below = logger_files[file_index_below].getMasterTS(nrec_below); 
		double ts_above = logger_files[file_index_above].getMasterTS(nrec_above);
		double ts_above = logger_files[file_index_above].getMasterTS(nrec_above);
		double frac = (ts_master - ts_below)/(ts_above - ts_below);
		double frac = (ts_master - ts_below)/(ts_above - ts_below);
		if ((debug_level >= min_debug) && (did == Imx5.DID_INS_2)) {
			System.out.println (String.format("%6d - %6d frac=%6.4f, ts_master = %17.6f, ts_below = %17.6f, ts_above = %17.6f",
					nrec_below, nrec_above, frac, ts_master, ts_below, ts_above));
		}
		
		
		// now read both byte arrays and set byte [][] payload
		// now read both byte arrays and set byte [][] payload
		EventLoggerFileInfo fileinfo_next_below =
		EventLoggerFileInfo fileinfo_next_below =
+6 −1
Original line number Original line Diff line number Diff line
@@ -130,9 +130,14 @@ public class EventLoggerFileInfo implements Comparable<EventLoggerFileInfo> {
			for (; (nrec > first_last_index[0]) && (nrec < first_last_index[1]); nrec += drec) {
			for (; (nrec > first_last_index[0]) && (nrec < first_last_index[1]); nrec += drec) {
				double ts_master_indx = getMasterTS(bb, nrec); 
				double ts_master_indx = getMasterTS(bb, nrec); 
				if (after?(ts_master_indx <= ts_master):(ts_master_indx > ts_master)) {
				if (after?(ts_master_indx <= ts_master):(ts_master_indx > ts_master)) {
					// still need to check type, as master timestamp may be in wrong order
					// Timestamp is frame start for images
					int [] full_type = getFullType(bb, nrec);
					if ((full_type != null) && (full_type[0] == type) && (full_type[1] == did)) {
						break search_opposite; // return nrec;
						break search_opposite; // return nrec;
					}
					}
				}
				}
			}
			System.out.println("getLastBeforeIndex(): could not find oppposite, ts_master="+ts_master+", after="+after);
			System.out.println("getLastBeforeIndex(): could not find oppposite, ts_master="+ts_master+", after="+after);
			return first_last_index[after ? 1 : 0]; // could not find
			return first_last_index[after ? 1 : 0]; // could not find
		}
		}
+2 −2
Original line number Original line Diff line number Diff line
@@ -194,8 +194,8 @@ public class ErsCorrection extends GeometryCorrection {
	public double [] ers_wxyz_center;     // world camera XYZ (meters) for the lens center (in camera coordinates, typically 0)
	public double [] ers_wxyz_center;     // world camera XYZ (meters) for the lens center (in camera coordinates, typically 0)
	public double [] ers_wxyz_center_dt;  // world camera Vx, Vy, Vz (m/s)
	public double [] ers_wxyz_center_dt;  // world camera Vx, Vy, Vz (m/s)
	public double [] ers_wxyz_center_d2t; // world camera Vx, Vy, Vz (m/s^2)
	public double [] ers_wxyz_center_d2t; // world camera Vx, Vy, Vz (m/s^2)
	public double [] ers_watr_center_dt;  // camera rotaions (az, tilt, roll in radians/s, corresponding to the frame center)
	public double [] ers_watr_center_dt;  // camera rotations (az, tilt, roll in radians/s, corresponding to the frame center)
	public double [] ers_watr_center_d2t; // camera rotaions (az, tilt, roll in radians/s, corresponding to the frame center)
	public double [] ers_watr_center_d2t; // camera rotations (az, tilt, roll in radians/s, corresponding to the frame center)
	
	
// absolute position and orientation of this camera in World coordinates	
// absolute position and orientation of this camera in World coordinates	
	public double []    camera_xyz = new double[3];  // camera center in world coordinates
	public double []    camera_xyz = new double[3];  // camera center in world coordinates
+123 −48
Original line number Original line Diff line number Diff line
@@ -200,7 +200,20 @@ public class Interscene {
			    debugLevel);                      // final int        debugLevel);
			    debugLevel);                      // final int        debugLevel);
// TODO: add {start,end} pointers to quadCLTs[cent_index]
// TODO: add {start,end} pointers to quadCLTs[cent_index]
// TODO: add pointer to center to ref_index
// TODO: add pointer to center to ref_index
		
// check quadCLTs[cent_index].dsi here		
		quadCLTs[cent_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
				set_channels[cent_index].set_name,
				clt_parameters,
				colorProcParameters, //
				threadsMax,
				debugLevel);
		quadCLTs[cent_index].setQuadClt(); // just in case ?
		// NOt needed?
//		quadCLTs[cent_index].setDSRBG(
//				clt_parameters, // CLTParameters  clt_parameters,
//				threadsMax,     // int            threadsMax,  // maximal number of threads to launch
//				updateStatus,   // boolean        updateStatus,
//				debugLevel);    // int            debugLevel)
		
		
		
		
		int [] start_ref_pointers2 = new int[2];
		int [] start_ref_pointers2 = new int[2];
@@ -220,7 +233,7 @@ public class Interscene {
		if (earliest_scene2 < 0) {
		if (earliest_scene2 < 0) {
			System.out.println("setInitialOrientationsIms() second half failed. Consider more graceful bail out.");
			System.out.println("setInitialOrientationsIms() second half failed. Consider more graceful bail out.");
			start_ref_pointers[0] = start_ref_pointers1[0];
			start_ref_pointers[0] = start_ref_pointers1[0];
			return cent_index;
			return earliest_scene2; // cent_index;
		}
		}
		// invert first half, reference to the cent_index, add to cent_index map, generate ref_index ponter and cent_index,
		// invert first half, reference to the cent_index, add to cent_index map, generate ref_index ponter and cent_index,
		// write config for both ref_index and cent_index scenes
		// write config for both ref_index and cent_index scenes
@@ -279,6 +292,8 @@ public class Interscene {
			final int                    debugLevel) {
			final int                    debugLevel) {
		double maximal_series_rms = 0.0;
		double maximal_series_rms = 0.0;
		double  min_ref_str =        clt_parameters.imp.min_ref_str;
		double  min_ref_str =        clt_parameters.imp.min_ref_str;
		boolean ref_need_lma =       clt_parameters.imp.ref_need_lma;
//		boolean ref_need_lma_combo = clt_parameters.imp.ref_need_lma_combo;
		double  min_ref_frac=     clt_parameters.imp.min_ref_frac;		
		double  min_ref_frac=     clt_parameters.imp.min_ref_frac;		
//    	int min_num_scenes =      clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it 
//    	int min_num_scenes =      clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it 
    	int max_num_scenes =      clt_parameters.imp.max_num_scenes; // cut longer series
    	int max_num_scenes =      clt_parameters.imp.max_num_scenes; // cut longer series
@@ -331,7 +346,8 @@ public class Interscene {
					false, // boolean use_combo,
					false, // boolean use_combo,
					min_ref_str,          // double min_strength,
					min_ref_str,          // double min_strength,
					min_ref_frac,         // double min_ref_frac,
					min_ref_frac,         // double min_ref_frac,
					true,         // boolean needs_lma);
					ref_need_lma,         // boolean needs_lma);
					true, // ref_need_lma_combo,   // boolean needs_lma_combo);
					reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
					reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
			if (reduced_strength[0] > 0) {
			if (reduced_strength[0] > 0) {
				use_lma_dsi = false; // too few points
				use_lma_dsi = false; // too few points
@@ -630,6 +646,7 @@ public class Interscene {
		int     avg_len	=                clt_parameters.imp.avg_len;
		int     avg_len	=                clt_parameters.imp.avg_len;
		double maximal_series_rms = 0.0;
		double maximal_series_rms = 0.0;
		double  min_ref_str =       clt_parameters.imp.min_ref_str;
		double  min_ref_str =       clt_parameters.imp.min_ref_str;
		boolean ref_need_lma =      clt_parameters.imp.ref_need_lma;
		double  min_ref_frac=       clt_parameters.imp.min_ref_frac;		
		double  min_ref_frac=       clt_parameters.imp.min_ref_frac;		
//    	int min_num_scenes =        clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it 
//    	int min_num_scenes =        clt_parameters.imp.min_num_scenes; // abandon series if there are less than this number of scenes in it 
    	int max_num_scenes =        clt_parameters.imp.max_num_scenes; // cut longer series
    	int max_num_scenes =        clt_parameters.imp.max_num_scenes; // cut longer series
@@ -673,7 +690,8 @@ public class Interscene {
					false, // boolean use_combo,
					false, // boolean use_combo,
					min_ref_str,   // double min_strength,
					min_ref_str,   // double min_strength,
					min_ref_frac,  // double min_ref_frac,
					min_ref_frac,  // double min_ref_frac,
					true,         // boolean needs_lma);
					ref_need_lma,  // boolean needs_lma);
					true,          // boolean needs_lma_combo);
					reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
					reduced_strength); // if not null will return >0 if had to reduce strength (no change if did not reduce)
			if (reduced_strength[0] > 0) {
			if (reduced_strength[0] > 0) {
				use_lma_dsi = false; // too few points
				use_lma_dsi = false; // too few points
@@ -976,6 +994,7 @@ public class Interscene {
    		QuadCLT []     quadCLTs,
    		QuadCLT []     quadCLTs,
    		int            ref_index,
    		int            ref_index,
    		int     []     range,
    		int     []     range,
    		int            ers_mode, // 0 - keep, 1 - set from velocity, 2 - set from IMS
    		boolean        test_motion_blur,
    		boolean        test_motion_blur,
			int            debugLevel)
			int            debugLevel)
	{ 
	{ 
@@ -1120,14 +1139,26 @@ public class Interscene {
        				scenes_xyzatr[nscene][1][0], scenes_xyzatr[nscene][1][1], scenes_xyzatr[nscene][1][2]));
        				scenes_xyzatr[nscene][1][0], scenes_xyzatr[nscene][1][1], scenes_xyzatr[nscene][1][2]));
        	}
        	}
        }
        }
        double [][][] dxyzatr_dt = OpticalFlow.getVelocitiesFromScenes(
        double [][][] dxyzatr_dt;
        switch (ers_mode) {
        case 1 : 
        	dxyzatr_dt = OpticalFlow.getVelocitiesFromScenes(
        			quadCLTs,        // QuadCLT []     scenes, // ordered by increasing timestamps
        			quadCLTs,        // QuadCLT []     scenes, // ordered by increasing timestamps
        			ref_index,
        			ref_index,
        			earliest_scene,  // int            start_scene,
        			earliest_scene,  // int            start_scene,
        			last_scene,       // int            end1_scene,
        			last_scene,       // int            end1_scene,
        			scenes_xyzatr,   // double [][][]  scenes_xyzatr,
        			scenes_xyzatr,   // double [][][]  scenes_xyzatr,
        			half_run_range); // double         half_run_range
        			half_run_range); // double         half_run_range
        	break;
        case 2: // read from ims
        default:
        	dxyzatr_dt = new double [quadCLTs.length][][];
        	for (int nscene = last_scene; nscene >= earliest_scene; nscene--) {
        		// read from map (ts)
        		// divide by dbg_scale_dt, so saved in map will match ERS, not *_dt (currently they are the same)
        	}        		


        }
    	if (debug_ers) {
    	if (debug_ers) {
    		System.out.println();
    		System.out.println();
    		for (int nscene = last_scene; nscene >= earliest_scene; nscene--) {
    		for (int nscene = last_scene; nscene >= earliest_scene; nscene--) {
@@ -1190,6 +1221,8 @@ public class Interscene {
					scaled_dxyzatr_dt[i][j] = dxyzatr_dt[nscene][i][j]* dbg_scale_dt[i][j];
					scaled_dxyzatr_dt[i][j] = dxyzatr_dt[nscene][i][j]* dbg_scale_dt[i][j];
				}
				}
			}
			}
			
			// **** Here *_dt is set!
			quadCLTs[nscene].getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!)
			quadCLTs[nscene].getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!)
					scaled_dxyzatr_dt[0], // (ers_use_xyz? dxyzatr_dt[nscene][0]: ZERO3), //, // dxyzatr_dt[nscene][0], // double []    ers_xyz_dt,
					scaled_dxyzatr_dt[0], // (ers_use_xyz? dxyzatr_dt[nscene][0]: ZERO3), //, // dxyzatr_dt[nscene][0], // double []    ers_xyz_dt,
					scaled_dxyzatr_dt[1]); // dxyzatr_dt[nscene][1]); // double []    ers_atr_dt)(ers_scene_original_xyz_dt);
					scaled_dxyzatr_dt[1]); // dxyzatr_dt[nscene][1]); // double []    ers_atr_dt)(ers_scene_original_xyz_dt);
@@ -1615,6 +1648,8 @@ public class Interscene {
		boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); //  -3; *********** Change to debug FPN correleation *** 
		boolean show_corr_fpn = (!clt_parameters.multiseq_run) && (debug_level > -1); //  -3; *********** Change to debug FPN correleation *** 
		
		
		int nlma = 0;
		int nlma = 0;
		// TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt before first run lma, restore on failure
		// it is saved to backup parameters when first lma run (nlma == 0),         // boolean           first_run,
		for (; nlma < clt_parameters.imp.max_cycles; nlma ++) {
		for (; nlma < clt_parameters.imp.max_cycles; nlma ++) {
			boolean near_important = nlma > 0;
			boolean near_important = nlma > 0;
			// FIXME: not re-calculating motion blur. Maybe do that after each parameter update?
			// FIXME: not re-calculating motion blur. Maybe do that after each parameter update?
@@ -1674,6 +1709,9 @@ public class Interscene {
					}
					}
				}
				}
			}
			}
			
			// update setting ers_scene
			
			if (disable_ers) {
			if (disable_ers) {
				param_select_mod = param_select.clone();
				param_select_mod = param_select.clone();
				for (int i:ErsCorrection.DP_ERS_INDICES) {
				for (int i:ErsCorrection.DP_ERS_INDICES) {
@@ -1682,9 +1720,11 @@ public class Interscene {
				// now just copy ers from the reference 
				// now just copy ers from the reference 
				ErsCorrection ers_ref =   reference_QuadClt.getErsCorrection();
				ErsCorrection ers_ref =   reference_QuadClt.getErsCorrection();
				ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
				ErsCorrection ers_scene = scene_QuadClt.getErsCorrection();
				// when disabled - scene ers from the same as reference one
				ers_scene.ers_watr_center_dt = ers_ref.ers_watr_center_dt.clone();
				ers_scene.ers_watr_center_dt = ers_ref.ers_watr_center_dt.clone();
				ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone();
				ers_scene.ers_wxyz_center_dt = ers_ref.ers_wxyz_center_dt.clone();
			}
			}
			// TODO: save ers_scene.ers_watr_center_dt and ers_scene.ers_wxyz_center_dt
			intersceneLma.prepareLMA(
			intersceneLma.prepareLMA(
					camera_xyz0,         // final double []   scene_xyz0,     // camera center in world coordinates (or null to use instance)
					camera_xyz0,         // final double []   scene_xyz0,     // camera center in world coordinates (or null to use instance)
					camera_atr0,         // final double []   scene_atr0,     // camera orientation relative to world frame (or null to use instance)
					camera_atr0,         // final double []   scene_atr0,     // camera orientation relative to world frame (or null to use instance)
@@ -1713,6 +1753,10 @@ public class Interscene {
				if (fail_reason != null) {
				if (fail_reason != null) {
					fail_reason[0]=FAIL_REASON_LMA;
					fail_reason[0]=FAIL_REASON_LMA;
				}
				}
				// TODO: Restore *_dt from backup_parameters_full
				scene_QuadClt.getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!)
						intersceneLma.getSceneERSXYZ(true), // true for initial values
						intersceneLma.getSceneERSATR(true)); // true for initial values
				return null;
				return null;
			}
			}
			camera_xyz0 = intersceneLma.getSceneXYZ(false); // true for initial values
			camera_xyz0 = intersceneLma.getSceneXYZ(false); // true for initial values
@@ -1723,6 +1767,14 @@ public class Interscene {
					(diffs_xyz[0] < clt_parameters.imp.exit_change_xyz)) {
					(diffs_xyz[0] < clt_parameters.imp.exit_change_xyz)) {
				break;
				break;
			}
			}
			// TODO: Is ers_scene.ers_wxyz_center_dt updated after running LMA?
			// No, update it here !
			scene_QuadClt.getErsCorrection().setErsDt( // set for ref also (should be set before non-ref!)
					intersceneLma.getSceneERSXYZ(false), // true for initial values
					intersceneLma.getSceneERSATR(false)); // true for initial values
					
//					scaled_dxyzatr_dt[0], // (ers_use_xyz? dxyzatr_dt[nscene][0]: ZERO3), //, // dxyzatr_dt[nscene][0], // double []    ers_xyz_dt,
//					scaled_dxyzatr_dt[1]); // dxyzatr_dt[nscene][1]); // double []    ers_atr_dt)(ers_scene_original_xyz_dt);
		}
		}
		if (show_corr_fpn && (debug_level > -1)) { // now not needed, restore if needed
		if (show_corr_fpn && (debug_level > -1)) { // now not needed, restore if needed
//			int num_components = intersceneLma.getNumComponents();
//			int num_components = intersceneLma.getNumComponents();
@@ -3676,7 +3728,7 @@ public class Interscene {
		ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
		ref_scene.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU) and Geometry
		return tp_tasks_ref;
		return tp_tasks_ref;
    }
    }
	
	@Deprecated
	public static void generateEgomotionTable0(
	public static void generateEgomotionTable0(
			CLTParameters  clt_parameters,
			CLTParameters  clt_parameters,
			QuadCLT []     quadCLTs,
			QuadCLT []     quadCLTs,
@@ -4019,9 +4071,33 @@ public class Interscene {
			String         comment) {
			String         comment) {
		double [] ims_ortho =     clt_parameters.imp.ims_ortho;
		double [] ims_ortho =     clt_parameters.imp.ims_ortho;
		double [] ims_mount_atr = clt_parameters.imp.getImsMountATR(); // converts to radians
		double [] ims_mount_atr = clt_parameters.imp.getImsMountATR(); // converts to radians
		QuadCLT ref_scene = quadCLTs[ref_index];
		ErsCorrection ers_reference = ref_scene.getErsCorrection();
		int num_processed = 0;
		double [][][] scenes_xyzatr =    new double [quadCLTs.length][][];
		double [][][] scenes_xyzatr_dt = new double [quadCLTs.length][][];
		
		for (int nscene = earliest_scene; nscene < quadCLTs.length; nscene++) {
			QuadCLT scene = quadCLTs[nscene];
			if (nscene == ref_index) {
				scenes_xyzatr[nscene] =    new double[2][3];
				scenes_xyzatr_dt[nscene] = new double[2][3];
			} else {
				String ts = scene.getImageName();
				scenes_xyzatr[nscene] =    new double [][] {ers_reference.getSceneXYZ(ts),ers_reference.getSceneATR(ts)};
				scenes_xyzatr_dt[nscene] = ers_reference.getSceneErsXYZATR_dt(ts);
				if (scenes_xyzatr[nscene] != null) {
					num_processed++;
				}
			}
		}
		boolean use_processed = num_processed > 1;

//    	double [] quat_ortho = {0.5, 0.5, -0.5, 0.5}; // approximate IMU orientation
//    	double [] quat_ortho = {0.5, 0.5, -0.5, 0.5}; // approximate IMU orientation
		String header_img="#\ttimestamp\tx(m)\ty(m)\tz(m)\ta(rad)\ttilt(rad)\troll(rad)"+
		String header_ts="#\ttimestamp";
			"\tVx(m/s)\tVy(m/s)\tVz(m/s)\tVa(rad/s)\tVt(rad/s)\tVr(rad/s)";
		String header_img="\tx(m)\ty(m)\tz(m)\ta(rad)\ttilt(rad)\troll(rad)"+
			"\tVx(m/s)\tVy(m/s)\tVz(m/s)\tVa(rad/s)\tVt(rad/s)\tVr(rad/s)"+
			"\tEVx(m/s)\tEVy(m/s)\tEVz(m/s)\tEVa(rad/s)\tEVt(rad/s)\tEVr(rad/s)";
		String header_ins1="\ttow\ttheta0\ttheta1\ttheta2\tu(m/s)\tv(m/s)\tw(m/s)"+
		String header_ins1="\ttow\ttheta0\ttheta1\ttheta2\tu(m/s)\tv(m/s)\tw(m/s)"+
			"\tlat\tlong\talt\tned0\tned1\tned2";
			"\tlat\tlong\talt\tned0\tned1\tned2";
		String header_ins2="\ttow\tqn2b0\tqn2b1\tqn2b2\tqn2b3\tu(m/s)\tv(m/s)\tw(m/s)\tlat\tlong\talt";
		String header_ins2="\ttow\tqn2b0\tqn2b1\tqn2b2\tqn2b3\tu(m/s)\tv(m/s)\tw(m/s)\tlat\tlong\talt";
@@ -4035,27 +4111,19 @@ public class Interscene {
		String header_pimu="\to0\to1\to2\ta0\ta1\ta2";
		String header_pimu="\to0\to1\to2\ta0\ta1\ta2";
		
		
		
		
		String header = header_img+header_ins1+header_ins2+header_ins2_extra+header_pimu;
		String header = header_ts+(use_processed?header_img:"")+header_ins1+header_ins2+header_ins2_extra+header_pimu;
		
		StringBuffer sb = new StringBuffer();
		StringBuffer sb = new StringBuffer();
		QuadCLT ref_scene = quadCLTs[ref_index];
		double [][][] dxyzatr_dt = null;
		ErsCorrection ers_reference = ref_scene.getErsCorrection();
		if (use_processed) {
		double [][][] scenes_xyzatr = new double [quadCLTs.length][][];
			dxyzatr_dt = OpticalFlow.getVelocitiesFromScenes(
		for (int nscene = earliest_scene; nscene < quadCLTs.length; nscene++) {
			QuadCLT scene = quadCLTs[nscene];
			if (nscene == ref_index) {
				scenes_xyzatr[nscene] = new double[2][3];
			} else {
				String ts = scene.getImageName();
				scenes_xyzatr[nscene] = new double [][] {ers_reference.getSceneXYZ(ts),ers_reference.getSceneATR(ts)};
			}
		}
		double [][][] dxyzatr_dt = OpticalFlow.getVelocitiesFromScenes(
					quadCLTs,          // QuadCLT []     scenes, // ordered by increasing timestamps
					quadCLTs,          // QuadCLT []     scenes, // ordered by increasing timestamps
					ref_index,
					ref_index,
					earliest_scene,    // int            start_scene,
					earliest_scene,    // int            start_scene,
					quadCLTs.length-1, // int            end1_scene,
					quadCLTs.length-1, // int            end1_scene,
					scenes_xyzatr,     // double [][][]  scenes_xyzatr,
					scenes_xyzatr,     // double [][][]  scenes_xyzatr,
					clt_parameters.ofp.lpf_series); // half_run_range); // double         half_run_range
					clt_parameters.ofp.lpf_series); // half_run_range); // double         half_run_range
		}
		Did_ins_2   d2_ref = quadCLTs[ref_index].did_ins_2;
		Did_ins_2   d2_ref = quadCLTs[ref_index].did_ins_2;
		double [] cam_quat_ref =Imx5.quaternionImsToCam(d2_ref.getQn2b() ,
		double [] cam_quat_ref =Imx5.quaternionImsToCam(d2_ref.getQn2b() ,
				ims_mount_atr, // new double[] {0, 0.13, 0},
				ims_mount_atr, // new double[] {0, 0.13, 0},
@@ -4086,15 +4154,22 @@ public class Interscene {
			Did_pimu    d3 = scene.did_pimu;
			Did_pimu    d3 = scene.did_pimu;
			
			
			sb.append(nscene+"\t"+timestamp);
			sb.append(nscene+"\t"+timestamp);
			// TODO: try saved, not calculated velocities!
			if (use_processed) {
				if (scenes_xyzatr[nscene] != null) {
					sb.append("\t"+scenes_xyzatr[nscene][0][0]+"\t"+scenes_xyzatr[nscene][0][1]+"\t"+scenes_xyzatr[nscene][0][2]);
					sb.append("\t"+scenes_xyzatr[nscene][0][0]+"\t"+scenes_xyzatr[nscene][0][1]+"\t"+scenes_xyzatr[nscene][0][2]);
					sb.append("\t"+scenes_xyzatr[nscene][1][0]+"\t"+scenes_xyzatr[nscene][1][1]+"\t"+scenes_xyzatr[nscene][1][2]);
					sb.append("\t"+scenes_xyzatr[nscene][1][0]+"\t"+scenes_xyzatr[nscene][1][1]+"\t"+scenes_xyzatr[nscene][1][2]);
			
					// TODO: try saved, not calculated velocities!
					sb.append("\t"+dxyzatr_dt[nscene][0][0]+"\t"+dxyzatr_dt[nscene][0][1]+"\t"+dxyzatr_dt[nscene][0][2]);
					sb.append("\t"+dxyzatr_dt[nscene][0][0]+"\t"+dxyzatr_dt[nscene][0][1]+"\t"+dxyzatr_dt[nscene][0][2]);
					sb.append("\t"+dxyzatr_dt[nscene][1][0]+"\t"+dxyzatr_dt[nscene][1][1]+"\t"+dxyzatr_dt[nscene][1][2]);
					sb.append("\t"+dxyzatr_dt[nscene][1][0]+"\t"+dxyzatr_dt[nscene][1][1]+"\t"+dxyzatr_dt[nscene][1][2]);
			
					// TODO: try saved, not calculated velocities - here they are:
//			String header_ins1="\ttow\ttheta0\ttheta1\ttheta2\tu(m/s)\tv(m/s)\tw(m/s)"+
					sb.append("\t"+scenes_xyzatr_dt[nscene][0][0]+"\t"+scenes_xyzatr_dt[nscene][0][1]+"\t"+scenes_xyzatr_dt[nscene][0][2]);
//					"\tlong\tlat\talt\tned0\tned1\tned2";
					sb.append("\t"+scenes_xyzatr_dt[nscene][1][0]+"\t"+scenes_xyzatr_dt[nscene][1][1]+"\t"+scenes_xyzatr_dt[nscene][1][2]);
				} else {
					for (int i = 0; i < 12; i++) {
						sb.append("\t---");
					}
				}
			}
			sb.append("\t"+d1.timeOfWeek);
			sb.append("\t"+d1.timeOfWeek);
			sb.append("\t"+d1.theta[0]+"\t"+d1.theta[1]+"\t"+d1.theta[2]);
			sb.append("\t"+d1.theta[0]+"\t"+d1.theta[1]+"\t"+d1.theta[2]);
			sb.append("\t"+d1.uvw[0]+  "\t"+d1.uvw[1]+  "\t"+d1.uvw[2]);
			sb.append("\t"+d1.uvw[0]+  "\t"+d1.uvw[1]+  "\t"+d1.uvw[2]);
Loading