Commit 748d396b authored by Andrey Filippov's avatar Andrey Filippov
Browse files

bug fixing for chained segments

parent 9616573c
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -220,15 +220,15 @@ public class Interscene {
			adjusted_scene_index++;
			if ((ref_index - adjusted_scene_index) >= min_num_scenes_half) {
				if (adjusted_scene_index > cent_index) {
					cent_index = adjusted_scene_index;
					if (debugLevel > -3) {
						System.out.println("Overlap mode, reusing previous scenes adjustment scenes, number of scenes = "+
								(ref_index - adjusted_scene_index));
						System.out.println("Overlap mode 1, reusing previous scenes adjustment scenes, number of scenes = "+
								(ref_index - adjusted_scene_index)+", cent_index = "+cent_index+", ref_index="+ref_index);
					}
					cent_index = adjusted_scene_index;
				} else {
					if (debugLevel > -3) {
						System.out.println("Overlap mode, partially reusing previous scenes adjustment scenes, number of scenes = "+
								(ref_index - cent_index)+ " of "+(ref_index - adjusted_scene_index));
						System.out.println("Overlap mode 2, partially reusing previous scenes adjustment scenes, number of scenes = "+
								(ref_index - cent_index)+ " of "+(ref_index - adjusted_scene_index)+", cent_index = "+cent_index+", ref_index="+ref_index);
					}
				}
				reused_overlap = true;
@@ -283,6 +283,10 @@ public class Interscene {
			}
		}				
		
		if (debugLevel > -3) {
			System.out.println("setInitialOrientationsCenterIms(): Running OpticalFlow.buildRefDSI() for center scene # "+cent_index+", : "+quadCLTs[cent_index].getImageName());
		}
		
		// create new dsi for quadCLTs[earliest_scene1]
		OpticalFlow.buildRefDSI( // returned is a different instance than input -FIXED
				clt_parameters,                   // CLTParameters                                 clt_parameters,
+41 −17
Original line number Diff line number Diff line
@@ -4077,8 +4077,8 @@ public class OpticalFlow {
			final boolean                                 updateStatus,
			final int                                     debugLevel) {
		final int debugLevelInner=   clt_parameters.batch_run? -2: debugLevel; // copied from TQ
		if (debugLevelInner > -2) {
			System.out.println("buildRefDSI(): clt_parameters.batch_run="+clt_parameters.batch_run+", debugLevel="+debugLevel+", debugLevelInner="+debugLevelInner);
		if (debugLevelInner > -3) {
			System.out.println("buildRefDSI(): clt_parameters.batch_run="+clt_parameters.batch_run+", debugLevel="+debugLevel+", debugLevelInner="+debugLevelInner+", fast="+fast);
		}
    	boolean  photo_each =        clt_parameters.photo_each; //        true;  // perform photogrammetric calibration to equalize pixel values
    	boolean sky_extract =        clt_parameters.imp.sky_extract;
@@ -4158,6 +4158,25 @@ public class OpticalFlow {
			photo_each =     false;
			sky_extract =    false;
		}
		if (debugLevel > -3) {
			System.out.println("buildRefDSI(): Running preExpandCLTQuad3d() for scene "+quadCLT_ref.getImageName());
			System.out.println("buildRefDSI(): quadCLT_ref.hasNewImageData() -> "+quadCLT_ref.hasNewImageData());
		}
		quadCLT_ref.saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU). Spend several days to find this bug!
		
		if (debugLevel > -3) {
			//quadCLT_main
			System.out.println("buildRefDSI():quadCLT_ref.tp.clt_3d_passes.size()="+quadCLT_ref.tp.clt_3d_passes.size());
			System.out.println("buildRefDSI(): suspecting processing *-DSI_MAIN.tiff without loading new images to the GPU, running quadCLT_ref.saveQuadClt(). 12/07/2025");
			boolean show_sources = debugLevel > 1000;
			if (show_sources) {
				quadCLT_ref.showImageData();
			}
			
			
		}
		
		
		quadCLT_ref.preExpandCLTQuad3d( // returns ImagePlus, but it already should be saved/shown
				clt_parameters,
@@ -5179,7 +5198,10 @@ public class OpticalFlow {
				if (center_reference) { // invalidate pointer to recalculate
					quadCLTs[last_index].setRefPointer((String) null); 
				}
//				quadCLTs[ref_index] = 
				if (debugLevel > -3) {
					System.out.println("buildSeries(): Running OpticalFlow.buildRefDSI() for last_index scene # "+last_index+", : "+quadCLTs[last_index].getImageName());
				}
 
				buildRefDSI( // returned is a different instance than input -FIXED
						clt_parameters,                   // CLTParameters                                 clt_parameters,
						fast,                             // boolean  fast,
@@ -5241,25 +5263,27 @@ public class OpticalFlow {
			}
		} // while (blue_sky == null)
		boolean early_try_back = false; //  true;
		
//		if (!force_initial_orientations) { // moved here as setDSRBG fails with .dsi={null, null,...,null};
		// by now if it was center_reference the last ref_dsi is restored with optional blue sky.
		boolean bypass_last_index = (debugLevel > 1000); //  && (quadCLTs[last_index] != null); // always. DEbugging 12/06/2025
		if (center_CLT == null) { // does not work in CUAS mode
			ref_blue_sky = quadCLTs[last_index].getDoubleBlueSky();
			ref_blue_sky = quadCLTs[last_index].getDoubleBlueSky(); // new
			if (!bypass_last_index) {
				quadCLTs[last_index] = (QuadCLT) quadCLT_main.spawnQuadCLT( // restores dsi from "DSI-MAIN"
						set_channels[last_index].set_name,
						clt_parameters,
						colorProcParameters, //
						threadsMax,
						debugLevel);
			}
			quadCLTs[last_index].setQuadClt(); // just in case ?
			quadCLTs[last_index].setBlueSky(ref_blue_sky); //quadCLTs[ref_index].dsi has it 
			quadCLTs[last_index].setDSRBG( // null
			quadCLTs[last_index].setDSRBG( // DSI is needed in 	I244: cent_index = setInitialOrientationsIms(
					clt_parameters, // CLTParameters  clt_parameters,
					threadsMax,     // int            threadsMax,  // maximal number of threads to launch
					updateStatus,   // boolean        updateStatus,
					debugLevel);    // int            debugLevel)
		}
		if (!force_initial_orientations) {
			// use master_clt? - where to look for stage. in CUAS mode build directory name and look there
@@ -6439,7 +6463,7 @@ public class OpticalFlow {
	        				}
	        			}
	        			final boolean       toRGB = col_mode > 0;
	        			String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+
	        			String scenes_suffix = master_CLT.getImageName()+ // uadCLTs[quadCLTs.length-1].getImageName()+
	        					"-SEQ-" + IntersceneMatchParameters.MODES3D[mode3d+1] + "-"+(toRGB?"COLOR":"MONO");
	        			String um_suffix = "";
	        			if (!toRGB && um_mono) {
@@ -7027,14 +7051,14 @@ public class OpticalFlow {
			}
		}
		
		boolean export_terrain_sequence = true;
		boolean export_terrain_sequence = true; // check master_CLT
		if (export_terrain_sequence && !clt_parameters.imp.lock_position) {
			combo_dsn_final =master_CLT.restoreComboDSI(true);
			if ((combo_dsn_final.length <= COMBO_DSN_INDX_TERRAIN) || (combo_dsn_final[COMBO_DSN_INDX_TERRAIN] == null)) {
				System.out.println ("No terrain data available");
			} else {
				double [] terrain_disparity = combo_dsn_final[COMBO_DSN_INDX_TERRAIN];
				String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+"-TERRAIN";
				String scenes_suffix = master_CLT.getImageName()+"-TERRAIN"; // quadCLTs[quadCLTs.length-1][quadCLTs.length-1].getImageName()+"-TERRAIN";
				ImagePlus imp_terrain = renderSceneSequence(
						clt_parameters,     // CLTParameters clt_parameters,
						master_CLT.hasCenterClt(), // boolean        mode_cuas,
@@ -7063,7 +7087,7 @@ public class OpticalFlow {
				System.out.println ("No terrain data available");
			} else {
				double [] elevation_disparity = combo_dsn_final[COMBO_DSN_INDX_DISP];
				String scenes_suffix = quadCLTs[quadCLTs.length-1].getImageName()+"-ELEVATION";
				String scenes_suffix = master_CLT.getImageName()+"-ELEVATION"; // quadCLTs[quadCLTs.length-1].getImageName()+"-ELEVATION";
				ImagePlus imp_elevation = renderSceneSequence(
						clt_parameters,     // CLTParameters clt_parameters,
						master_CLT.hasCenterClt(), // boolean        mode_cuas,
+34 −4
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class QuadCLT extends QuadCLTCPU {
	}
	
	
	public QuadCLT saveQuadClt() {
	public QuadCLT saveQuadClt() { // used a lot!
		if (gpuQuad == null) {
			return null;
		}
@@ -108,7 +108,7 @@ public class QuadCLT extends QuadCLTCPU {
		}
		return savedQuadClt;
	}
	void restoreQuadClt(QuadCLT savedQuadClt) {
	void restoreQuadClt(QuadCLT savedQuadClt) { // only used in QCC5185: getTileRBG()
		if (savedQuadClt !=  null) {
			gpuQuad.updateQuadCLT(savedQuadClt);
		}
@@ -5028,7 +5028,7 @@ public class QuadCLT extends QuadCLTCPU {
	}

	  /**
	   * Get GPU-calculated tiles centers coordinates for each sesnor
	   * Get GPU-calculated tiles centers coordinates for each sensor
	   * @return per-tile null 2*num_sesnors array of alternating X and Y 
	   */
	  public double [][] getPortsXY() // run after GPU 
@@ -5154,6 +5154,36 @@ public class QuadCLT extends QuadCLTCPU {
				  titles);
	  }
	  
	  public void showImageData() {
		  showImageData(null, null);
	  }
	  
	  public void showImageData(
			  double [][][] data,
			  String title) {
		  if (data == null) {
			  data = this.image_data;
		  }
		  if (title == null) {
			  title = this.getImageName()+"-IMAGE_DATA";
		  }
		  String [] sports =  new String [data.length];
		  String [] scolors = new String [data[0].length];
		  for (int i = 0; i < sports.length; i++) sports[i]="port-"+i;
		  for (int i = 0; i < scolors.length; i++) scolors[i]="col-"+i;
		  int width =  tp.getTilesX()*tp.getTileSize();
//		  int height =  tp.getTilesY()*tp.getTileSize();
		  ShowDoubleFloatArrays.showArraysHyperstack(
				  data, // double[][][] pixels,
				  width, // int          width,
				  title, // String       title,
				  scolors, // String []    titles, // all slices*frames titles or just slice titles or null
				  sports, // String []    frame_titles, // frame titles or null
				  true); // boolean      show)
		  return;
	  }
	  
	  
	  
	  
	  
+17 −1
Original line number Diff line number Diff line
@@ -14249,7 +14249,7 @@ public class QuadCLTCPU {
		  tp.clt_3d_passes.get(tp.clt_3d_passes.size()-1).setAvgVal(tp.clt_3d_passes.get(bg_pass).getAvgVal());
 ///// Refining after all added   - end
		  Runtime.getRuntime().gc();
	      System.out.println("preExpandCLTQuad3d(): processing  finished at "+
	      System.out.println("preExpandCLTQuad3d(): processing scene "+getImageName()+" finished at "+
			  IJ.d2s(0.000000001*(System.nanoTime()-this.startStepTime),3)+" sec, --- Free memory23="+Runtime.getRuntime().freeMemory()+" (of "+Runtime.getRuntime().totalMemory()+")");
		  return true;
	  }
@@ -17918,6 +17918,7 @@ public class QuadCLTCPU {
			  final boolean       updateStatus,
			  final int           debugLevel)
	  {
		  saveQuadClt(); // to re-load new set of Bayer images to the GPU (do nothing for CPU). Spend several days to find this bug!
		  boolean float_center = true;   // false - center around provided value TODO: Move to clt_parameters?		  
		  boolean show_2d_correlations = (debugLevel>100); // true; // debug feature
		  final int   tilesX = tp.getTilesX();
@@ -18053,6 +18054,21 @@ public class QuadCLTCPU {
						  mcorr_sel,                         // final int                 mcorr_sel,    // Which pairs to correlate // +1 - all, +2 - dia, +4 - sq, +8 - neibs, +16 - hor + 32 - vert
						  threadsMax,       // maximal number of threads to launch
						  debugLevel);
				  boolean show_dbg_img = debugLevel > 1000;
				  if (show_dbg_img) {
						int tile_size = getTileSize();
						int [] wh_dbg = {tilesX*tile_size,tilesY*tile_size};
						double [][] dbg = ((QuadCLT) this).renderDoubleFromTDMono (
								-1, // final int         sensor_mask,
								wh_dbg,              // null, // int []  wh,
				                false);          // boolean use_reference
						ShowDoubleFloatArrays.showArrays(
								dbg,
								wh_dbg[0],
								wh_dbg[1],
								true,
								getImageName()+"-test_CLTMeas");
				  }
				  
			  } else {
				  clt_data = image_dtt.quadCorrTD( // clt_data [task][sensor][color][][];