Commit 1183ecd4 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

trying different plane match criteria

parent 960d054f
Loading
Loading
Loading
Loading
+29 −14
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ public class ConnectionCosts {
	double         orthoWeight;
	double         orthoWeight;
	double         diagonalWeight;
	double         diagonalWeight;
	double         starPwr;    // Divide cost by number of connections to this power
	double         starPwr;    // Divide cost by number of connections to this power
	double         starValPwr; //  Raise value of each tile before averaging
	int            steps;
	int            steps;
	int [][][]     neibs_init;
	int [][][]     neibs_init;
	int []         mod_tiles;
	int []         mod_tiles;
@@ -47,6 +48,7 @@ public class ConnectionCosts {
			double         orthoWeight,
			double         orthoWeight,
			double         diagonalWeight,
			double         diagonalWeight,
			double         starPwr,    // Divide cost by number of connections to this power
			double         starPwr,    // Divide cost by number of connections to this power
			double         starValPwr, //  Raise value of each tile before averaging
			int            steps,
			int            steps,
			TilePlanes.PlaneData [][] planes,
			TilePlanes.PlaneData [][] planes,
			TileSurface.TileNeibs tnSurface,
			TileSurface.TileNeibs tnSurface,
@@ -58,6 +60,7 @@ public class ConnectionCosts {
		this.orthoWeight =     orthoWeight;
		this.orthoWeight =     orthoWeight;
		this.diagonalWeight =  diagonalWeight;
		this.diagonalWeight =  diagonalWeight;
		this.starPwr =         starPwr;         // Divide cost by number of connections to this power
		this.starPwr =         starPwr;         // Divide cost by number of connections to this power
		this.starValPwr =      starValPwr; //  Raise value of each tile before averaging
		this.steps =           steps;
		this.steps =           steps;
	}
	}
	
	
@@ -124,13 +127,16 @@ public class ConnectionCosts {
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
			if (val_weights[isTile] != null){
			if (val_weights[isTile] != null){
				for (int nl = 0; nl < val_weights[isTile].length; nl++) if ( val_weights[isTile][nl] != null){
				for (int nl = 0; nl < val_weights[isTile].length; nl++) if ( val_weights[isTile][nl] != null){
					init_val +=    val_weights[isTile][nl][0] * val_weights[isTile][nl][1];
					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_weight += val_weights[isTile][nl][1];
				}
				}
			}
			}
		}
		}
		// Likely weight will never change except first run, but we will still normalize by weight
		// Likely weight will never change except first run, but we will still normalize by weight
		if (init_weight != 0.0) init_val /= init_weight;
//		if (starValPwr != 1.0) init_val = Math.pow(init_val, 1.0/starValPwr);
//		if (init_weight != 0.0) init_val /= init_weight;
		
		
		return neibs_init; // neighbors to clone
		return neibs_init; // neighbors to clone
	}
	}
@@ -197,6 +203,7 @@ public class ConnectionCosts {
										orthoWeight,
										orthoWeight,
										diagonalWeight,
										diagonalWeight,
										starPwr, // double         starPwr,    // Divide cost by number of connections to this power
										starPwr, // double         starPwr,    // Divide cost by number of connections to this power
//										starValPwr, //double     starValPwr, //  Raise value of each tile before averaging
										tnSurface,
										tnSurface,
										preferDisparity,
										preferDisparity,
										-1); // debugLevel);
										-1); // debugLevel);
@@ -269,6 +276,7 @@ public class ConnectionCosts {
										orthoWeight,
										orthoWeight,
										diagonalWeight,
										diagonalWeight,
										starPwr, // double         starPwr,    // Divide cost by number of connections to this power
										starPwr, // double         starPwr,    // Divide cost by number of connections to this power
//										starValPwr, //double     starValPwr, //  Raise value of each tile before averaging
										tnSurface,
										tnSurface,
										preferDisparity,
										preferDisparity,
										-1); // debugLevel);
										-1); // debugLevel);
