Commit 86e21078 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

merging planes in the same supertile

parent d24659c3
Loading
Loading
Loading
Loading
+79 −18
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public class ConnectionCosts {
	double         diagonalWeight;
	double         starPwr;    // Divide cost by number of connections to this power
	double         starWeightPwr; // Use this power of tile weight when calculating connection cost
	double         weightToDens;    // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
	
	double         starValPwr; //  Raise value of each tile before averaging
	
	int            steps;
@@ -51,6 +53,7 @@ public class ConnectionCosts {
			double         diagonalWeight,
			double         starPwr,    // Divide cost by number of connections to this power
			double         starWeightPwr,    // Use this power of tile weight when calculating connection cost
			double         weightToDens,    // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
			double         starValPwr, //  Raise value of each tile before averaging
			int            steps,
			TilePlanes.PlaneData [][] planes,
@@ -64,12 +67,14 @@ public class ConnectionCosts {
		this.diagonalWeight =  diagonalWeight;
		this.starPwr =         starPwr;         // Divide cost by number of connections to this power
		this.starWeightPwr =   starWeightPwr;
		this.weightToDens =    weightToDens;    // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
		this.starValPwr =      starValPwr; //  Raise value of each tile before averaging
		this.steps =           steps;
	}
	
	public int [][][] initConnectionCosts(
			int []         nsTiles)
			int []    nsTiles,
			int       debugLevel)
	{
		int [] exp_tiles = nsTiles;
		for (int i = 1; i < steps; i++) exp_tiles = getInvolvedSupertiles(exp_tiles);
@@ -92,7 +97,7 @@ public class ConnectionCosts {
			if (planes[nsTile] != null){
				val_weights[isTile] = new double [planes[nsTile].length][];
				for (int nl = 0; nl < planes[nsTile].length; nl++) if ( planes[nsTile][nl] != null){
					val_weights[isTile][nl] = new double[2];
					val_weights[isTile][nl] = new double[3];
				}
			}
		}
@@ -111,17 +116,17 @@ public class ConnectionCosts {
		case 1:
			val_weights = getConnectionsCostSingleStep (
					null,	
					-1); // int        debugLevel)
					debugLevel - 1); // int        debugLevel)
			break;
		case 2:
			val_weights = getConnectionsCostDualStep (
					null,	
					-1); // int        debugLevel)
					debugLevel - 1); // int        debugLevel)
			break;
		default:
			val_weights = getConnectionsCostSingleStep (
					null,	
					-1); // int        debugLevel)			
					debugLevel - 1); // int        debugLevel)			
		}
		
		last_val_weights = val_weights;
@@ -131,10 +136,16 @@ public class ConnectionCosts {
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
			if (val_weights[isTile] != null){
				for (int nl = 0; nl < val_weights[isTile].length; nl++) if ( val_weights[isTile][nl] != null){
					double weighted = val_weights[isTile][nl][1];
					double density = val_weights[isTile][nl][2];
					
					double weight = (weightToDens >= 1.0) ? weighted :
						((weightToDens <= 0.0) ? density : 
							(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));
					double val = val_weights[isTile][nl][0];
					if (starValPwr != 1.0) val = Math.pow(val, starValPwr);
					init_val +=    val * val_weights[isTile][nl][1];
					init_weight += val_weights[isTile][nl][1];
					init_val +=    val * weight;
					init_weight += weight;
				}
			}
		}
@@ -259,6 +270,7 @@ public class ConnectionCosts {
									int ineib1 = (tile_map.containsKey(nsTile1))? tile_map.get(nsTile1) : -1;
									neibs2[dir] = (ineib1 >=0) ? neibs[tile_map.get(nsTile1)][nl1] : planes[nsTile1][nl1].getNeibBest();
									if (!neibs_changed && (ineib1 >= 0)) {
										/*
										if ((neibs_init[ineib1] == null) || (neibs_init[ineib1][nl1] == null)) {
											neibs_changed = true;
										} else {
@@ -267,6 +279,16 @@ public class ConnectionCosts {
												break;
											}
										}

										 */
										if ((neibs_init[ineib1] == null) || (neibs[ineib1][nl1] == null)) {
											neibs_changed = true;
										} else {
											for (int dir1 = 0; dir1 < 8; dir1++) if (neibs[ineib1][nl1][dir1] != neibs_init[ineib1][nl1][dir1]){
												neibs_changed = true;
												break;
											}
										}
									}
								}
							}
