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

refactoring, combining with the GPU

parent 4a49fd62
Loading
Loading
Loading
Loading
+81 −14
Original line number Diff line number Diff line
@@ -779,11 +779,22 @@ public class CLTParameters {
	public double     gpu_fatz =          30.0;
	public double     gpu_fatz_m =        30.0;

	public boolean    gpu_woi =             false; // if true - use gpu_woi_tx, ...
	public int        gpu_woi_tx =              0;
	public int        gpu_woi_ty =              0;
	public int        gpu_woi_twidth =        324;
	public int        gpu_woi_theight =       242;
	public boolean    gpu_woi_round =       false;
	public boolean    gpu_save_ports_xy =   false; // debug feature - save calculated ports X,Y to compare with Java-generated
	public boolean    gpu_show_jtextures =  true;  // debug feature - show Java-generated textures from non-overlapping in GPU (will not generate if false)
	public boolean    gpu_show_extra =      true;  // show low-res data for macro
	
	public boolean    gpu_use_main =        false; // accelerate tile processor for the main quad camera
	public boolean    gpu_use_main_macro =  false; // accelerate tile processor for the main quad camera in macro mode
	public boolean    gpu_use_main_adjust = false; // accelerate tile processor for the main quad camera for field calibration
	public boolean    gpu_use_aux =         false; // accelerate tile processor for the aux (lwir) quad camera
	public boolean    gpu_use_aux_macro =   false; // accelerate tile processor for the aux (lwir) quad camera in macro mode
	public boolean    gpu_use_aux_adjust =  false; // accelerate tile processor for the aux (lwir) quad camera for field calibration

	public boolean    replaceWeakOutliers =   true; // false;

@@ -830,6 +841,17 @@ public class CLTParameters {

	public boolean   batch_run =               false; // turned on only while running in batch mode

	public boolean useGPU() {
		return  useGPU(false) || useGPU(true);
	
	}
	public boolean useGPU(boolean aux) {
		return  aux? (gpu_use_aux  || gpu_use_aux_macro || gpu_use_aux_adjust)
				: (gpu_use_main || gpu_use_main_macro || gpu_use_main_adjust);
	}

	
	
	public double getCorrSigma(boolean monochrome) {
		return monochrome ? corr_sigma_mono : corr_sigma;
	}
@@ -1558,11 +1580,22 @@ public class CLTParameters {
		properties.setProperty(prefix+"gpu_fatz",                   this.gpu_fatz +"");
		properties.setProperty(prefix+"gpu_fatz_m",                 this.gpu_fatz_m +"");

		properties.setProperty(prefix+"gpu_woi",                    this.gpu_woi +"");
		properties.setProperty(prefix+"gpu_woi_tx",                 this.gpu_woi_tx +"");
		properties.setProperty(prefix+"gpu_woi_ty",                 this.gpu_woi_ty +"");
		properties.setProperty(prefix+"gpu_woi_twidth",             this.gpu_woi_twidth +"");
		properties.setProperty(prefix+"gpu_woi_theight",            this.gpu_woi_theight +"");
		properties.setProperty(prefix+"gpu_woi_round",              this.gpu_woi_round +"");
		properties.setProperty(prefix+"gpu_save_ports_xy",          this.gpu_save_ports_xy +"");
		properties.setProperty(prefix+"gpu_show_jtextures",         this.gpu_show_jtextures +"");
		properties.setProperty(prefix+"gpu_show_extra",             this.gpu_show_extra +"");

		properties.setProperty(prefix+"gpu_use_main",               this.gpu_use_main +"");
		properties.setProperty(prefix+"gpu_use_main_macro",         this.gpu_use_main_macro +"");
		properties.setProperty(prefix+"gpu_use_main_adjust",        this.gpu_use_main_adjust +"");
		properties.setProperty(prefix+"gpu_use_aux",                this.gpu_use_aux +"");
		properties.setProperty(prefix+"gpu_use_aux_macro",          this.gpu_use_aux_macro +"");
		properties.setProperty(prefix+"gpu_use_aux_adjust",         this.gpu_use_aux_adjust +"");
		
		properties.setProperty(prefix+"debug_initial_discriminate",       this.debug_initial_discriminate+"");
		properties.setProperty(prefix+"dbg_migrate",                      this.dbg_migrate+"");
@@ -2332,11 +2365,22 @@ public class CLTParameters {
		if (properties.getProperty(prefix+"gpu_fatz")!=null)                    this.gpu_fatz=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz"));
		if (properties.getProperty(prefix+"gpu_fatz_m")!=null)                  this.gpu_fatz_m=Double.parseDouble(properties.getProperty(prefix+"gpu_fatz_m"));

		if (properties.getProperty(prefix+"gpu_woi")!=null)                     this.gpu_woi=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_woi"));
		if (properties.getProperty(prefix+"gpu_woi_tx")!=null)                  this.gpu_woi_tx=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_tx"));
		if (properties.getProperty(prefix+"gpu_woi_ty")!=null)                  this.gpu_woi_ty=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_ty"));
		if (properties.getProperty(prefix+"gpu_woi_twidth")!=null)              this.gpu_woi_twidth=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_twidth"));
		if (properties.getProperty(prefix+"gpu_woi_theight")!=null)             this.gpu_woi_theight=Integer.parseInt(properties.getProperty(prefix+"gpu_woi_theight"));
		if (properties.getProperty(prefix+"gpu_woi_round")!=null)               this.gpu_woi_round=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_woi_round"));
		if (properties.getProperty(prefix+"gpu_save_ports_xy")!=null)           this.gpu_save_ports_xy=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_save_ports_xy"));
		if (properties.getProperty(prefix+"gpu_show_jtextures")!=null)          this.gpu_show_jtextures=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_show_jtextures"));
		if (properties.getProperty(prefix+"gpu_show_extra")!=null)              this.gpu_show_extra=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_show_extra"));
		
		if (properties.getProperty(prefix+"gpu_use_main")!=null)                this.gpu_use_main=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_main"));
		if (properties.getProperty(prefix+"gpu_use_main_macro")!=null)          this.gpu_use_main_macro=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_main_macro"));
		if (properties.getProperty(prefix+"gpu_use_main_adjust")!=null)         this.gpu_use_main_adjust=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_main_adjust"));
		if (properties.getProperty(prefix+"gpu_use_aux")!=null)                 this.gpu_use_aux=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_aux"));
		if (properties.getProperty(prefix+"gpu_use_aux_macro")!=null)           this.gpu_use_aux_macro=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_aux_macro"));
		if (properties.getProperty(prefix+"gpu_use_aux_adjust")!=null)          this.gpu_use_aux_adjust=Boolean.parseBoolean(properties.getProperty(prefix+"gpu_use_aux_adjust"));

		if (properties.getProperty(prefix+"debug_initial_discriminate")!=null)       this.debug_initial_discriminate=Boolean.parseBoolean(properties.getProperty(prefix+"debug_initial_discriminate"));
		if (properties.getProperty(prefix+"dbg_migrate")!=null)                      this.dbg_migrate=Boolean.parseBoolean(properties.getProperty(prefix+"dbg_migrate"));
@@ -3263,6 +3307,8 @@ public class CLTParameters {
				"Add squared fat zero to the sum of squared amplitudes, monochrome images");
		gd.addMessage     ("--- GPU WOI selection ---");

		gd.addCheckbox    ("Use following WOI for GPU processing (unchecked - ignore WOI dimensions)",                  this.gpu_woi);

		gd.addNumericField("WOI left",                                                                                  this.gpu_woi_tx, 0, 6,"tiles",
				"Left WOI margin, in tiles (0..323");
		gd.addNumericField("WOI top",                                                                                   this.gpu_woi_ty, 0, 6,"tiles",
@@ -3272,6 +3318,16 @@ public class CLTParameters {
		gd.addNumericField("WOI height",                                                                                this.gpu_woi_theight, 0, 6,"tiles",
				"WOI height, in tiles (1..242");
		gd.addCheckbox    ("Select circle/ellipse within the rectanghular WOI",                                         this.gpu_woi_round);
		gd.addCheckbox    ("Debug feature - save calculated ports X,Y to compare with Java-generated",                  this.gpu_save_ports_xy);
		gd.addCheckbox    ("Show Java-generated textures from non-overlapping in GPU (will not generate if false)",     this.gpu_show_jtextures);
		gd.addCheckbox    ("Show low-res data for macro (will not generate if false)",                                  this.gpu_show_extra);

		gd.addCheckbox    ("Accelerate tile processor for the main quad camera",                                        this.gpu_use_main);
		gd.addCheckbox    ("Accelerate tile processor for the main quad camera in macro mode",                          this.gpu_use_main_macro);
		gd.addCheckbox    ("Accelerate tile processor for the main quad camera for field calibration",                  this.gpu_use_main_adjust);
		gd.addCheckbox    ("Accelerate tile processor for the aux (lwir) quad camera",                                  this.gpu_use_aux);
		gd.addCheckbox    ("Accelerate tile processor for the aux (lwir) quad camera in macro mode",                    this.gpu_use_aux_macro);
		gd.addCheckbox    ("Accelerate tile processor for the aux (lwir) quad camera for field calibration",            this.gpu_use_aux_adjust);
		
		gd.addTab         ("LWIR", "parameters for LWIR/EO 8-camera rig");
		this.lwir.dialogQuestions(gd);
@@ -4014,11 +4070,22 @@ public class CLTParameters {
		this.gpu_fatz =             gd.getNextNumber();
		this.gpu_fatz_m =           gd.getNextNumber();

		this.gpu_woi=               gd.getNextBoolean();
		this.gpu_woi_tx =     (int) gd.getNextNumber();
		this.gpu_woi_ty =     (int) gd.getNextNumber();
		this.gpu_woi_twidth = (int) gd.getNextNumber();
		this.gpu_woi_theight =(int) gd.getNextNumber();
		this.gpu_woi_round=         gd.getNextBoolean();
		this.gpu_save_ports_xy=     gd.getNextBoolean();
		this.gpu_show_jtextures=    gd.getNextBoolean();
		this.gpu_show_extra=        gd.getNextBoolean();

		this.gpu_use_main=          gd.getNextBoolean();
		this.gpu_use_main_macro=    gd.getNextBoolean();
		this.gpu_use_main_adjust=   gd.getNextBoolean();
		this.gpu_use_aux=           gd.getNextBoolean();
		this.gpu_use_aux_macro=     gd.getNextBoolean();
		this.gpu_use_aux_adjust=    gd.getNextBoolean();
		
		this.lwir.dialogAnswers(gd);

+50 −6
Original line number Diff line number Diff line
@@ -4906,7 +4906,7 @@ private Panel panel1,
    	importAux();
    	return;
/* ======================================================================== */
    } else if (label.equals("CLT 2*4 images")) {
    } else if (label.equals("CLT 2*4 images")) { // never used 
        DEBUG_LEVEL=MASTER_DEBUG_LEVEL;
    	EYESIS_CORRECTIONS.setDebug(DEBUG_LEVEL);
    	getPairImages();
@@ -5416,7 +5416,7 @@ private Panel panel1,
		return true;
	}

	public boolean getPairImages() {
	public boolean getPairImages() { // Never Used
        if (QUAD_CLT == null){
        	QUAD_CLT = new  QuadCLT (
        			QuadCLT.PREFIX,
@@ -5810,10 +5810,7 @@ private Panel panel1,
		if (GPU_QUAD == null) {
			try {
				GPU_QUAD = GPU_TILE_PROCESSOR. new GpuQuad(
						2592,
						1936,
						164,   // final int kernels_hor,
			   			123,   // final int kernels_vert,
						QUAD_CLT,
						4,
						3);
			} catch (Exception e) {
@@ -5822,6 +5819,7 @@ private Panel panel1,
				e.printStackTrace();
				return false;
			} //final int        debugLevel);
			QUAD_CLT.setGPU(GPU_QUAD);
		}
		// For now keep GPU_QUAD_AUX==null
		
@@ -6266,6 +6264,8 @@ private Panel panel1,

	public boolean batchLwir() {
		long startTime=System.nanoTime();
		
		
		// load needed sensor and kernels files
		if (!prepareRigImages()) return false;
		String configPath=getSaveCongigPath();
@@ -6278,8 +6278,52 @@ private Panel panel1,
///		if (COLOR_PROC_PARAMETERS_AUX == null) {
///			COLOR_PROC_PARAMETERS_AUX = COLOR_PROC_PARAMETERS.clone();
///		}
		
		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);
			}
			if (CLT_PARAMETERS.useGPU(true) && (QUAD_CLT_AUX != null) && (GPU_QUAD_AUX == null)) { // if GPU AUX is needed
				try {
					GPU_QUAD_AUX = GPU_TILE_PROCESSOR. new GpuQuad(//
							QUAD_CLT_AUX,
							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_AUX.setGPU(GPU_QUAD_AUX);
			}
		}
		
		try {
			TWO_QUAD_CLT.batchLwirRig(
//					GPU_QUAD,     // GPUTileProcessor.GpuQuad gpuQuad_main, // may be null if GPU for MAIN is not use3d
//					GPU_QUAD_AUX, // GPUTileProcessor.GpuQuad gpuQuad_aux,  // may be null if GPU for AUX is not use3d
					QUAD_CLT, // QuadCLT quadCLT_main,
					QUAD_CLT_AUX, // QuadCLT quadCLT_aux,
					CLT_PARAMETERS,  // EyesisCorrectionParameters.DCTParameters           dct_parameters,
+326 −171

File changed.

Preview size limit exceeded, changes collapsed.

+6 −2
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ public class AlignmentCorrection {
	static final int    INDEX_14_DISPARITY = 0;
	static final double DISP_SCALE = 2.0;

	QuadCLT qc;
	QuadCLT    qc_gpu; // maybe will be used later?
	QuadCLTCPU qc;

	public class Sample{
		public int series;
@@ -265,9 +266,12 @@ public class AlignmentCorrection {
	}

	//System.arraycopy(dpixels, (tileY*width+tileX)*dct_size + i*width, tile_in, i*n2, n2);
	AlignmentCorrection (QuadCLT qc){
	AlignmentCorrection (QuadCLTCPU qc){
		this.qc = qc;
	}
	AlignmentCorrection (QuadCLT qc){
		this.qc_gpu = qc;
	}

	public double [][][] infinityCorrection(
			final boolean    use_poly,
+1 −3
Original line number Diff line number Diff line
@@ -2364,7 +2364,6 @@ public class ImageDtt {
			final double [][][][]     clt_corr_combo,  // [type][tilesY][tilesX][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
			                                           // [type][tilesY][tilesX] should be set by caller
													   // types: 0 - selected correlation (product+offset), 1 - sum
			final double [][][][][]   clt_corr_partial,// [tilesY][tilesX][quad]color][(2*transform_size-1)*(2*transform_size-1)] // if null - will not calculate
                                                       // [tilesY][tilesX] should be set by caller
			// When clt_mismatch is non-zero, no far objects extraction will be attempted
@@ -2374,7 +2373,6 @@ public class ImageDtt {
			final double [][]         disparity_map,   // [8][tilesY][tilesX], only [6][] is needed on input or null - do not calculate
			                                           // last 2 - contrast, avg/ "geometric average)
			final double [][][][]     texture_tiles,   // [tilesY][tilesX]["RGBA".length()][];  null - will skip images combining
			final int                 width,
			final double              corr_fat_zero,    // add to denominator to modify phase correlation (same units as data1, data2). <0 - pure sum
			final boolean             corr_sym,
@@ -3230,7 +3228,7 @@ public class ImageDtt {
										disparity_map[DISPARITY_INDEX_POLY]         [tIndex] = lma_disparity_strength[0];
										// if enabled overwrite - replace  DISPARITY_INDEX_CM and DISPARITY_STRENGTH_INDEX
										if (imgdtt_params.mix_corr_poly) {
										if (imgdtt_params.mix_corr_poly) { //true
											disp_str[0] =  lma_disparity_strength[0];
											disp_str[1] =  lma_disparity_strength[1];
											disparity_map[DISPARITY_INDEX_CM]       [tIndex] = disp_str[0];
Loading