@@ -317,12 +325,16 @@ public class ConnectionCosts {
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
		for (int isTile = 0; isTile < all_tiles.length; isTile++){
			if (vw[isTile] != null){
			if (vw[isTile] != null){
				for (int nl = 0; nl < vw[isTile].length; nl++) if ( vw[isTile][nl] != null){
				for (int nl = 0; nl < vw[isTile].length; nl++) if ( vw[isTile][nl] != null){
					new_value +=   vw[isTile][nl][0] * vw[isTile][nl][1];

					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_weight +=         vw[isTile][nl][1];
				}
				}
			}
			}
		}
		}
		if (new_weight != 0.0) new_value /= new_weight;
//		if (starValPwr != 1.0) new_value = Math.pow(new_value, 1.0/starValPwr);
//		if (new_weight != 0.0) new_value /= new_weight;
		return new_value - init_val; // negative - improvement
		return new_value - init_val; // negative - improvement
	}
	}
	
	
@@ -350,11 +362,12 @@ public class ConnectionCosts {
			double orthoWeight,
			double orthoWeight,
			double diagonalWeight,
			double diagonalWeight,
			double starPwr,    // Divide cost by number of connections to this power
			double starPwr,    // Divide cost by number of connections to this power
//			double     starValPwr, //  Raise value of each tile before averaging
			TileSurface.TileNeibs tnSurface,
			TileSurface.TileNeibs tnSurface,
			boolean preferDisparity,
			boolean preferDisparity,
			int    debugLevel)
			int    debugLevel)
	{
	{
		TilePlanes.PlaneData merged_plane = planes[nsTile][nl];
		TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // add weight
		for (int dir = 0; dir < 8; dir++){
		for (int dir = 0; dir < 8; dir++){
			if (neibs[dir] >= 0){
			if (neibs[dir] >= 0){
				double other_weight = ((dir & 1) != 0) ? diagonalWeight : orthoWeight;
				double other_weight = ((dir & 1) != 0) ? diagonalWeight : orthoWeight;
@@ -404,6 +417,7 @@ public class ConnectionCosts {
			double   orthoWeight,
			double   orthoWeight,
			double   diagonalWeight,
			double   diagonalWeight,
			double   starPwr,    // Divide cost by number of connections to this power
			double   starPwr,    // Divide cost by number of connections to this power
//			double   starValPwr, //  Raise value of each tile before averaging
			TileSurface.TileNeibs tnSurface,
			TileSurface.TileNeibs tnSurface,
			boolean preferDisparity,
			boolean preferDisparity,
			int     debugLevel)
			int     debugLevel)
@@ -417,7 +431,8 @@ public class ConnectionCosts {
				double weight1 = dir_weight[dir];
				double weight1 = dir_weight[dir];
				tile_weights.put(new Point(nsTile1, nl1), new Double(weight1)); // no need to check for existence here
				tile_weights.put(new Point(nsTile1, nl1), new Double(weight1)); // no need to check for existence here
				for (int dir1 = 0; dir1 < 8; dir1++){
				for (int dir1 = 0; dir1 < 8; dir1++){
					if ((dir1 != dir) && (neibs2[dir]!= null)){
//					if ((dir1 != dir) && (neibs2[dir]!= null)){
					if ((dir1 != ((dir + 4) %8)) && (neibs2[dir1]!= null)){ // not backwards to the center and exists
						 int nl2 =neibs2[dir][dir1];
						 int nl2 =neibs2[dir][dir1];
						 if (nl2 >= 0){
						 if (nl2 >= 0){
							 Point p = new Point (tnSurface.getNeibIndex(nsTile1, dir1), nl2);
							 Point p = new Point (tnSurface.getNeibIndex(nsTile1, dir1), nl2);
+18 −3
Original line number Original line Diff line number Diff line
@@ -2170,8 +2170,9 @@ public class EyesisCorrectionParameters {
  		public double     plMinStrength        =   0.1;  // Minimal total strength of a plane 
  		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.3;  // Maximal eigenvalue of a plane 
  		public boolean    plDbgMerge           =   true; // Combine 'other' plane with current
  		public boolean    plDbgMerge           =   true; // Combine 'other' plane with current
  		public double     plWorstWorsening     =   3.0;  // Worst case worsening after merge
  		public double     plWorstWorsening     =   2.0;  // Worst case worsening after merge
  		public double     plOKMergeEigen       =   0.03; // If result of the merged planes is below, OK to bypass worst worsening
  		public double     plWorstWorsening2    =   5.0;  // Worst case worsening for thin planes
  		public double     plOKMergeEigen       =   0.03; // If result of the merged planes is below, OK to use thin planes (higher) threshold 
  		public double     plMaxWorldSin2       =   0.1;  // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
  		public double     plMaxWorldSin2       =   0.1;  // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
  		public double     plWeakWorsening      =   1.0;  // Relax merge requirements for weaker planes
  		public double     plWeakWorsening      =   1.0;  // Relax merge requirements for weaker planes
  		
  		
@@ -2184,8 +2185,10 @@ public class EyesisCorrectionParameters {
  		public double     plStarOrtho          =   0.5;  // When calculating cost for the connections scale 4 ortho neighbors
  		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     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     plStarPwr            =   0.5;  // Divide cost by number of connections to this power
  		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 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
  		public boolean    plNewConfl           =   false; // Allow more conflicts if overall cost is reduced
  		public int        plMaxChanges         =   0;     // Maximal number of simultaneous connection changes around one tile (0 - any)
  		
  		
  		public boolean    plMutualOnly         =   true; // keep only mutual links, remove weakest if conflict
  		public boolean    plMutualOnly         =   true; // keep only mutual links, remove weakest if conflict
  		public boolean    plFillSquares        =   true; // Add diagonals to full squares
  		public boolean    plFillSquares        =   true; // Add diagonals to full squares
@@ -2531,6 +2534,7 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"plMaxEigen",       this.plMaxEigen +"");
			properties.setProperty(prefix+"plMaxEigen",       this.plMaxEigen +"");
			properties.setProperty(prefix+"plDbgMerge",       this.plDbgMerge+"");
			properties.setProperty(prefix+"plDbgMerge",       this.plDbgMerge+"");
			properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
			properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
			properties.setProperty(prefix+"plWorstWorsening2",this.plWorstWorsening2 +"");
			properties.setProperty(prefix+"plOKMergeEigen",   this.plOKMergeEigen +"");
			properties.setProperty(prefix+"plOKMergeEigen",   this.plOKMergeEigen +"");
			properties.setProperty(prefix+"plMaxWorldSin2",   this.plMaxWorldSin2 +"");
			properties.setProperty(prefix+"plMaxWorldSin2",   this.plMaxWorldSin2 +"");
			properties.setProperty(prefix+"plWeakWorsening",  this.plWeakWorsening +"");
			properties.setProperty(prefix+"plWeakWorsening",  this.plWeakWorsening +"");
@@ -2543,8 +2547,10 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"plStarOrtho",      this.plStarOrtho +"");
			properties.setProperty(prefix+"plStarOrtho",      this.plStarOrtho +"");
			properties.setProperty(prefix+"plStarDiag",       this.plStarDiag +"");
			properties.setProperty(prefix+"plStarDiag",       this.plStarDiag +"");
			properties.setProperty(prefix+"plStarPwr",        this.plStarPwr +"");
			properties.setProperty(prefix+"plStarPwr",        this.plStarPwr +"");
			properties.setProperty(prefix+"plStarValPwr",     this.plStarValPwr +"");
			properties.setProperty(prefix+"plDblTriLoss",     this.plDblTriLoss +"");
			properties.setProperty(prefix+"plDblTriLoss",     this.plDblTriLoss +"");
			properties.setProperty(prefix+"plNewConfl",       this.plNewConfl+"");
			properties.setProperty(prefix+"plNewConfl",       this.plNewConfl+"");
  			properties.setProperty(prefix+"plMaxChanges",     this.plMaxChanges+"");


			properties.setProperty(prefix+"plMutualOnly",     this.plMutualOnly+"");
			properties.setProperty(prefix+"plMutualOnly",     this.plMutualOnly+"");
			properties.setProperty(prefix+"plFillSquares",    this.plFillSquares+"");
			properties.setProperty(prefix+"plFillSquares",    this.plFillSquares+"");
@@ -2870,6 +2876,7 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"plMaxEigen")!=null)        this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
  			if (properties.getProperty(prefix+"plMaxEigen")!=null)        this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
  			if (properties.getProperty(prefix+"plDbgMerge")!=null)        this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
  			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+"plWorstWorsening")!=null)  this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
  			if (properties.getProperty(prefix+"plWorstWorsening2")!=null) this.plWorstWorsening2=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening2"));
  			if (properties.getProperty(prefix+"plOKMergeEigen")!=null)    this.plOKMergeEigen=Double.parseDouble(properties.getProperty(prefix+"plOKMergeEigen"));
  			if (properties.getProperty(prefix+"plOKMergeEigen")!=null)    this.plOKMergeEigen=Double.parseDouble(properties.getProperty(prefix+"plOKMergeEigen"));
  			if (properties.getProperty(prefix+"plMaxWorldSin2")!=null)    this.plMaxWorldSin2=Double.parseDouble(properties.getProperty(prefix+"plMaxWorldSin2"));
  			if (properties.getProperty(prefix+"plMaxWorldSin2")!=null)    this.plMaxWorldSin2=Double.parseDouble(properties.getProperty(prefix+"plMaxWorldSin2"));
  			if (properties.getProperty(prefix+"plWeakWorsening")!=null)   this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
  			if (properties.getProperty(prefix+"plWeakWorsening")!=null)   this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
@@ -2882,8 +2889,10 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"plStarOrtho")!=null)       this.plStarOrtho=Double.parseDouble(properties.getProperty(prefix+"plStarOrtho"));
  			if (properties.getProperty(prefix+"plStarOrtho")!=null)       this.plStarOrtho=Double.parseDouble(properties.getProperty(prefix+"plStarOrtho"));
  			if (properties.getProperty(prefix+"plStarDiag")!=null)        this.plStarDiag=Double.parseDouble(properties.getProperty(prefix+"plStarDiag"));
  			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+"plStarPwr")!=null)         this.plStarPwr=Double.parseDouble(properties.getProperty(prefix+"plStarPwr"));
  			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+"plDblTriLoss")!=null)      this.plDblTriLoss=Double.parseDouble(properties.getProperty(prefix+"plDblTriLoss"));
  			if (properties.getProperty(prefix+"plNewConfl")!=null)        this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
  			if (properties.getProperty(prefix+"plNewConfl")!=null)        this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
  			if (properties.getProperty(prefix+"plMaxChanges")!=null)      this.plMaxChanges=Integer.parseInt(properties.getProperty(prefix+"plMaxChanges"));
  			
  			
  			if (properties.getProperty(prefix+"plMutualOnly")!=null)      this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));
  			if (properties.getProperty(prefix+"plMutualOnly")!=null)      this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));
  			if (properties.getProperty(prefix+"plFillSquares")!=null)     this.plFillSquares=Boolean.parseBoolean(properties.getProperty(prefix+"plFillSquares"));
  			if (properties.getProperty(prefix+"plFillSquares")!=null)     this.plFillSquares=Boolean.parseBoolean(properties.getProperty(prefix+"plFillSquares"));