@@ -296,6 +318,35 @@ public class ConnectionCosts {
				}
			}
		}
		if (debugLevel > 0) {
			for (int isTile = 0; isTile < all_tiles.length; isTile++){
				int nsTile = all_tiles[isTile];
				System.out.print("getConnectionsCostDualStep(): "+isTile+" ("+nsTile+"): ");
				if (vw[isTile] != null) {
					for (int nl = 0; nl < vw[isTile].length; nl++){
//						System.out.print(" "+nl+":[");
						System.out.print("     "+nl+":[");
						if (vw[isTile][nl] != null ) {
							for (int i = 0; i < vw[isTile][nl].length;i++){
								System.out.print(vw[isTile][nl][i]);
//								if (i < (vw[isTile][nl].length -1)){
									System.out.print(", ");
//								}
							}
							double weighted = vw[isTile][nl][1];
							double density = vw[isTile][nl][2];
							double weight = (weightToDens >= 1.0) ? weighted :
								((weightToDens <= 0.0) ? density : 
									(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));
							System.out.print(weight);
						}
//						System.out.print("]");
						System.out.println("]");
					}
				}
				System.out.println();
			}			
		}
		return vw; // negative - improvement
	}
	
@@ -310,17 +361,17 @@ public class ConnectionCosts {
		case 1:
			vw = getConnectionsCostSingleStep (
					neibs,	
					-1); // int        debugLevel)
					debugLevel-1); // int        debugLevel)
			break;
		case 2:
			vw = getConnectionsCostDualStep (
					neibs,	
					-1); // int        debugLevel)
					debugLevel-1); // int        debugLevel)
			break;
		default:
			vw = getConnectionsCostSingleStep (
					neibs,	
					-1); // int        debugLevel)			
					debugLevel-1); // int        debugLevel)			
		}
		last_val_weights = vw;
		// calculate new cost
@@ -329,11 +380,16 @@ public class ConnectionCosts {
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
			if (vw[isTile] != null){
				for (int nl = 0; nl < vw[isTile].length; nl++) if ( vw[isTile][nl] != null){
					double weighted = vw[isTile][nl][1];
					double density = vw[isTile][nl][2];
					double weight = (weightToDens >= 1.0) ? weighted :
						((weightToDens <= 0.0) ? density : 
							(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));

					double val = vw[isTile][nl][0];
					if (starValPwr != 1.0) val = Math.pow(val, starValPwr);
					new_value +=          val * vw[isTile][nl][1];
					new_weight +=         vw[isTile][nl][1];
					new_value +=          val * weight;
					new_weight +=         weight;
				}
			}
		}
@@ -372,6 +428,7 @@ public class ConnectionCosts {
			int    debugLevel)
	{
		TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // add weight
		double conn_weight = 1.0; // center weight
		for (int dir = 0; dir < 8; dir++){
			if (neibs[dir] >= 0){
				double other_weight = ((dir & 1) != 0) ? diagonalWeight : orthoWeight;
@@ -386,9 +443,10 @@ public class ConnectionCosts {
						true,            // boolean   sum_weights,
						preferDisparity, 
						debugLevel - 1); // int       debugLevel)
				conn_weight += 1.0;
			}
		}
		double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
		double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
		if (starPwr != 0){
			value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr));
		}
@@ -451,6 +509,7 @@ public class ConnectionCosts {
			}
		}
		TilePlanes.PlaneData merged_plane =  planes[nsTile][nl]; // center point
		double conn_weight = 1.0; // center weight
		for (HashMap.Entry<Point, Double> entry : tile_weights.entrySet()){
			TilePlanes.PlaneData other_plane = merged_plane.getPlaneToThis(  // layer here does not matter
					planes[entry.getKey().x][entry.getKey().y],
@@ -463,8 +522,10 @@ public class ConnectionCosts {
					true,             // boolean   sum_weights,
					preferDisparity, 
					debugLevel - 1);  // int       debugLevel)
			
			conn_weight += entry.getValue();
		}
		double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
		double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
		if (starPwr != 0){
			value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr));
		}
+12 −2
Original line number Diff line number Diff line
@@ -2168,7 +2168,8 @@ public class EyesisCorrectionParameters {
  		public double     plFractOutliers      =   0.3;  // Maximal fraction of outliers to remove
  		public int        plMaxOutliers        =    20;  // Maximal number of outliers to remove
  		public double     plMinStrength        =   0.1;  // Minimal total strength of a plane 
  		public double     plMaxEigen           =   0.3;  // Maximal eigenvalue of a plane 
  		public double     plMaxEigen           =   0.05; // Maximal eigenvalue of a plane 
  		public double     plEigenFloor         =   0.01; // Add to eigenvalues of each participating plane and result to validate connections 
  		public boolean    plDbgMerge           =   true; // Combine 'other' plane with current
  		public double     plWorstWorsening     =   2.0;  // Worst case worsening after merge
  		public double     plWorstWorsening2    =   5.0;  // Worst case worsening for thin planes
@@ -2183,11 +2184,12 @@ public class EyesisCorrectionParameters {
  		public boolean    plConflDiag          =   false; // Resolve diagonal (ood) conflicts
  		public boolean    plConflStar          =   true;  // Resolve all conflicts around a supertile 

  		public int        plStarSteps          =   2;    // How far to look around when calculationg connection cost
  		public int        plStarSteps          =   2;    // How far to look around when calculating connection cost
  		public double     plStarOrtho          =   0.5;  // When calculating cost for the connections scale 4 ortho neighbors
  		public double     plStarDiag           =   0.25; // When calculating cost for the connections scale 4 diagonal neighbors
  		public double     plStarPwr            =   0.5;  // Divide cost by number of connections to this power
  		public double     plStarWeightPwr      =   0.5;  // use this power of tile weight when calculating connection cost
  		public double     plWeightToDens       =   0.3;  // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
  		public double     plStarValPwr         =   1.0;  // Raise value of each tile before averaging
  		public double     plDblTriLoss         =   0.0001; // When resolving double triangles allow minor degradation (0.0 - strict)
  		public boolean    plNewConfl           =   false; // Allow more conflicts if overall cost is reduced
@@ -2535,6 +2537,7 @@ public class EyesisCorrectionParameters {
  			properties.setProperty(prefix+"plMaxOutliers",    this.plMaxOutliers+"");
			properties.setProperty(prefix+"plMinStrength",    this.plMinStrength +"");
			properties.setProperty(prefix+"plMaxEigen",       this.plMaxEigen +"");
			properties.setProperty(prefix+"plEigenFloor",     this.plEigenFloor +"");
			properties.setProperty(prefix+"plDbgMerge",       this.plDbgMerge+"");
			properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
			properties.setProperty(prefix+"plWorstWorsening2",this.plWorstWorsening2 +"");
@@ -2553,6 +2556,7 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"plStarDiag",       this.plStarDiag +"");
			properties.setProperty(prefix+"plStarPwr",        this.plStarPwr +"");
			properties.setProperty(prefix+"plStarWeightPwr",  this.plStarWeightPwr +"");
			properties.setProperty(prefix+"plWeightToDens",   this.plWeightToDens +"");
			properties.setProperty(prefix+"plStarValPwr",     this.plStarValPwr +"");
			properties.setProperty(prefix+"plDblTriLoss",     this.plDblTriLoss +"");
			properties.setProperty(prefix+"plNewConfl",       this.plNewConfl+"");
@@ -2880,6 +2884,7 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"plMaxOutliers")!=null)     this.plMaxOutliers=Integer.parseInt(properties.getProperty(prefix+"plMaxOutliers"));
  			if (properties.getProperty(prefix+"plMinStrength")!=null)     this.plMinStrength=Double.parseDouble(properties.getProperty(prefix+"plMinStrength"));
  			if (properties.getProperty(prefix+"plMaxEigen")!=null)        this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
  			if (properties.getProperty(prefix+"plEigenFloor")!=null)      this.plEigenFloor=Double.parseDouble(properties.getProperty(prefix+"plEigenFloor"));
  			if (properties.getProperty(prefix+"plDbgMerge")!=null)        this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
  			if (properties.getProperty(prefix+"plWorstWorsening")!=null)  this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
  			if (properties.getProperty(prefix+"plWorstWorsening2")!=null) this.plWorstWorsening2=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening2"));
