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

merging planes in the same supertile

parent d24659c3
......@@ -33,6 +33,8 @@ public class ConnectionCosts {
double diagonalWeight;
double starPwr; // Divide cost by number of connections to this power
double starWeightPwr; // Use this power of tile weight when calculating connection cost
double weightToDens; // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr; // Raise value of each tile before averaging
int steps;
......@@ -51,6 +53,7 @@ public class ConnectionCosts {
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
int steps,
TilePlanes.PlaneData [][] planes,
......@@ -64,12 +67,14 @@ public class ConnectionCosts {
this.diagonalWeight = diagonalWeight;
this.starPwr = starPwr; // Divide cost by number of connections to this power
this.starWeightPwr = starWeightPwr;
this.weightToDens = weightToDens; // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
this.starValPwr = starValPwr; // Raise value of each tile before averaging
this.steps = steps;
}
public int [][][] initConnectionCosts(
int [] nsTiles)
int [] nsTiles,
int debugLevel)
{
int [] exp_tiles = nsTiles;
for (int i = 1; i < steps; i++) exp_tiles = getInvolvedSupertiles(exp_tiles);
......@@ -92,7 +97,7 @@ public class ConnectionCosts {
if (planes[nsTile] != null){
val_weights[isTile] = new double [planes[nsTile].length][];
for (int nl = 0; nl < planes[nsTile].length; nl++) if ( planes[nsTile][nl] != null){
val_weights[isTile][nl] = new double[2];
val_weights[isTile][nl] = new double[3];
}
}
}
......@@ -111,17 +116,17 @@ public class ConnectionCosts {
case 1:
val_weights = getConnectionsCostSingleStep (
null,
-1); // int debugLevel)
debugLevel - 1); // int debugLevel)
break;
case 2:
val_weights = getConnectionsCostDualStep (
null,
-1); // int debugLevel)
debugLevel - 1); // int debugLevel)
break;
default:
val_weights = getConnectionsCostSingleStep (
null,
-1); // int debugLevel)
debugLevel - 1); // int debugLevel)
}
last_val_weights = val_weights;
......@@ -131,10 +136,16 @@ public class ConnectionCosts {
for (int isTile = 0; isTile < all_tiles.length; isTile++){
if (val_weights[isTile] != null){
for (int nl = 0; nl < val_weights[isTile].length; nl++) if ( val_weights[isTile][nl] != null){
double weighted = val_weights[isTile][nl][1];
double density = val_weights[isTile][nl][2];
double weight = (weightToDens >= 1.0) ? weighted :
((weightToDens <= 0.0) ? density :
(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));
double val = val_weights[isTile][nl][0];
if (starValPwr != 1.0) val = Math.pow(val, starValPwr);
init_val += val * val_weights[isTile][nl][1];
init_weight += val_weights[isTile][nl][1];
init_val += val * weight;
init_weight += weight;
}
}
}
......@@ -259,6 +270,7 @@ public class ConnectionCosts {
int ineib1 = (tile_map.containsKey(nsTile1))? tile_map.get(nsTile1) : -1;
neibs2[dir] = (ineib1 >=0) ? neibs[tile_map.get(nsTile1)][nl1] : planes[nsTile1][nl1].getNeibBest();
if (!neibs_changed && (ineib1 >= 0)) {
/*
if ((neibs_init[ineib1] == null) || (neibs_init[ineib1][nl1] == null)) {
neibs_changed = true;
} else {
......@@ -267,6 +279,16 @@ public class ConnectionCosts {
break;
}
}
*/
if ((neibs_init[ineib1] == null) || (neibs[ineib1][nl1] == null)) {
neibs_changed = true;
} else {
for (int dir1 = 0; dir1 < 8; dir1++) if (neibs[ineib1][nl1][dir1] != neibs_init[ineib1][nl1][dir1]){
neibs_changed = true;
break;
}
}
}
}
}
......@@ -296,6 +318,35 @@ public class ConnectionCosts {
}
}
}
if (debugLevel > 0) {
for (int isTile = 0; isTile < all_tiles.length; isTile++){
int nsTile = all_tiles[isTile];
System.out.print("getConnectionsCostDualStep(): "+isTile+" ("+nsTile+"): ");
if (vw[isTile] != null) {
for (int nl = 0; nl < vw[isTile].length; nl++){
// System.out.print(" "+nl+":[");
System.out.print(" "+nl+":[");
if (vw[isTile][nl] != null ) {
for (int i = 0; i < vw[isTile][nl].length;i++){
System.out.print(vw[isTile][nl][i]);
// if (i < (vw[isTile][nl].length -1)){
System.out.print(", ");
// }
}
double weighted = vw[isTile][nl][1];
double density = vw[isTile][nl][2];
double weight = (weightToDens >= 1.0) ? weighted :
((weightToDens <= 0.0) ? density :
(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));
System.out.print(weight);
}
// System.out.print("]");
System.out.println("]");
}
}
System.out.println();
}
}
return vw; // negative - improvement
}
......@@ -310,17 +361,17 @@ public class ConnectionCosts {
case 1:
vw = getConnectionsCostSingleStep (
neibs,
-1); // int debugLevel)
debugLevel-1); // int debugLevel)
break;
case 2:
vw = getConnectionsCostDualStep (
neibs,
-1); // int debugLevel)
debugLevel-1); // int debugLevel)
break;
default:
vw = getConnectionsCostSingleStep (
neibs,
-1); // int debugLevel)
debugLevel-1); // int debugLevel)
}
last_val_weights = vw;
// calculate new cost
......@@ -329,11 +380,16 @@ public class ConnectionCosts {
for (int isTile = 0; isTile < all_tiles.length; isTile++){
if (vw[isTile] != null){
for (int nl = 0; nl < vw[isTile].length; nl++) if ( vw[isTile][nl] != null){
double weighted = vw[isTile][nl][1];
double density = vw[isTile][nl][2];
double weight = (weightToDens >= 1.0) ? weighted :
((weightToDens <= 0.0) ? density :
(Math.pow(weighted, weightToDens) * Math.pow(density, 1.0 - weightToDens)));
double val = vw[isTile][nl][0];
if (starValPwr != 1.0) val = Math.pow(val, starValPwr);
new_value += val * vw[isTile][nl][1];
new_weight += vw[isTile][nl][1];
new_value += val * weight;
new_weight += weight;
}
}
}
......@@ -372,6 +428,7 @@ public class ConnectionCosts {
int debugLevel)
{
TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // add weight
double conn_weight = 1.0; // center weight
for (int dir = 0; dir < 8; dir++){
if (neibs[dir] >= 0){
double other_weight = ((dir & 1) != 0) ? diagonalWeight : orthoWeight;
......@@ -386,9 +443,10 @@ public class ConnectionCosts {
true, // boolean sum_weights,
preferDisparity,
debugLevel - 1); // int debugLevel)
conn_weight += 1.0;
}
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
if (starPwr != 0){
value_weight[0] /= (Math.pow((planes[nsTile][nl].getNumNeibBest() + 1.0), starPwr));
}
......@@ -451,6 +509,7 @@ public class ConnectionCosts {
}
}
TilePlanes.PlaneData merged_plane = planes[nsTile][nl]; // center point
double conn_weight = 1.0; // center weight
for (HashMap.Entry<Point, Double> entry : tile_weights.entrySet()){
TilePlanes.PlaneData other_plane = merged_plane.getPlaneToThis( // layer here does not matter
planes[entry.getKey().x][entry.getKey().y],
......@@ -458,13 +517,15 @@ public class ConnectionCosts {
merged_plane = merged_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
entry.getValue(), // double scale_other,
starPwr, // Divide cost by number of connections to this power
false, // boolean ignore_weights,
true, // boolean sum_weights,
starPwr, // Divide cost by number of connections to this power
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
debugLevel - 1); // int debugLevel)
debugLevel - 1); // int debugLevel)
conn_weight += entry.getValue();
}
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight()};
double [] value_weight = {merged_plane.getValue(),merged_plane.getWeight(),conn_weight};
if (starPwr != 0){
value_weight[0] /= (Math.pow(tile_weights.size() + 1.0, starPwr));
}
......
......@@ -2168,7 +2168,8 @@ public class EyesisCorrectionParameters {
public double plFractOutliers = 0.3; // Maximal fraction of outliers to remove
public int plMaxOutliers = 20; // Maximal number of outliers to remove
public double plMinStrength = 0.1; // Minimal total strength of a plane
public double plMaxEigen = 0.3; // Maximal eigenvalue of a plane
public double plMaxEigen = 0.05; // Maximal eigenvalue of a plane
public double plEigenFloor = 0.01; // Add to eigenvalues of each participating plane and result to validate connections
public boolean plDbgMerge = true; // Combine 'other' plane with current
public double plWorstWorsening = 2.0; // Worst case worsening after merge
public double plWorstWorsening2 = 5.0; // Worst case worsening for thin planes
......@@ -2183,11 +2184,12 @@ public class EyesisCorrectionParameters {
public boolean plConflDiag = false; // Resolve diagonal (ood) conflicts
public boolean plConflStar = true; // Resolve all conflicts around a supertile
public int plStarSteps = 2; // How far to look around when calculationg connection cost
public int plStarSteps = 2; // How far to look around when calculating connection cost
public double plStarOrtho = 0.5; // When calculating cost for the connections scale 4 ortho neighbors
public double plStarDiag = 0.25; // When calculating cost for the connections scale 4 diagonal neighbors
public double plStarPwr = 0.5; // Divide cost by number of connections to this power
public double plStarWeightPwr = 0.5; // use this power of tile weight when calculating connection cost
public double plWeightToDens = 0.3; // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
public double plStarValPwr = 1.0; // Raise value of each tile before averaging
public double plDblTriLoss = 0.0001; // When resolving double triangles allow minor degradation (0.0 - strict)
public boolean plNewConfl = false; // Allow more conflicts if overall cost is reduced
......@@ -2535,6 +2537,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plMaxOutliers", this.plMaxOutliers+"");
properties.setProperty(prefix+"plMinStrength", this.plMinStrength +"");
properties.setProperty(prefix+"plMaxEigen", this.plMaxEigen +"");
properties.setProperty(prefix+"plEigenFloor", this.plEigenFloor +"");
properties.setProperty(prefix+"plDbgMerge", this.plDbgMerge+"");
properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
properties.setProperty(prefix+"plWorstWorsening2",this.plWorstWorsening2 +"");
......@@ -2553,6 +2556,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plStarDiag", this.plStarDiag +"");
properties.setProperty(prefix+"plStarPwr", this.plStarPwr +"");
properties.setProperty(prefix+"plStarWeightPwr", this.plStarWeightPwr +"");
properties.setProperty(prefix+"plWeightToDens", this.plWeightToDens +"");
properties.setProperty(prefix+"plStarValPwr", this.plStarValPwr +"");
properties.setProperty(prefix+"plDblTriLoss", this.plDblTriLoss +"");
properties.setProperty(prefix+"plNewConfl", this.plNewConfl+"");
......@@ -2880,6 +2884,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plMaxOutliers")!=null) this.plMaxOutliers=Integer.parseInt(properties.getProperty(prefix+"plMaxOutliers"));
if (properties.getProperty(prefix+"plMinStrength")!=null) this.plMinStrength=Double.parseDouble(properties.getProperty(prefix+"plMinStrength"));
if (properties.getProperty(prefix+"plMaxEigen")!=null) this.plMaxEigen=Double.parseDouble(properties.getProperty(prefix+"plMaxEigen"));
if (properties.getProperty(prefix+"plEigenFloor")!=null) this.plEigenFloor=Double.parseDouble(properties.getProperty(prefix+"plEigenFloor"));
if (properties.getProperty(prefix+"plDbgMerge")!=null) this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
if (properties.getProperty(prefix+"plWorstWorsening")!=null) this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
if (properties.getProperty(prefix+"plWorstWorsening2")!=null) this.plWorstWorsening2=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening2"));
......@@ -2898,6 +2903,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plStarDiag")!=null) this.plStarDiag=Double.parseDouble(properties.getProperty(prefix+"plStarDiag"));
if (properties.getProperty(prefix+"plStarPwr")!=null) this.plStarPwr=Double.parseDouble(properties.getProperty(prefix+"plStarPwr"));
if (properties.getProperty(prefix+"plStarWeightPwr")!=null) this.plStarWeightPwr=Double.parseDouble(properties.getProperty(prefix+"plStarWeightPwr"));
if (properties.getProperty(prefix+"plWeightToDens")!=null) this.plWeightToDens=Double.parseDouble(properties.getProperty(prefix+"plWeightToDens"));
if (properties.getProperty(prefix+"plStarValPwr")!=null) this.plStarValPwr=Double.parseDouble(properties.getProperty(prefix+"plStarValPwr"));
if (properties.getProperty(prefix+"plDblTriLoss")!=null) this.plDblTriLoss=Double.parseDouble(properties.getProperty(prefix+"plDblTriLoss"));
if (properties.getProperty(prefix+"plNewConfl")!=null) this.plNewConfl=Boolean.parseBoolean(properties.getProperty(prefix+"plNewConfl"));
......@@ -3253,6 +3259,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Maximal number of outliers to remove", this.plMaxOutliers, 0);
gd.addNumericField("Minimal total strength of a plane", this.plMinStrength, 6);
gd.addNumericField("Maximal eigenvalue of a plane", this.plMaxEigen, 6);
gd.addNumericField("Add to eigenvalues of each participating plane and result to validate connections",this.plEigenFloor, 6);
gd.addCheckbox ("Combine 'other' plane with the current (unused)", this.plDbgMerge);
gd.addNumericField("Worst case worsening after merge", this.plWorstWorsening, 6);
gd.addNumericField("Worst case worsening for thin planes", this.plWorstWorsening2, 6);
......@@ -3271,6 +3278,7 @@ public class EyesisCorrectionParameters {
gd.addNumericField("When calculating cost for the connections scale 4 diagonal neighbors", this.plStarDiag, 6);
gd.addNumericField("Divide cost by number of connections to this power", this.plStarPwr, 6);
gd.addNumericField("Use this power of tile weight when calculating connection cost", this.plStarWeightPwr, 6);
gd.addNumericField("Balance weighted density against density. 0.0 - density, 1.0 - weighted density", this.plWeightToDens, 6);
gd.addNumericField("Raise value of each tile before averaging", this.plStarValPwr, 6);
gd.addNumericField("When resolving double triangles allow minor degradation (0.0 - strict)", this.plDblTriLoss, 6);
gd.addCheckbox ("Allow more conflicts if overall cost is reduced", this.plNewConfl);
......@@ -3611,6 +3619,7 @@ public class EyesisCorrectionParameters {
this.plMaxOutliers= (int) gd.getNextNumber();
this.plMinStrength= gd.getNextNumber();
this.plMaxEigen= gd.getNextNumber();
this.plEigenFloor= gd.getNextNumber();
this.plDbgMerge= gd.getNextBoolean();
this.plWorstWorsening= gd.getNextNumber();
this.plWorstWorsening2= gd.getNextNumber();
......@@ -3629,6 +3638,7 @@ public class EyesisCorrectionParameters {
this.plStarDiag= gd.getNextNumber();
this.plStarPwr= gd.getNextNumber();
this.plStarWeightPwr= gd.getNextNumber();
this.plWeightToDens= gd.getNextNumber();
this.plStarValPwr= gd.getNextNumber();
this.plDblTriLoss= gd.getNextNumber();
this.plNewConfl= gd.getNextBoolean();
......
......@@ -505,7 +505,7 @@ private Panel panel1,
addButton("CLT show fine corr", panelClt1, color_configure);
addButton("CLT apply fine corr", panelClt1, color_process);
addButton("CLT reset 3D", panelClt1, color_stop);
addButton("CLT 3D", panelClt1, color_conf_process);
addButton("CLT 3D", panelClt1, color_process);
addButton("CLT planes", panelClt1, color_conf_process);
addButton("CLT ASSIGN", panelClt1, color_process);
addButton("CLT OUT 3D", panelClt1, color_process);
......
......@@ -3244,17 +3244,22 @@ public class SuperTiles{
* @param L smallest eigenvalue of the merged plane
* @param w1 weight of the first plane
* @param w2 weight of the second plane
* @param eigen_floor add to each L
* @return degrading by merging measure. 0 if both are co-planar, is supposed to be positive. very "bad" planes do produce negative results -
* not yet clear why (related to non-linear coordinate transformation?)
*/
public double mergeRQuality(
double L1,
double L2,
double L,
double L1_in,
double L2_in,
double L_in,
double w1,
double w2)
double w2,
double eigen_floor)
{
double L1 = L1_in + eigen_floor;
double L2 = L2_in + eigen_floor;
double L = L_in + eigen_floor;
// double Lav = Math.sqrt((L1*L1*w1 + L2*L2*w2)/(w1+w2));
double Lav = (L1*w1 + L2*w2)/(w1+w2);
/// double wors = (L - Lav)*(w1+w2)*(w1+w2) /(Lav*w1*w2);
......@@ -3719,6 +3724,7 @@ public class SuperTiles{
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double dispNorm,
double maxEigen, // maximal eigenvalue of planes to consider
double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
boolean preferDisparity,
int [][][] conflicts,
int debugLevel,
......@@ -3757,6 +3763,7 @@ public class SuperTiles{
starWeightPwr, // Use this power of tile weight when calculating connection cost
dispNorm,
maxEigen, // maximal eigenvalue of planes to consider
eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
tnSurface,
preferDisparity,
debugLevel);
......@@ -3783,6 +3790,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
......@@ -3824,6 +3832,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity, // boolean preferDisparity,
......@@ -3852,7 +3861,8 @@ public class SuperTiles{
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
......@@ -3915,13 +3925,14 @@ public class SuperTiles{
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps,
this.planes,
tnSurface,
preferDisparity);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
int [][][] neibs_prev_old = new int [mod_supertiles.length][][];
double [][][] val_weights = new double [mod_supertiles.length][][];
......@@ -4112,6 +4123,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
......@@ -4174,13 +4186,14 @@ public class SuperTiles{
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps,
this.planes,
tnSurface,
preferDisparity);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
/** */
int [][][] neibs_prev_old = new int [mod_supertiles.length][][];
......@@ -4383,6 +4396,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
......@@ -4417,6 +4431,7 @@ public class SuperTiles{
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
preferDisparity,
......@@ -4436,8 +4451,9 @@ public class SuperTiles{
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starValPwr, // Raise value of each tile before averaging
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
......@@ -4471,6 +4487,7 @@ public class SuperTiles{
diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
newConfl, // boolean newConfl, // Allow more conflicts if overall cost is reduced
......@@ -4497,6 +4514,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
......@@ -4581,13 +4599,14 @@ public class SuperTiles{
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps,
this.planes,
tnSurface,
preferDisparity);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
int [][][] conflicts_old = new int [nsTiles.length][][];
for (int isTile = 0; isTile < nsTiles.length; isTile++){
......@@ -4792,6 +4811,7 @@ public class SuperTiles{
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
......@@ -4879,13 +4899,14 @@ public class SuperTiles{
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps,
this.planes,
tnSurface,
preferDisparity);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
// connectionCosts now contains last calculated val/weight pairs for broader array of tile data
int [][][] conflicts_old = new int [nsTiles.length][][];
......@@ -5036,12 +5057,16 @@ public class SuperTiles{
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) &&
// ((variant_costs_diff[best_variant] >= 0.0) && (conflicts_var_cost[best_variant] >= conflicts_old_cost) &&
((conflicts_var_cost[best_variant] >= conflicts_old_cost) && // try always prohibit worse conflicts
(num_var_conflicts[best_variant] >= 0))){
if (debugLevel > -1) {
System.out.println("resolveStarConflict(): FAILED find a sutable solution for tile "+nsTile+
", nl1 = "+nl1+
", nl2 = "+nl2 +" of "+ neibs_vars.length+" variants");
if (debugLevel > 1){
System.out.println("resolveStarConflict(): for tile "+nsTile+" FAILURE");
}
return false;
}
} else {
......@@ -5062,45 +5087,50 @@ public class SuperTiles{
true, // use_all,
true, //use_odo,
true); // use_ood);
// update statistics
conflict_stats.addConflicts(variant_conflicts_stats[best_variant]);
}
// update statistics
conflict_stats.addConflicts(variant_conflicts_stats[best_variant]);
// update conflict
for (int i = 0; i < nsTiles.length; i++){
conflicts[nsTiles[i]]= variant_conflicts[best_variant][i];
// update conflict
for (int i = 0; i < nsTiles.length; i++){
conflicts[nsTiles[i]]= variant_conflicts[best_variant][i];
}
// apply resolution
for (int i = 0; i < mod_supertiles.length; i++){
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nsTile = "+nsTile+ "mod_supertiles["+i+"]="+mod_supertiles[i]);
}
// apply resolution
for (int i = 0; i < mod_supertiles.length; i++){
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nsTile = "+nsTile+ "mod_supertiles["+i+"]="+mod_supertiles[i]);
}
if (neibs_vars[best_variant][i] != null) {
for (int nl = 0; nl < neibs_vars[best_variant][i].length; nl ++){
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nl= = "+nl);
}
if (neibs_vars[best_variant][i][nl] != null){
planes[mod_supertiles[i]][nl].setNeibBest(neibs_vars[best_variant][i][nl]);
}
if (neibs_vars[best_variant][i] != null) {
for (int nl = 0; nl < neibs_vars[best_variant][i].length; nl ++){
if (debugLevel > 1){
System.out.println("resolveStarConflict(): nl= = "+nl);
}
if (neibs_vars[best_variant][i][nl] != null){
planes[mod_supertiles[i]][nl].setNeibBest(neibs_vars[best_variant][i][nl]);
}
}
}
// recalculate starValueWeights for and around tiles with modified neighbors (no outside connections changed )nsTiles
updateStarValueStrength(
nsTiles, // final int [] mod_supertiles,
orthoWeight, // final double orthoWeight,
diagonalWeight, // final double diagonalWeight,
starPwr, // final double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, // final int steps,
planes, // final TilePlanes.PlaneData [][] planes,
preferDisparity); // final boolean preferDisparity)
}
// recalculate starValueWeights for and around tiles with modified neighbors (no outside connections changed )nsTiles
updateStarValueStrength(
nsTiles, // final int [] mod_supertiles,
orthoWeight, // final double orthoWeight,
diagonalWeight, // final double diagonalWeight,
starPwr, // final double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, // final int steps,
planes, // final TilePlanes.PlaneData [][] planes,
preferDisparity, // final boolean preferDisparity)
debugLevel);
}
if (debugLevel > 1){
System.out.println("resolveStarConflict(): for tile "+nsTile+" OK");
}
return true;
}
......@@ -5109,10 +5139,12 @@ public class SuperTiles{
final double diagonalWeight,
final double starPwr, // Divide cost by number of connections to this power
final double starWeightPwr, // Use this power of tile weight when calculating connection cost
final double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
final double starValPwr, // Raise value of each tile before averaging
final int steps,
final TilePlanes.PlaneData [][] planes,
final boolean preferDisparity)
final boolean preferDisparity,
final int debugLevel)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
......@@ -5132,6 +5164,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes,
......@@ -5141,7 +5174,7 @@ public class SuperTiles{
for (int nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) {
if ( planes[nsTile] != null) {
mod_supertiles[0] = nsTile;
connectionCosts.initConnectionCosts(mod_supertiles);
connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
double [][][] val_weights = connectionCosts.getValWeights();
for (int np = 0; np < planes[nsTile].length; np++){ // nu
if (planes[nsTile][np] != null) {
......@@ -5162,10 +5195,12 @@ public class SuperTiles{
final double diagonalWeight,
final double starPwr, // Divide cost by number of connections to this power
final double starWeightPwr, // Use this power of tile weight when calculating connection cost
final double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
final double starValPwr, // Raise value of each tile before averaging
final int steps,
final TilePlanes.PlaneData [][] planes,
final boolean preferDisparity)
final boolean preferDisparity,
final int debugLevel)
{
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
......@@ -5184,17 +5219,18 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
steps, // int steps,
planes, // TilePlanes.PlaneData [][] planes,
tnSurface, // TileSurface.TileNeibs tnSurface,
preferDisparity); // boolean preferDisparity)
int [] mod_supertile = new int[1];
int [] supertiles = new int[1];
for (int isTile = ai.getAndIncrement(); isTile < mod_supertiles.length; isTile = ai.getAndIncrement()) {
int nsTile = mod_supertiles[isTile];
if ((nsTile >= 0) && ( planes[nsTile] != null)) {
mod_supertile[0] = nsTile;
connectionCosts.initConnectionCosts(mod_supertile);
supertiles[0] = nsTile;
connectionCosts.initConnectionCosts(supertiles, debugLevel - 2);
double [][][] val_weights = connectionCosts.getValWeights();
for (int np = 0; np < planes[nsTile].length; np++){ // nu
if (planes[nsTile][np] != null) {
......@@ -5467,8 +5503,9 @@ public class SuperTiles{
int starSteps, // How far to look around when calculationg connection cost
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean newConfl, // Allow more conflicts if overall cost is reduced
......@@ -5484,10 +5521,12 @@ public class SuperTiles{
diagonalWeight, // final double diagonalWeight,
starPwr, // final double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps, // final int steps,
this.planes, // final TilePlanes.PlaneData [][] planes,
preferDisparity); // final boolean preferDisparity)
preferDisparity, // final boolean preferDisparity)
debugLevel);
Conflicts iconflicts0 = new Conflicts(this);
int [][][] conflicts0 = iconflicts0.detectTriangularConflicts(
......@@ -5511,7 +5550,8 @@ public class SuperTiles{
orthoWeight, // double orthoWeight,
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // double diagonalWeight,
preferDisparity,
......@@ -5529,6 +5569,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // double diagonalWeight,
preferDisparity,
......@@ -5546,6 +5587,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // double diagonalWeight,
preferDisparity,
......@@ -5563,6 +5605,7 @@ public class SuperTiles{
diagonalWeight, // double diagonalWeight,
starPwr, // double starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
dblTriLoss, // double diagonalWeight,
newConfl, // Allow more conflicts if overall cost is reduced
......@@ -5631,7 +5674,8 @@ public class SuperTiles{
double orthoWeight,
double diagonalWeight,
double starPwr, // Divide cost by number of connections to this power
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
double starValPwr, // Raise value of each tile before averaging
double dblTriLoss, // When resolving double triangles allow minor degradation (0.0 - strict)
boolean preferDisparity,
......@@ -5709,12 +5753,13 @@ public class SuperTiles{
diagonalWeight,
starPwr, // Divide cost by number of connections to this power
starWeightPwr, // Use this power of tile weight when calculating connection cost
weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
starValPwr, //double starValPwr, // Raise value of each tile before averaging
starSteps,
this.planes,
tnSurface,
preferDisparity);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles);
int [][][] neibs_prev = connectionCosts.initConnectionCosts(mod_supertiles, debugLevel);
int [][][] neibs_prev_old = new int [mod_supertiles.length][][];
double [][][] val_weights = new double [mod_supertiles.length][][];
......@@ -6237,6 +6282,7 @@ public class SuperTiles{
double starWeightPwr, // Use this power of tile weight when calculating connection cost
double dispNorm,
double maxEigen, // maximal eigenvalue of planes to consider
double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
TileSurface.TileNeibs tnSurface,
boolean preferDisparity,
int debugLevel)
......@@ -6311,7 +6357,8 @@ public class SuperTiles{
merged[np].getValue(), // double L2,
merged[np].getValue(), // double L,
w1, // double w1,
w2); // double w2)
w2, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_norm = this_rq[np];
if ((w1 + w2) < weakWorsening) this_rq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
......@@ -6375,6 +6422,7 @@ public class SuperTiles{
final double maxWorldSin2,
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
final double minWeight, // minimal pain weight to consider
final int debugLevel,
final int dbg_X,
......@@ -6442,18 +6490,20 @@ public class SuperTiles{
double w2 = planes[nsTile][np].getWeight();
double this_rq = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
planes[nsTile][np].getValue() , // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2); // double w2)
w2, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_norm = this_rq;
if ((w1 + w2) < weakWorsening) this_rq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
double this_rq_eq = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
planes[nsTile0][np0].getValue() + eigenFloor, // double L1,
planes[nsTile][np].getValue() + eigenFloor, // double L2,
merge_ev[np], // double L,
1.0, // double w1,
1.0); // double w2)
1.0, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_eq_norm = this_rq_eq;
if ((w1 + w2) < weakWorsening) this_rq_eq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
......@@ -6487,7 +6537,7 @@ public class SuperTiles{
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
}
}
if (dl > 3) {
if (dl > 0) {
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
", this_rq_eq="+this_rq_eq+
" w1="+w1+" w2="+w2+
......@@ -6515,10 +6565,273 @@ public class SuperTiles{
ImageDtt.startAndJoin(threads);
}
public int [][][] getMergeSameTileCandidates(
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 int [][][] merge_candidates = new int [nStiles][][];
final int debug_stile = dbg_Y * stilesX + dbg_X;
class LayersLinks{
int nl1, nl2, links1, links2, shared;
LayersLinks (int nl1, int nl2, int links1, int links2, int shared){
this.nl1 = nl1;
this.nl2 = nl2;
this.links1 = links1;
this.links2 = links2;
this.shared = shared;
}
int [] toArray()
{
int [] data = {nl1, nl2, links1, links2, shared};
return data;
}
}
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 nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) if ( planes[nsTile] != null) {
ArrayList<LayersLinks> links_list = new ArrayList<LayersLinks>();
int dl = ((debugLevel > 0) && (nsTile == debug_stile)) ? 1:0;
if (dl > 0){
System.out.println("getMergeCandidates(): nsTile="+nsTile);
}
for (int np1 = 0; np1 < planes[nsTile].length; np1++) if (planes[nsTile][np1] != null){ // nu
boolean [][] merged_valid1 = planes[nsTile][np1].getMergedValid();
if (merged_valid1 != null){
for (int np2 = np1 + 1; np2 < planes[nsTile].length; np2++) if (planes[nsTile][np2] != null){ // nu
boolean [][] merged_valid2 = planes[nsTile][np2].getMergedValid();
if (merged_valid2 != null){
int num_links1 = 0;
int num_links2 = 0;
int num_shared = 0;
for (int dir = 0; dir < 8; dir++){
if (merged_valid1[dir] != null){
for (int nl = 0; nl < merged_valid1[dir].length; nl++){
if (merged_valid1[dir][nl]) num_links1++;
}
}
if (merged_valid2[dir] != null){
for (int nl = 0; nl < merged_valid2[dir].length; nl++){
if (merged_valid2[dir][nl]) num_links2++;
}
}
if ((merged_valid1[dir] != null) && (merged_valid2[dir] != null)) { // should be the same length
for (int nl = 0; nl < merged_valid2[dir].length; nl++){
if (merged_valid1[dir][nl] && merged_valid2[dir][nl]) num_shared++;
}
}
}
if (num_shared > 0) links_list.add(new LayersLinks(np1, np2, num_links1, num_links2, num_shared));
}
}
}
}
if (!links_list.isEmpty()){
merge_candidates[nsTile] = new int [links_list.size()][];
int indx = 0;
for (LayersLinks ll : links_list){
merge_candidates[nsTile][indx++] = ll.toArray();
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
if (debugLevel > 1){
System.out.println("Supertile planes that are candidates for merging:");
for (int nsTile = 0; nsTile < nStiles; nsTile++){
int stx = nsTile % stilesX;
int sty = nsTile / stilesX;
if (merge_candidates[nsTile] != null){
for (int i = 0 ; i < merge_candidates[nsTile].length; i++){
double sharedRatio = 2.0 * merge_candidates[nsTile][i][4] / (merge_candidates[nsTile][i][2] + merge_candidates[nsTile][i][3]);
System.out.println(nsTile+" ["+stx+":"+sty+"] ("+merge_candidates[nsTile][i][0]+", "+merge_candidates[nsTile][i][1]+")"+
" shared "+(((int) (sharedRatio * 1000)) / 10) + "%" +
" links1 = "+merge_candidates[nsTile][i][2]+
" links2 = "+merge_candidates[nsTile][i][3]+
" shared links = "+merge_candidates[nsTile][i][4]);
}
}
}
}
return merge_candidates;
}
public boolean [][] mergeSameTileEvaluate(
final int [][][] merge_candidates,
final double rquality,
final double worstWorsening2,// Worst case worsening for thin planes,
final double worstEq, // Worst case worsening after merge with equal weights
final double worstEq2, // Worst case worsening for thin planes with equal weights
final double weakWorsening,
final double okMergeEigen,
final double maxWorldSin2,
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
final double minWeight, // minimal pain weight to consider
final boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
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 boolean [][] merge_pairs = new boolean [nStiles][];
final int debug_stile = dbg_Y * stilesX + dbg_X;
final Thread[] threads = ImageDtt.newThreadArray((debugLevel > 1)? 1 : 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 nsTile = ai.getAndIncrement(); nsTile < nStiles; nsTile = ai.getAndIncrement()) if ( merge_candidates[nsTile] != null) {
merge_pairs[nsTile] = new boolean [merge_candidates[nsTile].length];
int dl = ((debugLevel > 0) && (nsTile == debug_stile)) ? 1: ((debugLevel > 1) ? 1:0);
if (dl > 0){
System.out.println("mergeSameTileEvaluate(): nsTile="+nsTile);
}
for (int pair = 0; pair < merge_candidates[nsTile].length; pair ++){
int np1 = merge_candidates[nsTile][pair][0];
int np2 = merge_candidates[nsTile][pair][1];
// check planes are plane, both eigenvalues below threshold and strengths above threshold (may be set t0 0)
if ( ((maxEigen == 0.0) || (
(planes[nsTile][np1].getValue() < corrMaxEigen(
maxEigen,
dispNorm,
planes[nsTile][np1])) &&
(planes[nsTile][np2].getValue() < corrMaxEigen(
maxEigen,
dispNorm,
planes[nsTile][np2]))
)) &&
(planes[nsTile][np1].getWeight() > minWeight) &&
(planes[nsTile][np2].getWeight() > minWeight)
) {
TilePlanes.PlaneData merged_pd = planes[nsTile][np1].mergePlaneToThis(
planes[nsTile][np2], // PlaneData otherPd,
1.0, // double scale_other,
1.0, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
dl-1); // int debugLevel)
if (merged_pd !=null) { // now always, but may add later
/// merged_pd.scaleWeight(0.5);
// this_plane.setNeibMatch(dir, np, merged_pd.getValue()); // smallest eigenValue
}
TilePlanes.PlaneData merged_pd_eq = planes[nsTile][np1].mergePlaneToThis(
planes[nsTile][np2], // PlaneData otherPd,
1.0, // double scale_other,
1.0, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
true, // false, // boolean ignore_weights,
true, // boolean sum_weights,
preferDisparity,
dl-1); // int debugLevel)
if (merged_pd_eq !=null) { // now always, but may add later
/// merged_pd.scaleWeight(0.5);
// this_plane.setNeibMatchEq(dir, np, merged_pd.getValue()); // smallest eigenValue
}
double w1 = planes[nsTile][np1].getWeight();
double w2 = planes[nsTile][np2].getWeight();
double this_rq = mergeRQuality(
planes[nsTile][np1].getValue(), // double L1,
planes[nsTile][np2].getValue() , // double L2,
merged_pd.getValue(), // double L,
w1, // double w1,
w2, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_norm = this_rq;
if ((w1 + w2) < weakWorsening) this_rq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
double this_rq_eq = mergeRQuality(
planes[nsTile][np1].getValue() + eigenFloor, // double L1,
planes[nsTile][np2].getValue() + eigenFloor, // double L2,
merged_pd_eq.getValue(), // double L,
1.0, // double w1,
1.0, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_eq_norm = this_rq_eq;
if ((w1 + w2) < weakWorsening) this_rq_eq_norm *= (w1 + w2) / weakWorsening; // forgive more for weak planes
if ((this_rq_norm <= rquality) ||
((merged_pd.getValue() <= okMergeEigen) && (this_rq_norm <= worstWorsening2)) || // use higher threshold
(this_rq_eq_norm <= worstEq) ||
((merged_pd_eq.getValue() <= okMergeEigen) && (this_rq_eq_norm <= worstEq2)) // use higher threshold
) {
if ((maxWorldSin2 >= 1.0) || (planes[nsTile][np1].getWorldSin2(planes[nsTile][np2]) <=maxWorldSin2)) {
if (dl > 0){
System.out.print("mergeSameTileEvaluate() : nsTile="+nsTile+":"+np1+":"+np2+" merging is VALID, because ");
if (this_rq_norm <= rquality)
System.out.print(" (this_rq_norm="+this_rq_norm+" <= rquality)");
if ((merged_pd.getValue() <= okMergeEigen) && (this_rq_norm <= worstWorsening2))
System.out.print(" merge_ev[np]="+merged_pd.getValue()+" <= okMergeEigen) && (this_rq_norm="+this_rq_norm+" <= worstWorsening2)");
if (this_rq_eq_norm <= worstEq)
System.out.print(" this_rq_eq_norm="+this_rq_eq_norm+" <= worstEq");
if ((merged_pd_eq.getValue() <= okMergeEigen) && (this_rq_eq_norm <= worstEq2))
System.out.print(" ((merge_ev_eq[np]="+merged_pd_eq.getValue()+" <= okMergeEigen) && (this_rq_eq_norm="+this_rq_eq_norm+" <= worstEq2)");
System.out.println();
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+", this_rq="+this_rq+
", this_rq_eq="+this_rq_eq+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile][np1].getValue()+" L2="+planes[nsTile][np2].getValue()+
" L="+merged_pd.getValue()+" L_eq="+merged_pd_eq.getValue());
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+", world sin2 ="+
planes[nsTile][np1].getWorldSin2(planes[nsTile][np2]));
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+
", world dist this="+ Math.sqrt(planes[nsTile][np1].getWorldPlaneDist2(planes[nsTile][np2]))+
", world dist other="+Math.sqrt(planes[nsTile][np2].getWorldPlaneDist2(planes[nsTile][np1]))+
", world dist sum="+Math.sqrt(planes[nsTile][np1].getWorldPlaneDist2(planes[nsTile][np2])+
planes[nsTile][np2].getWorldPlaneDist2(planes[nsTile][np1])));
}
merge_pairs[nsTile][pair] = true;
}
}
if (dl > 0) {
if (!merge_pairs[nsTile][pair]){
System.out.print("mergeSameTileEvaluate() : nsTile="+nsTile+":"+np1+":"+np2+" merging is INVALID");
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+", this_rq="+this_rq+
", this_rq_eq="+this_rq_eq+
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile][np1].getValue()+" L2="+planes[nsTile][np2].getValue()+
" L="+merged_pd.getValue()+" L_eq="+merged_pd_eq.getValue());
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+", world sin2 ="+
planes[nsTile][np1].getWorldSin2(planes[nsTile][np2]));
System.out.println("nsTile="+nsTile+":"+np1+":"+np2+
", world dist this="+ Math.sqrt(planes[nsTile][np1].getWorldPlaneDist2(planes[nsTile][np2]))+
", world dist other="+Math.sqrt(planes[nsTile][np2].getWorldPlaneDist2(planes[nsTile][np1]))+
", world dist sum="+Math.sqrt(planes[nsTile][np1].getWorldPlaneDist2(planes[nsTile][np2])+
planes[nsTile][np2].getWorldPlaneDist2(planes[nsTile][np1])));
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return merge_pairs;
}
/**
* 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
......@@ -6539,6 +6852,7 @@ public class SuperTiles{
// final double dispNorm,
// final double maxEigen, // maximal eigenvalue of planes to consider
// final double minWeight, // minimal pain weight to consider
final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -6618,7 +6932,8 @@ public class SuperTiles{
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);
double [] merge_ev = planes[nsTile0][np0].getMergedValue(dir);
double [] merge_ev_eq = planes[nsTile0][np0].getMergedValueEq(dir);
// if (dl > 0){
// System.out.println(" np0 = "+np0+" (of ("+np0_min+"..."+this_matched.length+"), ");
// }
......@@ -6636,7 +6951,22 @@ public class SuperTiles{
planes[nsTile][np].getValue(), // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2); // double w2)
w2, // double w2)
eigenFloor);// double eigen_floor)
double this_rq_nofloor = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2, // double w2)
0); // eigenFloor);// double eigen_floor)
double this_rq_eq = mergeRQuality(
planes[nsTile0][np0].getValue(), // double L1,
planes[nsTile][np].getValue(), // double L2,
merge_ev_eq[np], // double L,
1.0, // double w1,
1.0, // double w2)
eigenFloor);// double eigen_floor)
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){
......@@ -6651,13 +6981,18 @@ public class SuperTiles{
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]);
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]+
" L_eq="+merge_ev_eq[np]);
}
}
if (dl > 0) {
System.out.println("nsTile0="+nsTile0+":"+np0+", nsTile="+nsTile+":"+np+", this_rq="+this_rq+
" this_rq_raw="+(this_rq * (w1+w2)) +
" this_rq_eq="+(this_rq_eq) +
" this_rq_nofloor="+(this_rq_nofloor) +
" w1="+w1+" w2="+w2+
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]);
" L1="+planes[nsTile0][np0].getValue()+" L2="+planes[nsTile][np].getValue()+" L="+merge_ev[np]+
" L_eq="+merge_ev_eq[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+
......@@ -6672,7 +7007,7 @@ public class SuperTiles{
}
if (Double.isNaN(best_rqual)){
if (dl >0) {
System.out.println("selectNeighborPlanesMutual - nothing found");
System.out.println("selectNeighborPlanesMutual - nothing found for dir = " + dir);
}
break; // nothing found
}
......@@ -6751,6 +7086,7 @@ public class SuperTiles{
final double maxWorldSin2,
final double dispNorm,
final double maxEigen, // maximal eigenvalue of planes to consider
final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
final double minWeight, // minimal pain weight to consider
final int debugLevel,
final int dbg_X,
......@@ -6865,7 +7201,8 @@ public class SuperTiles{
planes[nsTile][np].getValue(), // double L2,
merge_ev[np], // double L,
w1, // double w1,
w2); // double w2)
w2, // double w2)
eigenFloor);// double eigen_floor)
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)) {
......
......@@ -87,6 +87,7 @@ public class TilePlanes {
double smplRms = 0.1; // Maximal RMS of the remaining tiles in a sample
double [] starValueWeight = null;
double conn_density = Double.NaN; //
boolean preferDisparity = false;
......@@ -142,17 +143,32 @@ public class TilePlanes {
if (starValueWeight != null){
pd.starValueWeight = starValueWeight.clone();
}
pd.conn_density = this.conn_density;
return pd;
}
// public void setConnectionDensity(double density){
// conn_density = density;
// }
public void setStarValueWeight(double value, double weight){
this.starValueWeight = new double[2];
this.starValueWeight[0] = value;
this.starValueWeight[1] = weight;
public double getConnectionDensity(){
return conn_density;
}
// public void setStarValueWeight(double value, double weight){
// this.starValueWeight = new double[2];
// this.starValueWeight[0] = value;
// this.starValueWeight[1] = weight;
// System.out.println("setStarValueWeight(): conn_density is not set");
// }
public void setStarValueWeight(double[] val_weight){
this.starValueWeight = val_weight;
this.starValueWeight = new double[2];
this.starValueWeight[0] = val_weight[0];
this.starValueWeight[1] = val_weight[1];
this.conn_density = 0.0;
// if (val_weight.length > 2){
this.conn_density = val_weight[2];
// }
}
public double [] getStarValueWeight()
......
......@@ -3424,15 +3424,42 @@ public class TileProcessor {
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.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
clt_parameters.plMinStrength,
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/* */
int [][][] merge_candidates = st.getMergeSameTileCandidates(
2, // final int debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
boolean [][] pairs_to_merge = st.mergeSameTileEvaluate(
merge_candidates, // final int [][][] merge_candidates,
clt_parameters.plWorstWorsening, // final double worst_worsening,
clt_parameters.plWorstWorsening2,// final double worst_worsening2 Worst case worsening for thin planes,
clt_parameters.plWorstEq, // final double worstEq, // Worst case worsening after merge with equal weights
clt_parameters.plWorstEq2, // final double worstEq2, // Worst case worsening for thin planes with equal weights
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.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
0.0, // clt_parameters.plMinStrength,
clt_parameters.plPreferDisparity,
2, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.selectNeighborPlanesMutual(
clt_parameters.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3445,6 +3472,7 @@ public class TileProcessor {
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
clt_parameters.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
clt_parameters.plMinStrength,
0, // final int debugLevel)
clt_parameters.tileX,
......@@ -3461,6 +3489,7 @@ public class TileProcessor {
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
......@@ -3476,7 +3505,7 @@ public class TileProcessor {
clt_parameters.plConflMulti, // boolean conflMulti, // Resolve multiple odo triangles conflicts
clt_parameters.plConflDiag, // boolean conflDiag, // Resolve diagonal (ood) conflicts
clt_parameters.plConflStar, // boolean conflStar, // Resolve all conflicts around a supertile
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 calculating connection cost
clt_parameters.plStarOrtho, // double orthoWeight,
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
......@@ -3579,12 +3608,14 @@ public class TileProcessor {
clt_parameters.plDispNorm,
clt_parameters.plMaxEigen,
clt_parameters.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
clt_parameters.plMinStrength,
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.selectNeighborPlanesMutual(
clt_parameters.plEigenFloor, // final double eigenFloor, // Add to eigenvalues of each participating plane and result to validate connections
0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3600,6 +3631,7 @@ public class TileProcessor {
clt_parameters.plStarDiag, // double diagonalWeight,
clt_parameters.plStarPwr, // double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr, // double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // double weightToDens, // // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // double starValPwr, // Raise value of each tile before averaging
clt_parameters.plDblTriLoss, // double diagonalWeight,
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
......
......@@ -180,15 +180,23 @@ public class TwoLayerNeighbors {
{
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)) {
/*// uncomment to debug
if ( (dir8 >= merge_valid.length) ||
(merge_valid[dir8] == null) ||
(nl1 >= merge_valid[dir8].length) ||
(merge_valid[dir8][nl1] == null) ||
(dir12 >= merge_valid[dir8][nl1].length) ||
(merge_valid[dir8][nl1][dir12] == null) ||
(nl2 >= merge_valid[dir8][nl1][dir12].length)) {
System.out.println("BUG in isValidConn("+dir1+","+dir12+","+nl1+","+nl2+")");
return true;
return false;
}
if (merge_valid[dir8][nl1][dir12][nl2]) return true;
*/
if ( (merge_valid[dir8][nl1] != null ) && // should not happen
(merge_valid[dir8][nl1][dir12] != null ) && // can happen
(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);
System.out.println(" -- Filterd out connection "+dir1+":"+nl1+" in direction "+dir12+" to layer "+nl2);
}
return false;
}
......
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