@@ -3237,7 +3246,8 @@ public class EyesisCorrectionParameters {
  			gd.addNumericField("Maximal eigenvalue of a plane",                                                this.plMaxEigen,  6);
  			gd.addNumericField("Maximal eigenvalue of a plane",                                                this.plMaxEigen,  6);
  			gd.addCheckbox    ("Combine 'other' plane with the current (unused)",                              this.plDbgMerge);
  			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 after merge",                                             this.plWorstWorsening,  6);
  			gd.addNumericField("If result of the merged planes is below, OK to bypass worst worsening",        this.plOKMergeEigen,  6);
  			gd.addNumericField("Worst case worsening for thin planes",                                         this.plWorstWorsening2,  6);
  			gd.addNumericField("If result of the merged planes is below, OK to use thin planes (higher) threshold ",this.plOKMergeEigen,  6);
  			gd.addNumericField("Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable", this.plMaxWorldSin2,  6);
  			gd.addNumericField("Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable", this.plMaxWorldSin2,  6);
  			gd.addNumericField("Relax merge requirements for weaker planes",                                   this.plWeakWorsening,  6);
  			gd.addNumericField("Relax merge requirements for weaker planes",                                   this.plWeakWorsening,  6);


@@ -3249,8 +3259,10 @@ public class EyesisCorrectionParameters {
  			gd.addNumericField("When calculating cost for the connections scale 4 ortho neighbors",            this.plStarOrtho,  6);
  			gd.addNumericField("When calculating cost for the connections scale 4 ortho neighbors",            this.plStarOrtho,  6);
  			gd.addNumericField("When calculating cost for the connections scale 4 diagonal neighbors",         this.plStarDiag,  6);
  			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("Divide cost by number of connections to this power",                           this.plStarPwr,  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.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);
  			gd.addCheckbox    ("Allow more conflicts if overall cost is reduced",                              this.plNewConfl);
  			gd.addNumericField("aximal number of simultaneous connection changes around one tile (0 - any)",   this.plMaxChanges,  0);


  			gd.addCheckbox    ("Keep only mutual links, remove weakest if conflict",                           this.plMutualOnly);
  			gd.addCheckbox    ("Keep only mutual links, remove weakest if conflict",                           this.plMutualOnly);


@@ -3589,6 +3601,7 @@ public class EyesisCorrectionParameters {
  			this.plMaxEigen=            gd.getNextNumber();
  			this.plMaxEigen=            gd.getNextNumber();
  			this.plDbgMerge=            gd.getNextBoolean();
  			this.plDbgMerge=            gd.getNextBoolean();
  			this.plWorstWorsening=      gd.getNextNumber();
  			this.plWorstWorsening=      gd.getNextNumber();
  			this.plWorstWorsening2=     gd.getNextNumber();
  			this.plOKMergeEigen=        gd.getNextNumber();
  			this.plOKMergeEigen=        gd.getNextNumber();
  			this.plMaxWorldSin2=        gd.getNextNumber();
  			this.plMaxWorldSin2=        gd.getNextNumber();
  			this.plWeakWorsening=       gd.getNextNumber();
  			this.plWeakWorsening=       gd.getNextNumber();
@@ -3601,8 +3614,10 @@ public class EyesisCorrectionParameters {
  			this.plStarOrtho=           gd.getNextNumber();
  			this.plStarOrtho=           gd.getNextNumber();
  			this.plStarDiag=            gd.getNextNumber();
  			this.plStarDiag=            gd.getNextNumber();
  			this.plStarPwr=             gd.getNextNumber();
  			this.plStarPwr=             gd.getNextNumber();
  			this.plStarValPwr=          gd.getNextNumber();
  			this.plDblTriLoss=          gd.getNextNumber();
  			this.plDblTriLoss=          gd.getNextNumber();
  			this.plNewConfl=            gd.getNextBoolean();
  			this.plNewConfl=            gd.getNextBoolean();
  			this.plMaxChanges=    (int) gd.getNextNumber();


  			this.plMutualOnly=          gd.getNextBoolean();
  			this.plMutualOnly=          gd.getNextBoolean();


Loading