@@ -2898,6 +2903,7 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"plStarDiag")!=null)        this.plStarDiag=Double.parseDouble(properties.getProperty(prefix+"plStarDiag"));
  			if (properties.getProperty(prefix+"plStarPwr")!=null)         this.plStarPwr=Double.parseDouble(properties.getProperty(prefix+"plStarPwr"));
  			if (properties.getProperty(prefix+"plStarWeightPwr")!=null)   this.plStarWeightPwr=Double.parseDouble(properties.getProperty(prefix+"plStarWeightPwr"));
  			if (properties.getProperty(prefix+"plWeightToDens")!=null)    this.plWeightToDens=Double.parseDouble(properties.getProperty(prefix+"plWeightToDens"));
  			if (properties.getProperty(prefix+"plStarValPwr")!=null)      this.plStarValPwr=Double.parseDouble(properties.getProperty(prefix+"plStarValPwr"));
  			if (properties.getProperty(prefix+"plDblTriLoss")!=null)      this.plDblTriLoss=Double.parseDouble(properties.getProperty(prefix+"plDblTriLoss"));
  			if (properties.getProperty(prefix+"plNewConfl")!=null)        this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
@@ -3253,6 +3259,7 @@ public class EyesisCorrectionParameters {
  			gd.addNumericField("Maximal number of outliers to remove",                                         this.plMaxOutliers,  0);
  			gd.addNumericField("Minimal total strength of a plane",                                            this.plMinStrength,  6);
  			gd.addNumericField("Maximal eigenvalue of a plane",                                                this.plMaxEigen,  6);
  			gd.addNumericField("Add to eigenvalues of each participating plane and result to validate connections",this.plEigenFloor,  6);
  			gd.addCheckbox    ("Combine 'other' plane with the current (unused)",                              this.plDbgMerge);
  			gd.addNumericField("Worst case worsening after merge",                                             this.plWorstWorsening,  6);
  			gd.addNumericField("Worst case worsening for thin planes",                                         this.plWorstWorsening2,  6);
@@ -3271,6 +3278,7 @@ public class EyesisCorrectionParameters {
  			gd.addNumericField("When calculating cost for the connections scale 4 diagonal neighbors",         this.plStarDiag,  6);
  			gd.addNumericField("Divide cost by number of connections to this power",                           this.plStarPwr,  6);
  			gd.addNumericField("Use this power of tile weight when calculating connection cost",               this.plStarWeightPwr,  6);
  			gd.addNumericField("Balance weighted density against density. 0.0 - density, 1.0 - weighted density", this.plWeightToDens,  6);
  			gd.addNumericField("Raise value of each tile before averaging",                                    this.plStarValPwr,  6);
  			gd.addNumericField("When resolving double triangles allow minor degradation (0.0 - strict)",       this.plDblTriLoss,  6);
  			gd.addCheckbox    ("Allow more conflicts if overall cost is reduced",                              this.plNewConfl);
@@ -3611,6 +3619,7 @@ public class EyesisCorrectionParameters {
  			this.plMaxOutliers=   (int) gd.getNextNumber();
  			this.plMinStrength=         gd.getNextNumber();
  			this.plMaxEigen=            gd.getNextNumber();
  			this.plEigenFloor=          gd.getNextNumber();
  			this.plDbgMerge=            gd.getNextBoolean();
  			this.plWorstWorsening=      gd.getNextNumber();
  			this.plWorstWorsening2=     gd.getNextNumber();
@@ -3629,6 +3638,7 @@ public class EyesisCorrectionParameters {
  			this.plStarDiag=            gd.getNextNumber();
  			this.plStarPwr=             gd.getNextNumber();
  			this.plStarWeightPwr=       gd.getNextNumber();
  			this.plWeightToDens=        gd.getNextNumber();
  			this.plStarValPwr=          gd.getNextNumber();
  			this.plDblTriLoss=          gd.getNextNumber();
  			this.plNewConfl=            gd.getNextBoolean();
+1 −1
Original line number Diff line number Diff line
@@ -505,7 +505,7 @@ private Panel panel1,
			addButton("CLT show fine corr",        panelClt1, color_configure);
			addButton("CLT apply fine corr",       panelClt1, color_process);
			addButton("CLT reset 3D",              panelClt1, color_stop);
			addButton("CLT 3D",                    panelClt1, color_conf_process);
			addButton("CLT 3D",                    panelClt1, color_process);
			addButton("CLT planes",                panelClt1, color_conf_process);
			addButton("CLT ASSIGN",                panelClt1, color_process);
			addButton("CLT OUT 3D",                panelClt1, color_process);
Loading