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

trying different plane match criteria

parent 960d054f
...@@ -32,6 +32,7 @@ public class ConnectionCosts { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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];
new_weight += 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];
} }
} }
} }
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 { ...@@ -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;
...@@ -397,16 +410,17 @@ public class ConnectionCosts { ...@@ -397,16 +410,17 @@ public class ConnectionCosts {
public double [] getStarValueWeight( public double [] getStarValueWeight(
int nsTile, int nsTile,
int nl, int nl,
int [] neibs, int [] neibs,
int [][] neibs2, // neighbors' neighbors int [][] neibs2, // neighbors' neighbors
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)
{ {
double [] dir_weight = {orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight}; double [] dir_weight = {orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight, orthoWeight, diagonalWeight};
HashMap<Point, Double> tile_weights = new HashMap<Point, Double>(); HashMap<Point, Double> tile_weights = new HashMap<Point, Double>();
...@@ -417,7 +431,8 @@ public class ConnectionCosts { ...@@ -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);
......
...@@ -2170,8 +2170,9 @@ public class EyesisCorrectionParameters { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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();
......
...@@ -3401,7 +3401,7 @@ public class SuperTiles{ ...@@ -3401,7 +3401,7 @@ public class SuperTiles{
} }
// Oscolete? // Oscolete?
public void selectNeighborPlanes( public void selectNeighborPlanesOld(
final double worst_worsening, final double worst_worsening,
final boolean mutual_only, final boolean mutual_only,
final int debugLevel) final int debugLevel)
...@@ -3514,6 +3514,7 @@ public class SuperTiles{ ...@@ -3514,6 +3514,7 @@ public class SuperTiles{
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
} }
} }
public int fillSquares() public int fillSquares()
{ {
final int tilesX = tileProcessor.getTilesX(); final int tilesX = tileProcessor.getTilesX();
...@@ -3754,6 +3755,7 @@ public class SuperTiles{ ...@@ -3754,6 +3755,7 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity, boolean preferDisparity,
int debugLevel, int debugLevel,
...@@ -3793,6 +3795,7 @@ public class SuperTiles{ ...@@ -3793,6 +3795,7 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
dblTriLoss, // double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) dblTriLoss, // double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity, // boolean preferDisparity, preferDisparity, // boolean preferDisparity,
dl); // int debugLevel) dl); // int debugLevel)
...@@ -3820,6 +3823,7 @@ public class SuperTiles{ ...@@ -3820,6 +3823,7 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
...@@ -3880,6 +3884,7 @@ public class SuperTiles{ ...@@ -3880,6 +3884,7 @@ public class SuperTiles{
orthoWeight, orthoWeight,
diagonalWeight, diagonalWeight,
starPwr, // Divide cost by number of connections to this power starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, starSteps,
this.planes, this.planes,
tnSurface, tnSurface,
...@@ -3891,7 +3896,7 @@ public class SuperTiles{ ...@@ -3891,7 +3896,7 @@ public class SuperTiles{
double [][][] val_weights = new double [mod_supertiles.length][][]; double [][][] val_weights = new double [mod_supertiles.length][][];
// Calculate original costs and neighhbors // Calculate original costs and neighhbors
updateConnectionsCost ( updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
null, // int [][][] neibs_prev, null, // int [][][] neibs_prev,
neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -3971,7 +3976,7 @@ public class SuperTiles{ ...@@ -3971,7 +3976,7 @@ public class SuperTiles{
", improvement (negative diff) = "+new_costs_diff); ", improvement (negative diff) = "+new_costs_diff);
} }
double new_costs_diff_old = updateConnectionsCost ( double new_costs_diff_old = updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
neibs_prev_old, // int [][][] neibs_prev, neibs_prev_old, // int [][][] neibs_prev,
neibs_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -4073,6 +4078,7 @@ public class SuperTiles{ ...@@ -4073,6 +4078,7 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
...@@ -4133,6 +4139,7 @@ public class SuperTiles{ ...@@ -4133,6 +4139,7 @@ public class SuperTiles{
orthoWeight, orthoWeight,
diagonalWeight, diagonalWeight,
starPwr, // Divide cost by number of connections to this power starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, starSteps,
this.planes, this.planes,
tnSurface, tnSurface,
...@@ -4143,7 +4150,7 @@ public class SuperTiles{ ...@@ -4143,7 +4150,7 @@ public class SuperTiles{
/** */ /** */
int [][][] neibs_prev_old = new int [mod_supertiles.length][][]; int [][][] neibs_prev_old = new int [mod_supertiles.length][][];
double [][][] val_weights_original = new double [mod_supertiles.length][][]; double [][][] val_weights_original = new double [mod_supertiles.length][][];
updateConnectionsCost ( updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
null, // int [][][] neibs_prev, null, // int [][][] neibs_prev,
neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -4213,7 +4220,7 @@ public class SuperTiles{ ...@@ -4213,7 +4220,7 @@ public class SuperTiles{
val_weights[nt][nl] = val_weights_original[nt][nl].clone(); val_weights[nt][nl] = val_weights_original[nt][nl].clone();
} }
} }
variant_costs_diff_old[variant] = updateConnectionsCost ( variant_costs_diff_old[variant] = updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
neibs_prev_old, // int [][][] neibs_prev, neibs_prev_old, // int [][][] neibs_prev,
neibs_vars[variant], // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs_vars[variant], // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -4338,6 +4345,7 @@ public class SuperTiles{ ...@@ -4338,6 +4345,7 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity, boolean preferDisparity,
int debugLevel, int debugLevel,
...@@ -4370,6 +4378,7 @@ public class SuperTiles{ ...@@ -4370,6 +4378,7 @@ public class SuperTiles{
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
dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity, preferDisparity,
dl); // debugLevel, dl); // debugLevel,
...@@ -4388,8 +4397,10 @@ public class SuperTiles{ ...@@ -4388,8 +4397,10 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced boolean newConfl, // Allow more conflicts if overall cost is reduced
int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
boolean preferDisparity, boolean preferDisparity,
int debugLevel, int debugLevel,
int dbg_X, int dbg_X,
...@@ -4419,8 +4430,10 @@ public class SuperTiles{ ...@@ -4419,8 +4430,10 @@ public class SuperTiles{
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
dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) starValPwr, //double starValPwr, // Raise value of each tile before averaging
newConfl, // boolean newConfl, // Allow more conflicts if overall cost is reduced dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
newConfl, // boolean newConfl, // Allow more conflicts if overall cost is reduced
maxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
preferDisparity, preferDisparity,
dl); // debugLevel, dl); // debugLevel,
if (OK) rslt[0]++; if (OK) rslt[0]++;
...@@ -4442,8 +4455,10 @@ public class SuperTiles{ ...@@ -4442,8 +4455,10 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced boolean newConfl, // Allow more conflicts if overall cost is reduced
int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
{ {
...@@ -4470,7 +4485,9 @@ public class SuperTiles{ ...@@ -4470,7 +4485,9 @@ public class SuperTiles{
System.out.println("resolveStarConflict(): nsTile ="+nsTile+" nl1="+nl1+" nl2="+nl2); System.out.println("resolveStarConflict(): nsTile ="+nsTile+" nl1="+nl1+" nl2="+nl2);
} }
int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants(debugLevel); int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants(
maxChanges,
debugLevel);
int [] mod_supertiles = {nsTile}; int [] mod_supertiles = {nsTile};
mod_supertiles = getInvolvedSupertiles( // first mod_supertiles.length entries will be mod_supertiles[] mod_supertiles = getInvolvedSupertiles( // first mod_supertiles.length entries will be mod_supertiles[]
...@@ -4521,6 +4538,7 @@ public class SuperTiles{ ...@@ -4521,6 +4538,7 @@ public class SuperTiles{
orthoWeight, orthoWeight,
diagonalWeight, diagonalWeight,
starPwr, // Divide cost by number of connections to this power starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, starSteps,
this.planes, this.planes,
tnSurface, tnSurface,
...@@ -4730,8 +4748,10 @@ public class SuperTiles{ ...@@ -4730,8 +4748,10 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced boolean newConfl, // Allow more conflicts if overall cost is reduced
int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
boolean preferDisparity, boolean preferDisparity,
int debugLevel) int debugLevel)
{ {
...@@ -4747,10 +4767,13 @@ public class SuperTiles{ ...@@ -4747,10 +4767,13 @@ public class SuperTiles{
int nt = tnSurface.getNeibIndex(nsTile, dir); int nt = tnSurface.getNeibIndex(nsTile, dir);
if ((nt >= 0) && (planes[nt] != null)) { if ((nt >= 0) && (planes[nt] != null)) {
int [][] neibs = new int [planes[nt].length][]; int [][] neibs = new int [planes[nt].length][];
boolean [][][] merge_valid = new boolean [planes[nt].length][][];
for (int nl = 0; nl < planes[nt].length; nl++) if ( planes[nt][nl] != null){ for (int nl = 0; nl < planes[nt].length; nl++) if ( planes[nt][nl] != null){
neibs[nl] = planes[nt][nl].getNeibBest(); neibs[nl] = planes[nt][nl].getNeibBest();
merge_valid[nl] = planes[nt][nl].getMergedValid();
} }
twoLayerNeighbors.setNeighbors(neibs,dir); twoLayerNeighbors.setNeighbors(neibs,dir);
twoLayerNeighbors.setMergeValid(merge_valid,dir);
} }
} }
twoLayerNeighbors.setLayers(nl1, nl2); twoLayerNeighbors.setLayers(nl1, nl2);
...@@ -4758,7 +4781,9 @@ public class SuperTiles{ ...@@ -4758,7 +4781,9 @@ public class SuperTiles{
System.out.println("resolveStarConflict(): nsTile ="+nsTile+" nl1="+nl1+" nl2="+nl2); System.out.println("resolveStarConflict(): nsTile ="+nsTile+" nl1="+nl1+" nl2="+nl2);
} }
int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants(debugLevel); int [][][][] neibs_vars_dir = twoLayerNeighbors.getNeighborVariants(
maxChanges,
debugLevel);
int [] mod_supertiles = {nsTile}; int [] mod_supertiles = {nsTile};
mod_supertiles = getInvolvedSupertiles( // first mod_supertiles.length entries will be mod_supertiles[] mod_supertiles = getInvolvedSupertiles( // first mod_supertiles.length entries will be mod_supertiles[]
...@@ -4809,6 +4834,7 @@ public class SuperTiles{ ...@@ -4809,6 +4834,7 @@ public class SuperTiles{
orthoWeight, orthoWeight,
diagonalWeight, diagonalWeight,
starPwr, // Divide cost by number of connections to this power starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, starSteps,
this.planes, this.planes,
tnSurface, tnSurface,
...@@ -4944,8 +4970,8 @@ public class SuperTiles{ ...@@ -4944,8 +4970,8 @@ public class SuperTiles{
if (debugLevel > 1){ if (debugLevel > 1){
System.out.println("resolveStarConflict(): for tile "+nsTile); System.out.println("resolveStarConflict(): for tile "+nsTile);
} }
/*
if ((best_variant < 0) && newConfl && (variant_costs_diff[best_ignore_conflicts] < 0)){ // should be cost improvement if ((best_variant < 0) && newConfl && (best_ignore_conflicts >= 0) && (variant_costs_diff[best_ignore_conflicts] < 0)){ // should be cost improvement
best_variant = best_ignore_conflicts; best_variant = best_ignore_conflicts;
if (debugLevel > -1) { if (debugLevel > -1) {
System.out.println("resolveMultiTriangularConflict(): conflicts increase but cost decreases "+nsTile+ System.out.println("resolveMultiTriangularConflict(): conflicts increase but cost decreases "+nsTile+
...@@ -4953,9 +4979,22 @@ public class SuperTiles{ ...@@ -4953,9 +4979,22 @@ public class SuperTiles{
", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants"); ", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants");
} }
} }
if ((best_variant < 0) || (variant_costs_diff[best_variant] > dblTriLoss)){ */
if (newConfl){ // should be cost improvement
best_variant = best_ignore_conflicts;
if (debugLevel > -1) { if (debugLevel > -1) {
System.out.println("resolveMultiTriangularConflict(): FAILED find a sutable solution for tile "+nsTile+ System.out.println("resolveStarConflict(): ignoring conflicts if any for "+nsTile+
", nl1 = "+nl1+
", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants");
}
}
if ((best_variant < 0) || (variant_costs_diff[best_variant] > dblTriLoss) ||
((variant_costs_diff[best_variant] >= 0.0) && (conflicts_var_cost[best_variant] >= conflicts_old_cost) &&
(num_var_conflicts[best_variant] >= 0))){
if (debugLevel > -1) {
System.out.println("resolveStarConflict(): FAILED find a sutable solution for tile "+nsTile+
", nl1 = "+nl1+ ", nl1 = "+nl1+
", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants"); ", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants");
return false; return false;
...@@ -5010,6 +5049,7 @@ public class SuperTiles{ ...@@ -5010,6 +5049,7 @@ public class SuperTiles{
orthoWeight, // final double orthoWeight, orthoWeight, // final double orthoWeight,
diagonalWeight, // final double diagonalWeight, diagonalWeight, // final double diagonalWeight,
starPwr, // final double starPwr, // Divide cost by number of connections to this power starPwr, // final double starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, // final int steps, starSteps, // final int steps,
planes, // final TilePlanes.PlaneData [][] planes, planes, // final TilePlanes.PlaneData [][] planes,
preferDisparity); // final boolean preferDisparity) preferDisparity); // final boolean preferDisparity)
...@@ -5022,6 +5062,7 @@ public class SuperTiles{ ...@@ -5022,6 +5062,7 @@ public class SuperTiles{
final double orthoWeight, final double orthoWeight,
final double diagonalWeight, final double diagonalWeight,
final double starPwr, // Divide cost by number of connections to this power final double starPwr, // Divide cost by number of connections to this power
final double starValPwr, // Raise value of each tile before averaging
final int steps, final int steps,
final TilePlanes.PlaneData [][] planes, final TilePlanes.PlaneData [][] planes,
final boolean preferDisparity) final boolean preferDisparity)
...@@ -5043,6 +5084,7 @@ public class SuperTiles{ ...@@ -5043,6 +5084,7 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
steps, // int steps, steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes, planes, // TilePlanes.PlaneData [][] planes,
tnSurface, // TileSurface.TileNeibs tnSurface, tnSurface, // TileSurface.TileNeibs tnSurface,
...@@ -5071,6 +5113,7 @@ public class SuperTiles{ ...@@ -5071,6 +5113,7 @@ public class SuperTiles{
final double orthoWeight, final double orthoWeight,
final double diagonalWeight, final double diagonalWeight,
final double starPwr, // Divide cost by number of connections to this power final double starPwr, // Divide cost by number of connections to this power
final double starValPwr, // Raise value of each tile before averaging
final int steps, final int steps,
final TilePlanes.PlaneData [][] planes, final TilePlanes.PlaneData [][] planes,
final boolean preferDisparity) final boolean preferDisparity)
...@@ -5091,6 +5134,7 @@ public class SuperTiles{ ...@@ -5091,6 +5134,7 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
steps, // int steps, steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes, planes, // TilePlanes.PlaneData [][] planes,
tnSurface, // TileSurface.TileNeibs tnSurface, tnSurface, // TileSurface.TileNeibs tnSurface,
...@@ -5374,8 +5418,10 @@ public class SuperTiles{ ...@@ -5374,8 +5418,10 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced boolean newConfl, // Allow more conflicts if overall cost is reduced
int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
boolean preferDisparity, boolean preferDisparity,
int debugLevel, int debugLevel,
int dbg_X, int dbg_X,
...@@ -5386,6 +5432,7 @@ public class SuperTiles{ ...@@ -5386,6 +5432,7 @@ public class SuperTiles{
orthoWeight, // final double orthoWeight, orthoWeight, // final double orthoWeight,
diagonalWeight, // final double diagonalWeight, diagonalWeight, // final double diagonalWeight,
starPwr, // final double starPwr, // Divide cost by number of connections to this power starPwr, // final double starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, // final int steps, starSteps, // final int steps,
this.planes, // final TilePlanes.PlaneData [][] planes, this.planes, // final TilePlanes.PlaneData [][] planes,
preferDisparity); // final boolean preferDisparity) preferDisparity); // final boolean preferDisparity)
...@@ -5408,10 +5455,11 @@ public class SuperTiles{ ...@@ -5408,10 +5455,11 @@ public class SuperTiles{
conflicts0, // int [][][] conflicts, conflicts0, // int [][][] conflicts,
conflicts0_stats, conflicts0_stats,
maxEigen, maxEigen,
starSteps, // How far to look around when calculationg connection cost starSteps, // How far to look around when calculating connection cost
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
dblTriLoss, // double diagonalWeight, dblTriLoss, // double diagonalWeight,
preferDisparity, preferDisparity,
debugLevel, // 1, // final int debugLevel) debugLevel, // 1, // final int debugLevel)
...@@ -5427,6 +5475,7 @@ public class SuperTiles{ ...@@ -5427,6 +5475,7 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
dblTriLoss, // double diagonalWeight, dblTriLoss, // double diagonalWeight,
preferDisparity, preferDisparity,
debugLevel, // 1, // final int debugLevel) debugLevel, // 1, // final int debugLevel)
...@@ -5442,6 +5491,7 @@ public class SuperTiles{ ...@@ -5442,6 +5491,7 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
dblTriLoss, // double diagonalWeight, dblTriLoss, // double diagonalWeight,
preferDisparity, preferDisparity,
((pass == 3)? 1: 0), // debugLevel, // 1, // final int debugLevel) ((pass == 3)? 1: 0), // debugLevel, // 1, // final int debugLevel)
...@@ -5457,8 +5507,10 @@ public class SuperTiles{ ...@@ -5457,8 +5507,10 @@ public class SuperTiles{
orthoWeight, // double orthoWeight, orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight, diagonalWeight, // double 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
dblTriLoss, // double diagonalWeight, dblTriLoss, // double diagonalWeight,
newConfl, // Allow more conflicts if overall cost is reduced newConfl, // Allow more conflicts if overall cost is reduced
maxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
preferDisparity, preferDisparity,
debugLevel, // 1, // final int debugLevel) debugLevel, // 1, // final int debugLevel)
dbg_X, dbg_X,
...@@ -5488,7 +5540,7 @@ public class SuperTiles{ ...@@ -5488,7 +5540,7 @@ public class SuperTiles{
1); // final int debugLevel) 1); // final int debugLevel)
conflicts1_stats.printConflictSummary("Recounted conflicts (all):", true,false,false); conflicts1_stats.printConflictSummary("Recounted conflicts (all):", true,false,false);
conflicts1_stats.printConflictSummary("Recounted conflicts (ortho-diag-ortho):", false, true,false); conflicts1_stats.printConflictSummary("Recounted conflicts (ortho-diag-ortho):", false, true,false);
conflicts1_stats.printConflictSummary("Recounted conflicts(ortho-ortho-diag):", false, false, true); conflicts1_stats.printConflictSummary("Recounted conflicts (ortho-ortho-diag):", false, false, true);
/* /*
...@@ -5523,6 +5575,7 @@ public class SuperTiles{ ...@@ -5523,6 +5575,7 @@ public class SuperTiles{
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
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict) double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity, boolean preferDisparity,
int debugLevel, int debugLevel,
...@@ -5597,6 +5650,7 @@ public class SuperTiles{ ...@@ -5597,6 +5650,7 @@ public class SuperTiles{
orthoWeight, orthoWeight,
diagonalWeight, diagonalWeight,
starPwr, // Divide cost by number of connections to this power starPwr, // Divide cost by number of connections to this power
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, starSteps,
this.planes, this.planes,
tnSurface, tnSurface,
...@@ -5605,7 +5659,7 @@ public class SuperTiles{ ...@@ -5605,7 +5659,7 @@ public class SuperTiles{
int [][][] neibs_prev_old = new int [mod_supertiles.length][][]; int [][][] neibs_prev_old = new int [mod_supertiles.length][][];
double [][][] val_weights = new double [mod_supertiles.length][][]; double [][][] val_weights = new double [mod_supertiles.length][][];
updateConnectionsCost ( updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
null, // int [][][] neibs_prev, null, // int [][][] neibs_prev,
neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs_prev_old, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -5673,7 +5727,7 @@ public class SuperTiles{ ...@@ -5673,7 +5727,7 @@ public class SuperTiles{
", dir4 = "+dir4+" improvement (negative diff) = "+cost_diff); ", dir4 = "+dir4+" improvement (negative diff) = "+cost_diff);
} }
double cost_diff_old = updateConnectionsCost ( double cost_diff_old = updateConnectionsCost_old (
mod_supertiles, // int [] nsTiles, mod_supertiles, // int [] nsTiles,
neibs_prev, // int [][][] neibs_prev, neibs_prev, // int [][][] neibs_prev,
neibs, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null neibs, // int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -5903,7 +5957,7 @@ public class SuperTiles{ ...@@ -5903,7 +5957,7 @@ public class SuperTiles{
* @return a pair of eigenvalue of the combine plane and its weight * @return a pair of eigenvalue of the combine plane and its weight
*/ */
public double [] getStarValueWeight( public double [] getStarValueWeight_old(
int nsTile, int nsTile,
int nl, int nl,
int [] neibs, int [] neibs,
...@@ -5990,7 +6044,7 @@ public class SuperTiles{ ...@@ -5990,7 +6044,7 @@ public class SuperTiles{
*/ */
public double updateConnectionsCost ( public double updateConnectionsCost_old (
int [] nsTiles, int [] nsTiles,
int [][][] neibs_prev, int [][][] neibs_prev,
int [][][] neibs, // should be initialized at top dimension if neibs_prev==null int [][][] neibs, // should be initialized at top dimension if neibs_prev==null
...@@ -6045,7 +6099,7 @@ public class SuperTiles{ ...@@ -6045,7 +6099,7 @@ public class SuperTiles{
} }
} }
if (neibs_changed){ if (neibs_changed){
val_weights[isTile][nl] = getStarValueWeight( val_weights[isTile][nl] = getStarValueWeight_old(
nsTile, nsTile,
nl, nl,
neibs[isTile][nl], neibs[isTile][nl],
...@@ -6229,6 +6283,144 @@ public class SuperTiles{ ...@@ -6229,6 +6283,144 @@ public class SuperTiles{
return -1; return -1;
} }
/**
* Mark which links between neighbor planes are valid
* @param rquality maximal degradation by merging (does not depend on the total weight)
* @param okMergeEigen if result eigenvalue of the merged planes is below, OK to bypass worst worsening
* @param maxWorldSin2 maximal square of the sine of the angle between the planes to allow merge (>= 1.0 - disable)
* @param maxEigen maximal eigenvalue of each of the merged planes
* @param minWeight minimal weight of each of the planes
* @param debugLevel debug level
* @param dbg_X debug supertile X coordinate
* @param dbg_Y debug supertile Y coordinate
*/
public void filterNeighborPlanes(
final double rquality,
final double worstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
final double weakWorsening,
final double okMergeEigen,
final double maxWorldSin2,
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double minWeight, // minimal pain weight to consider
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final double [] nan_plane = new double [superTileSize*superTileSize];
for (int i = 0; i < nan_plane.length; i++) nan_plane[i] = Double.NaN;
final int [][] dirsYX = {{-1, 0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
// final int debug_stile = 20 * stilesX + 27;
// final int debug_stile = 17 * stilesX + 27;
// final int debug_stile = 9 * stilesX + 26;
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TilePlanes.PlaneData [][] dbg_planes = planes;
for (int nsTile0 = ai.getAndIncrement(); nsTile0 < nStiles; nsTile0 = ai.getAndIncrement()) {
int sty0 = nsTile0 / stilesX;
int stx0 = nsTile0 % stilesX;
int dl = (nsTile0 == debug_stile) ? 1:0;
if ( planes[nsTile0] != null) {
if (dl > 0){
System.out.println("filterNeighborPlanes() nsTile0="+nsTile0);
}
int np0_min = (planes[nsTile0].length > 1) ? 1:0; // Modify if overall plane will be removed
for (int dir = 0; dir < 4; dir++){ //
int stx = stx0 + dirsYX[dir][1];
int sty = sty0 + dirsYX[dir][0];
int nsTile = sty * stilesX + stx; // from where to get
for (int np0 = np0_min; np0 < planes[nsTile0].length; np0++){
if ((planes[nsTile0][np0] != null) && (planes[nsTile0][np0].getMergedValue(dir) != null)){
double [] merge_ev = planes[nsTile0][np0].getMergedValue(dir);
if ( (merge_ev != null) &&
((maxEigen == 0.0) ||
(planes[nsTile0][np0].getValue() < corrMaxEigen(
maxEigen,
dispNorm,
planes[nsTile0][np0]))) &&
(planes[nsTile0][np0].getWeight() > minWeight)) {
int np_min = LOWEST_PLANE(merge_ev.length);
for (int np = np_min; np < merge_ev.length; np++){
if ( (planes[nsTile][np] != null) &&
!Double.isNaN(merge_ev[np]) &&
((maxEigen == 0.0) ||
(planes[nsTile][np].getValue() < corrMaxEigen(
maxEigen,
dispNorm,
planes[nsTile][np]))) &&
(planes[nsTile][np].getWeight() > minWeight)) {
double w1 = planes[nsTile0][np0].getWeight();
double w2 = planes[nsTile][np].getWeight();
double this_rq = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2); // double w2)
double this_rq_norm = this_rq;
if ((w1 + w2) < weakWorsening) this_rq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
if ((this_rq_norm <= rquality) ||
((merge_ev[np] <= okMergeEigen) && (this_rq_norm <= worstWorsening2)) // use higher threshold
) {
if ((maxWorldSin2 >= 1.0) || (planes[nsTile0][np0].getWorldSin2(planes[nsTile][np]) <=maxWorldSin2)) {
if (dl > 0){
System.out.println("filterNeighborPlanes : nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+" dir="+dir+" is VALID");
}
planes[nsTile0][np0].setMergedValid(dir, np, true, planes[nsTile].length);
planes[nsTile][np].setMergedValid((dir + 4) %8, np0, true, planes[nsTile0].length);
}
}
if (debugLevel > 0){
if ((merge_ev[np] < 0.4) && (w1 > 1.0) && (w2 > 1.0) ){
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
", this_rq*(w1+w2)="+(this_rq * (w1 + w2))+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
}
}
if (dl >0) {
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", world sin2 ="+
planes[nsTile0][np0].getWorldSin2(planes[nsTile][np]));
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+
", world dist this="+ Math.sqrt(planes[nsTile0][np0].getWorldPlaneDist2(planes[nsTile][np]))+
", world dist other="+Math.sqrt(planes[nsTile][np].getWorldPlaneDist2(planes[nsTile0][np0]))+
", world dist sum="+Math.sqrt(planes[nsTile0][np0].getWorldPlaneDist2(planes[nsTile][np])+
planes[nsTile][np].getWorldPlaneDist2(planes[nsTile0][np0])));
}
}
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
/** /**
...@@ -6244,6 +6436,219 @@ public class SuperTiles{ ...@@ -6244,6 +6436,219 @@ public class SuperTiles{
* @param dbg_Y debug supertile Y coordinate * @param dbg_Y debug supertile Y coordinate
*/ */
public void selectNeighborPlanesMutual( public void selectNeighborPlanesMutual(
// final double rquality,
// final double weakWorsening,
// final double okMergeEigen,
// final double maxWorldSin2,
// final double dispNorm,
// final double maxEigen, // maximal eigenvalue of planes to consider
// final double minWeight, // minimal pain weight to consider
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final double [] nan_plane = new double [superTileSize*superTileSize];
for (int i = 0; i < nan_plane.length; i++) nan_plane[i] = Double.NaN;
final int [][] dirsYX = {{-1, 0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
// final int debug_stile = 20 * stilesX + 27;
// final int debug_stile = 17 * stilesX + 27;
// final int debug_stile = 9 * stilesX + 26;
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nsTile0 = ai.getAndIncrement(); nsTile0 < nStiles; nsTile0 = ai.getAndIncrement()) {
if ( planes[nsTile0] != null) {
for (int np0 = 0; np0 < planes[nsTile0].length; np0++){ // nu
TilePlanes.PlaneData this_plane = planes[nsTile0][np0];
if (this_plane != null) {
this_plane.initNeibBest();
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
TilePlanes.PlaneData [][] dbg_planes = planes;
for (int nsTile0 = ai.getAndIncrement(); nsTile0 < nStiles; nsTile0 = ai.getAndIncrement()) {
int sty0 = nsTile0 / stilesX;
int stx0 = nsTile0 % stilesX;
int dl = (nsTile0 == debug_stile) ? 1:0;
if ( planes[nsTile0] != null) {
if (dl > 0){
System.out.println(" ===== selectNeighborPlanesMutual() nsTile0="+nsTile0+" =====");
}
int np0_min = (planes[nsTile0].length > 1) ? 1:0; // Modify if overall plane will be removed
for (int dir = 0; dir < 4; dir++){ //
int stx = stx0 + dirsYX[dir][1];
int sty = sty0 + dirsYX[dir][0];
int nsTile = sty * stilesX + stx; // from where to get
int num_other_planes = 0;
for (int np0 = np0_min; np0 < planes[nsTile0].length; np0++){
if ((planes[nsTile0][np0] != null) && (planes[nsTile0][np0].getMergedValue(dir) != null)){
int l = planes[nsTile0][np0].getMergedValue(dir).length;
if (l > num_other_planes)num_other_planes = l;
}
}
if (num_other_planes > 0){ // will eliminate bad margins
int np_min = LOWEST_PLANE(num_other_planes);
boolean [] this_matched = new boolean [planes[nsTile0].length];
boolean [] other_matched = new boolean [num_other_planes];
int num_pairs = this_matched.length - np0_min;
if ((other_matched.length - np_min) < num_pairs) num_pairs = other_matched.length - np_min;
for (int pair = 0; pair < num_pairs; pair ++){
// if (dl > 0){
// System.out.println(" pair = "+pair+" (of "+num_pairs+")");
// }
int [] best_pair = {-1,-1};
double best_rqual = Double.NaN;
for (int np0 = np0_min; np0 < this_matched.length; np0++) if (planes[nsTile0][np0] != null){
double [] merge_ev = planes[nsTile0][np0].getMergedValue(dir);
// if (dl > 0){
// System.out.println(" np0 = "+np0+" (of ("+np0_min+"..."+this_matched.length+"), ");
// }
boolean [] merge_valid = planes[nsTile0][np0].getMergedValid(dir);
if (!this_matched[np0] &&(merge_valid != null)) {
for (int np = np_min; np < merge_ev.length; np++){
// if (dl > 0){
// System.out.println(" np = "+np+" (of ("+np_min+"..."+merge_ev.length+"), ");
// }
if (!other_matched[np] && merge_valid[np]) {
double w1 = planes[nsTile0][np0].getWeight();
double w2 = planes[nsTile][np].getWeight();
double this_rq = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2); // double w2)
this_rq /= (w1 + w2); // for comparison reduce this value for stronger planes
if (Double.isNaN(best_rqual) || (this_rq < best_rqual)){ // OK if Double.isNaN(this_rq[np])
if (dl > 0){
System.out.println(" ===== selectNeighborPlanesMutual) : nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq);
}
best_rqual = this_rq;
best_pair[0]= np0;
best_pair[1]= np;
}
if (debugLevel > 0){
if ((merge_ev[np] < 0.4) && (w1 > 1.0) && (w2 > 1.0) ){
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
", this_rq*(w1+w2)="+(this_rq * (w1 + w2))+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
}
}
if (dl > 0) {
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", world sin2 ="+
planes[nsTile0][np0].getWorldSin2(planes[nsTile][np]));
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+
", world dist this="+ Math.sqrt(planes[nsTile0][np0].getWorldPlaneDist2(planes[nsTile][np]))+
", world dist other="+Math.sqrt(planes[nsTile][np].getWorldPlaneDist2(planes[nsTile0][np0]))+
", world dist sum="+Math.sqrt(planes[nsTile0][np0].getWorldPlaneDist2(planes[nsTile][np])+
planes[nsTile][np].getWorldPlaneDist2(planes[nsTile0][np0])));
}
}
}
}
}
if (Double.isNaN(best_rqual)){
if (dl >0) {
System.out.println("selectNeighborPlanesMutual - nothing found");
}
break; // nothing found
}
this_matched[best_pair[0]] = true;
other_matched[best_pair[1]] = true;
// neib_best should be initialized as int [8];
// planes[nsTile0][0].initNeibBest();
if (dl >0) {
System.out.println("1. planes["+nsTile0+"]["+best_pair[0]+"].setNeibBest("+dir+","+best_pair[1]+")");
}
if (dl >0) {
System.out.println("2. planes["+nsTile+"]["+best_pair[1]+"].setNeibBest("+(dir+4)+","+best_pair[0]+")");
}
planes[nsTile0][best_pair[0]].setNeibBest(dir,best_pair[1]);
planes[nsTile][best_pair[1]].setNeibBest(dir + 4,best_pair[0]);
}
// disable remaining neighbors
for (int np = 0; np < this_matched.length; np++) if (planes[nsTile0][np] != null){
if (dl >0) {
System.out.println("this_matched["+np+"]="+this_matched[np]);
}
if (!this_matched[np]){
planes[nsTile0][np].setNeibBest(dir,-1);
}
}
// for (int np = 0; np < other_matched.length; np++) if (planes[nsTile][np] != null){
for (int np = 0; np < other_matched.length; np++) if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() > 0.0)){ // disregard 0-weight planes
if (!other_matched[np]){
if (dl >0) {
System.out.println("other_matched["+np+"]="+other_matched[np]);
}
planes[nsTile][np].setNeibBest(dir + 4,-1);
}
}
if (dl >0) {
for (int np = 0; np < this_matched.length; np++) if (planes[nsTile0][np] != null){
int [] bn = planes[nsTile0][np].getNeibBest();
System.out.println("nsTile0="+nsTile0+":"+np+" : ["+
bn[0]+","+bn[1]+","+bn[2]+","+bn[3]+","+bn[4]+","+bn[5]+","+bn[6]+","+bn[7]+"]");
}
// for (int np = 0; np < other_matched.length; np++) if (planes[nsTile][np] != null){
for (int np = 0; np < other_matched.length; np++) if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() > 0.0)){ // disregard 0-weight planes
int [] bn = planes[nsTile][np].getNeibBest();
System.out.println("nsTile="+nsTile+":"+np+" best neighbors : ["+
bn[0]+","+bn[1]+","+bn[2]+","+bn[3]+","+bn[4]+","+bn[5]+","+bn[6]+","+bn[7]+"]");
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
/**
* Find mutual links between multi-layer planes for supertiles. requires that for each plane there are calculated smalles eigenvalues
* for merging with each plane for each of 8 neighbors
* @param rquality maximal degradation by merging (does not depend on the total weight)
* @param okMergeEigen if result eigenvalue of the merged planes is below, OK to bypass worst worsening
* @param maxWorldSin2 maximal square of the sine of the angle between the planes to allow merge (>= 1.0 - disable)
* @param maxEigen maximal eigenvalue of each of the merged planes
* @param minWeight minimal weight of each of the planes
* @param debugLevel debug level
* @param dbg_X debug supertile X coordinate
* @param dbg_Y debug supertile Y coordinate
*/
public void selectNeighborPlanesMutual_old(
final double rquality, final double rquality,
final double weakWorsening, final double weakWorsening,
final double okMergeEigen, final double okMergeEigen,
...@@ -6301,7 +6706,7 @@ public class SuperTiles{ ...@@ -6301,7 +6706,7 @@ public class SuperTiles{
int dl = (nsTile0 == debug_stile) ? 1:0; int dl = (nsTile0 == debug_stile) ? 1:0;
if ( planes[nsTile0] != null) { if ( planes[nsTile0] != null) {
if (dl > 0){ if (dl > 0){
System.out.println("selectNeighborPlanesMutual() nsTile0="+nsTile0); System.out.println(" ===== selectNeighborPlanesMutual_old() nsTile0="+nsTile0+" =====");
} }
int np0_min = (planes[nsTile0].length > 1) ? 1:0; // Modify if overall plane will be removed int np0_min = (planes[nsTile0].length > 1) ? 1:0; // Modify if overall plane will be removed
for (int dir = 0; dir < 4; dir++){ // for (int dir = 0; dir < 4; dir++){ //
...@@ -6325,10 +6730,17 @@ public class SuperTiles{ ...@@ -6325,10 +6730,17 @@ public class SuperTiles{
if ((other_matched.length - np_min) < num_pairs) num_pairs = other_matched.length - np_min; if ((other_matched.length - np_min) < num_pairs) num_pairs = other_matched.length - np_min;
for (int pair = 0; pair < num_pairs; pair ++){ for (int pair = 0; pair < num_pairs; pair ++){
// if (dl > 0){
// System.out.println(" pair = "+pair+" (of "+num_pairs+")");
// }
int [] best_pair = {-1,-1}; int [] best_pair = {-1,-1};
double best_rqual = Double.NaN; double best_rqual = Double.NaN;
for (int np0 = np0_min; np0 < this_matched.length; np0++) if (planes[nsTile0][np0] != null){ for (int np0 = np0_min; np0 < this_matched.length; np0++) if (planes[nsTile0][np0] != null){
double [] merge_ev = planes[nsTile0][np0].getMergedValue(dir); double [] merge_ev = planes[nsTile0][np0].getMergedValue(dir);
// if (dl > 0){
// System.out.println(" np0 = "+np0+" (of ("+np0_min+"..."+this_matched.length+"), ");
// }
if (!this_matched[np0] && if (!this_matched[np0] &&
(merge_ev != null) && (merge_ev != null) &&
((maxEigen == 0.0) || ((maxEigen == 0.0) ||
...@@ -6338,6 +6750,9 @@ public class SuperTiles{ ...@@ -6338,6 +6750,9 @@ public class SuperTiles{
planes[nsTile0][np0]))) && planes[nsTile0][np0]))) &&
(planes[nsTile0][np0].getWeight() > minWeight)) { (planes[nsTile0][np0].getWeight() > minWeight)) {
for (int np = np_min; np < merge_ev.length; np++){ for (int np = np_min; np < merge_ev.length; np++){
// if (dl > 0){
// System.out.println(" np = "+np+" (of ("+np_min+"..."+merge_ev.length+"), ");
// }
if (!other_matched[np] && if (!other_matched[np] &&
(planes[nsTile][np] != null) && (planes[nsTile][np] != null) &&
!Double.isNaN(merge_ev[np]) && !Double.isNaN(merge_ev[np]) &&
...@@ -6361,6 +6776,10 @@ public class SuperTiles{ ...@@ -6361,6 +6776,10 @@ public class SuperTiles{
if ((maxWorldSin2 >= 1.0) || (planes[nsTile0][np0].getWorldSin2(planes[nsTile][np]) <=maxWorldSin2)) { if ((maxWorldSin2 >= 1.0) || (planes[nsTile0][np0].getWorldSin2(planes[nsTile][np]) <=maxWorldSin2)) {
this_rq /= (w1 + w2); // for comparison reduce this value for stronger planes this_rq /= (w1 + w2); // for comparison reduce this value for stronger planes
if (Double.isNaN(best_rqual) || (this_rq < best_rqual)){ // OK if Double.isNaN(this_rq[np]) if (Double.isNaN(best_rqual) || (this_rq < best_rqual)){ // OK if Double.isNaN(this_rq[np])
if (dl > 0){
System.out.println("==== selectNeighborPlanesMutual_old) : nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq);
}
best_rqual = this_rq; best_rqual = this_rq;
best_pair[0]= np0; best_pair[0]= np0;
best_pair[1]= np; best_pair[1]= np;
...@@ -6392,17 +6811,30 @@ public class SuperTiles{ ...@@ -6392,17 +6811,30 @@ public class SuperTiles{
} }
} }
if (Double.isNaN(best_rqual)){ if (Double.isNaN(best_rqual)){
if (dl >0) {
System.out.println("selectNeighborPlanesMutual - nothing found");
}
break; // nothing found break; // nothing found
} }
this_matched[best_pair[0]] = true; this_matched[best_pair[0]] = true;
other_matched[best_pair[1]] = true; other_matched[best_pair[1]] = true;
// neib_best should be initialized as int [8]; // neib_best should be initialized as int [8];
// planes[nsTile0][0].initNeibBest(); // planes[nsTile0][0].initNeibBest();
if (dl >0) {
System.out.println("1. planes["+nsTile0+"]["+best_pair[0]+"].setNeibBest("+dir+","+best_pair[1]+")");
}
if (dl >0) {
System.out.println("2. planes["+nsTile+"]["+best_pair[1]+"].setNeibBest("+(dir+4)+","+best_pair[0]+")");
}
planes[nsTile0][best_pair[0]].setNeibBest(dir,best_pair[1]); planes[nsTile0][best_pair[0]].setNeibBest(dir,best_pair[1]);
planes[nsTile][best_pair[1]].setNeibBest(dir + 4,best_pair[0]); planes[nsTile][best_pair[1]].setNeibBest(dir + 4,best_pair[0]);
} }
// disable remaining neighbors // disable remaining neighbors
for (int np = 0; np < this_matched.length; np++) if (planes[nsTile0][np] != null){ for (int np = 0; np < this_matched.length; np++) if (planes[nsTile0][np] != null){
if (dl >0) {
System.out.println("this_matched["+np+"]="+this_matched[np]);
}
if (!this_matched[np]){ if (!this_matched[np]){
planes[nsTile0][np].setNeibBest(dir,-1); planes[nsTile0][np].setNeibBest(dir,-1);
} }
...@@ -6410,6 +6842,9 @@ public class SuperTiles{ ...@@ -6410,6 +6842,9 @@ public class SuperTiles{
// for (int np = 0; np < other_matched.length; np++) if (planes[nsTile][np] != null){ // for (int np = 0; np < other_matched.length; np++) if (planes[nsTile][np] != null){
for (int np = 0; np < other_matched.length; np++) if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() > 0.0)){ // disregard 0-weight planes for (int np = 0; np < other_matched.length; np++) if ((planes[nsTile][np] != null) && (planes[nsTile][np].getWeight() > 0.0)){ // disregard 0-weight planes
if (!other_matched[np]){ if (!other_matched[np]){
if (dl >0) {
System.out.println("other_matched["+np+"]="+other_matched[np]);
}
planes[nsTile][np].setNeibBest(dir + 4,-1); planes[nsTile][np].setNeibBest(dir + 4,-1);
} }
} }
...@@ -6437,7 +6872,8 @@ public class SuperTiles{ ...@@ -6437,7 +6872,8 @@ public class SuperTiles{
} }
public double [][] getShowPlanes( public double [][] getShowPlanes(
TilePlanes.PlaneData [][] planes, TilePlanes.PlaneData [][] planes,
double minWeight, double minWeight,
......
...@@ -58,7 +58,11 @@ public class TilePlanes { ...@@ -58,7 +58,11 @@ public class TilePlanes {
double [] world_v1 = null; // world in-plane vector, corresponding to vectors[1] double [] world_v1 = null; // world in-plane vector, corresponding to vectors[1]
double [] world_v2 = null; // world in-plane vector, corresponding to vectors[1] double [] world_v2 = null; // world in-plane vector, corresponding to vectors[1]
// double [] daxy = null; // disparity and 2 relative angles (ax and ay) corresponding to fisheye view, near (0,0) scale is pixel size // double [] daxy = null; // disparity and 2 relative angles (ax and ay) corresponding to fisheye view, near (0,0) scale is pixel size
// for now keeping both weighted and equal weight merged value - later remove less useful
double [][] merged_eig_val = null; // for each of the directions (N, NE, .. NW) quality match for each layer double [][] merged_eig_val = null; // for each of the directions (N, NE, .. NW) quality match for each layer
double [][] merged_eig_eq = null; // for each of the directions (N, NE, .. NW) quality match for each layer - ignoring weights
boolean [][] merged_valid = null; // for each of the directions (N, NE, .. NW) if it is possible to connect with link swaps
int [] neib_best = null; // new int [8]; // for each of the directions (N, NE, .. NW) index of best match, -1 if none int [] neib_best = null; // new int [8]; // for each of the directions (N, NE, .. NW) index of best match, -1 if none
// stores "worsening" of merging 2 planes. if L1,L2,L = values[0] of plane1, plane2 plane composite: w1, w2 - weights for plane1, plane2 // stores "worsening" of merging 2 planes. if L1,L2,L = values[0] of plane1, plane2 plane composite: w1, w2 - weights for plane1, plane2
// Lav = Math.sqrt((L1 * L1 * w1 + L2 * L2 * w2)/(w1 + w2)) // Lav = Math.sqrt((L1 * L1 * w1 + L2 * L2 * w2)/(w1 + w2))
...@@ -209,6 +213,26 @@ public class TilePlanes { ...@@ -209,6 +213,26 @@ public class TilePlanes {
} }
} }
} }
if (src.merged_eig_eq != null){
dst.merged_eig_eq = src.merged_eig_eq.clone();
for (int i = 0; i < src.merged_eig_eq.length; i++){
if (src.merged_eig_eq[i] != null){
dst.merged_eig_eq[i] = src.merged_eig_eq[i].clone();
}
}
}
if (src.merged_valid != null){
dst.merged_valid = src.merged_valid.clone();
for (int i = 0; i < src.merged_valid.length; i++){
if (src.merged_valid[i] != null){
dst.merged_valid[i] = src.merged_valid[i].clone();
}
}
}
if (src.neib_best != null) dst.neib_best = src.neib_best.clone(); if (src.neib_best != null) dst.neib_best = src.neib_best.clone();
// also copy original plane parameters - tile selection and number of points // also copy original plane parameters - tile selection and number of points
...@@ -1130,16 +1154,29 @@ public class TilePlanes { ...@@ -1130,16 +1154,29 @@ public class TilePlanes {
public double [][] initMergedValue() public double [][] initMergedValue()
{ {
this.merged_eig_val = new double[8][]; this.merged_eig_val = new double[8][];
this.merged_eig_eq = new double[8][];
this.merged_valid = new boolean[8][];
return this.merged_eig_val; return this.merged_eig_val;
} }
public double [][] getMergedValue() public double [][] getMergedValue()
{ {
return this.merged_eig_val; return this.merged_eig_val;
} }
public double [][] getMergedValueEq()
{
return this.merged_eig_eq;
}
public double [] initMergedValue(int dir, int leng) public double [] initMergedValue(int dir, int leng)
{ {
this.merged_eig_val[dir] = new double[leng]; this.merged_eig_val[dir] = new double[leng];
for (int i = 0; i < leng; i++) this.merged_eig_val[dir][i] = Double.NaN; this.merged_eig_eq[dir] = new double[leng];
this.merged_valid[dir] = new boolean[leng];
for (int i = 0; i < leng; i++) {
this.merged_eig_val[dir][i] = Double.NaN;
this.merged_eig_eq[dir][i] = Double.NaN;
}
return getMergedValue(dir); return getMergedValue(dir);
} }
...@@ -1151,6 +1188,14 @@ public class TilePlanes { ...@@ -1151,6 +1188,14 @@ public class TilePlanes {
return this.merged_eig_val[dir]; return this.merged_eig_val[dir];
} }
public double [] getMergedValueEq(int dir)
{
if (this.merged_eig_eq == null) {
return null;
}
return this.merged_eig_eq[dir];
}
public double getMergedValue(int dir, int plane) public double getMergedValue(int dir, int plane)
{ {
if ((this.merged_eig_val == null) ||(this.merged_eig_val[dir] == null)){ if ((this.merged_eig_val == null) ||(this.merged_eig_val[dir] == null)){
...@@ -1158,10 +1203,63 @@ public class TilePlanes { ...@@ -1158,10 +1203,63 @@ public class TilePlanes {
} }
return this.merged_eig_val[dir][plane]; return this.merged_eig_val[dir][plane];
} }
public double getMergedValueEq(int dir, int plane)
{
if ((this.merged_eig_eq == null) ||(this.merged_eig_eq[dir] == null)){
return Double.NaN;
}
return this.merged_eig_eq[dir][plane];
}
public void setNeibMatch(int dir, int plane, double value) public void setNeibMatch(int dir, int plane, double value)
{ {
this.merged_eig_val[dir][plane] = value; this.merged_eig_val[dir][plane] = value;
} }
public void setNeibMatchEq(int dir, int plane, double value)
{
this.merged_eig_eq[dir][plane] = value;
}
public boolean [][] getMergedValid()
{
return this.merged_valid;
}
public boolean [] getMergedValid(int dir)
{
if (this.merged_valid == null) {
return null;
}
return this.merged_valid[dir];
}
public boolean isMergedValid(int dir, int plane)
{
if ((this.merged_valid == null) || (this.merged_valid[dir] == null)){
return false;
}
return this.merged_valid[dir][plane];
}
public void setMergedValid(int dir, int plane, boolean valid)
{
this.merged_valid[dir][plane] = valid;
}
public void setMergedValid(int dir, int plane, boolean valid, int leng)
{
if (this.merged_valid == null){
this.merged_valid = new boolean[8][];
}
if (this.merged_valid[dir] == null){
this.merged_valid[dir] = new boolean[leng];
}
this.merged_valid[dir][plane] = valid;
}
public int [] initNeibBest() public int [] initNeibBest()
{ {
......
...@@ -3416,7 +3416,26 @@ public class TileProcessor { ...@@ -3416,7 +3416,26 @@ public class TileProcessor {
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
st.filterNeighborPlanes(
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWorstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen, f result of the merged planes is below, OK to use thin planes (higher) threshold
clt_parameters.plMaxWorldSin2, // final double maxWorldSin2,
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
clt_parameters.plMinStrength,
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/* */
st.selectNeighborPlanesMutual( st.selectNeighborPlanesMutual(
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/*
st.selectNeighborPlanesMutual_old(
clt_parameters.plWorstWorsening, // final double worst_worsening, clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWeakWorsening, // final double worst_worsening, clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen, clt_parameters.plOKMergeEigen, // final double okMergeEigen,
...@@ -3428,7 +3447,7 @@ public class TileProcessor { ...@@ -3428,7 +3447,7 @@ public class TileProcessor {
0, // final int debugLevel) 0, // final int debugLevel)
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
*/
st.resolveConflicts( st.resolveConflicts(
clt_parameters.plMaxEigen, clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo) clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
...@@ -3438,9 +3457,11 @@ public class TileProcessor { ...@@ -3438,9 +3457,11 @@ public class TileProcessor {
clt_parameters.plStarSteps, // int starSteps, // How far to look around when calculationg connection cost clt_parameters.plStarSteps, // int starSteps, // How far to look around when calculationg connection cost
clt_parameters.plStarOrtho, // double orthoWeight, clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight, clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight, clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity, clt_parameters.plPreferDisparity,
1, // final int debugLevel) 1, // final int debugLevel)
clt_parameters.tileX, clt_parameters.tileX,
...@@ -3456,6 +3477,7 @@ public class TileProcessor { ...@@ -3456,6 +3477,7 @@ public class TileProcessor {
clt_parameters.plStarOrtho, // double orthoWeight, clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight, clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight, clt_parameters.plDblTriLoss, // double diagonalWeight,
true, // clt_parameters.plNewConfl, // Allow more conflicts if overall cost is reduced true, // clt_parameters.plNewConfl, // Allow more conflicts if overall cost is reduced
clt_parameters.plPreferDisparity, clt_parameters.plPreferDisparity,
...@@ -3543,11 +3565,13 @@ public class TileProcessor { ...@@ -3543,11 +3565,13 @@ public class TileProcessor {
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
st.selectNeighborPlanesMutual( st.filterNeighborPlanes(
clt_parameters.plWorstWorsening, // final double worst_worsening, clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWorstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
clt_parameters.plWeakWorsening, // final double worst_worsening, clt_parameters.plWeakWorsening, // final double worst_worsening,
clt_parameters.plOKMergeEigen, // final double okMergeEigen, clt_parameters.plOKMergeEigen, // final double okMergeEigen,
clt_parameters.plMaxWorldSin2, // final double maxWorldSin2, clt_parameters.plMaxWorldSin2, // final double maxWorldSin2,
clt_parameters.plDispNorm, clt_parameters.plDispNorm,
clt_parameters.plMaxEigen, clt_parameters.plMaxEigen,
clt_parameters.plMinStrength, clt_parameters.plMinStrength,
...@@ -3555,6 +3579,11 @@ public class TileProcessor { ...@@ -3555,6 +3579,11 @@ public class TileProcessor {
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
st.selectNeighborPlanesMutual(
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.resolveConflicts( st.resolveConflicts(
clt_parameters.plMaxEigen, clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo) clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
...@@ -3565,8 +3594,10 @@ public class TileProcessor { ...@@ -3565,8 +3594,10 @@ public class TileProcessor {
clt_parameters.plStarOrtho, // double orthoWeight, clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight, clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight, clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity, clt_parameters.plPreferDisparity,
1, // final int debugLevel) 1, // final int debugLevel)
clt_parameters.tileX, clt_parameters.tileX,
......
...@@ -68,6 +68,7 @@ public class TwoLayerNeighbors { ...@@ -68,6 +68,7 @@ public class TwoLayerNeighbors {
int [][][] conns = new int [PAIRS.length][][]; int [][][] conns = new int [PAIRS.length][][];
int [] selection_star = null; int [] selection_star = null;
int [] selection_conns = null; int [] selection_conns = null;
boolean [][][][] merge_valid = new boolean[9][][][];
class NeibVariant { class NeibVariant {
...@@ -119,15 +120,16 @@ public class TwoLayerNeighbors { ...@@ -119,15 +120,16 @@ public class TwoLayerNeighbors {
* @param nl1 start layer to connect (-1 - just disconnect the end) * @param nl1 start layer to connect (-1 - just disconnect the end)
* @param dir2 direction from the center to the end of the connection (-1 - center) * @param dir2 direction from the center to the end of the connection (-1 - center)
* @param nl2 end layer to connect (-1 - just disconnect the start) * @param nl2 end layer to connect (-1 - just disconnect the start)
* @return true if connection is possible (looking at merge_valid)
*/ */
public void connect( public boolean connect(
int dir1, int dir1,
int nl1, int nl1,
int dir2, int dir2,
int nl2, int nl2,
int debugLevel){ int debugLevel){
int dir12 = getDir2From1(dir1, dir2); int dir12 = getDir2From1(dir1, dir2);
if (dir12 <0){ if (dir12 < 0){
throw new IllegalArgumentException ("Invalid connection from "+dir1+" to "+dir2+": resulted in direction 1->2 = "+dir12); throw new IllegalArgumentException ("Invalid connection from "+dir1+" to "+dir2+": resulted in direction 1->2 = "+dir12);
} }
if (debugLevel > 1){ if (debugLevel > 1){
...@@ -140,20 +142,55 @@ public class TwoLayerNeighbors { ...@@ -140,20 +142,55 @@ public class TwoLayerNeighbors {
if (nl1 >= 0){ if (nl1 >= 0){
old_nl2 = neibs_start[nl1][dir12]; // where it was connected before, may be -1 old_nl2 = neibs_start[nl1][dir12]; // where it was connected before, may be -1
if (old_nl2 != nl2) { if (old_nl2 != nl2) {
if (!isValidConn(dir1, dir12, nl1, nl2, debugLevel)) {
return false;
}
neibs_start[nl1][dir12] = nl2; neibs_start[nl1][dir12] = nl2;
} }
} }
if (nl2 >= 0){ if (nl2 >= 0){
if (!isValidConn(dir2, dir21, nl2, nl1, debugLevel)) {
return false;
}
old_nl1 = neibs_end[nl2][dir21]; old_nl1 = neibs_end[nl2][dir21];
neibs_end[nl2][dir21] = nl1; neibs_end[nl2][dir21] = nl1;
} }
// reconnect or plug broken links // reconnect or plug broken links
if (old_nl2 >= 0){ if (old_nl2 >= 0){
if (!isValidConn(dir2, dir21, old_nl2, old_nl1, debugLevel)) {
return false;
}
neibs_end[old_nl2][dir21] = old_nl1; // (old_nl1 may be -1 here) neibs_end[old_nl2][dir21] = old_nl1; // (old_nl1 may be -1 here)
} }
if (old_nl1 >= 0){ if (old_nl1 >= 0){
if (!isValidConn(dir1, dir12, old_nl1, old_nl2, debugLevel)) {
return false;
}
neibs_start[old_nl1][dir12] = old_nl2; // (old_nl2 may be -1 here) neibs_start[old_nl1][dir12] = old_nl2; // (old_nl2 may be -1 here)
} }
return true;
}
boolean isValidConn(
int dir1,
int dir12,
int nl1,
int nl2,
int debugLevel)
{
if (nl2 < 0) return true; // connection nowhere is always valid;
int dir8 = (dir1 < 0) ? 8: dir1;
if ((dir8 >= merge_valid.length) || (nl1 >= merge_valid[dir8].length) || (dir12 >= merge_valid[dir8][nl1].length) || (nl2 >= merge_valid[dir8][nl1][dir12].length)) {
System.out.println("BUG in isValidConn("+dir1+","+dir12+","+nl1+","+nl2+")");
return true;
}
if (merge_valid[dir8][nl1][dir12][nl2]) return true;
if (debugLevel > 0){
System.out.println(" -- Fileterd out connection "+dir1+":"+nl1+" in direction "+dir12+" to layer "+nl2);
}
return false;
} }
public int getConnection( public int getConnection(
...@@ -177,8 +214,11 @@ public class TwoLayerNeighbors { ...@@ -177,8 +214,11 @@ public class TwoLayerNeighbors {
public void diffToOther(NeibVariant other_variant) public int diffToOther(
NeibVariant other_variant,
int debugLevel)
{ {
int numChanges = 0;
for (int dir0 = 0; dir0 < neighbors.length; dir0++){ for (int dir0 = 0; dir0 < neighbors.length; dir0++){
if ((neighbors[dir0] != null) || (other_variant.neighbors[dir0] != null)){ if ((neighbors[dir0] != null) || (other_variant.neighbors[dir0] != null)){
if ((neighbors[dir0] == null) || (other_variant.neighbors[dir0] == null)){ if ((neighbors[dir0] == null) || (other_variant.neighbors[dir0] == null)){
...@@ -191,8 +231,11 @@ public class TwoLayerNeighbors { ...@@ -191,8 +231,11 @@ public class TwoLayerNeighbors {
} else { } else {
for (int dir = 0; dir < 8; dir++){ for (int dir = 0; dir < 8; dir++){
if (neighbors[dir0][nl][dir] != other_variant.neighbors[dir0][nl][dir]){ if (neighbors[dir0][nl][dir] != other_variant.neighbors[dir0][nl][dir]){
numChanges++;
if (debugLevel > 0) {
System.out.print(" "+dir0+":"+nl+":"+dir+":("+neighbors[dir0][nl][dir]+"/"+ System.out.print(" "+dir0+":"+nl+":"+dir+":("+neighbors[dir0][nl][dir]+"/"+
other_variant.neighbors[dir0][nl][dir]+")"); other_variant.neighbors[dir0][nl][dir]+")");
}
} }
} }
...@@ -202,9 +245,11 @@ public class TwoLayerNeighbors { ...@@ -202,9 +245,11 @@ public class TwoLayerNeighbors {
} }
} }
} }
System.out.println(); if (debugLevel > 0) {
System.out.println();
}
return numChanges;
} }
} }
/** /**
...@@ -273,12 +318,15 @@ public class TwoLayerNeighbors { ...@@ -273,12 +318,15 @@ public class TwoLayerNeighbors {
} }
for (int dir = 0; dir < 8; dir++) if (options_around[dir] > 0){ for (int dir = 0; dir < 8; dir++) if (options_around[dir] > 0){
// make a first connection, if there are two - other will be created simultaneously // make a first connection, if there are two - other will be created simultaneously
variant.connect( if (!variant.connect( // will println when return false
-1, // int dir1, -1, // int dir1,
((selection_star[dir] > 0) ? nl2 : nl1), // int nl1, ((selection_star[dir] > 0) ? nl2 : nl1), // int nl1,
dir, // int dir2, dir, // int dir2,
layers_around[dir][0], // int nl2); layers_around[dir][0], // int nl2);
debugLevel); debugLevel)) {
return null; // such connection was filtered out by filterNeighborPlanes()
}
} }
if (debugLevel > 1){ if (debugLevel > 1){
System.out.println(); System.out.println();
...@@ -306,12 +354,14 @@ public class TwoLayerNeighbors { ...@@ -306,12 +354,14 @@ public class TwoLayerNeighbors {
opts[1] = 1; // assuming there are two variants for the connection end as it should be opts[1] = 1; // assuming there are two variants for the connection end as it should be
} }
} }
variant.connect( if (!variant.connect( // will println when return false
start_dir, // int dir1, start_dir, // int dir1,
layers_around[start_dir][opts[0]], // int nl1, layers_around[start_dir][opts[0]], // int nl1,
end_dir, // int dir2, end_dir, // int dir2,
layers_around[end_dir][opts[1]], // int nl2); layers_around[end_dir][opts[1]], // int nl2);
debugLevel); debugLevel)) {
return null;
};
if (selection_conns[np] > 1){ if (selection_conns[np] > 1){
// add 3-rd variant if possible, if not - return null // add 3-rd variant if possible, if not - return null
// if at least one of the unused ends has a pair - connect other ends // if at least one of the unused ends has a pair - connect other ends
...@@ -319,12 +369,14 @@ public class TwoLayerNeighbors { ...@@ -319,12 +369,14 @@ public class TwoLayerNeighbors {
int nl_end_other = layers_around[end_dir][1-opts[1]]; int nl_end_other = layers_around[end_dir][1-opts[1]];
if ( (variant.getConnection(start_dir,nl_start_other,end_dir) >= 0) || if ( (variant.getConnection(start_dir,nl_start_other,end_dir) >= 0) ||
(variant.getConnection(end_dir,nl_end_other,start_dir) >= 0)) { (variant.getConnection(end_dir,nl_end_other,start_dir) >= 0)) {
variant.connect( if (!variant.connect(
start_dir, // int dir1, start_dir, // int dir1,
nl_start_other, // int nl1, nl_start_other, // int nl1,
end_dir, // int dir2, end_dir, // int dir2,
nl_end_other, // int nl2); nl_end_other, // int nl2);
debugLevel); debugLevel)) {
return null;
}
} else { } else {
return null; // failed to swap connection - other ends are both not connected return null; // failed to swap connection - other ends are both not connected
} }
...@@ -335,20 +387,30 @@ public class TwoLayerNeighbors { ...@@ -335,20 +387,30 @@ public class TwoLayerNeighbors {
} }
return variant; return variant;
} }
public int [][][][] getNeighborVariants() public int [][][][] getNeighborVariants(
int max_changes)
{ {
return getNeighborVariants(0); return getNeighborVariants(max_changes,0);
} }
public int [][][][] getNeighborVariants(int debugLevel) public int [][][][] getNeighborVariants(
int max_changes,
int debugLevel)
{ {
ArrayList<NeibVariant> variant_list = new ArrayList<NeibVariant>(); ArrayList<NeibVariant> variant_list = new ArrayList<NeibVariant>();
while (nextSelection()){ while (nextSelection()){
NeibVariant variant = generateVariant(debugLevel); NeibVariant variant = generateVariant(debugLevel);
if (variant != null){ if (variant != null){
variant_list.add(variant); int num_changes = variant.diffToOther(neibs_init, 0);
if ((max_changes == 0) || (num_changes <= max_changes)) {
variant_list.add(variant);
}
if (debugLevel > 0){ if (debugLevel > 0){
System.out.print("getNeighborVariants() "+(variant_list.size()-1)+": ["); System.out.print("getNeighborVariants() "+(variant_list.size()-1));
if ((max_changes != 0) && (num_changes > max_changes)){
System.out.print(" -IGNORED (as changes = "+num_changes+" > "+max_changes+")");
}
System.out.print(": [");
for (int i = 0; i < selection_star.length; i++){ for (int i = 0; i < selection_star.length; i++){
System.out.print(selection_star[i]); System.out.print(selection_star[i]);
} }
...@@ -357,7 +419,8 @@ public class TwoLayerNeighbors { ...@@ -357,7 +419,8 @@ public class TwoLayerNeighbors {
System.out.print(selection_conns[i]); System.out.print(selection_conns[i]);
} }
System.out.print("]: "); System.out.print("]: ");
variant.diffToOther(neibs_init); System.out.print("CHANGES: "+num_changes+" ");
variant.diffToOther(neibs_init, debugLevel);
} }
} }
} }
...@@ -374,7 +437,17 @@ public class TwoLayerNeighbors { ...@@ -374,7 +437,17 @@ public class TwoLayerNeighbors {
{ {
neibs_init.setNeighbors(neibs, dir); neibs_init.setNeighbors(neibs, dir);
} }
public void setMergeValid (boolean [][][] valid, int dir)
{
if (dir < 0){
merge_valid[8] = valid;
} else {
merge_valid[dir] = valid;
}
}
public int [][] getInitNeighbors (int dir) public int [][] getInitNeighbors (int dir)
{ {
return neibs_init.getNeighbors(dir); return neibs_init.getNeighbors(dir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment