Commit d1be5d00 authored by Andrey Filippov's avatar Andrey Filippov

moe on connection costs, adding parameters

parent c44613be
......@@ -2187,11 +2187,19 @@ public class EyesisCorrectionParameters {
public double plWeakEigen = 0.1; // Maximal eigenvalue of the result of non-weighted merge
public double plWeakWeight2 = 10.0 ; // Maximal weight of the weak plane to merge (second variant)
public double plWeakEigen2 = 0.05; // Maximal eigenvalue of the result of non-weighted merge (second variant)
public double plSumThick = 1.2; // Do not merge if any sqrt of merged eigenvalue exceeds scaled sum of components
public double plSumThick = 1.6; // Do not merge if any sqrt of merged eigenvalue exceeds scaled sum of components
public double plNeNeibCost = 5.0; // When calculating non-exclusive planes, do not use neighbors with high cost
public double plNeOwn = 5.0; // When calculating non-exclusive planes, use center plane relative weight
public double plExNeibCost = 5.0; // When calculating exclusive planes links, do not use neighbors with high cost
public double plExNeibCostSngl = 10.0; // When calculating exclusive planes links, do not use no-link neighbors with high cost
public double plExNeibSmooth = 0.5; // Scale down maximal costs for smoothed planes (tighter requirements)
public boolean plConflMerge = true; // Try to merge conflicting planes
public double plConflRelax = 1.5; // Scale parameters to relax planes fit for merging conflicting planes
public boolean plConflSngl = true; // Only merge conflicting planes if this is the only conflicting pair in the supertile
public boolean plConflSnglPair = true; // Only merge conflicting planes only if there are only two planes in the supertile
public double plNeOwn = 5.0; // When calculating non-exclusive planes, use cenrter plane relative weight
public double plMaxZRatio = 2.0; // Maximal ratio of Z to allow plane merging
public double plMaxDisp = 0.6; // Maximal disparity of one of the planes to apply maximal ratio
public double plCutTail = 1.4; // When merging with neighbors cut the tail that is worse than scaled best
......@@ -2218,12 +2226,13 @@ public class EyesisCorrectionParameters {
public double plDiscrXMedian = 1.5; // Remove outliers from the final selection that have distance more than scaled median
// comparing merge quality for plane pairs
public double plCostKrq = 0.8; // cost of merge quality weighted in disparity space
public double plCostKrqEq = 0.2; // cost of merge quality equal weight in disparity space
public double plCostWrq = 0.8; // cost of merge quality weighted in world space
public double plCostWrqEq = 0.2; // cost of merge quality equal weight in world space
public double plCostSin2 = 10.0; // cost of sin squared between normals
public double plCostRdist2 =1000.0; // cost of squared relative distances
public double plCostDist = 4.0; // Disparity (pix) - closer cost will use more of the real world, farther - disparity
public double plCostKrq = 0.8; // Cost of merge quality sqrt(weighted*equal) in disparity space
public double plCostKrqEq = 0.2; // Cost of merge quality averaje of weighted and equal weight in disparity space
public double plCostWrq = 0.8; // Cost of merge quality sqrt(weighted*equal) in world space
public double plCostWrqEq = 0.2; // Cost of merge quality average of weighted and equal weight in world space
public double plCostSin2 = 10.0; // Cost of sin squared between normals
public double plCostRdist2 =1000.0; // Cost of squared relative distances
public boolean plConflDualTri = false; // Resolve dual triangles conflict (odoodo)
......@@ -2604,9 +2613,17 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plWeakEigen2", this.plWeakEigen2 +"");
properties.setProperty(prefix+"plSumThick", this.plSumThick +"");
properties.setProperty(prefix+"plNeNeibCost", this.plNeNeibCost +"");
properties.setProperty(prefix+"plExNeibCost", this.plExNeibCost +"");
properties.setProperty(prefix+"plNeOwn", this.plNeOwn +"");
properties.setProperty(prefix+"plExNeibCost", this.plExNeibCost +"");
properties.setProperty(prefix+"plExNeibCostSngl", this.plExNeibCostSngl +"");
properties.setProperty(prefix+"plExNeibSmooth", this.plExNeibSmooth +"");
properties.setProperty(prefix+"plConflMerge", this.plConflMerge+"");
properties.setProperty(prefix+"plConflRelax", this.plConflRelax +"");
properties.setProperty(prefix+"plConflSngl", this.plConflSngl+"");
properties.setProperty(prefix+"plConflSnglPair", this.plConflSnglPair+"");
properties.setProperty(prefix+"plMaxZRatio", this.plMaxZRatio +"");
properties.setProperty(prefix+"plMaxDisp", this.plMaxDisp +"");
properties.setProperty(prefix+"plCutTail", this.plCutTail +"");
......@@ -2630,6 +2647,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plDiscrGrown", this.plDiscrGrown+"");
properties.setProperty(prefix+"plDiscrXMedian", this.plDiscrXMedian +"");
properties.setProperty(prefix+"plCostDist", this.plCostDist +"");
properties.setProperty(prefix+"plCostKrq", this.plCostKrq +"");
properties.setProperty(prefix+"plCostKrqEq", this.plCostKrqEq +"");
properties.setProperty(prefix+"plCostWrq", this.plCostWrq +"");
......@@ -2994,9 +3012,17 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plWeakEigen2")!=null) this.plWeakEigen2=Double.parseDouble(properties.getProperty(prefix+"plWeakEigen2"));
if (properties.getProperty(prefix+"plSumThick")!=null) this.plSumThick=Double.parseDouble(properties.getProperty(prefix+"plSumThick"));
if (properties.getProperty(prefix+"plNeNeibCost")!=null) this.plNeNeibCost=Double.parseDouble(properties.getProperty(prefix+"plNeNeibCost"));
if (properties.getProperty(prefix+"plExNeibCost")!=null) this.plExNeibCost=Double.parseDouble(properties.getProperty(prefix+"plExNeibCost"));
if (properties.getProperty(prefix+"plNeOwn")!=null) this.plNeOwn=Double.parseDouble(properties.getProperty(prefix+"plNeOwn"));
if (properties.getProperty(prefix+"plExNeibCost")!=null) this.plExNeibCost=Double.parseDouble(properties.getProperty(prefix+"plExNeibCost"));
if (properties.getProperty(prefix+"plExNeibCostSngl")!=null) this.plExNeibCostSngl=Double.parseDouble(properties.getProperty(prefix+"plExNeibCostSngl"));
if (properties.getProperty(prefix+"plExNeibSmooth")!=null) this.plExNeibSmooth=Double.parseDouble(properties.getProperty(prefix+"plExNeibSmooth"));
if (properties.getProperty(prefix+"plConflMerge")!=null) this.plConflMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plConflMerge"));
if (properties.getProperty(prefix+"plConflRelax")!=null) this.plConflRelax=Double.parseDouble(properties.getProperty(prefix+"plConflRelax"));
if (properties.getProperty(prefix+"plConflSngl")!=null) this.plConflSngl=Boolean.parseBoolean(properties.getProperty(prefix+"plConflSngl"));
if (properties.getProperty(prefix+"plConflSnglPair")!=null) this.plConflSnglPair=Boolean.parseBoolean(properties.getProperty(prefix+"plConflSnglPair"));
if (properties.getProperty(prefix+"plMaxZRatio")!=null) this.plMaxZRatio=Double.parseDouble(properties.getProperty(prefix+"plMaxZRatio"));
if (properties.getProperty(prefix+"plMaxDisp")!=null) this.plMaxDisp=Double.parseDouble(properties.getProperty(prefix+"plMaxDisp"));
if (properties.getProperty(prefix+"plCutTail")!=null) this.plCutTail=Double.parseDouble(properties.getProperty(prefix+"plCutTail"));
......@@ -3020,6 +3046,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plDiscrGrown")!=null) this.plDiscrGrown=Integer.parseInt(properties.getProperty(prefix+"plDiscrGrown"));
if (properties.getProperty(prefix+"plDiscrXMedian")!=null) this.plDiscrXMedian=Double.parseDouble(properties.getProperty(prefix+"plDiscrXMedian"));
if (properties.getProperty(prefix+"plCostDist")!=null) this.plCostDist=Double.parseDouble(properties.getProperty(prefix+"plCostDist"));
if (properties.getProperty(prefix+"plCostKrq")!=null) this.plCostKrq=Double.parseDouble(properties.getProperty(prefix+"plCostKrq"));
if (properties.getProperty(prefix+"plCostKrqEq")!=null) this.plCostKrqEq=Double.parseDouble(properties.getProperty(prefix+"plCostKrqEq"));
if (properties.getProperty(prefix+"plCostWrq")!=null) this.plCostWrq=Double.parseDouble(properties.getProperty(prefix+"plCostWrq"));
......@@ -3413,17 +3440,25 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Maximal eigenvalue of the result of non-weighted merge (second variant)", this.plWeakEigen2, 6);
gd.addNumericField("Do not merge if any sqrt of merged eigenvalue exceeds scaled sum of components", this.plSumThick, 6);
gd.addNumericField("When calculating non-exclusive planes, do not use neighbors with high cost", this.plNeNeibCost, 6);
gd.addNumericField(" When calculating exclusive planes links, do not use neighbors with high cost",this.plExNeibCost, 6);
gd.addNumericField("When calculating non-exclusive planes, use cenrter plane relative weight", this.plNeOwn, 6);
gd.addNumericField("When calculating exclusive planes links, do not use neighbors with high cost", this.plExNeibCost, 6);
gd.addNumericField("When calculating exclusive planes links, do not use no-link neighbors with high cost", this.plExNeibCostSngl, 6);
gd.addNumericField("Scale down maximal costs for smoothed planes links (tighter requirements)", this.plExNeibSmooth, 6);
gd.addMessage ("--- Merging planes with topological conflicts ---");
gd.addCheckbox ("Try to merge conflicting planes", this.plConflMerge);
gd.addNumericField("Scale parameters to relax planes fit for merging conflicting planes", this.plConflRelax, 6);
gd.addCheckbox ("Only merge conflicting planes if this is the only conflicting pair in the supertile",this.plConflSngl);
gd.addCheckbox ("Only merge conflicting planes only if there are only two planes in the supertile", this.plConflSnglPair);
gd.addMessage ("--- ---");
gd.addNumericField("Maximal ratio of Z to allow plane merging", this.plMaxZRatio, 6);
gd.addNumericField("Maximal disparity of one of the planes to apply maximal ratio", this.plMaxDisp, 6);
gd.addNumericField("When merging with neighbors cut the tail that is worse than scaled best", this.plCutTail, 6);
gd.addNumericField("Set cutoff value livel not less than this", this.plMinTail, 6);
gd.addNumericField("Set cutoff value level not less than this", this.plMinTail, 6);
gd.addMessage ("--- Parameters to regenerate planes using preliminary tile connections ---");
gd.addCheckbox (" Enable planes tiles selection regeneration hinted by supertile neighbors", this.plDiscrEn);
gd.addCheckbox ("Enable planes tiles selection regeneration hinted by supertile neighbors", this.plDiscrEn);
gd.addNumericField("Maximal disparity difference from the plane to consider tile", this.plDiscrTolerance, 6);
gd.addNumericField("Parallel move known planes around original know value for the best overall fit",this.plDiscrDispRange, 6);
gd.addNumericField("Number of steps (each direction) for each plane to search for the best fit (0 - single, 1 - 1 each side)",this.plDiscrSteps, 0);
......@@ -3442,10 +3477,11 @@ public class EyesisCorrectionParameters {
gd.addNumericField("Remove outliers from the final selection that have distance more than scaled median",this.plDiscrXMedian, 6);
gd.addMessage ("--- Planes merge costs ---");
gd.addNumericField("Cost of merge quality weighted in disparity space", this.plCostKrq, 6);
gd.addNumericField("Cost of merge quality equal weight in disparity space", this.plCostKrqEq, 6);
gd.addNumericField("Cost of merge quality weighted in world space", this.plCostWrq, 6);
gd.addNumericField("Cost of merge quality equal weight in world space", this.plCostWrqEq, 6);
gd.addNumericField(" Disparity (pix) - closer cost will use more of the real world, farther - disparity",this.plCostDist, 6);
gd.addNumericField("Cost of merge quality sqrt(weighted*equal) in disparity space", this.plCostKrq, 6);
gd.addNumericField("Cost of merge quality averaje of weighted and equal weight in disparity space",this.plCostKrqEq, 6);
gd.addNumericField("Cost of merge quality sqrt(weighted*equal) in world space", this.plCostWrq, 6);
gd.addNumericField("Cost of merge quality average of weighted and equal weight in world space", this.plCostWrqEq, 6);
gd.addNumericField("Cost of sin squared between normals", this.plCostSin2, 6);
gd.addNumericField("Cost of squared relative plane-to-other-center distances", this.plCostRdist2, 6);
......@@ -3819,9 +3855,17 @@ public class EyesisCorrectionParameters {
this.plWeakEigen2= gd.getNextNumber();
this.plSumThick= gd.getNextNumber();
this.plNeNeibCost= gd.getNextNumber();
this.plExNeibCost= gd.getNextNumber();
this.plNeOwn= gd.getNextNumber();
this.plExNeibCost= gd.getNextNumber();
this.plExNeibCostSngl= gd.getNextNumber();
this.plExNeibSmooth= gd.getNextNumber();
this.plConflMerge= gd.getNextBoolean();
this.plConflRelax= gd.getNextNumber();
this.plConflSngl= gd.getNextBoolean();
this.plConflSnglPair= gd.getNextBoolean();
this.plMaxZRatio= gd.getNextNumber();
this.plMaxDisp= gd.getNextNumber();
this.plCutTail= gd.getNextNumber();
......@@ -3845,6 +3889,7 @@ public class EyesisCorrectionParameters {
this.plDiscrGrown= (int) gd.getNextNumber();
this.plDiscrXMedian= gd.getNextNumber();
this.plCostDist= gd.getNextNumber();
this.plCostKrq= gd.getNextNumber();
this.plCostKrqEq= gd.getNextNumber();
this.plCostWrq= gd.getNextNumber();
......
......@@ -56,11 +56,14 @@ public class LinkPlanes {
public double plWeakEigen2; // = 0.05; // Maximal eigenvalue of the result of non-weighted merge (second variant)
public double plSumThick; // = 1.2; // Do not merge if any sqrt of merged eigenvalue exceeds scaled sum of components
public double plNeNeibCost; // = 5.0; // When calculating non-exclusive planes, do not use neighbors with high cost
public double plExNeibCost; // = 5.0; // When calculating non-exclusive planes, do not use neighbors with high cost
public double plNeOwn; // = 5.0; // When calculating non-exclusive planes, use center plane relative weight
public double plExNeibCost; // = 5.0; // When calculating non-exclusive planes, do not use neighbors with high cost
public double plExNeibCostSngl; // = 10.0; // When calculating exclusive planes links, do not use no-link neighbors with high cost
public double plExNeibSmooth; // = 0.5; // Scale down maximal costs for smoothed planes (tighter requirements)
// comparing merge quality for plane pairs
public double plCostDist; // = 4.0; // Disparity (pix) - closer cost will use more of the real world, farther - disparity
public double plCostKrq; // = 0.8; // cost of merge quality weighted in disparity space
public double plCostKrqEq; // = 0.2; // cost of merge quality equal weight in disparity space
public double plCostWrq; // = 0.8; // cost of merge quality weighted in world space
......@@ -106,10 +109,12 @@ public class LinkPlanes {
plWeakEigen2 = clt_parameters.plWeakEigen2;
plSumThick = clt_parameters.plSumThick;
plNeNeibCost = clt_parameters.plNeNeibCost;
plExNeibCost = clt_parameters.plExNeibCost;
plNeOwn = clt_parameters.plNeOwn;
plExNeibCost = clt_parameters.plExNeibCost;
plExNeibCostSngl = clt_parameters.plExNeibCostSngl;
plExNeibSmooth = clt_parameters.plExNeibSmooth;
plCostDist = clt_parameters.plCostDist;
plCostKrq = clt_parameters.plCostKrq;
plCostKrqEq = clt_parameters.plCostKrqEq;
plCostWrq = clt_parameters.plCostWrq;
......@@ -126,6 +131,17 @@ public class LinkPlanes {
dbg_tileY = clt_parameters.tileY;
this.st = st;
}
public double getExNeibCost(){
return plExNeibCost;
}
public double ExNeibCostSngl(){
return plExNeibCostSngl;
}
public double getExNeibSmooth(){
return plExNeibSmooth;
}
public boolean areWeakSimilar(
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
......@@ -136,6 +152,7 @@ public class LinkPlanes {
return planesFit(
plane1, // should belong to the same supertile (or be converted for one)
plane2,
1.0, // double relax,
true, // use for same supertile merge
true, // boolean check_is_weak_only, // only verify if the two planes are close and one is weak
Double.NaN, // if NaN will calculate assuming the same supertile
......@@ -150,6 +167,7 @@ public class LinkPlanes {
public boolean planesFit(
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
double relax,
boolean merge_weak, // use for same supertile merge
double merged_ev, // if NaN will calculate assuming the same supertile
double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -161,6 +179,7 @@ public class LinkPlanes {
return planesFit(
plane1, // should belong to the same supertile (or be converted for one)
plane2,
relax, // double relax,
merge_weak, // use for same supertile merge
false, // boolean check_is_weak_only, // only verify if the two planes are close and one is weak
merged_ev, // if NaN will calculate assuming the same supertile
......@@ -174,6 +193,7 @@ public class LinkPlanes {
public boolean planesFit(
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
double relax,
boolean merge_weak, // use for same supertile merge
boolean check_is_weak_only, // only verify if the two planes are close and one is weak
double merged_ev, // if NaN will calculate assuming the same supertile
......@@ -183,6 +203,9 @@ public class LinkPlanes {
String prefix,
int debugLevel)
{
double plSumThick = this.plSumThick * relax;
double plWeakEigen = this.plWeakEigen * relax;
double plWeakEigen2 = this.plWeakEigen2 * relax;
merge_weak |= check_is_weak_only;
if ((plane1 == null) || (plane2 == null)) return false;
boolean dbg = debugLevel > 1;
......@@ -325,7 +348,7 @@ public class LinkPlanes {
double sum_wthick = Math.sqrt(plane1.getWValue()) + Math.sqrt(plane2.getWValue());
if (Math.sqrt(merged_ev) > plSumThick * sum_thick){
notOK_to_merge = true;
if (dbg) System.out.println(prefix+": planes do not fit as weighted pixel thickness = "+Math.sqrt(merged_ev_eq)+
if (dbg) System.out.println(prefix+": planes do not fit as weighted pixel thickness = "+Math.sqrt(merged_ev)+
" > " +plSumThick+" * "+ sum_thick+" = "+(plSumThick * sum_thick) );
}
if (Math.sqrt(merged_ev_eq) > plSumThick * sum_thick){
......@@ -383,10 +406,15 @@ public class LinkPlanes {
double min2d = Math.min(plane1.get2dRatio(), plane2.get2dRatio());
if (Double.isNaN(min2d)) min2d = pl2dForSin;
if ((plMaxWorldSin2 < 1.0) && (min2d >= pl2dForSin) && (!merge_weak || (weakest > plWeakWeight)) && (plane1.getWorldSin2(plane2) > plMaxWorldSin2)) {
if ((plMaxWorldSin2 < 1.0) &&
(min2d >= pl2dForSin) &&
(!merge_weak || (weakest > plWeakWeight)) &&
(plane1.checkBadPlate(true) < plBadPlate) &&
(plane2.checkBadPlate(true) < plBadPlate) &&
(plane1.getWorldSin2(plane2) > plMaxWorldSin2)) {
notOK_to_merge = true;
if (dbg) System.out.println(prefix+": planes do not fit as sin2 > "+plMaxWorldSin2+" weakest="+weakest+
" or minimal 2d = "+min2d+" >= pl2dForSin=" + pl2dForSin);
" or minimal 2d = "+min2d+" >= pl2dForSin=" + pl2dForSin +" and none of the planes is \"bad\"");
}
if (weak_and_close){
OK_to_merge = true;
......@@ -434,7 +462,8 @@ public class LinkPlanes {
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq);
" L_eqW="+merged_wev_eq+
" relax=" +relax);
System.out.println(prefix+" (fit) world sin2 ="+
plane1.getWorldSin2(plane2));
System.out.println(prefix+ " (fit)" +
......@@ -457,7 +486,8 @@ public class LinkPlanes {
" L1="+plane1.getValue()+" L2="+plane2.getValue()+
" L="+merged_ev+" L_eq="+merged_ev_eq+
" L1W="+plane1.getWValue()+" L2W="+plane2.getWValue()+" LW="+merged_wev+
" L_eqW="+merged_wev_eq);
" L_eqW="+merged_wev_eq +
" relax=" +relax);
System.out.println(prefix+" (do not fit) world sin2 ="+
plane1.getWorldSin2(plane2));
System.out.println(prefix+" (do not fit)"+
......@@ -601,6 +631,16 @@ public class LinkPlanes {
} else if (plate2 && plate1){
rdist2 = 2 * plane1.getWorldPlaneRDist2(plane2);
}
// reduce cost contribution for disparity space parameters for near objects, increase - for far
double average_disp = 0.5 * (plane1.getZxy()[0] + plane2.getZxy()[0]);
double cost_near = average_disp * average_disp / (average_disp * average_disp + this.plCostDist * this.plCostDist);
double plCostKrq = this.plCostKrq * (1.0 - cost_near);
double plCostKrqEq = this.plCostKrqEq * (1.0 - cost_near);
double plCostWrq = this.plCostWrq * cost_near;
double plCostWrqEq = this.plCostWrqEq * cost_near;
double [] costs = {
Math.sqrt(this_rq * this_rq_eq) * plCostKrq,
0.5 * (this_rq + this_rq_eq) * plCostKrqEq,
......@@ -1082,6 +1122,8 @@ public class LinkPlanes {
final int dbg_X,
final int dbg_Y)
{
final double relax = 1.0;
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
......@@ -1138,6 +1180,7 @@ public class LinkPlanes {
if (planesFit(
planes[nsTile0][np0], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np], // TilePlanes.PlaneData plane2,
relax, // double relax = 1.0;
true, // merge_low_eigen, // false, // boolean merge_weak, // use for same supertile merge
merge_ev[np], // double merged_ev, // if NaN will calculate assuming the same supertile
merge_ev_eq[np], //double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -1151,6 +1194,7 @@ public class LinkPlanes {
if (planesFit(
planes[nsTile0][np0], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np], // TilePlanes.PlaneData plane2,
relax, // double relax = 1.0;
false, // merge_low_eigen, // false, // boolean merge_weak, // use for same supertile merge
merge_ev[np], // double merged_ev, // if NaN will calculate assuming the same supertile
merge_ev_eq[np], //double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2105,10 +2149,15 @@ public class LinkPlanes {
public boolean [][][] overlapSameTileCandidates(
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
// may be a hack - has problems with not merging some close portions of the (horizontal) pavement -
// maybe just some dirty window glitches
// ignore overlap if the planes are close in real world. Only comparing distances from good plates
final double min_distance,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final double min_distance2 = min_distance * min_distance;
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
......@@ -2189,11 +2238,68 @@ public class LinkPlanes {
){
overlap_merge_candidates[nsTile][np1][np2] = true;
overlap_merge_candidates[nsTile][np2][np1] = true;
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): ACCEPTED pair nsTile="+nsTile+":"+np1+":"+np2+
" even as it has HIGH overlap: "+
" overlap1="+ ((int) (100 *overlaps[0]))+"% "+
" overlap2="+ ((int) (100 *overlaps[1]))+"% "+
"because at least one plane is weak and they have small disparity difference");
}
// see if the planes are close enough to still be merged
} else if (min_distance > 0){
boolean bad_plate1 = (planes[nsTile][np1].checkBadPlate(true) > plBadPlate);
boolean bad_plate2 = (planes[nsTile][np2].checkBadPlate(true) > plBadPlate);
if (bad_plate1 && bad_plate2) {
/*
overlap_merge_candidates[nsTile][np1][np2] = true;
overlap_merge_candidates[nsTile][np2][np1] = true;
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): ACCEPTED pair nsTile="+nsTile+":"+np1+":"+np2+
" even as it has HIGH overlap: "+
" overlap1="+ ((int) (100 *overlaps[0]))+"% "+
" overlap2="+ ((int) (100 *overlaps[1]))+"% "+
"because both are \"bad plates\" (should it be?)");
}
*/
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): REJECTED pair nsTile="+nsTile+":"+np1+":"+np2+
" even as it has HIGH overlap: "+
" overlap1="+ ((int) (100 *overlaps[0]))+"% "+
" overlap2="+ ((int) (100 *overlaps[1]))+"% "+
"because both are \"bad plates\"");
}
} else {
// from plane2 to 1 center
double wd2_1 = planes[nsTile][np1].getWorldPlaneDist2(planes[nsTile][np2]);
double wd2_2 = planes[nsTile][np2].getWorldPlaneDist2(planes[nsTile][np1]);
double wd2 = (!bad_plate1 && !bad_plate2) ? Math.min(wd2_1,wd2_2): (bad_plate1 ? wd2_1 : wd2_2);
// wd2 = Math.sqrt(wd2); // just fro printing
if (wd2 < min_distance2) {
overlap_merge_candidates[nsTile][np1][np2] = true;
overlap_merge_candidates[nsTile][np2][np1] = true;
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): ACCEPTED pair nsTile="+nsTile+":"+np1+":"+np2+
" even as it has HIGH overlap: "+
" overlap1="+ ((int) (100 *overlaps[0]))+"% "+
" overlap2="+ ((int) (100 *overlaps[1]))+"% "+
"because theay are close to each other: "+
Math.sqrt(wd2) + " < " + min_distance + " meters.");
}
} else {
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): REJECTED pair nsTile="+nsTile+":"+np1+":"+np2+
" as it has HIGH overlap: "+
" overlap1="+ ((int) (100 *overlaps[0]))+"% "+
" overlap2="+ ((int) (100 *overlaps[1]))+"% "+
" and no other excuses - strong enough and the distance "+
Math.sqrt(wd2) + " >= " + min_distance + " meters.");
}
}
}
// if ()
// double d
} else {
if (debugLevel > 0){
System.out.println("overlapSameTileCandidates(): REJECTED pair nsTile="+nsTile+":"+np1+":"+np2+
......@@ -2225,6 +2331,7 @@ public class LinkPlanes {
final int dbg_X,
final int dbg_Y)
{
final double relax = 1.0;
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
......@@ -2323,6 +2430,7 @@ public class LinkPlanes {
if (planesFit(
merged_pd, // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
other_plane, // TilePlanes.PlaneData plane2,
relax, // double relax = 1.0;
merge_low_eigen, // false, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, //double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2382,6 +2490,7 @@ public class LinkPlanes {
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] valid_candidates, // will be updated
final double relax,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -2416,6 +2525,7 @@ public class LinkPlanes {
boolean fit1 = planesFit(
planes[nsTile0][np1].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarFb(), // TilePlanes.PlaneData plane2,
relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2427,6 +2537,7 @@ public class LinkPlanes {
boolean fit2 = planesFit(
planes[nsTile0][np1].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile0][np2].getNonexclusiveStarEqFb(), // TilePlanes.PlaneData plane2,
relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -2555,6 +2666,67 @@ public class LinkPlanes {
}
ImageDtt.startAndJoin(threads);
}
public int [][][] filterPairsByConflicts(
final int [][][] merge_candidates,
final int [][][] conflicts)
{
final int [][][] filtered_pairs = new int [merge_candidates.length][][];
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int nStiles = stilesX * stilesY;
final Thread[] threads = ImageDtt.newThreadArray(st.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) && (conflicts[nsTile] != null)) {
HashSet<Point> pairs_set = new HashSet<Point>();
for (int i = 0; i < merge_candidates[nsTile].length; i++ ){
if (merge_candidates[nsTile][i] != null){
Point p = new Point(merge_candidates[nsTile][i][0],merge_candidates[nsTile][i][1]);
if (p.x > p.y){ // currently they are always ordered, just in case
int tmp = p.x;
p.x = p.y;
p.y = tmp;
}
pairs_set.add(p);
}
}
HashSet<Point> conflicts_set = new HashSet<Point>();
for (int i = 0; i < conflicts[nsTile].length; i++ ){
if (conflicts[nsTile][i] != null){
Point p = new Point(conflicts[nsTile][i][0],conflicts[nsTile][i][1]);
if (p.x > p.y){ // currently they are always ordered, just in case
int tmp = p.x;
p.x = p.y;
p.y = tmp;
}
conflicts_set.add(p);
}
}
pairs_set.retainAll(conflicts_set);
if (!pairs_set.isEmpty()){
filtered_pairs[nsTile] = new int [pairs_set.size()][2];
int indx = 0;
for (Point p: pairs_set){
filtered_pairs[nsTile][indx][0] = p.x;
filtered_pairs[nsTile][indx++][1] = p.y;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return filtered_pairs;
}
public void costSameTileConnectionsAlt(
final double threshold,
final double threshold_nostar,
......@@ -2590,6 +2762,9 @@ public class LinkPlanes {
// get original directions
for (int np1 = 0; np1 < planes[nsTile0].length; np1++) if (planes[nsTile0][np1] != null){
for (int np2 = np1 + 1; np2 < planes[nsTile0].length; np2++) if (planes[nsTile0][np2] != null){
if ((valid_candidates[nsTile0] == null) || (valid_candidates[nsTile0][np1] == null)){
System.out.println("BUG in costSameTileConnectionsAlt()");
}
if (valid_candidates[nsTile0][np1][np2]) { // only check pair considered valid
String prefix = "costSameTileConnectionsAlt() fit weighted: nsTile0="+nsTile0+" np1="+np1+" np2="+np2;
double [] costs = new double[2];
......@@ -2732,13 +2907,13 @@ public class LinkPlanes {
System.out.println("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
System.out.println("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs:");
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs weighted: ");
for (int i = 0; i < costs0[0].length;i++) {
System.out.print(costs0[0][i]+" ");
}
System.out.println();
System.out.print("costSameTileConnections(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized: ");
System.out.print("costSameTileConnectionsAlt(): nsTile="+nsTile0+":"+np1+":"+np2+" costs equalized: ");
for (int i = 0; i < costs0[1].length;i++) {
System.out.print(costs0[1][i]+" ");
}
......@@ -2977,6 +3152,7 @@ public class LinkPlanes {
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] plane_nooverlaps,
final double relax,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -3010,6 +3186,7 @@ public class LinkPlanes {
if (planesFit(
planes[nsTile][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np2], // TilePlanes.PlaneData plane2,
relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......@@ -3034,6 +3211,8 @@ public class LinkPlanes {
final TilePlanes.PlaneData [][] planes,
final int [][][] merge_candidates,
final boolean [][][] plane_nooverlaps,
final double relax,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
......@@ -3068,10 +3247,11 @@ public class LinkPlanes {
if ((plane_nooverlaps == null) || (plane_nooverlaps[nsTile] == null) || plane_nooverlaps[nsTile][np1][np2]) {
yet_to_merge.add(np1);
yet_to_merge.add(np2);
String prefix = "mergeSameTileEvaluate() pair="+pair+" nsTile="+nsTile+" np1="+np1+" np2="+np2;
String prefix = "extractMergeSameTileGroups() pair="+pair+" nsTile="+nsTile+" np1="+np1+" np2="+np2;
if (planesFit(
planes[nsTile][np1], // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
planes[nsTile][np2], // TilePlanes.PlaneData plane2,
relax, // double relax,
true, // boolean merge_weak, // use for same supertile merge
Double.NaN, // double merged_ev, // if NaN will calculate assuming the same supertile
Double.NaN, // double merged_ev_eq, // if NaN will calculate assuming the same supertile
......
......@@ -4594,7 +4594,7 @@ public class TilePlanes {
}
// Raise weight of the center part of the histogram - there can be originally distinct parallel planes
// alternatively - use planes_mod or star* and no histograms at all?
final double initial_trust_sigma = 0.3*disp_tolerance; // TODO: use dispNorm !
final double initial_trust_sigma = 0.3 * disp_tolerance; // TODO: use dispNorm !
for (int np = 0; np < num_planes; np++) {
double k_sigma = 0.5/(initial_trust_sigma*initial_trust_sigma);
for (int nb = 0; nb < steps; nb++) {
......
......@@ -3347,6 +3347,7 @@ public class TileProcessor {
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
0.2, // final double min_distance,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3372,6 +3373,7 @@ public class TileProcessor {
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
1.0, // double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3393,6 +3395,7 @@ public class TileProcessor {
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
1.0, // double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3851,6 +3854,8 @@ public class TileProcessor {
TilePlanes.PlaneData [][] planes_mod = null;
// smooth planes (by averaging with neighbors and the "measured" one with variable "pull")
double relax_for_conflicts = 1.5;
if (clt_parameters.plIterations > 0) {
for (int num_merge_try = 0; num_merge_try < 10; num_merge_try ++ ) { // smooth and merge
st.resetPlanesMod(); // clean start
......@@ -3875,6 +3880,7 @@ public class TileProcessor {
clt_parameters.tileY);
lp.setExclusiveLinks(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2.5, //final double max_cost
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3900,6 +3906,7 @@ public class TileProcessor {
// recalculate links? more smooth?
lp.setExclusiveLinks(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
2.5, //final double max_cost
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3924,6 +3931,7 @@ public class TileProcessor {
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
0.2, // final double min_distance,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3939,6 +3947,16 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
// Consider supertiles with conflicts, merge conflicting layers with relaxed requirements
Conflicts iconflicts0 = new Conflicts(st);
int [][][] conflicts0 = iconflicts0.detectTriangularConflicts(
1); // final int debugLevel)
int [][][] conflicting_candidates = lp.filterPairsByConflicts(
merge_candidates, // final int [][][] merge_candidates,
conflicts0); // final int [][][] conflicts)
// * Possible problem is that "normalizing" merge quality for low weights is not applicable for "star" plane that include neighhbors
// * Switch to a single "cost" function (costSameTileConnectionsAlt())
// Still - how to merge stray tiles that do not have neighbors/star? Still merge them "old way" (costSameTileConnections()) if at least 1 does not
......@@ -3947,6 +3965,7 @@ public class TileProcessor {
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
1.0, // final double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3967,6 +3986,7 @@ public class TileProcessor {
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
1.0, // final double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -3990,8 +4010,95 @@ public class TileProcessor {
System.out.println("Try "+num_merge_try+ ": removed "+num_removed_by_merging+" planes by merging, recalculating connections");
if (num_removed_by_merging == 0){ // re-calculate all links
break;
// Consider supertiles with conflicts, merge conflicting layers with relaxed requirements
//TODO: Fix the mess to get rid of the plane_nooverlaps
Conflicts conflicts0_stats = new Conflicts(
conflicts0,
st,
-1); // debugLevel);
System.out.println("Trying relaxed merging for conflicting plane pairs");
plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,\
0.4, // final double min_distance,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// remove merge candidates that break connections to neighbors
if (debugLevel>100) lp.keepSameTileConnections(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
true, // final boolean merge_low_eigen, here it should be true
true, // final boolean useNonExcl, // consider only directions available for non-exclusive merges
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// Consider supertiles with conflicts, merge conflicting layers with relaxed requirements
//end of TODO: Fix the mess to get rid of the plane_nooverlaps
// try to merge original (measured) planes, not smoothed ones
lp.costSameTileConnections(
// st.planes_mod, // final TilePlanes.PlaneData [][] planes,
st.planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
relax_for_conflicts, // final double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// System.out.println("merge_cost_data.length = " + merge_cost_data.length);
lp.costSameTileConnectionsAlt(
// relax_for_conflicts, // final double relax,
relax_for_conflicts * 5.0, // final double threshold, //
relax_for_conflicts * 10.0, // final double threshold_nostar,
// st.planes_mod, // final TilePlanes.PlaneData [][] planes,
st.planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
merge_groups = lp.extractMergeSameTileGroups(
// st.planes_mod, // final TilePlanes.PlaneData [][] planes,
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
relax_for_conflicts, // final double relax,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
num_removed_by_merging = st.applyMergePlanes(
st.planes, // final TilePlanes.PlaneData[][] planes,
merge_groups, // final int [][][] merge_groups,
// parameters to generate ellipsoids
0.0, // 3, // final double disp_far, // minimal disparity to select (or NaN)
Double.NaN, // final double disp_near, // maximal disparity to select (or NaN)
clt_parameters.plDispNorm, // final double dispNorm, // Normalize disparities to the average if above
0.0, // final double min_weight,
clt_parameters.plMinPoints, // final int min_tiles,
// parameters to reduce outliers
clt_parameters.plTargetEigen, // final double targetEigen, // = 0.1; // Remove outliers until main axis eigenvalue (possibly scaled by plDispNorm) gets below
clt_parameters.plFractOutliers, // final double fractOutliers, // = 0.3; // Maximal fraction of outliers to remove
clt_parameters.plMaxOutliers, // final int maxOutliers, // = 20; // Maximal number of outliers to remove
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
System.out.println("Try "+num_merge_try+ ": removed "+num_removed_by_merging+" conflicting planes by merging, recalculating connections");
if (num_removed_by_merging == 0){ // re-calculate all links
break;
}
}
// Do the same as in conditionSuperTiles before smoothing again
......@@ -4036,6 +4143,7 @@ public class TileProcessor {
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
2.5, //final double max_cost
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
......@@ -4099,6 +4207,11 @@ public class TileProcessor {
}
} else {
st.planes_mod = st.planes; // just use the measured ones
}
......
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