Commit 508ee2cb authored by Andrey Filippov's avatar Andrey Filippov
Browse files

added new surface generation, working on resolving 'impossible triangle' conflicts

parent dfe9ae9d
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -2171,7 +2171,8 @@ public class EyesisCorrectionParameters {
  		public double     plMaxEigen           =   0.3;  // Maximal eigenvalue of a plane 
  		public boolean    plDbgMerge           =   true; // Combine 'other' plane with current
  		public double     plWorstWorsening     =   3.0;  // Worst case worsening after merge
  		public double     plOKMergeEigen       =   0.01; // If result of the merged planes is below, OK to bypass worst worsening
  		public double     plOKMergeEigen       =   0.03; // If result of the merged planes is below, OK to bypass worst worsening
  		public double     plMaxWorldSin2       =   0.1;  // Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable
  		public double     plWeakWorsening      =   1.0;  // Relax merge requirements for weaker planes
  		public boolean    plMutualOnly         =   true; // keep only mutual links, remove weakest if conflict
  		public boolean    plFillSquares        =   true; // Add diagonals to full squares
@@ -2217,12 +2218,13 @@ public class EyesisCorrectionParameters {
  		public double     msScaleProj          =   1.5;  // Scale projection of the plane ellipsoid 
  		public double     msFractUni           =   0.3;  // Spread this fraction of the ellipsoid weight among extended (double) supertile
  		
		public boolean    tsNoEdge             = true;   // Do not assigned tiles to thesurface edges (not having all 8 neighbors)
		public boolean    tsNoEdge             = true;   // Do not assign tiles to the surface edges (not having all 8 neighbors)
		public boolean    tsUseCenter          = true;   // Only assign outside of 8x8 center if no suitable alternative
  		public double     tsMaxDiff            = 0.3;    // Maximal disparity difference when assigning tiles
		public double     tsMinDiffOther       = 0.35;   // Minimal disparity difference to be considered as a competitor surface
		public double     tsMinStrength        = 0.05;   // Minimal tile correlation strength to be assigned
		public double     tsMaxStrength        = 10.0;   // Maximal tile correlation strength to be assigned
		public double     tsMinSurface         = 0.0001; // Minimal surface strength at the tile location
		public double     tsMinSurface         = 0.001;  // Minimal surface strength at the tile location
		public int        tsMoveDirs           = 3;      // Allowed tile disparity correction: 1 increase, 2 - decrease, 3 - both directions
		public double     tsSurfStrPow         = 0.0;    // Raise surface strengths ratio to this power when comparing candidates
		public double     tsAddStrength        = 0.01;   // Add to strengths when calculating pull of assigned tiles
@@ -2517,6 +2519,7 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"plDbgMerge",       this.plDbgMerge+"");
			properties.setProperty(prefix+"plWorstWorsening", this.plWorstWorsening +"");
			properties.setProperty(prefix+"plOKMergeEigen",   this.plOKMergeEigen +"");
			properties.setProperty(prefix+"plMaxWorldSin2",   this.plMaxWorldSin2 +"");
			properties.setProperty(prefix+"plWeakWorsening",  this.plWeakWorsening +"");
			properties.setProperty(prefix+"plMutualOnly",     this.plMutualOnly+"");
			properties.setProperty(prefix+"plFillSquares",    this.plFillSquares+"");
@@ -2557,6 +2560,7 @@ public class EyesisCorrectionParameters {
			properties.setProperty(prefix+"msFractUni",       this.msFractUni +"");

			properties.setProperty(prefix+"tsNoEdge",         this.tsNoEdge+"");
			properties.setProperty(prefix+"tsUseCenter",      this.tsUseCenter+"");
			properties.setProperty(prefix+"tsMaxDiff",        this.tsMaxDiff +"");
			properties.setProperty(prefix+"tsMinDiffOther",   this.tsMinDiffOther +"");
			properties.setProperty(prefix+"tsMinStrength",    this.tsMinStrength +"");
@@ -2842,6 +2846,7 @@ public class EyesisCorrectionParameters {
  			if (properties.getProperty(prefix+"plDbgMerge")!=null)        this.plDbgMerge=Boolean.parseBoolean(properties.getProperty(prefix+"plDbgMerge"));
  			if (properties.getProperty(prefix+"plWorstWorsening")!=null)  this.plWorstWorsening=Double.parseDouble(properties.getProperty(prefix+"plWorstWorsening"));
  			if (properties.getProperty(prefix+"plOKMergeEigen")!=null)    this.plOKMergeEigen=Double.parseDouble(properties.getProperty(prefix+"plOKMergeEigen"));
  			if (properties.getProperty(prefix+"plMaxWorldSin2")!=null)    this.plMaxWorldSin2=Double.parseDouble(properties.getProperty(prefix+"plMaxWorldSin2"));
  			if (properties.getProperty(prefix+"plWeakWorsening")!=null)   this.plWeakWorsening=Double.parseDouble(properties.getProperty(prefix+"plWeakWorsening"));
  			if (properties.getProperty(prefix+"plMutualOnly")!=null)      this.plMutualOnly=Boolean.parseBoolean(properties.getProperty(prefix+"plMutualOnly"));

@@ -2885,6 +2890,7 @@ public class EyesisCorrectionParameters {


  			if (properties.getProperty(prefix+"tsNoEdge")!=null)          this.tsNoEdge=Boolean.parseBoolean(properties.getProperty(prefix+"tsNoEdge"));
  			if (properties.getProperty(prefix+"tsUseCenter")!=null)       this.tsUseCenter=Boolean.parseBoolean(properties.getProperty(prefix+"tsUseCenter"));
  			if (properties.getProperty(prefix+"tsMaxDiff")!=null)         this.tsMaxDiff=Double.parseDouble(properties.getProperty(prefix+"tsMaxDiff"));
  			if (properties.getProperty(prefix+"tsMinDiffOther")!=null)    this.tsMinDiffOther=Double.parseDouble(properties.getProperty(prefix+"tsMinDiffOther"));
  			if (properties.getProperty(prefix+"tsMinStrength")!=null)     this.tsMinStrength=Double.parseDouble(properties.getProperty(prefix+"tsMinStrength"));
@@ -3196,6 +3202,7 @@ public class EyesisCorrectionParameters {
  			gd.addCheckbox    ("Combine 'other' plane with the current (unused)",                              this.plDbgMerge);
  			gd.addNumericField("Worst case worsening after merge",                                             this.plWorstWorsening,  6);
  			gd.addNumericField("If result of the merged planes is below, OK to bypass worst worsening",        this.plOKMergeEigen,  6);
  			gd.addNumericField("Maximal sine squared of the world angle between planes to merge. Set to >= 1.0 to disable", this.plMaxWorldSin2,  6);
  			gd.addNumericField("Relax merge requirements for weaker planes",                                   this.plWeakWorsening,  6);
  			gd.addCheckbox    ("Keep only mutual links, remove weakest if conflict",                           this.plMutualOnly);

@@ -3240,7 +3247,8 @@ public class EyesisCorrectionParameters {

  			gd.addMessage     ("--- Tiles assignment ---");
  			 
  			gd.addCheckbox    ("Do not assigned tiles to the surface edges (not having all 8 neighbors)",         this.tsNoEdge);
  			gd.addCheckbox    ("Do not assign tiles to the surface edges (not having all 8 neighbors)",           this.tsNoEdge);
  			gd.addCheckbox    ("Only assign outside of 8x8 center if no suitable alternative",                    this.tsUseCenter);
  			gd.addNumericField("Maximal disparity difference when assigning tiles",                               this.tsMaxDiff,  6);
  			gd.addNumericField("Minimal disparity difference to be considered as a competitor surface",           this.tsMinDiffOther,  6);
  			gd.addNumericField("Minimal tile correlation strength to be assigned",                                this.tsMinStrength,  6);
@@ -3534,6 +3542,7 @@ public class EyesisCorrectionParameters {
  			this.plDbgMerge=            gd.getNextBoolean();
  			this.plWorstWorsening=      gd.getNextNumber();
  			this.plOKMergeEigen=        gd.getNextNumber();
  			this.plMaxWorldSin2=        gd.getNextNumber();
  			this.plWeakWorsening=       gd.getNextNumber();
  			this.plMutualOnly=          gd.getNextBoolean();

@@ -3576,6 +3585,7 @@ public class EyesisCorrectionParameters {
  			this.msFractUni=            gd.getNextNumber();

  			this.tsNoEdge=              gd.getNextBoolean();
  			this.tsUseCenter=           gd.getNextBoolean();
  			this.tsMaxDiff=             gd.getNextNumber();
  			this.tsMinDiffOther=        gd.getNextNumber();
  			this.tsMinStrength=         gd.getNextNumber();
@@ -3626,7 +3636,8 @@ public class EyesisCorrectionParameters {
  		
  		public boolean showTsDialog() {
  			GenericDialog gd = new GenericDialog("Set CLT tiles to surfaces assignment parameters");
  			gd.addCheckbox    ("Do not assigned tiles to the surface edges (not having all 8 neighbors)",         this.tsNoEdge);
  			gd.addCheckbox    ("Do not assign tiles to the surface edges (not having all 8 neighbors)",           this.tsNoEdge);
  			gd.addCheckbox    ("Only assign outside of 8x8 center if no suitable alternative",                    this.tsUseCenter);
  			gd.addNumericField("Maximal disparity difference when assigning tiles",                               this.tsMaxDiff,  6);
  			gd.addNumericField("Minimal disparity difference to be considered as a competitor surface",           this.tsMinDiffOther,  6);
  			gd.addNumericField("Minimal tile correlation strength to be assigned",                                this.tsMinStrength,  6);
@@ -3659,6 +3670,7 @@ public class EyesisCorrectionParameters {
  			gd.showDialog();
  			if (gd.wasCanceled()) return false;
  			this.tsNoEdge=              gd.getNextBoolean();
  			this.tsUseCenter=           gd.getNextBoolean();
  			this.tsMaxDiff=             gd.getNextNumber();
  			this.tsMinDiffOther=        gd.getNextNumber();
  			this.tsMinStrength=         gd.getNextNumber();
+14 −10
Original line number Diff line number Diff line
@@ -5233,10 +5233,11 @@ public class QuadCLT {
        			  tp.clt_3d_passes.get(scanIndex), // CLTPass3d   scan,
        			  "X3D-"+scanIndex);
			  }
			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||(scanIndex == 49) || (scanIndex == 54);
			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||((scanIndex - next_pass) == 73);
			  generateClusterX3d(
					  x3dOutput,
					  texturePath,
					  "shape_id-"+(scanIndex - next_pass), // id
					  scan.bounds,
					  scan.selected,
					  scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
@@ -5286,7 +5287,8 @@ public class QuadCLT {
		  tp.showScan(
				  tp.clt_3d_passes.get(next_pass-1),   // CLTPass3d   scan,
				  "after_pass2-"+(next_pass-1)); //String title)
		  tp.thirdPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
//		  tp.thirdPassSetup( // prepare tile tasks for the second pass based on the previous one(s)
		  tp.thirdPassSetupSurf( // prepare tile tasks for the second pass based on the previous one(s)
				  clt_parameters,
				  clt_parameters.bgnd_range, // double            disparity_far, 
				  clt_parameters.grow_disp_max, // other_range, //double            disparity_near,   //
@@ -5323,11 +5325,6 @@ public class QuadCLT {
					  threadsMax,  // maximal number of threads to launch                         
					  updateStatus,
					  debugLevel);
/**			  
			  if ((scanIndex == 49) || (scanIndex == 54) ) tp.showScan(
					  scan, // tp.clt_3d_passes.get(scanIndex), // CLTPass3d   scan,
					  "MEASURED-"+scanIndex);
*/					  
		  }

		  // TEMPORARY EXIT
@@ -5353,13 +5350,14 @@ public class QuadCLT {

			  CLTPass3d scan = tp.clt_3d_passes.get(scanIndex);

/*			  
			  if ((scanIndex == 73) ) {
				  tp.showScan(
						  tp.clt_3d_passes.get(scanIndex), // CLTPass3d   scan,
						  "SELECTED-"+scanIndex);
			  }


*/

			  // TODO: use new updated disparity, for now just what was forced for the picture
			  double [] scan_disparity = new double [tilesX * tilesY];
@@ -5383,17 +5381,21 @@ public class QuadCLT {
					  scan_disparity[i] = sdw;
				  }
			  }

/*
			  if ((scanIndex == 73)) {
				  tp.showScan(
						  tp.clt_3d_passes.get(scanIndex), // CLTPass3d   scan,
						  "X3D-"+scanIndex);
			  }
			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||(scanIndex == 73);
*/			  
//			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||(scanIndex < 3);
			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||((scanIndex - next_pass) == 73);
			  
//			  boolean showTri = ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||(scanIndex == 49) || (scanIndex == 54);
			  generateClusterX3d(
					  x3dOutput,
					  texturePath,
					  "shape_id-"+(scanIndex - next_pass), // id
					  scan.bounds,
					  scan.selected,
					  scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
@@ -5429,6 +5431,7 @@ public class QuadCLT {
	  public void generateClusterX3d(
			  X3dOutput  x3dOutput,
			  String     texturePath,
			  String     id,
			  Rectangle  bounds,
			  boolean [] selected,
			  double []  disparity,
@@ -5486,6 +5489,7 @@ public class QuadCLT {

		  x3dOutput.addCluster(
				  texturePath,
				  id,
				  texCoord,
				  worldXYZ,
				  triangles);
+398 −65

File changed.

Preview size limit exceeded, changes collapsed.

+188 −0
Original line number Diff line number Diff line
/**
 **
 ** SurfaceData - represents rectangualar area with per-tile disparity
 **
 ** Copyright (C) 2017 Elphel, Inc.
 **
 ** -----------------------------------------------------------------------------**
 **  
 **  SurfaceData.java is free software: you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License as published by
 **  the Free Software Foundation, either version 3 of the License, or
 **  (at your option) any later version.
 **
 **  This program is distributed in the hope that it will be useful,
 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 **  GNU General Public License for more details.
 **
 **  You should have received a copy of the GNU General Public License
 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ** -----------------------------------------------------------------------------**
 **
 */

public class SurfaceData {
	private int []     window;
	private int        tilesX;
	private int        tilesY;
	private double []  disparity;
	private boolean [] selected; // should include border
	private boolean [] border;
	private int []     sizes;
	private int []     clusters;

	public  SurfaceData(int [] tilesWH, int [] window)
	{
		this.tilesX = tilesWH[0];
		this.tilesY = tilesWH[1];
		this.window = window;
		int len = window[2]*window[3];
		this.disparity = new double [len];
		this.selected =  new boolean [len];
		this.border =    new boolean [len];
	}
	public SurfaceData(int tilesX, int tilesY, int x0, int y0, int width,int height)
	{
		this.tilesX = tilesX;
		this.tilesY = tilesY;
		int [] window = {x0,y0,width,height}; 
		this.window = window;
		int len = window[2]*window[3];
		this.disparity = new double [len];
		this.selected =  new boolean [len];
		this.border =    new boolean [len];
	}
	
	public void setCluster(int [] clusters)
	{
		this.clusters = clusters;
	}
	public int []  getCluster()
	{
		return this.clusters;
	}
	
	public int getWidth()
	{
		return window[2];
	}
	public int getHeight()
	{
		return window[3];
	}
	public int getLeft()
	{
		return window[0];
	}
	public int getTop()
	{
		return window[1];
	}
	public int [] getWindow()
	{
		return window;
	}
	
	
	public void setDisparity(double [] disparity)
	{
		this.disparity = disparity;
	}
	public void setDisparity(int indx, double disparity)
	{
		this.disparity[indx] = disparity;
	}
	public double [] getDisparity()
	{
		return this.disparity;
	}
	public double getDisparity(int indx)
	{
		return this.disparity[indx];
	}

	
	public void setSelected(boolean [] selected)
	{
		this.selected = selected;
		this.sizes = null;
	}
	public void setSelected(int indx, boolean selected)
	{
		this.selected[indx] = selected;
		this.sizes = null;
	}
	public boolean [] getSelected()
	{
		return this.selected;
	}
	public boolean getSelected(int indx)
	{
		return this.selected[indx];
	}

	
	public void setBorder(boolean [] border)
	{
		this.border = border;
		this.sizes = null;
	}
	public void setBorder(int indx, boolean border)
	{
		this.border[indx] = border;
		this.sizes = null;
	}
	public boolean [] getBorder()
	{
		return this.border;
	}
	public boolean getBorder(int indx)
	{
		return this.border[indx];
	}
	
	int getImageIndex(int indx)
	{
		int x = (indx % window[2]) + window[0];
		int y = (indx / window[2]) + window[1];
		if ((y <0) || (x < 0) || (y >= tilesY) || (x >= tilesX)){
			return -1;
		}
		return  y * tilesX + x;
	}
	
	public int getSize(
			boolean include_border)
	{
		if (this.sizes == null){
			int [] sizes = {0,0};
			this.sizes = sizes;
			for (int i = 0; i < selected.length; i++){
				if (selected[i]) {
					sizes[1]++;
					if (!border[i]){
						sizes[0]++;
					}
				}
			}
		}
		return this.sizes[include_border ? 1 : 0];

	}
	public double [] getDisparityNaN(
			boolean include_border)
	{
		double [] data = new double [tilesX*tilesY];
		for (int i = 0; i < data.length; i++){
			data[i] = Double.NaN;
		}
		for (int i = 0; i < disparity.length; i++){
			if (selected[i] && (include_border || !border[i])){
				data[getImageIndex(i)] = disparity[i];
			}
		}
		return data;
	}

}
+237 −44

File changed.

Preview size limit exceeded, changes collapsed.

Loading