Commit 9cfff83b authored by Andrey Filippov's avatar Andrey Filippov

added/tested adding final links after planes smooth

parent 9b725244
......@@ -2202,6 +2202,12 @@ public class EyesisCorrectionParameters {
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 just two planes in the supertile
public double plThickWorld = 0.2; // Maximal real-world thickness of merged overlapping planes (meters)
public double plThickWorldConfl = 0.4; // Maximal real-world merged thickness for conflicting planes
public double plRelaxComplete = 1.5; // Relax cost requirements when adding exclusive links to complete squares and triangles
public double plRelaxComplete2 = 2.0; // Relax cost requirements during the second pass
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
......@@ -2256,6 +2262,7 @@ public class EyesisCorrectionParameters {
public boolean plMutualOnly = true; // keep only mutual links, remove weakest if conflict
public boolean plFillSquares = true; // Add diagonals to full squares
public boolean plCutCorners = true; // Add ortho to 45-degree corners
public boolean plHypotenuse = true; // Add hypotenuse connection if both legs exist
public double plPull = 5.0; // .3; // Relative weight of original (measured) plane compared to average neighbor pull
// when combing with neighbors
......@@ -2626,6 +2633,10 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plConflRelax", this.plConflRelax +"");
properties.setProperty(prefix+"plConflSngl", this.plConflSngl+"");
properties.setProperty(prefix+"plConflSnglPair", this.plConflSnglPair+"");
properties.setProperty(prefix+"plThickWorld", this.plThickWorld +"");
properties.setProperty(prefix+"plThickWorldConfl",this.plThickWorldConfl +"");
properties.setProperty(prefix+"plRelaxComplete", this.plRelaxComplete +"");
properties.setProperty(prefix+"plRelaxComplete2", this.plRelaxComplete2 +"");
properties.setProperty(prefix+"plMaxZRatio", this.plMaxZRatio +"");
properties.setProperty(prefix+"plMaxDisp", this.plMaxDisp +"");
......@@ -2676,6 +2687,7 @@ public class EyesisCorrectionParameters {
properties.setProperty(prefix+"plMutualOnly", this.plMutualOnly+"");
properties.setProperty(prefix+"plFillSquares", this.plFillSquares+"");
properties.setProperty(prefix+"plCutCorners", this.plCutCorners+"");
properties.setProperty(prefix+"plHypotenuse", this.plHypotenuse+"");
properties.setProperty(prefix+"plPull", this.plPull +"");
properties.setProperty(prefix+"plNormPow", this.plNormPow +"");
properties.setProperty(prefix+"plIterations", this.plIterations+"");
......@@ -3026,6 +3038,10 @@ public class EyesisCorrectionParameters {
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+"plThickWorld")!=null) this.plThickWorld=Double.parseDouble(properties.getProperty(prefix+"plThickWorld"));
if (properties.getProperty(prefix+"plThickWorldConfl")!=null) this.plThickWorldConfl=Double.parseDouble(properties.getProperty(prefix+"plThickWorldConfl"));
if (properties.getProperty(prefix+"plRelaxComplete")!=null) this.plRelaxComplete=Double.parseDouble(properties.getProperty(prefix+"plRelaxComplete"));
if (properties.getProperty(prefix+"plRelaxComplete2")!=null) this.plRelaxComplete2=Double.parseDouble(properties.getProperty(prefix+"plRelaxComplete2"));
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"));
......@@ -3076,6 +3092,7 @@ public class EyesisCorrectionParameters {
if (properties.getProperty(prefix+"plMutualOnly")!=null) this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));
if (properties.getProperty(prefix+"plFillSquares")!=null) this.plFillSquares=Boolean.parseBoolean(properties.getProperty(prefix+"plFillSquares"));
if (properties.getProperty(prefix+"plCutCorners")!=null) this.plCutCorners=Boolean.parseBoolean(properties.getProperty(prefix+"plCutCorners"));
if (properties.getProperty(prefix+"plHypotenuse")!=null) this.plHypotenuse=Boolean.parseBoolean(properties.getProperty(prefix+"plHypotenuse"));
if (properties.getProperty(prefix+"plPull")!=null) this.plPull=Double.parseDouble(properties.getProperty(prefix+"plPull"));
if (properties.getProperty(prefix+"plNormPow")!=null) this.plNormPow=Double.parseDouble(properties.getProperty(prefix+"plNormPow"));
......@@ -3453,8 +3470,12 @@ public class EyesisCorrectionParameters {
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 if this is the only conflicting pair in the supertile", this.plConflSngl);
gd.addCheckbox ("Only merge conflicting planes only if there are just two planes in the supertile", this.plConflSnglPair);
gd.addNumericField("Maximal real-world thickness of merged overlapping planes (meters)", this.plThickWorld, 6);
gd.addNumericField("Maximal real-world merged thickness for conflicting planes", this.plThickWorldConfl, 6);
gd.addNumericField("Relax cost requirements when adding exclusive links to complete squares and triangles",this.plRelaxComplete, 6);
gd.addNumericField("Relax cost requirements more during the second pass", this.plRelaxComplete2, 6);
gd.addMessage ("--- ---");
gd.addNumericField("Maximal ratio of Z to allow plane merging", this.plMaxZRatio, 6);
......@@ -3509,6 +3530,7 @@ public class EyesisCorrectionParameters {
gd.addCheckbox ("Add diagonals to full squares", this.plFillSquares);
gd.addCheckbox ("Add ortho to 45-degree corners", this.plCutCorners);
gd.addCheckbox ("Add hypotenuse connection if both legs exist", this.plHypotenuse);
gd.addNumericField("Relative (to average neighbor) weight of the measured plane when combing with neighbors", this.plPull, 6);
gd.addNumericField("0.0: 8 neighbors pull 8 times as 1, 1.0 - same as 1", this.plNormPow, 6);
......@@ -3871,6 +3893,10 @@ public class EyesisCorrectionParameters {
this.plConflRelax= gd.getNextNumber();
this.plConflSngl= gd.getNextBoolean();
this.plConflSnglPair= gd.getNextBoolean();
this.plThickWorld= gd.getNextNumber();
this.plThickWorldConfl= gd.getNextNumber();
this.plRelaxComplete= gd.getNextNumber();
this.plRelaxComplete2= gd.getNextNumber();
this.plMaxZRatio= gd.getNextNumber();
this.plMaxDisp= gd.getNextNumber();
......@@ -3922,6 +3948,7 @@ public class EyesisCorrectionParameters {
this.plFillSquares= gd.getNextBoolean();
this.plCutCorners= gd.getNextBoolean();
this.plHypotenuse= gd.getNextBoolean();
this.plPull= gd.getNextNumber();
this.plNormPow= gd.getNextNumber();
......
......@@ -67,6 +67,16 @@ public class LinkPlanes {
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 plThickWorld; // = 0.2; // Maximal real-world thickness of merged overlapping planes (meters)
public double plThickWorldConfl; // = 0.4; // Maximal real-world merged thickness for conflicting planes
public double plRelaxComplete; // = 1.5; // Relax cost requirements when adding exclusive links to complete squares and triangles
public double plRelaxComplete2; // = 2.0; // Relax cost requirements during the second pass
public boolean plFillSquares; // = true; // Add diagonals to full squares
public boolean plCutCorners; // = true; // Add ortho to 45-degree corners
public boolean plHypotenuse; // = true; // Add hypotenuse connection if both legs exist
// 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
......@@ -137,6 +147,15 @@ public class LinkPlanes {
plConflSngl = clt_parameters.plConflSngl;
plConflSnglPair = clt_parameters.plConflSnglPair;
plThickWorld = clt_parameters.plThickWorld;
plThickWorldConfl = clt_parameters.plThickWorldConfl;
plRelaxComplete = clt_parameters.plRelaxComplete;
plRelaxComplete2 = clt_parameters.plRelaxComplete2;
plFillSquares = clt_parameters.plFillSquares;
plCutCorners = clt_parameters.plCutCorners;
plHypotenuse = clt_parameters.plHypotenuse;
plCostDist = clt_parameters.plCostDist;
plCostKrq = clt_parameters.plCostKrq;
plCostKrqEq = clt_parameters.plCostKrqEq;
......@@ -187,6 +206,13 @@ public class LinkPlanes {
return plConflMerge;
}
public double getRelaxComplete(){
return plRelaxComplete;
}
public double getRelaxComplete2(){
return plRelaxComplete2;
}
public boolean areWeakSimilar(
TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
TilePlanes.PlaneData plane2,
......@@ -3654,11 +3680,7 @@ public class LinkPlanes {
boolean [][][] valid_candidates = overlapSameTileCandidates (
planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
// TODO: use parameters
0.2, // final double min_distance,
plThickWorld, // 0.2, // final double min_distance,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4169,10 +4191,7 @@ public class LinkPlanes {
boolean [][][] valid_candidates = overlapSameTileCandidates (
planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
// TODO: Use programmed parameters
0.2, // final double min_distance, //?
plThickWorld, // 0.2, // final double min_distance,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4263,9 +4282,7 @@ public class LinkPlanes {
valid_candidates = overlapSameTileCandidates (
planes_mod, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,\\
0.4, // final double min_distance,
plThickWorldConfl, // 0.4, // final double min_distance,
debugLevel, // final int debugLevel)
dbg_tileX,
dbg_tileY);
......@@ -4373,5 +4390,565 @@ public class LinkPlanes {
return planes_mod;
}
public boolean goodLink(
double threshold,
int nsTile,
int np,
int dir,
int dest_plane,
TilePlanes.PlaneData [][] planes,
TileNeibs tnSurface)
{
if (threshold == 0.0) return true;
double cost = getMutualLinkCost(
nsTile,
np,
dir,
dest_plane,
planes,
tnSurface);
return cost <= threshold; // cost may be Double.NaN, will return false
}
public double getMutualLinkCost(
int nsTile,
int np,
int dir,
int dest_plane,
TilePlanes.PlaneData [][] planes,
TileNeibs tnSurface)
{
double cost = planes[nsTile][np].getLinkCosts(dir, dest_plane);
if (!Double.isNaN(cost)){
int back_dir = (dir + 4) % 8;
cost = 0.5 * (cost + planes[tnSurface.getNeibIndex(nsTile, dir)][dest_plane].getLinkCosts(back_dir, np));
}
return cost;
}
public int fillSquares(
final TilePlanes.PlaneData[][] planes,
final double threshold,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
final int debug_stile = dbg_Y * stilesX + dbg_X;
// final int nStiles = stilesX * stilesY;
int num_added = 0;
for (int stY = 0; stY < (stilesY - 1); stY++ ) {
for (int stX = 0; stX < (stilesX - 1); stX++ ) {
int nsTile = stY * stilesX + stX;
int [] nsTiles = { nsTile, nsTile + 1, nsTile + stilesX, nsTile + stilesX + 1};
int dl = ((debugLevel > 1) && (nsTile == debug_stile)) ? 3: debugLevel;
if (dl > 2){
System.out.println("fillSquares(): nsTile="+nsTile);
}
TilePlanes.PlaneData [][] planes4 = {planes[nsTiles[0]],planes[nsTiles[1]],planes[nsTiles[2]],planes[nsTiles[3]]};
if ((planes4[0] != null) && (planes4[1] != null) && (planes4[2] != null) && (planes4[3] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] == null) continue;
int [] neibs0 = planes4[0][np].getNeibBest();
if ((neibs0[2] < 0) || (neibs0[4] < 0)) continue;
if (planes4[1][neibs0[2]] == null) continue;
if (planes4[2][neibs0[4]] == null) continue;
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if ((neibs1[4] < 0) || (neibs2[2] < 0) || (neibs1[4] != neibs2[2])) continue;
int [] neibs3 = planes4[3][neibs1[4]].getNeibBest();
// got full square, does it already have diagonals
if ((neibs0[3] < 0) && (neibs3[7] < 0)){
// See if the link cost is below threshold
// from this to right-down and back
if (goodLink(threshold,nsTiles[0], np, 3, neibs1[4], planes, tnSurface )) {
neibs0[3] = neibs1[4];
neibs3[7] = np;
num_added++;
if (dl > 0){
System.out.println("fillSquares().1: added link "+
nsTiles[0]+":" + np+ "-(3)->"+neibs1[4]+", " + nsTiles[3]+":" + neibs1[4]+"-(7)->" + np+
" cost = "+getMutualLinkCost(nsTiles[0], np, 3, neibs1[4], planes, tnSurface ));
}
}
}
if ((neibs1[5] < 0) && (neibs2[1] < 0)){
// See if the link cost is below threshold
// from right to down and back
if (goodLink(threshold, nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface )) {
neibs1[5] = neibs0[4];
neibs2[1] = neibs0[2];
num_added++;
if (dl > 0){
System.out.println("fillSquares().2: added link "+
nsTiles[1]+":" + neibs0[2]+"-(5)->"+neibs0[4]+", " + nsTiles[2]+":" + neibs0[4]+"-(1)->" + neibs0[2]+
" cost = " + getMutualLinkCost(nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface ));
}
}
}
}
}
}
}
return num_added;
}
public int fillHypotenuse(
final TilePlanes.PlaneData[][] planes,
final double threshold,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.tileProcessor.getSuperTileSize();
// final int tileSize = tileProcessor.getTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
final int debug_stile = dbg_Y * stilesX + dbg_X;
// final int nStiles = stilesX * stilesY;
int num_added = 0;
for (int stY = 0; stY < (stilesY - 1); stY++ ) {
for (int stX = 0; stX < (stilesX - 1); stX++ ) {
int nsTile = stY * stilesX + stX;
int [] nsTiles = { nsTile, nsTile + 1, nsTile + stilesX, nsTile + stilesX + 1};
int dl = ((debugLevel > 1) && (nsTile == debug_stile)) ? 3: debugLevel;
if (dl > 2){
System.out.println("fillHypotenuse(): nsTile="+nsTile);
}
TilePlanes.PlaneData [][] planes4 = {planes[nsTiles[0]],planes[nsTiles[1]],planes[nsTiles[2]],planes[nsTiles[3]]};
// when right and down links exist
if ((planes4[0] != null) && (planes4[1] != null) && (planes4[2] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] == null) continue;
int [] neibs0 = planes4[0][np].getNeibBest();
if ((neibs0[2] < 0) || (neibs0[4] < 0)) continue;
// if (planes4[1][neibs0[2]] == null) continue; // should never happen
// if (planes4[2][neibs0[4]] == null) continue; // should never happen
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if ((neibs1[5] < 0) && (neibs2[1] < 0)){
// See if the link cost is below threshold
// from right to down and back
if (goodLink(threshold, nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface )) {
neibs1[5] = neibs0[4];
neibs2[1] = neibs0[2];
num_added++;
if (dl > 0){
System.out.println("fillHypotenuse().1: added link "+
nsTiles[1]+":" + neibs0[2]+"-(5)->"+neibs0[4]+", " + nsTiles[2]+":" + neibs0[4]+"-(1)->" + neibs0[2]+
" cost = " + getMutualLinkCost(nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface ));
}
}
}
}
}
// when right and down from right links exist
if ((planes4[0] != null) && (planes4[1] != null) && (planes4[3] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] == null) continue;
int [] neibs0 = planes4[0][np].getNeibBest();
if (neibs0[2] < 0) continue;
// if (planes4[1][neibs0[2]] == null) continue;
// if (planes4[2][neibs0[4]] == null) continue;
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
if (neibs1[4] < 0) continue;
int [] neibs3 = planes4[3][neibs1[4]].getNeibBest();
// got right then down, connect if possible
if ((neibs0[3] < 0) && (neibs3[7] < 0)){
// See if the link cost is below threshold
// from this to right-down and back
if (goodLink(threshold,nsTiles[0], np, 3, neibs1[4], planes, tnSurface )) {
neibs0[3] = neibs1[4];
neibs3[7] = np;
num_added++;
if (dl > 0){
System.out.println("fillHypotenuse().2: added link "+
nsTiles[0]+":" + np+ "-(3)->"+neibs1[4]+", " + nsTiles[3]+":" + neibs1[4]+"-(7)->" + np+
" cost = "+getMutualLinkCost(nsTiles[0], np, 3, neibs1[4], planes, tnSurface ));
}
}
}
}
}
// when down and right from down links exist
if ((planes4[0] != null) && (planes4[2] != null) && (planes4[3] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] == null) continue;
int [] neibs0 = planes4[0][np].getNeibBest();
if (neibs0[4] < 0) continue;
// if (planes4[1][neibs0[2]] == null) continue;
// if (planes4[2][neibs0[4]] == null) continue;
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if (neibs2[2] < 0) continue;
int [] neibs3 = planes4[3][neibs2[2]].getNeibBest();
// got down then right, connect if possible
if ((neibs0[3] < 0) && (neibs3[7] < 0)){
// See if the link cost is below threshold
// from this to right-down and back
if (goodLink(threshold,nsTiles[0], np, 3, neibs2[2], planes, tnSurface )) {
neibs0[3] = neibs2[2];
neibs3[7] = np;
num_added++;
if (dl > 0){
System.out.println("fillHypotenuse().3: added link "+
nsTiles[0]+":" + np+ "-(3)->"+neibs2[2]+", " + nsTiles[3]+":" + neibs2[2]+"-(7)->" + np+
" cost = "+getMutualLinkCost(nsTiles[0], np, 3, neibs2[2], planes, tnSurface ));
}
}
}
}
}
// when both ortho links exist from the opposite ([3]) tile
if ((planes4[1] != null) && (planes4[2] != null) && (planes4[3] != null)){
for (int np = 0; np < planes4[3].length; np++){
if (planes4[3][np] == null) continue;
int [] neibs3 = planes4[3][np].getNeibBest();
if ((neibs3[6] < 0) || (neibs3[0] < 0)) continue;
// if (planes4[1][neibs0[2]] == null) continue;
// if (planes4[2][neibs0[4]] == null) continue;
int [] neibs1 = planes4[1][neibs3[0]].getNeibBest();
int [] neibs2 = planes4[2][neibs3[6]].getNeibBest();
if ((neibs1[5] < 0) && (neibs2[1] < 0)){
// See if the link cost is below threshold
// from right to down and back
if (goodLink(threshold, nsTiles[1], neibs3[0], 5, neibs3[6], planes, tnSurface )) {
neibs1[5] = neibs3[6];
neibs2[1] = neibs3[0];
num_added++;
if (dl > 0){
System.out.println("fillSquares().2: added link "+
nsTiles[1]+":" + neibs3[0]+"-(5)->"+neibs3[6]+", " + nsTiles[2]+":" + neibs3[6]+"-(1)->" + neibs3[0]+
" cost = " + getMutualLinkCost(nsTiles[1], neibs3[0], 5, neibs3[6], planes, tnSurface ));
}
}
}
}
}
if ((planes4[0] != null) && (planes4[1] != null) && (planes4[2] != null) && (planes4[3] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] == null) continue;
int [] neibs0 = planes4[0][np].getNeibBest();
if ((neibs0[2] < 0) || (neibs0[4] < 0)) continue;
if (planes4[1][neibs0[2]] == null) continue;
if (planes4[2][neibs0[4]] == null) continue;
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if ((neibs1[4] < 0) || (neibs2[2] < 0) || (neibs1[4] != neibs2[2])) continue;
int [] neibs3 = planes4[3][neibs1[4]].getNeibBest();
// got full square, does it already have diagonals
if ((neibs0[3] < 0) && (neibs3[7] < 0)){
// See if the link cost is below threshold
// from this to right-down and back
if (goodLink(threshold,nsTiles[0], np, 3, neibs1[4], planes, tnSurface )) {
neibs0[3] = neibs1[4];
neibs3[7] = np;
num_added++;
if (dl > 0){
System.out.println("fillSquares().1: added link "+
nsTiles[0]+":" + np+ "-(3)->"+neibs1[4]+", " + nsTiles[3]+":" + neibs1[4]+"-(7)->" + np+
" cost = "+getMutualLinkCost(nsTiles[0], np, 3, neibs1[4], planes, tnSurface ));
}
}
}
if ((neibs1[5] < 0) && (neibs2[1] < 0)){
// See if the link cost is below threshold
// from right to down and back
if (goodLink(threshold, nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface )) {
neibs1[5] = neibs0[4];
neibs2[1] = neibs0[2];
num_added++;
if (dl > 0){
System.out.println("fillSquares().2: added link "+
nsTiles[1]+":" + neibs0[2]+"-(5)->"+neibs0[4]+", " + nsTiles[2]+":" + neibs0[4]+"-(1)->" + neibs0[2]+
" cost = " + getMutualLinkCost(nsTiles[1], neibs0[2], 5, neibs0[4], planes, tnSurface ));
}
}
}
}
}
}
}
return num_added;
}
public int cutCorners(
final TilePlanes.PlaneData[][] planes,
final double threshold,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int tilesX = st.tileProcessor.getTilesX();
final int tilesY = st.tileProcessor.getTilesY();
final int superTileSize = st.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 TileNeibs tnSurface = new TileNeibs(stilesX, stilesY);
int num_added = 0;
final int debug_stile = dbg_Y * stilesX + dbg_X;
for (int stY = 0; stY < (stilesY - 1); stY++ ) {
for (int stX = 0; stX < (stilesX - 1); stX++ ) {
int nsTile = stY * stilesX + stX;
int dl = ((debugLevel > 1) && (nsTile == debug_stile)) ? 3: debugLevel;
if (dl > 2){
System.out.println("cutCorners(): nsTile="+nsTile);
}
int [] nsTiles = { nsTile, nsTile + 1, nsTile + stilesX, nsTile + stilesX + 1};
TilePlanes.PlaneData [][] planes4 = {planes[nsTiles[0]],planes[nsTiles[1]],planes[nsTiles[2]],planes[nsTiles[3]]};
if (planes4[0] != null) { // && (planes4[1] != null) && (planes4[2] != null)){
for (int np = 0; np < planes4[0].length; np++){
if (planes4[0][np] != null) {
int [] neibs0 = planes4[0][np].getNeibBest();
if ((neibs0[2] >= 0) && (neibs0[4] < 0)){
if (planes4[1][neibs0[2]] != null) {
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
if (neibs1[5] >= 0) {
int [] neibs2 = planes4[2][neibs1[5]].getNeibBest();
// from this to down and back
if (neibs2[0] < 0) {
if (goodLink(threshold, nsTiles[0], np, 4, neibs1[5], planes, tnSurface )) {
neibs0[4] = neibs1[5];
neibs2[0] = np; //?
num_added++;
if (dl > 0){
System.out.println("cutCorners().1: added link "+
nsTiles[0]+":" + np +"-(4)->"+neibs1[5]+", "+nsTiles[2]+":" + neibs1[5]+"-(0)->"+np+
" cost = " + getMutualLinkCost(nsTiles[0], np, 4, neibs1[5], planes, tnSurface ));
}
}
}
}
}
}
if ((neibs0[2] < 0) && (neibs0[4] >= 0)){
if (planes4[2][neibs0[4]] != null) {
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if (neibs2[1] >= 0) {
int [] neibs1 = planes4[1][neibs2[1]].getNeibBest();
// from this to right and back
if (neibs1[6] < 0) {
if (goodLink(threshold, nsTiles[0], np, 2, neibs2[1], planes, tnSurface )) {
neibs0[2] = neibs2[1];
neibs1[6] = np;
num_added++;
if (dl > 0){
System.out.println("cutCorners().2: added link "+
nsTiles[0]+":" + np+"-(2)->"+neibs2[1]+", "+nsTiles[1]+":" + neibs2[1]+"-(6)->"+np+
" cost = " + getMutualLinkCost(nsTiles[0], np, 2, neibs2[1], planes, tnSurface ));
}
}
}
}
}
}
if ((neibs0[2] >= 0) && (neibs0[3] >= 0)){
int [] neibs1 = planes4[1][neibs0[2]].getNeibBest();
if (neibs1[4] < 0) {
int [] neibs3 = planes4[3][neibs0[3]].getNeibBest();
// from right to right-down and back
if (neibs3[0] < 0) {
if (goodLink(threshold, nsTiles[1], neibs0[2], 4, neibs0[3], planes, tnSurface )) {
neibs1[4] = neibs0[3];
neibs3[0] = neibs0[2];
num_added++;
if (dl > 0){
System.out.println("cutCorners().3: added link "+
nsTiles[1]+":" + neibs0[2]+"-(4)->"+neibs0[3]+", " + nsTiles[3]+":" + neibs0[3]+"-(0)->" + neibs0[2]+
" cost = " + getMutualLinkCost(nsTiles[1], neibs0[2], 4, neibs0[3], planes, tnSurface ));
}
}
}
}
}
if ((neibs0[3] >= 0) && (neibs0[4] >= 0)){
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
if (neibs2[2] < 0) {
int [] neibs3 = planes4[3][neibs0[3]].getNeibBest();
// from down to right-down and back
if (neibs3[6] < 0) {
if (goodLink(threshold, nsTiles[2], neibs0[4], 2, neibs0[3], planes, tnSurface )) {
neibs2[2] = neibs0[3];
neibs3[6] = neibs0[4];
num_added++;
if (dl > 0){
System.out.println("cutCorners().4: added link "+
nsTiles[2]+":" + neibs0[4]+"-(2)->"+neibs0[3]+", " + nsTiles[3]+":" + neibs0[3]+"-(6)->" + neibs0[4]+
" cost = " + getMutualLinkCost(nsTiles[2], neibs0[4], 2, neibs0[3], planes, tnSurface ));
}
}
}
}
}
}
}
}
if (planes4[3] != null) { // && (planes4[1] != null) && (planes4[2] != null)){
for (int np = 0; np < planes4[3].length; np++){
if (planes4[3][np] != null){
int [] neibs3 = planes4[3][np].getNeibBest();
if ((neibs3[0] >= 0) && (neibs3[7] >= 0)){
int [] neibs0 = planes4[0][neibs3[7]].getNeibBest();
if (neibs0[2] < 0) {
int [] neibs1 = planes4[1][neibs3[0]].getNeibBest();
// from this to right and back
if ( neibs1[6] < 0) {
if (goodLink(threshold, nsTiles[0], neibs3[7], 2, neibs3[0], planes, tnSurface )) {
neibs0[2] = neibs3[0];
neibs1[6] = neibs3[7];
num_added++;
if (dl > 0){
System.out.println("cutCorners().5: added link "+
nsTiles[0]+":" + neibs3[7]+"-(2)->"+neibs3[0]+", " + nsTiles[1]+":" + neibs3[0]+"-(6)->" + neibs3[7]+
" cost = " + getMutualLinkCost(nsTiles[0], neibs3[7], 2, neibs3[0], planes, tnSurface ));
}
}
}
}
}
if ((neibs3[6] >= 0) && (neibs3[7] >= 0)){
int [] neibs0 = planes4[0][neibs3[7]].getNeibBest();
if (neibs0[4] < 0) {
int [] neibs2 = planes4[2][neibs3[6]].getNeibBest();
// from this to down and back
if (neibs2[0] < 0) {
if (goodLink(threshold, nsTiles[0], neibs3[7], 4, neibs3[6], planes, tnSurface )) {
neibs0[4] = neibs3[6];
neibs2[0] = neibs3[7];
num_added++;
if (dl > 0){
System.out.println("cutCorners().6: added link "+
nsTiles[0]+":" + neibs3[7]+"-(4)->"+neibs3[6]+", " + nsTiles[2]+":" + neibs3[6]+"-(0)->" + neibs3[7]+
" cost = " + getMutualLinkCost(nsTiles[0], neibs3[7], 4, neibs3[6], planes, tnSurface ));
}
}
}
}
}
if ((neibs3[7] >= 0) && (neibs3[6] < 0)){
int [] neibs0 = planes4[0][neibs3[7]].getNeibBest();
if (neibs0[4] >= 0) {
int [] neibs2 = planes4[2][neibs0[4]].getNeibBest();
// from down to down-right and back
if (neibs2[2] < 0) {
if (goodLink(threshold, nsTiles[2], neibs0[4], 2, np, planes, tnSurface )) {
neibs3[6] = neibs0[4];
neibs2[2] = np; //?
num_added++;
if (dl > 0){
System.out.println("cutCorners().7: added link "+
nsTiles[3]+":" + np+"-(6)->"+neibs0[4]+", " + nsTiles[2]+":" + neibs0[4]+"-(2)->" + np+
" cost = " + getMutualLinkCost(nsTiles[2], neibs0[4], 2, np, planes, tnSurface ));
}
}
}
}
}
if ((neibs3[6] >= 0) && (neibs3[0] < 0)){
int [] neibs2 = planes4[2][neibs3[6]].getNeibBest();
if (neibs2[1] >= 0) {
int [] neibs1 = planes4[1][neibs2[1]].getNeibBest();
// from right to down-right and back
if (neibs1[4] < 0) {
if (goodLink(threshold, nsTiles[1], neibs2[1], 4, np, planes, tnSurface )) {
neibs3[0] = neibs2[1]; //?
neibs1[4] = np;
num_added++;
if (dl > 0){
System.out.println("cutCorners().8: added link "+
nsTiles[3]+":" + np+"-(0)->"+neibs2[1]+", " + nsTiles[1]+":" + neibs2[1]+"-(4)->" + np+
" cost = " + getMutualLinkCost(nsTiles[1], neibs2[1], 4, np, planes, tnSurface ));
}
}
}
}
}
}
}
}
}
}
return num_added;
}
public int addFinalLinks (
final TilePlanes.PlaneData[][] planes,
final double threshold_sq,
final double threshold_corn,
final double threshold_hyp,
final boolean en_sq,
final boolean en_corn,
final boolean en_hyp,
final int debugLevel)
{
int total_added = 0;
while (true) {
while (true) {
int num_added = 0;
if (en_sq){
num_added += fillSquares(
planes,
threshold_sq,
debugLevel,
dbg_tileX,
dbg_tileY);
}
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
if (en_corn){
num_added += cutCorners(
planes,
threshold_corn,
debugLevel,
dbg_tileX,
dbg_tileY);
}
if (debugLevel > -1) {
System.out.println("after cutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
total_added += num_added;
}
int num_added = 0;
if (en_hyp){
num_added += fillHypotenuse(
planes,
threshold_hyp,
debugLevel,
dbg_tileX,
dbg_tileY);
}
if (debugLevel > -1) {
System.out.println("after fillHypotenuse() added "+num_added);
}
if (num_added == 0) break;
total_added += num_added;
}
return total_added;
}
}
......@@ -5508,11 +5508,16 @@ public class QuadCLT {
int debugLevel
)
{
final boolean new_mode = false;
final int tilesX = tp.getTilesX();
final int tilesY = tp.getTilesY();
showDoubleFloatArrays sdfa_instance = null;
if (clt_parameters.debug_filters && (debugLevel > -1)) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
if (clt_parameters.debug_filters && (debugLevel > -1))
sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
CLTPass3d bgnd_data = tp.clt_3d_passes.get(0);
double [][][][] texture_tiles = bgnd_data.texture_tiles;
......@@ -5527,6 +5532,26 @@ public class QuadCLT {
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
clt_parameters.show_bgnd_nonbgnd,
(clt_parameters.debug_filters ? (debugLevel) : -1));
boolean [] bgnd_tiles_new = tp.getBackgroundMask_new( // which tiles do belong to the background
clt_parameters.bgnd_range, // disparity range to be considered background
clt_parameters.bgnd_sure, // minimal strength to be considered definitely background
clt_parameters.bgnd_maybe, // maximal strength to ignore as non-background
clt_parameters.sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
clt_parameters.min_clstr_seed, // number of tiles in a cluster to seed (just background?)
clt_parameters.min_clstr_block,// number of tiles in a cluster to block (just non-background?)
disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
clt_parameters.show_bgnd_nonbgnd,
(clt_parameters.debug_filters ? (debugLevel) : -1));
boolean [] bgnd_dbg = bgnd_tiles.clone(); // only these have non 0 alpha
// TODO: fix mess - after modifying getBackgroundMask() to getBackgroundMask_new (before road with tractor was identified as a background because of a double
// tile glitch, the background was wrong. So temporarily both old/new are used and combined (new is grown twice)
// still does not work - using old variant for now
// background selections (slightly) influences the plane mertging / connections
for (int i = 0; i < bgnd_tiles.length; i++){
// bgnd_tiles[i] &= bgnd_tiles_new[i];
}
boolean [] bgnd_strict = bgnd_tiles.clone(); // only these have non 0 alpha
tp.growTiles(
clt_parameters.bgnd_grow, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
......@@ -5538,25 +5563,50 @@ public class QuadCLT {
bgnd_tiles,
null); // prohibit
bgnd_data.selected = bgnd_tiles_grown; // selected for background w/o extra transparent layer
// hacking - grow bgnd texture even more, without changing selection
boolean [] bgnd_tiles_grown2 = bgnd_tiles_grown.clone(); // only these have non 0 alpha
bgnd_data.selected = bgnd_tiles_grown; // selected for background w/o extra transparent layer
tp.growTiles(
2, // grow tile selection by 1 over non-background tiles 1: 4 directions, 2 - 8 directions, 3 - 8 by 1, 4 by 1 more
bgnd_tiles_grown2,
null); // prohibit
if (sdfa_instance!=null){
double [][] dbg_img = new double[3][tilesY * tilesX];
String [] titles = {"strict","grown","more_grown"};
double [][] dbg_img = new double[5][tilesY * tilesX];
String [] titles = {"old","new","strict","grown","more_grown"};
for (int i = 0; i<dbg_img[0].length;i++){
dbg_img[0][i] = bgnd_strict[i]?1:0;
dbg_img[1][i] = bgnd_tiles_grown[i]?1:0;
dbg_img[2][i] = bgnd_tiles[i]?1:0;
//
dbg_img[0][i] = bgnd_dbg[i]?1:0;
dbg_img[1][i] = bgnd_tiles_new[i]?1:0;
dbg_img[2][i] = bgnd_strict[i]?1:0;
dbg_img[3][i] = bgnd_tiles_grown[i]?1:0;
dbg_img[4][i] = bgnd_tiles[i]?1:0;
}
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "strict_grown",titles);
}
double [][][][] texture_tiles_bgnd = new double[tilesY][tilesX][][];
double [] alpha_zero = new double [4*clt_parameters.transform_size*clt_parameters.transform_size];
int alpha_index = 3;
for (int i = 0; i < alpha_zero.length; i++) alpha_zero[i]=0.0;
if (new_mode) {
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
texture_tiles_bgnd[tileY][tileX]= null;
if ((texture_tiles[tileY][tileX] != null) &&
// bgnd_tiles[tileY * tilesX + tileX]) {
bgnd_tiles_grown2[tileY * tilesX + tileX]) {
// if (bgnd_tiles_grown[tileY * tilesX + tileX]) {
if (bgnd_tiles[tileY * tilesX + tileX]) {
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX];
}else{
texture_tiles_bgnd[tileY][tileX]= texture_tiles[tileY][tileX].clone();
texture_tiles_bgnd[tileY][tileX][alpha_index] = alpha_zero;
}
}
}
}
} else {
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
texture_tiles_bgnd[tileY][tileX]= null;
......@@ -5571,6 +5621,7 @@ public class QuadCLT {
}
}
}
}
ImageDtt image_dtt = new ImageDtt();
double [][] texture_overlap = image_dtt.combineRGBATiles(
......
......@@ -5855,361 +5855,6 @@ public class SuperTiles{
public TilePlanes.PlaneData[][] copyPlanes_old(
TilePlanes.PlaneData[][] src_planes)
{
TilePlanes.PlaneData[][] dst_planes = new TilePlanes.PlaneData[src_planes.length][];
return copyPlanes_old(src_planes, dst_planes);
}
public TilePlanes.PlaneData[][] copyPlanes_old(
final TilePlanes.PlaneData[][] src_planes,
final TilePlanes.PlaneData[][] dst_planes)
{
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 < src_planes.length; nsTile = ai.getAndIncrement()) {
if (src_planes[nsTile] != null){
dst_planes[nsTile] = new TilePlanes.PlaneData[src_planes[nsTile].length];
for (int np = 0; np < src_planes[nsTile].length; np++){
if (src_planes[nsTile][np] != null){
dst_planes[nsTile][np] = src_planes[nsTile][np].clone();
} else {
dst_planes[nsTile][np] = null;
}
}
} else {
dst_planes[nsTile] = null;
}
}
}
};
}
ImageDtt.startAndJoin(threads);
return dst_planes;
}
public TilePlanes.PlaneData[][] planesSmooth_old(
final LinkPlanes lp,
final double meas_pull,// relative pull of the original (measured) plane with respect to the average of the neighbors
final double maxValue, // do not combine with too bad planes with primary eigenvalue above this value ( 0 any OK)
final int num_passes,
final boolean stopBadNeib, // do not update supertile if any of connected neighbors is not good (false: just skip that neighbor)
final double normPow,
final double maxDiff, // maximal change in any of the disparity values
final boolean preferDisparity, // Always start with disparity-most axis (false - lowest eigenvalue)
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
if (this.planes_mod == null){
this.planes_mod =copyPlanes_old(this.planes); // make always (for now) *********************
}
for (int pass = 0; pass < num_passes; pass++){
double diff = planesSmoothStep_old(
lp, // LinkPlanes lp,
meas_pull, // relative pull of the original (measured) plane with respect to the average of the neighbors
maxValue, // final double maxValue, // do not combine with too bad planes
stopBadNeib, // do not update supertile if any of connected neighbors is not good (false: just skip that neighbor)
normPow, // 0.0 - 8 neighbors pull 8 times more than 1. 1.0 - same as one
this.planes, // final TilePlanes.PlaneData[][] measured_planes,
this.planes_mod, // final TilePlanes.PlaneData[][] mod_planes,
true, // final boolean calc_diff,
preferDisparity,
(pass < 10)? debugLevel: 0,
dbg_X,
dbg_Y);
if (diff < maxDiff){
if (debugLevel > -1){
System.out.println("planesSmooth(): pass:"+pass+" (of "+num_passes+"), rms = "+diff+" < "+maxDiff);
break;
}
}
if (debugLevel > -1){
System.out.println("planesSmooth() - pass:"+pass+" (of "+num_passes+"), rms = "+diff);
}
}
return this.planes_mod;
}
public double planesSmoothStep_old(
final LinkPlanes lp,
final double meas_pull,// relative pull of the original (measured) plane with respect to the average of the neighbors
final double maxValue, // do not combine with too bad planes, do not merge if result is above
final boolean stopBadNeib, // do not update supertile if any of connected neighbors is not good (false: just skip that neighbor)
final double normPow,
final TilePlanes.PlaneData[][] measured_planes,
final TilePlanes.PlaneData[][] mod_planes,
final boolean calc_diff,
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 [][] dirsYX = {{-1, 0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
final int tilesX = tileProcessor.getTilesX();
final int tilesY = tileProcessor.getTilesY();
final int superTileSize = tileProcessor.getSuperTileSize();
final int stilesX = (tilesX + superTileSize -1)/superTileSize;
// final int stilesY = (tilesY + superTileSize -1)/superTileSize;
final int debug_stile = dbg_Y * stilesX + dbg_X;
final TilePlanes.PlaneData[][] new_planes = copyPlanes_old(mod_planes);
final Thread[] threads = ImageDtt.newThreadArray(tileProcessor.threadsMax);
final int numThreads = threads.length;
final double [] rslt_diffs = calc_diff ? new double [numThreads] : null; // all 0;
final AtomicInteger ai_numThread = new AtomicInteger(0);
final AtomicInteger ai = new AtomicInteger(0);
final String [] titles= {
"orig", // 0
"measured", // 1
"n0","n1","n2","n3","n4","n5","n6","n7", // 2 .. 9
"m0","m1","m2","m3","m4","m5","m6","m7","mm", // 10..18
"diff"}; // 19
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
double [][] dbg_img=null;
int numThread = ai_numThread.getAndIncrement(); // unique number of thread to write to rslt_diffs[numThread]
for (int nsTile0 = ai.getAndIncrement(); nsTile0 < mod_planes.length; nsTile0 = ai.getAndIncrement()) {
int sty0 = nsTile0 / stilesX;
int stx0 = nsTile0 % stilesX;
int dl = ((debugLevel > -1) && (nsTile0 == debug_stile)) ? 1:0;
if ( new_planes[nsTile0] != null) {
if (dl > 0){
System.out.println("planesSmoothStep nsTile0="+nsTile0);
dbg_img = new double [titles.length][];
}
int np0_min = (new_planes[nsTile0].length > 1) ? 1:0; // Modify if overall plane will be removed
for (int np0 = np0_min; np0 < new_planes[nsTile0].length; np0 ++){
TilePlanes.PlaneData this_new_plane = new_planes[nsTile0][np0];
if (this_new_plane == null){
System.out.println("Bug? new_planes["+nsTile0+"]["+np0+"] == null");
continue;
}
if (dl > 0) dbg_img[ 0] = this_new_plane.getSinglePlaneDisparity(false);
if (dl > 0) dbg_img[ 1] = measured_planes[nsTile0][np0].getSinglePlaneDisparity(false);
int [] neibs = this_new_plane.getNeibBest();
double [][] costs = new double[neibs.length][];
double [] weights = new double[neibs.length];
int cost_index = 2; // overall cost
double sum_rcosts = 0.0;
int non_zero = 0;
for (int dir = 0; dir < neibs.length; dir++) if (neibs[dir] >= 0) {
int stx = stx0 + dirsYX[dir][1];
int sty = sty0 + dirsYX[dir][0];
int nsTile = sty * stilesX + stx; // from where to get
TilePlanes.PlaneData other_plane = this_new_plane.getPlaneToThis(
mod_planes[nsTile][neibs[dir]], // neighbor, previous value
dl - 1); // debugLevel);
costs[dir] = lp.getFitQualities(
// there probably be no sticks here after merging
false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
this_new_plane, // TilePlanes.PlaneData plane1, // should belong to the same supertile (or be converted for one)
other_plane, // TilePlanes.PlaneData plane2,
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
Double.NaN, // double merged_wev, // if NaN will calculate assuming the same supertile - for world
Double.NaN, // double merged_wev_eq, // if NaN will calculate assuming the same supertile - for world
nsTile0+":"+np0+"-"+dir, // String prefix,
0); // int debugLevel)
for (int i = 3; i < costs[dir].length; i++) costs[dir][i] *= costs[dir][2];
non_zero ++;
weights[dir] = 1.0/costs[dir][cost_index];
sum_rcosts += weights[dir];
}
for (int dir = 0; dir < neibs.length; dir++) if (neibs[dir] >= 0) {
weights[dir] *= non_zero/sum_rcosts; // average weight for active links will be 1.0
}
if (dl > 0) {
for (int dir = 0; dir <8; dir++)if (costs[dir] != null){
System.out.print(nsTile0+":"+np0+"-"+dir+" "+String.format(" weight= %6.3f ",weights[dir]));
for (int i = 0; i < costs[dir].length; i++){
System.out.print(String.format("%8.3f", costs[dir][i]));
// if (i < 3) System.out.print(String.format("%8.3f", costs[dir][i]));
// else System.out.print(String.format("%8.3f", costs[dir][i]*costs[dir][2]));
}
System.out.println();
}
System.out.println();
}
this_new_plane =this_new_plane.clone(); // not to change weight!
this_new_plane.setWeight(0.0); //
double num_merged = 0.0; // double to add fractional pull weight of the center
double true_num_merged = 0.0;
for (int dir = 0; dir < neibs.length; dir++){
if (neibs[dir] >= 0) {
int stx = stx0 + dirsYX[dir][1];
int sty = sty0 + dirsYX[dir][0];
int nsTile = sty * stilesX + stx; // from where to get
TilePlanes.PlaneData other_plane = this_new_plane.getPlaneToThis(
mod_planes[nsTile][neibs[dir]], // neighbor, previous value
dl - 1); // debugLevel);
if (dl > 0) dbg_img[ 2 + dir] = other_plane.getSinglePlaneDisparity(false);
if ((other_plane != null) && ((other_plane.getValue() <= maxValue) || (maxValue == 0))) { // TODO:
if (this_new_plane.getWeight() > 0.0){
this_new_plane = this_new_plane.mergePlaneToThis(
other_plane, // PlaneData otherPd,
weights[dir], // 1.0, // double scale_other,
// here it should be no power function for the weights
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)
} else {
this_new_plane.copyNeib(this_new_plane, other_plane); // keep neighbors of the original center plane
this_new_plane.copyStar(this_new_plane, other_plane);
this_new_plane = other_plane; // should increment num_merged
this_new_plane.scaleWeight(weights[dir]);
this_new_plane.invalidateCalculated();
}
if (this_new_plane != null){
num_merged += 1.0;
true_num_merged += 1.0;
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
}
new_planes[nsTile0][np0] = this_new_plane;
if (dl > 0) dbg_img[10 + dir] = this_new_plane.getSinglePlaneDisparity(false);
} else if (stopBadNeib){ // just skip, not abandon? (set to false)
this_new_plane = null;
break;
}
}
}
if (this_new_plane != null) {
// average weight over participating directions, so the relative pull
// does not depend on number of neighbors
if ((num_merged > 0.0) && (this_new_plane != null) && (normPow > 1.0)){
double scale = Math.pow(num_merged, normPow);
this_new_plane.scaleWeight(1.0/scale);
num_merged /=scale;
true_num_merged /= scale;
}
if ( (meas_pull > 0.0) &&
(measured_planes != null) &&
(measured_planes[nsTile0] != null) &&
(measured_planes[nsTile0][np0] != null) &&
// ((measured_planes[nsTile0][np0].getValue() < maxValue) || (maxValue == 0))
((measured_planes[nsTile0][np0].getValue() < maxValue) || (maxValue == 0) ||
(this_new_plane == null) || (this_new_plane.getWeight() == 0.0)) // keep measured if impossible to merge
){ // merge with "measured"
if (this_new_plane.getWeight() > 0.0){
this_new_plane = this_new_plane.mergePlaneToThis(
measured_planes[nsTile0][np0], // PlaneData otherPd,
meas_pull, // 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 (this_new_plane != null){
num_merged += meas_pull; // num_merged was 1.0 and weight is averaged over all neighbors
true_num_merged += 1.0;
}
} else {
this_new_plane = measured_planes[nsTile0][np0].clone();
num_merged = 1.0;
true_num_merged = 1.0;
}
new_planes[nsTile0][np0] = this_new_plane;
if (dl > 0) dbg_img[18] = this_new_plane.getSinglePlaneDisparity(false);
}
if ((num_merged > 0.0) && (this_new_plane != null)){
this_new_plane.scaleWeight(1.0/num_merged);
// double true_num_merged = num_merged - meas_pull + 1;
this_new_plane.setNumPoints((int) (this_new_plane.getNumPoints()/true_num_merged));
}
// Revert if the result value is higher than imposed maximum
if ((this_new_plane.getValue() > maxValue) && (maxValue != 0)){ // TODO: Set more relaxed here?
if (dl > -1){
System.out.println("planesSmoothStep nsTile0="+nsTile0+" smoothed plane is too thick, using previous one");
dbg_img = new double [titles.length][];
}
this_new_plane = mod_planes[nsTile0][np0].clone();
new_planes[nsTile0][np0] = this_new_plane;
}
// Use non-exclusive
// just for debug / calculate
this_new_plane.getWorldXYZ(0);
// calculate largest disparity difference between old and new plane
if (rslt_diffs != null){ // filter out outliers here?
// get plane for both old and new, calc rms of diff
double [] oldPlane = mod_planes[nsTile0][np0].getSinglePlaneDisparity(
false); // use_NaN)
double [] newPlane = new_planes[nsTile0][np0].getSinglePlaneDisparity(
false); // use_NaN)
double s = 0.0;
for (int i = 0; i < oldPlane.length; i++){
double d = newPlane[i] - oldPlane[i];
s+= d*d;
}
s= Math.sqrt(s/oldPlane.length);
if (s > rslt_diffs[numThread]){
rslt_diffs[numThread] = s;
}
if (dl > 0) {
dbg_img[19] = new double[oldPlane.length];
for (int i = 0; i < oldPlane.length; i++){
dbg_img[19][i] = newPlane[i] - oldPlane[i];
}
if (debugLevel > 0) {
System.out.println("planesSmoothStep() nsTile0="+nsTile0+" rms = "+s);
}
}
if (debugLevel > -1) {
// if ((s > 5.0) || (dl > 0)){
if ((s > 5.0) || (dl > 0)){
System.out.println("planesSmoothStep() nsTile0="+nsTile0+":"+np0+
" num_merged="+num_merged + " rms = "+s+
" new_weight = "+new_planes[nsTile0][np0].getWeight()+
" old_weight = "+mod_planes[nsTile0][np0].getWeight()+
" new_value = "+new_planes[nsTile0][np0].getValue()+
" old_value = "+mod_planes[nsTile0][np0].getValue()+
" measured_weight = "+measured_planes[nsTile0][np0].getWeight()+
" measured_value = "+measured_planes[nsTile0][np0].getValue());
}
}
}
if ((dl > 0) && (debugLevel > 0)){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(dbg_img, superTileSize, superTileSize, true, "smooth_step_x"+stx0+"_y"+sty0, titles);
}
} else { // if (this_new_plane != null)
this_new_plane = mod_planes[nsTile0][np0].clone();
new_planes[nsTile0][np0] = this_new_plane;
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
copyPlanes_old (new_planes, mod_planes); // copy back
if (rslt_diffs == null){
return Double.NaN;
}
double diff = 0.0;
for (int i = 0; (i < numThreads) ; i++) if (diff < rslt_diffs[i]) diff = rslt_diffs[i];
return diff; // return maximal difference
}
/**
* Prepare visualization of the plane separation lines
......
......@@ -858,7 +858,8 @@ public class TileProcessor {
}
//sure_smth
public boolean [] getBackgroundMask( // which tiles do belong to the background
double bgnd_range, // disparity range to be considered background
double bgnd_sure, // minimal strength to be considered definitely background
......@@ -875,7 +876,151 @@ public class TileProcessor {
boolean [] block_propagate = new boolean [tilesY * tilesX];
int quad = 4;
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
if (debugLevel > -1)
sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// boolean [] new_tiles = new boolean [tilesY * tilesX]; // grow selection by 1 tile over non-background?
CLTPass3d bgnd_data = clt_3d_passes.get(0);
// double [][][][] texture_tiles = bgnd_data.texture_tiles;
double [][] disparity_map= bgnd_data.disparity_map;
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < tilesX; tileX++){
int tindx = tileY * tilesX + tileX;
if (Math.abs(disparity_map[disparity_index][tindx]) < bgnd_range){
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] >= bgnd_sure){
bgnd_tiles[tindx] = true;
}
} else {
if (disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][tindx] > bgnd_maybe){ // maybe non-bkgnd
if (disparity_map[disparity_index][tindx] > 0.0) { // disregard negative disparity points
nonbgnd_tiles[tindx] = true;
}
}
}
// see if the second worst variation exceeds sure_smth (like a window), really close object
int imax1 = 0;
for (int i = 1; i< quad; i++){
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax1][tindx]) imax1 = i;
}
int imax2 = (imax1 == 0)? 1 : 0;
for (int i = 0; i< quad; i++) if (i != imax1) {
if (disparity_map[ImageDtt.IMG_DIFF0_INDEX+i][tindx] > disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx]) imax2 = i;
}
block_propagate[tindx] = (disparity_map[ImageDtt.IMG_DIFF0_INDEX + imax2][tindx] > sure_smth);
}
}
// TODO: check if minimal cluster strengh should be limited here
if (min_clstr_seed > 1){
removeSmallClusters(
true, // boolean diag_en, // enable diagonal directions, false only up, dowm, right,left
bgnd_tiles, // boolean [] tiles_src, // selected tiles, will modified
null, // double [] weights_src, // or null
min_clstr_seed, // int min_area, // minimal number of pixels
0.0, //clt_parameters.min_clstr_weight, // double min_weight // minimal total weight of the cluster
0.0); // clt_parameters.min_clstr_max); // double min_max_weight // minimal value of the maximal strengh in the cluster
}
if (min_clstr_block > 1){
removeSmallClusters(
true, // boolean diag_en, // enable diagonal directions, false only up, dowm, right,left
nonbgnd_tiles, // boolean [] tiles_src, // selected tiles, will modified
null, // double [] weights_src, // or null
min_clstr_block, // int min_area, // minimal number of pixels
0.0, //clt_parameters.min_clstr_weight, // double min_weight // minimal total weight of the cluster
0.0); // clt_parameters.min_clstr_max); // double min_max_weight // minimal value of the maximal strengh in the cluster
}
if ((sdfa_instance != null) && show_bgnd_nonbgnd) {
String [] titles = {"bgnd","nonbgnd","block","strength","disparity"};
double [][] dbg_img = new double[titles.length][tilesY * tilesX];
for (int i = 0; i<dbg_img[0].length;i++){
dbg_img[0][i] = bgnd_tiles [i] ? 1 : 0;
dbg_img[1][i] = nonbgnd_tiles [i] ? 1 : 0;
dbg_img[2][i] = block_propagate[i] ? 1 : 0;
dbg_img[3][i] = disparity_map[ImageDtt.DISPARITY_STRENGTH_INDEX][i];
dbg_img[4][i] = disparity_map[disparity_index][i];
}
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, true, "bgnd_nonbgnd",titles);
}
for (int gain = 1; gain > 0;){
gain = 0;
// extend to the right
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = 0; tileX < (tilesX - 1); tileX++){
int tindx = tileY * tilesX + tileX;
if (bgnd_tiles[tindx] && !bgnd_tiles[tindx + 1] && !nonbgnd_tiles[tindx + 1] && !block_propagate[tindx + 1]){
bgnd_tiles[tindx+1] = true;
gain++;
}
}
}
// extend to the left
for (int tileY = 0; tileY < tilesY; tileY++){
for (int tileX = tilesX - 1; tileX > 1; tileX--){
int tindx = tileY * tilesX + tileX;
if (bgnd_tiles[tindx] && !bgnd_tiles[tindx - 1] && !nonbgnd_tiles[tindx -1] && !block_propagate[tindx - 1]){
bgnd_tiles[tindx - 1] = true;
gain++;
}
}
}
// extend down
for (int tileX = 0; tileX < tilesX; tileX++){
for (int tileY = 0; tileY < (tilesY -1); tileY++){
int tindx = tileY * tilesX + tileX;
if (bgnd_tiles[tindx] && !bgnd_tiles[tindx + tilesX] && !nonbgnd_tiles[tindx + tilesX] && !block_propagate[tindx + tilesX]){
bgnd_tiles[tindx + tilesX] = true;
gain++;
}
}
}
// extend up
for (int tileX = 0; tileX < tilesX; tileX++){
for (int tileY = tilesY - 1; tileY > 1; tileY--){
int tindx = tileY * tilesX + tileX;
if (bgnd_tiles[tindx] && !bgnd_tiles[tindx - tilesX] && !nonbgnd_tiles[tindx - tilesX] && !block_propagate[tindx - tilesX]){
bgnd_tiles[tindx - tilesX] = true;
gain++;
}
}
}
if (debugLevel > -1) {
System.out.println("getBackgroundMask(), gain="+gain);
}
if (sdfa_instance!=null){
double [] dbg_img = new double[tilesY * tilesX];
for (int i = 0; i<dbg_img.length;i++){
dbg_img[i] = bgnd_tiles[i]?1:0;
}
sdfa_instance.showArrays(dbg_img, tilesX, tilesY, "tiles");
}
}
return bgnd_tiles;
}
//sure_smth
public boolean [] getBackgroundMask_new( // which tiles do belong to the background
double bgnd_range, // disparity range to be considered background
double bgnd_sure, // minimal strength to be considered definitely background
double bgnd_maybe, // maximal strength to ignore as non-background
double sure_smth, // if 2-nd worst image difference (noise-normalized) exceeds this - do not propagate bgnd
int min_clstr_seed, // number of tiles in a cluster to seed (just background?)
int min_clstr_block, // number of tiles in a cluster to block (just non-background?)
int disparity_index, // index of disparity value in disparity_map == 2 (0,2 or 4)
boolean show_bgnd_nonbgnd,
int debugLevel
){
boolean [] bgnd_tiles = new boolean [tilesY * tilesX];
boolean [] nonbgnd_tiles = new boolean [tilesY * tilesX];
boolean [] block_propagate = new boolean [tilesY * tilesX];
int quad = 4;
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1)
sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// boolean [] new_tiles = new boolean [tilesY * tilesX]; // grow selection by 1 tile over non-background?
CLTPass3d bgnd_data = clt_3d_passes.get(0);
......@@ -1025,6 +1170,11 @@ public class TileProcessor {
}
}
// was not in tghe original
tnSurface.growSelection(
4, // grow,
bgnd_tiles, // tiles,
null); // prohibit);
return bgnd_tiles;
}
......@@ -3262,280 +3412,102 @@ public class TileProcessor {
return true;
}
public void conditionSuperTilesOld(
//======================
public void showPlanes(
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
SuperTiles st,
LinkPlanes lp,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
// try to merge multiple times
trimCLTPasses(); // make possible to run this method multiple time - remove extra passes added by it last time
CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
int max_num_merge_try = 8;
TilePlanes.PlaneData [][][] dbg_orig_planes = new TilePlanes.PlaneData [max_num_merge_try][][];
boolean show_st = clt_parameters.stShow || (debugLevel > 1);
// recalculate supertiles (may be removed later)
// if (use_supertiles || show_st) {
String [] dbg_st_titles = {"raw", "sampled", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
if (show_st) { // otherwise only blured version is needed
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
}
for (int num_merge_try = 0; num_merge_try < max_num_merge_try; num_merge_try++){
lp.matchPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts( //
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// SuperTiles st =
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
clt_parameters.stSigma, // with blur double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
if (show_st) { // otherwise only blured version is needed
dbg_hist[2] = scan_prev.getSuperTiles().showDisparityHistogram();
dbg_hist[3] = scan_prev.getSuperTiles().showMaxMinMax();
}
lp.filterNeighborPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
true, // final boolean merge_low_eigen,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// calculate it here - use results to keep some planes from merging
double [][] quality_stats1 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats1.length);
if (show_st){
int hist_width0 = scan_prev.getSuperTiles().showDisparityHistogramWidth();
int hist_height0 = dbg_hist[0].length/hist_width0;
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(dbg_hist, hist_width0, hist_height0, true, "disparity_supertiles_histograms",dbg_st_titles);
}
if (clt_parameters.stSmplMode){ // just temporary making it last
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
}
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
lp.getExNeibCost(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.calcStarValueStrength(
true, // boolean set_start_planes,
clt_parameters.plStarOrtho, // orthoWeight, // final double orthoWeight,
clt_parameters.plStarDiag, // diagonalWeight, // final double diagonalWeight,
clt_parameters.plStarPwr, // starPwr, // final double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // starValPwr, //double starValPwr, // Raise value of each tile before averaging
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
debugLevel-2);
int [][][] merge_candidates = lp.getMergeSameTileCandidates(
st.planes, // final TilePlanes.PlaneData [][] planes,
2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
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);
// remove merge candidates that break connections to neighbors
if (debugLevel>100) lp.keepSameTileConnections(
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_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
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// * 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
// have a "star"
// double [][][][][][] merge_cost_data =
lp.costSameTileConnections(
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,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// System.out.println("merge_cost_data.length = " + merge_cost_data.length);
lp.costSameTileConnectionsAlt(
//5.0, // final double threshold,
//10.0, // final double threshold_nostar,
lp.getMergeCostStar(), // relax_for_conflicts * 5.0, // final double threshold, //
lp.getMergeCostNoStar(), //relax_for_conflicts * 10.0, // final double threshold_nostar,
st.planes, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
int [][][] merge_groups = lp.extractMergeSameTileGroups(
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);
dbg_orig_planes[num_merge_try] = st.planes.clone();
for (int nsTile=0; nsTile < st.planes.length; nsTile++) if (st.planes[nsTile] != null){
dbg_orig_planes[num_merge_try][nsTile] = st.planes[nsTile].clone();
for (int np = 0; np < st.planes[nsTile].length; np++ ) if (st.planes[nsTile][np] != null){
dbg_orig_planes[num_merge_try][nsTile][np] = st.planes[nsTile][np].clone();
}
}
int 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
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
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;
}
}
}
//======================
public void showPlanes(
EyesisCorrectionParameters.CLTParameters clt_parameters,
GeometryCorrection geometryCorrection,
final int threadsMax, // maximal number of threads to launch
final boolean updateStatus,
final int debugLevel)
{
trimCLTPasses(); // make possible to run this method multiple time - remove extra passes added by it last time
CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
boolean show_st = clt_parameters.stShow || (debugLevel > 1);
// recalculate supertiles (may be removed later)
// if (use_supertiles || show_st) {
String [] dbg_st_titles = {"raw", "sampled", "blurred"+clt_parameters.stSigma,"max-min-max"};
double [][] dbg_hist = new double[dbg_st_titles.length][];
if (show_st) { // otherwise only blured version is needed
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[0] = scan_prev.getSuperTiles().showDisparityHistogram();
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
dbg_hist[1] = scan_prev.getSuperTiles().showDisparityHistogram();
}
// SuperTiles st =
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
clt_parameters.stSigma, // with blur double stBlurSigma)
false, //clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
if (show_st) { // otherwise only blured version is needed
dbg_hist[2] = scan_prev.getSuperTiles().showDisparityHistogram();
dbg_hist[3] = scan_prev.getSuperTiles().showMaxMinMax();
}
if (show_st){
int hist_width0 = scan_prev.getSuperTiles().showDisparityHistogramWidth();
int hist_height0 = dbg_hist[0].length/hist_width0;
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(dbg_hist, hist_width0, hist_height0, true, "disparity_supertiles_histograms",dbg_st_titles);
}
if (clt_parameters.stSmplMode){ // just temporary making it last
scan_prev.setSuperTiles(
clt_parameters.stStepNear, // double step_disparity,
clt_parameters.stStepFar, // double step_near,
clt_parameters.stStepThreshold, // double step_threshold,
clt_parameters.stMinDisparity, // double min_disparity,
clt_parameters.stMaxDisparity, // double max_disparity,
clt_parameters.stFloor, // double strength_floor,
clt_parameters.stPow, // double strength_pow,
0.0, // NO BLUR double stBlurSigma)
clt_parameters.stSmplMode, // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide, // Sample size (side of a square)
clt_parameters.stSmplNum, // Number after removing worst
clt_parameters.stSmplRms, // Maximal RMS of the remaining tiles in a sample
clt_parameters.stMeasSel); // bitmask of the selected measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
}
SuperTiles st = scan_prev.getSuperTiles();
st.setTileSurface(geometryCorrection); // tileSurface);
SuperTiles st = scan_prev.getSuperTiles();
st.setTileSurface(geometryCorrection); // tileSurface);
double [] world_hor = {0.0, 1.0, 0.0};
st.processPlanes5(
......@@ -3572,8 +3544,8 @@ public class TileProcessor {
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
showDoubleFloatArrays sdfa_instance = null;
if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
// showDoubleFloatArrays sdfa_instance = null;
// if (debugLevel > -1) sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
//==========================
......@@ -3642,7 +3614,7 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
// condition the redcefined planes
// condition the redefined planes
lp.conditionSuperTiles(
st.planes, // final TilePlanes.PlaneData [][] planes,
10, // final int max_num_merge_try,
......@@ -3661,467 +3633,61 @@ public class TileProcessor {
debugLevel - 2);
}
/*
double [][] quality_stats1 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats1.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
//Just overwrite results of the previous method
*/
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
lp.getExNeibCost(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/*
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
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.plStarOrtho, // double orthoWeight,
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
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity,
debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
*/
if (clt_parameters.plSplitApply) {
while (true) {
int num_added = 0;
num_added += st.fillSquares();
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
num_added += st.cutCorners();
if (debugLevel > -1) {
System.out.println("after plCutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
}
double [][][] dispStrength = st.getDisparityStrengths(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
boolean [][] tileSel = st.getMeasurementSelections(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
TilePlanes.PlaneData[][][] split_planes = // use original (measured planes. See if smoothed are needed here)
st.breakPlanesToPairs(
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] center_planes, // measured_planes,
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] neib_planes, //mod_planes,
clt_parameters.plSplitPull , // final double center_pull,
clt_parameters.plSplitMinNeib , // min_neibs, // 2
clt_parameters.plSplitMinWeight, // final double splitMinWeight, // = 2.0; // Minimal weight of split plains to show
clt_parameters.plSplitMinQuality, // final double splitMinQuality, // = 1.1; // Minimal split quality to show
clt_parameters.plPreferDisparity,
debugLevel,
clt_parameters.tileX,
clt_parameters.tileY);
if (clt_parameters.plSplitApply) {
int numSplitPlanes = st.replaceBrokenPlanes(
st.getPlanes(), // final TilePlanes.PlaneData[][] planes,
split_planes, // final TilePlanes.PlaneData[][][] brokenPd,
clt_parameters.plMaxDiff, // final double max_diff, // maximal disparity difference (0 - any), will be normalized by dispNorm
clt_parameters.plOtherDiff, // final double other_diff, // other_diff maximal difference of the added tile ratio to the average disparity difference
clt_parameters.plNonExclusive, // final boolean non_exclusive,
clt_parameters.plUseOtherPlanes, // final boolean use_other_planes, // TODO:
clt_parameters.stMeasSel, // final int measSel, // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plAllowParallel, // final boolean allow_parallel,
clt_parameters.plSplitXY, // final boolean splitXY,
clt_parameters.plSplitXYTolerance, // final double splitXYTolerance,
// 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
clt_parameters.stFloor, // final double strength_floor,
clt_parameters.stPow, // final double strength_pow,
// clt_parameters.dbg_migrate && clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel > -1){
System.out.println("replaceBrokenPlanes(): Replaced " + numSplitPlanes + " planes by pairs.");
}
// now re-create connections and best neighbors
lp = new LinkPlanes (clt_parameters, st);
lp.matchPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts( // not used yet, just for testing
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.filterNeighborPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
true, // final boolean merge_low_eigen,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// Try replacing lp.selectNeighborPlanesMutual with
// lp.setExclusiveLinks()
double [][] quality_stats2 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats2.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
lp.getExNeibCost(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
clt_parameters.plConflDualTri, // boolean conflDualTri, // Resolve dual triangles conflict (odoodo)
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.plStarOrtho, // double orthoWeight,
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
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity,
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
} // if (clt_parameters.plSplitApply)
while (true) {
int num_added = 0;
if (clt_parameters.plFillSquares){
num_added += st.fillSquares();
}
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
if (clt_parameters.plCutCorners){
num_added += st.cutCorners();
}
if (debugLevel > -1) {
System.out.println("after plCutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
TilePlanes.PlaneData [][] planes_mod = null;
// smooth planes (by averaging with neighbors and the "measured" one with variable "pull")
// double relax_for_conflicts = lp.getConflRelax(); // 1.5;
int max_num_tries = 20;
if (clt_parameters.plIterations > 0) {
if (debugLevel <= 100) {
st.planes_mod = lp.planesSmoothAndMerge(
st.planes, // final TilePlanes.PlaneData[][] planes, // planes will be modified
max_num_tries, // final int max_num_tries,
debugLevel); // final int debugLevel)
// currently results of below calcStarValueStrength() are not used, just to fill instances fields
lp.calcStarValueStrength(
true, // boolean set_start_planes,
clt_parameters.plStarOrtho, // orthoWeight, // final double orthoWeight,
clt_parameters.plStarDiag, // diagonalWeight, // final double diagonalWeight,
clt_parameters.plStarPwr, // starPwr, // final double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // starValPwr, //double starValPwr, // Raise value of each tile before averaging
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
0); // debugLevel);
planes_mod = st.planes_mod; // temporarily
} else { // to be removed after testing the new version
for (int num_merge_try = 0; num_merge_try < max_num_tries; num_merge_try ++ ) { // smooth and merge
st.resetPlanesMod(); // clean start
planes_mod = st.planesSmooth_old(
lp, // LinkPlanes lp,
clt_parameters.plPull, // final double meas_pull,// relative pull of the original (measured) plane with respect to the average of the neighbors
clt_parameters.plMaxEigen, // final double maxValue, // do not combine with too bad planes
clt_parameters.plIterations, // final int num_passes,
clt_parameters.plStopBad, // Do not update supertile if any of connected neighbors is not good (false: just skip that neighbor)
clt_parameters.plNormPow, // 0.0: 8 neighbors pull 8 times as 1, 1.0 - same as 1
Math.pow(10.0, -clt_parameters.plPrecision), // final double maxDiff, // maximal change in any of the disparity values
clt_parameters.plPreferDisparity,
debugLevel, // 0, // 1,// 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// create costs for the modified planes
lp.interPlaneCosts(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setExclusiveLinks(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
// 2.5, //final double max_cost
lp.getExNeibCost()*lp.getExNeibSmooth(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// once more after updating exclusive links
planes_mod = st.planesSmooth_old(
lp, // LinkPlanes lp,
clt_parameters.plPull, // final double meas_pull,// relative pull of the original (measured) plane with respect to the average of the neighbors
clt_parameters.plMaxEigen, // final double maxValue, // do not combine with too bad planes
clt_parameters.plIterations, // final int num_passes,
clt_parameters.plStopBad, // Do not update supertile if any of connected neighbors is not good (false: just skip that neighbor)
clt_parameters.plNormPow, // 0.0: 8 neighbors pull 8 times as 1, 1.0 - same as 1
Math.pow(10.0, -clt_parameters.plPrecision), // final double maxDiff, // maximal change in any of the disparity values
clt_parameters.plPreferDisparity,
debugLevel, // 0, // 1,// 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts(
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// recalculate links? more smooth?
lp.setExclusiveLinks(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
// 2.5, //final double max_cost
lp.getExNeibCost()*lp.getExNeibSmooth(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// just in case? Not yet needed
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
// see if some modified planes need to be merged (but merge originals)
// TODO: Stricter requirements for merging here than for original planes?
int [][][] merge_candidates = lp.getMergeSameTileCandidates(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
boolean [][][] plane_nooverlaps = lp.overlapSameTileCandidates (
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
0.2, // final double min_distance, //?
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,
merge_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
debugLevel, // final int debugLevel)
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(
debugLevel); // 1); // final int debugLevel)
int [][][] conflicting_candidates = lp.filterPairsByConflicts(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
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
// have a "star"
lp.costSameTileConnections(
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,
debugLevel, // 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(
//5.0, // final double threshold,
//10.0, // final double threshold_nostar,
lp.getMergeCostStar(), // relax_for_conflicts * 5.0, // final double threshold, //
lp.getMergeCostNoStar(), //relax_for_conflicts * 10.0, // final double threshold_nostar,
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
int [][][] merge_groups = lp.extractMergeSameTileGroups(
st.planes_mod, // final TilePlanes.PlaneData [][] planes,
merge_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
1.0, // final double relax,
debugLevel + 1, // 2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
int 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
debugLevel, // 2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
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
// 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,
debugLevel, // 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
debugLevel, // 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
lp.getConflRelax(), //relax_for_conflicts, // final double relax,
debugLevel, // 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,
lp.getConflRelax() * lp.getMergeCostStar(), // relax_for_conflicts * 5.0, // final double threshold, //
lp.getConflRelax() * lp.getMergeCostNoStar(), //relax_for_conflicts * 10.0, // final double threshold_nostar,
// st.planes_mod, // final TilePlanes.PlaneData [][] planes,
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // final boolean [][][] valid_candidates, // will be updated
lp.getExNeibCost(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
/*
if (clt_parameters.plSplitApply) {
while (true) {
int num_added = 0;
num_added += st.fillSquares();
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
num_added += st.cutCorners();
if (debugLevel > -1) {
System.out.println("after plCutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
}
*/
double [][][] dispStrength = st.getDisparityStrengths(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
boolean [][] tileSel = st.getMeasurementSelections(
clt_parameters.stMeasSel); // int stMeasSel) // = 1; // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert)
merge_groups = lp.extractMergeSameTileGroups(
// st.planes_mod, // final TilePlanes.PlaneData [][] planes,
st.planes, // final TilePlanes.PlaneData [][] planes,
conflicting_candidates, // final int [][][] merge_candidates,
plane_nooverlaps, // boolean [][][] plane_overlaps,
lp.getConflRelax(), // relax_for_conflicts, // final double relax,
debugLevel+ 1, // 2, // -1, // debugLevel, // final int debugLevel)
TilePlanes.PlaneData[][][] split_planes = // use original (measured planes. See if smoothed are needed here)
st.breakPlanesToPairs(
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] center_planes, // measured_planes,
st.getPlanes(), // Mod(), // final TilePlanes.PlaneData[][] neib_planes, //mod_planes,
clt_parameters.plSplitPull , // final double center_pull,
clt_parameters.plSplitMinNeib , // min_neibs, // 2
clt_parameters.plSplitMinWeight, // final double splitMinWeight, // = 2.0; // Minimal weight of split plains to show
clt_parameters.plSplitMinQuality, // final double splitMinQuality, // = 1.1; // Minimal split quality to show
clt_parameters.plPreferDisparity,
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,
if (clt_parameters.plSplitApply) {
int numSplitPlanes = st.replaceBrokenPlanes(
st.getPlanes(), // final TilePlanes.PlaneData[][] planes,
split_planes, // final TilePlanes.PlaneData[][][] brokenPd,
clt_parameters.plMaxDiff, // final double max_diff, // maximal disparity difference (0 - any), will be normalized by dispNorm
clt_parameters.plOtherDiff, // final double other_diff, // other_diff maximal difference of the added tile ratio to the average disparity difference
clt_parameters.plNonExclusive, // final boolean non_exclusive,
clt_parameters.plUseOtherPlanes, // final boolean use_other_planes, // TODO:
clt_parameters.stMeasSel, // final int measSel, // Select measurements for supertiles : +1 - combo, +2 - quad +4 - hor +8 - vert
clt_parameters.plAllowParallel, // final boolean allow_parallel,
clt_parameters.plSplitXY, // final boolean splitXY,
clt_parameters.plSplitXYTolerance, // final double splitXYTolerance,
// 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)
......@@ -4132,29 +3698,29 @@ public class TileProcessor {
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
debugLevel, // 2, // -1, // debugLevel, // final int debugLevel)
clt_parameters.stFloor, // final double strength_floor,
clt_parameters.stPow, // final double strength_pow,
// clt_parameters.dbg_migrate && clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.stSmplMode , // final boolean smplMode, // = true; // Use sample mode (false - regular tile mode)
clt_parameters.stSmplSide , // final int smplSide, // = 2; // Sample size (side of a square)
clt_parameters.stSmplNum , // final int smplNum, // = 3; // Number after removing worst
clt_parameters.stSmplRms , // final double smplRms, // = 0.1; // Maximal RMS of the remaining tiles in a sample
debugLevel, // 1, // 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_merge_try >= max_num_tries) {
System.out.println("Exceeded maximal number of iterations, beaking anyway...");
break;
}
if (num_removed_by_merging == 0){ // re-calculate all links
break;
}
if (debugLevel > -1){
System.out.println("replaceBrokenPlanes(): Replaced " + numSplitPlanes + " planes by pairs.");
}
// Do the same as in conditionSuperTiles before smoothing again
// now re-create connections and best neighbors
lp = new LinkPlanes (clt_parameters, st);
lp.matchPlanes(
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.interPlaneCosts( //
true, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
lp.interPlaneCosts( // not used yet, just for testing
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
......@@ -4167,62 +3733,27 @@ public class TileProcessor {
clt_parameters.tileX,
clt_parameters.tileY);
// calculate it here - use results to keep some planes from merging
/*
// Try replacing lp.selectNeighborPlanesMutual with
// lp.setExclusiveLinks()
double [][] quality_stats2 = lp.selectNeighborPlanesMutual(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
st.planes, // final TilePlanes.PlaneData [][] planes,
debugLevel, // 2, // final int debugLevel)
debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
if (debugLevel>100) System.out.println(quality_stats2.length);
System.out.println("Testing - overwriting selectNeighborPlanesMutual() results with setExclusiveLinks()");
*/
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
// 2.5, //final double max_cost
lp.getExNeibCost()*lp.getExNeibSmooth(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.setNonExclusive(
// false, // final boolean en_sticks, // treat planes with second eigenvalue below plEigenStick as "sticks"
true, // final boolean en_sticks, // allow merging with bad plates
// Just overwrite results of the previous method
lp.setExclusiveLinks(
st.planes, // final TilePlanes.PlaneData [][] planes,
lp.getExNeibCost(), // final double max_cost,
debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
lp.calcStarValueStrength(
true, // boolean set_start_planes,
clt_parameters.plStarOrtho, // orthoWeight, // final double orthoWeight,
clt_parameters.plStarDiag, // diagonalWeight, // final double diagonalWeight,
clt_parameters.plStarPwr, // starPwr, // final double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // starValPwr, //double starValPwr, // Raise value of each tile before averaging
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
0); // debugLevel);
// end of possible merge, can try smoothing again
// just to show them, not currently processed
/*
* will not work - hard-wired to use planes, not planes_mod!
st.resolveConflicts(
lp, // LinkPlanes lp,
clt_parameters.plMaxEigen,
......@@ -4241,19 +3772,114 @@ public class TileProcessor {
clt_parameters.plNewConfl, // boolean preferDisparity, // Allow more conflicts if overall cost is reduced
clt_parameters.plMaxChanges, // int maxChanges, // Maximal number of simultaneous connection changes around one tile (0 - any)
clt_parameters.plPreferDisparity,
1, // final int debugLevel)
debugLevel, // 1, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
*/
} // if (clt_parameters.plSplitApply)
/*
while (true) {
int num_added = 0;
if (clt_parameters.plFillSquares){
num_added += st.fillSquares();
}
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
if (clt_parameters.plCutCorners){
num_added += st.cutCorners();
}
if (debugLevel > -1) {
System.out.println("after plCutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
} // if (debugLevel > 100) {
*/
int max_num_tries = 20;
if (clt_parameters.plIterations > 0) {
st.planes_mod = lp.planesSmoothAndMerge(
st.planes, // final TilePlanes.PlaneData[][] planes, // planes will be modified
max_num_tries, // final int max_num_tries,
debugLevel); // final int debugLevel)
// currently results of below calcStarValueStrength() are not used, just to fill instances fields
lp.calcStarValueStrength(
true, // boolean set_start_planes,
clt_parameters.plStarOrtho, // orthoWeight, // final double orthoWeight,
clt_parameters.plStarDiag, // diagonalWeight, // final double diagonalWeight,
clt_parameters.plStarPwr, // starPwr, // final double starPwr, // Divide cost by number of connections to this power
clt_parameters.plStarWeightPwr,// starWeightPwr, // final double starWeightPwr, // Use this power of tile weight when calculating connection cost
clt_parameters.plWeightToDens, // weightToDens, // Balance weighted density against density. 0.0 - density, 1.0 - weighted density
clt_parameters.plStarValPwr, // starValPwr, //double starValPwr, // Raise value of each tile before averaging
2, // starSteps, // final int steps,
st.planes, // final TilePlanes.PlaneData [][] planes,
clt_parameters.plPreferDisparity, // preferDisparity, // final boolean preferDisparity)
0); // debugLevel);
} else { //if (clt_parameters.plIterations > 0)
st.planes_mod = st.planes; // just use the measured ones
}
// Add "missing" links with relaxed threshold
if (lp.getRelaxComplete() > 0.0) {
int total = 0;
int num_added = lp.addFinalLinks (
st.planes_mod, // final TilePlanes.PlaneData[][] planes,
lp.getRelaxComplete() * lp.getExNeibCost(), // final double threshold_sq,
lp.getRelaxComplete() * lp.getExNeibCost(), // final double threshold_corn,
lp.getRelaxComplete() * lp.getExNeibCost(), //final double threshold_hyp,
clt_parameters.plFillSquares, // final boolean en_sq,
clt_parameters.plCutCorners, // final boolean en_corn,
clt_parameters.plHypotenuse, // final boolean en_hyp,
1); // final int debugLevel)
total += num_added;
if (lp.getRelaxComplete2() > 0.0) {
num_added = lp.addFinalLinks (
st.planes_mod, // final TilePlanes.PlaneData[][] planes,
lp.getRelaxComplete2() * lp.getExNeibCost(), // final double threshold_sq,
lp.getRelaxComplete2() * lp.getExNeibCost(), // final double threshold_corn,
lp.getRelaxComplete2() * lp.getExNeibCost(), //final double threshold_hyp,
clt_parameters.plFillSquares, // final boolean en_sq,
clt_parameters.plCutCorners, // final boolean en_corn,
clt_parameters.plHypotenuse, // final boolean en_hyp,
1); // final int debugLevel)
total += num_added;
System.out.println("Total: added "+total+ " links between supertiles");
}
/*
while (true) {
int num_added = 0;
if (clt_parameters.plFillSquares){
num_added += lp.fillSquares(
st.planes_mod,
lp.getRelaxComplete() * lp.getExNeibCost(),
2, // debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
}
if (debugLevel > -1) {
System.out.println("after fillSquares() added "+num_added);
}
if (clt_parameters.plCutCorners){
num_added += lp.cutCorners(
st.planes_mod,
lp.getRelaxComplete() * lp.getExNeibCost(),
2, // debugLevel, // 0, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
}
if (debugLevel > -1) {
System.out.println("after cutCorners() added (cumulative) "+num_added);
}
if (num_added == 0) break;
}
*/
}
// filter out weak planes, create boolean array [per-supertile][per disparity plane]
boolean [][] selected_planes = st.selectPlanes(
clt_parameters.plDispNorm,
......@@ -4263,6 +3889,48 @@ public class TileProcessor {
st.getPlanesMod());
if (clt_parameters.show_planes){
showPlaneData(
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
st, // SuperTiles st,
split_planes); // TilePlanes.PlaneData[][][] split_planes
}
st.tileSurface.createTileShells (
clt_parameters.msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, // final double scale_projection,
clt_parameters.msFractUni, // final double fraction_uni,
st.planes_mod, // st.planes, // final TilePlanes.PlaneData [][] planes,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.tileSurface.InitTilesAssignment(
true,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
if (debugLevel > -10){
return; // just cut off the rest
}
createShells_old (
clt_parameters, // EyesisCorrectionParameters.CLTParameters clt_parameters,
st, // SuperTiles st,
selected_planes, // boolean [][] selected_planes,
geometryCorrection, // GeometryCorrection geometryCorrection,
debugLevel); // final int debugLevel)
}
public void showPlaneData(
EyesisCorrectionParameters.CLTParameters clt_parameters,
SuperTiles st,
TilePlanes.PlaneData[][][] split_planes
)
{
double [] split_lines = st.showSplitLines(
split_planes,
1, // final int debugLevel)
......@@ -4287,7 +3955,7 @@ public class TileProcessor {
0.0,
10.0);
double [][] plane_data_nonan = st.getShowPlanes(
(planes_mod != null) ? st.getPlanesMod():st.getPlanes(),
(st.planes_mod != null) ? st.getPlanesMod():st.getPlanes(),
clt_parameters.plMinStrength, // minWeight,
clt_parameters.plMaxEigen, // maxEigen,
clt_parameters.plDispNorm,
......@@ -4295,7 +3963,7 @@ public class TileProcessor {
0.0,
10.0);
double [][] plane_data_nan = st.getShowPlanes(
(planes_mod != null) ? st.getPlanesMod():st.getPlanes(),
(st.planes_mod != null) ? st.getPlanesMod():st.getPlanes(),
clt_parameters.plMinStrength, // minWeight,
clt_parameters.plMaxEigen, // maxEigen,
clt_parameters.plDispNorm,
......@@ -4343,43 +4011,20 @@ public class TileProcessor {
}
}
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
sdfa_instance.showArrays(plane_data, wh[0], wh[1], true, "plane_data");
/*
TileSurface tileSurface = new TileSurface(
st.tileProcessor.getTileSize(), // int tileSize,
st.tileProcessor.getSuperTileSize(), // int superTileSize,
st.tileProcessor.getTilesX(), // int tilesX,
st.tileProcessor.getTilesY(), // int tilesY,
geometryCorrection, // GeometryCorrection geometryCorrection,
st.tileProcessor.threadsMax); // int threadsMax);
st.setTileSurface(tileSurface);
*/
st.tileSurface.createTileShells (
clt_parameters.msUseSel, // final boolean use_sel,
clt_parameters.msDivideByArea, // final boolean divide_by_area,
clt_parameters.msScaleProj, // final double scale_projection,
clt_parameters.msFractUni, // final double fraction_uni,
st.planes_mod, // st.planes, // final TilePlanes.PlaneData [][] planes,
0, // -1, // debugLevel, // final int debugLevel)
clt_parameters.tileX,
clt_parameters.tileY);
st.tileSurface.InitTilesAssignment(
true,
dispStrength, // final double [][][] dispStrength,
tileSel, // final boolean [][] tileSel,
debugLevel); // final int debugLevel,
if (debugLevel > -10){
return; // just cut off the rest
}
//*******************************************************************************
public void createShells_old (
EyesisCorrectionParameters.CLTParameters clt_parameters,
SuperTiles st,
boolean [][] selected_planes,
GeometryCorrection geometryCorrection,
final int debugLevel)
{
//*******************************************************************************
// detect connected "shells" by running wave algorithm over multi-plane supertiles, create integer array (same structure as planes and selected_planes
// Each element [per supertile][per disparity plane] is either 0 (not used) or unique shell index (started from 1)
int [][] shells = st.createSupertileShells(
......@@ -4407,7 +4052,12 @@ public class TileProcessor {
// save surfaces with SuperTiles instance. They can be used to snap to for the per-tile disparity maps.
st.setSurfaces(surfaces);
plane_data = st.getShowShells(
if (clt_parameters.show_planes){
showDoubleFloatArrays sdfa_instance = new showDoubleFloatArrays(); // just for debugging?
int [] wh = st.getShowPlanesWidthHeight();
double [][] plane_data = st.getShowShells(
0, // int nlayer, // over multi-layer - do not render more than nlayer on top of each other
st.getPlanesMod(), // TilePlanes.PlaneData [][] planes,
st.getShellMap(), // shells, // int [][] shells,
......@@ -4532,11 +4182,8 @@ public class TileProcessor {
snap_img[6] = strength_masked;
sdfa_instance.showArrays(snap_img, tilesX, tilesY, true, "snap",snap_titles);
CLTPass3d scan_prev = clt_3d_passes.get(clt_3d_passes.size() -1); // get last one
boolean [] these_tiles = scan_prev.getSelected();
DisparityProcessor dp = new DisparityProcessor(this, clt_parameters.transform_size * geometryCorrection.getScaleDzDx());
boolean [] grown = these_tiles.clone();
growTiles(
......@@ -4578,11 +4225,9 @@ public class TileProcessor {
tilesY*clt_parameters.transform_size,
true,
"surf-neighbors");
}
}
}
......
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