Commit f7d1b998 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

Started debugging 2-level triangulation

parent 0ef14ecf
Loading
Loading
Loading
Loading
+15 −176
Original line number Diff line number Diff line
@@ -12037,7 +12037,10 @@ public class QuadCLTCPU {
					  boolean showTri = false; // ((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||((scanIndex - next_pass) == 73);
					  try {
						  generateClusterX3d(
						  TriMesh.generateClusterX3d(
								  false,     //   boolean         full_texture, // true - full size image, false - bounds only
								  0,         //   int             subdivide_mesh, // 0,1 - full tiles only, 2 - 2x2 pixels, 4 - 2x2 pixels
//								  null,      //   boolean []      alpha,     // boolean alpha - true - opaque, false - transparent. Full/bounds
								  x3dOutput,
								  wfOutput,  // output WSavefront if not null
								  tri_meshes, // ArrayList<TriMesh> tri_meshes,
@@ -12048,6 +12051,9 @@ public class QuadCLTCPU {
								  bgndScan.getSelected(), // selected,
								  scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
								  clt_parameters.transform_size,
								  tp.getTilesX(), // int             tilesX,
								  tp.getTilesY(), // int             tilesY,
								  getGeometryCorrection(), // GeometryCorrection geometryCorrection,
								  clt_parameters.correct_distortions, // requires backdrop image to be corrected also
								  showTri, // (scanIndex < next_pass + 1) && clt_parameters.show_triangles,
								  infinity_disparity,  // 0.3
@@ -12136,7 +12142,10 @@ public class QuadCLTCPU {
			  }
			  boolean showTri = !batch_mode && (debugLevel > -1) && (((scanIndex < next_pass + 1) && clt_parameters.show_triangles) ||((scanIndex - next_pass) == 73));
			  try {
				  generateClusterX3d(
				  TriMesh.generateClusterX3d(
						  false, //   boolean         full_texture, // true - full size image, false - bounds only
						  0, //   int             subdivide_mesh, // 0,1 - full tiles only, 2 - 2x2 pixels, 4 - 2x2 pixels
//						  null, //   boolean []      alpha,     // boolean alpha - true - opaque, false - transparent. Full/bounds
						  x3dOutput,
						  wfOutput,  // output WSavefront if not null
						  tri_meshes, // ArrayList<TriMesh> tri_meshes,
@@ -12147,6 +12156,9 @@ public class QuadCLTCPU {
						  scan.getSelected(),
						  scan_disparity, // scan.disparity_map[ImageDtt.DISPARITY_INDEX_CM],
						  clt_parameters.transform_size,
						  tp.getTilesX(), // int             tilesX,
						  tp.getTilesY(), // int             tilesY,
						  getGeometryCorrection(), // GeometryCorrection geometryCorrection,
						  clt_parameters.correct_distortions, // requires backdrop image to be corrected also
						  showTri, // (scanIndex < next_pass + 1) && clt_parameters.show_triangles,
						  // FIXME: make a separate parameter:
@@ -12187,179 +12199,6 @@ public class QuadCLTCPU {
	  public void generateClusterX3d( // USED in lwir
			  X3dOutput       x3dOutput, // output x3d if not null
			  WavefrontExport wfOutput,  // output WSavefront if not null
			  ArrayList<TriMesh> tri_meshes,
			  String          texturePath,
			  String          id,
			  String          class_name,
			  Rectangle       bounds,
			  boolean []      selected,
			  double []       disparity, // if null, will use min_disparity
			  int             tile_size,
			  boolean         correctDistortions, // requires backdrop image to be corrected also
			  boolean         show_triangles,
			  double          min_disparity,
			  double          max_disparity,
			  double          maxDispTriangle, // relative <=0 - do not use
			  double          maxZtoXY,        // 10.0. <=0 - do not use
			  double          maxZ,            // far clip (0 - do not clip). Negative - limit by max
			  boolean         limitZ,
			  double [][]     dbg_disp_tri_slice,
			  int             debug_level
			  ) throws IOException
	  {
//		  int debug_level = 1;
		  if (bounds == null) {
			  return; // not used in lwir
		  }
		  int [][] indices =  tp.getCoordIndices( // starting with 0, -1 - not selected // updated 09.18.2022
				  bounds, 
				  selected); 
		  double [][] texCoord = TileProcessor.getTexCoords( // get texture coordinates for indices
				  indices);
		  double [][] worldXYZ = tp.getCoords( // get world XYZ in meters for indices // updated 09.18.2022
				  disparity,
				  min_disparity,
				  max_disparity,
				  bounds,
				  indices,
				  tile_size,
				  correctDistortions, // requires backdrop image to be corrected also
				  this.geometryCorrection);
          double [] indexedDisparity = tp.getIndexedDisparities( // get disparity for each index // updated 09.18.2022
							disparity,
							min_disparity,
							max_disparity,
							bounds,
							indices,
							tile_size);
		  int [][] triangles = 	TileProcessor.triangulateCluster(
				  indices);
//		  double maxZtoXY = 10.0; // maximal delta_z to sqrt(dx^23 + dy^2)
		  int num_removed = 0;
		  if (maxDispTriangle > 0.0) {
			  int pre_num = triangles.length;
			  triangles = 	TileProcessor.filterTriangles( // remove crazy triangles with large disparity difference
					  triangles,
					  indexedDisparity, // disparities per vertex index
					  maxDispTriangle,  // maximal disparity difference in a triangle
					  debug_level + 0); // 	int       debug_level);
			  if (triangles.length < pre_num) {
				  num_removed += pre_num - triangles.length;
				  if (debug_level > 0) {
					  System.out.println("filterTriangles() removed "+ (pre_num - triangles.length)+" triangles");
				  }
			  }
			  
		  }
		  if ((maxZ != 0.0) && limitZ) {
			  for (int i = 0; i < worldXYZ.length; i++) {
				  if (worldXYZ[i][2] < -maxZ) {
					  double k = -maxZ/worldXYZ[i][2];
					  worldXYZ[i][0] *= k;
					  worldXYZ[i][1] *= k;
					  worldXYZ[i][2] *= k;
				  }
			  }
		  }
		  if ((maxZtoXY > 0.0) || ((maxZ != 0) && !limitZ) ) {
			  int pre_num = triangles.length;
			  triangles = 	TileProcessor.filterTrianglesWorld(
					  triangles,
					  worldXYZ,  // world per vertex index
					  maxZtoXY,
					  maxZ);
			  if (triangles.length < pre_num) {
				  num_removed += pre_num - triangles.length;
				  if (debug_level > 0) {
					  System.out.println("filterTrianglesWorld() removed "+ (pre_num - triangles.length)+" triangles");
				  }
			  }
		  }
		  if (triangles.length == 0) {
			  if (debug_level > 0) {
				  System.out.println("generateClusterX3d() no triangles left in a cluster");
			  }
			  return; // all triangles removed
			  
		  }
		  if (num_removed > 0) { 
			  int [] re_index = TileProcessor.reIndex( // Move to TriMesh?
					  indices, // will be modified if needed (if some indices are removed
					  triangles);
			  if (re_index != null) {// need to update other arrays: texCoord, worldXYZ. indexedDisparity[] will not be used
				  int num_indices_old = worldXYZ.length;
				  int [] inv_index = new int [num_indices_old];
				  Arrays.fill(inv_index,-1); // just to get an error
				  for (int i = 0; i < re_index.length; i++) {
					  inv_index[re_index[i]] = i;
				  }
				  double [][]  texCoord_new = new double [re_index.length][];
				  double [][]  worldXYZ_new = new double [re_index.length][];
				  for (int i = 0; i < re_index.length; i++) {
					  texCoord_new[i] = texCoord[re_index[i]];
					  worldXYZ_new[i] = worldXYZ[re_index[i]];
				  }
				  texCoord = texCoord_new;
				  worldXYZ = worldXYZ_new;
				  for (int i = 0; i < triangles.length; i++) {
					  for (int j=0; j < triangles[i].length; j++) {
						  triangles[i][j] = inv_index[triangles[i][j]];
					  }
				  }
			  }
			  if (debug_level > 0) {
				  show_triangles = true; // show after removed
			  }
		  }
		  if (show_triangles || (dbg_disp_tri_slice != null)) {
			  double [] ddisp = (disparity == null)?(new double[1]):disparity;
			  if (disparity == null) {
				  ddisp[0] = min_disparity;
			  }
			  tp.testTriangles(
					  (show_triangles? texturePath: null),
					  bounds,
					  selected,
					  ddisp, // disparity, // if disparity.length == 1 - use for all
					  tile_size,
					  indices,
					  triangles,
					  dbg_disp_tri_slice); // double [][] debug_triangles);
		  }
		  if (x3dOutput != null) {
		  x3dOutput.addCluster(
				  texturePath,
				  id,
				  class_name,
				  texCoord,
				  worldXYZ,
				  triangles);
		  }
		  if (wfOutput != null) {
			  wfOutput.addCluster(
				  texturePath,
				  id,
//				  class_name,
				  texCoord,
				  worldXYZ,
				  triangles);
		  }
		  if (tri_meshes != null) {
			  tri_meshes.add(new TriMesh(
					  texturePath, // String texture_image,
					  worldXYZ,    // double [][] worldXYZ,
					  texCoord,    // double [][] texCoord,
					  triangles)); // 								int [][] triangles					  
		  }
	  }
//	  public ImagePlus getBackgroundImage( // USED in lwir
	  public boolean[] getBackgroundImageMasks( // USED in lwir
@@ -14690,7 +14529,7 @@ public class QuadCLTCPU {
					  true,  // smart,
					  true);  //newAllowed, // save
			  double ts = Double.parseDouble(image_name.replace('_', '.'));
			  (new X3dOutput()).generateKML(
			  X3dOutput.generateKML(
					  kml_copy_dir+ Prefs.getFileSeparator()+image_name+".kml", // String path,
					  false, // boolean overwrite,
					  "", // String icon_path, //<href>x3d/1487451413_967079.x3d</href> ?
+196 −55

File changed.

Preview size limit exceeded, changes collapsed.

+4 −2
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ public class TileNeibs{
	final public static int DIR_LEFT =    2; // Right
	final public static int DIR_DOWN =    4; // Down
	final public static int DIR_RIGHT =   6; // Left
	final public static int DIRS =        8; // total dirs
	final public static int [][] DIR_XY = {{0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,1}, {-1,0}, {-1,-1}};
	final public static int DIRS =        DIR_XY.length; //8; // total dirs
	
	
	public static int reverseDir(int dir) {
		if ((dir < 0) || (dir >= DIRS)) {
+2 −446
Original line number Diff line number Diff line
@@ -8619,167 +8619,9 @@ ImageDtt.startAndJoin(threads);
		return rslt;
	}

	public int [][] getCoordIndices( // starting with 0, -1 - not selected
			Rectangle bounds,
			boolean [] selected
			)
	{
		int [][] indices = new int [bounds.height][bounds.width];
		int indx = 0;
		if (selected.length > (bounds.height * bounds.width)) { // old version - selected is full size
			for (int y = 0; y < bounds.height; y++) {
				for (int x = 0; x < bounds.width; x++){
					if (selected[this.tilesX * (bounds.y + y) + (bounds.x + x)]){
						indices[y][x] = indx++;
					} else {
						indices[y][x] = -1;
					}
				}
			}
		} else { // 09.18.2022
			for (int y = 0; y < bounds.height; y++) {
				for (int x = 0; x < bounds.width; x++){
					if (selected[bounds.width * y + x]){
						indices[y][x] = indx++;
					} else {
						indices[y][x] = -1;
					}
				}
			}
		}
		return indices;
	}

	public static double [][] getTexCoords( // get texture coordinates for indices
			int [][] indices)
	{
		int maxIndex = -1;
		int height = indices.length;
		int width = indices[0].length;
		outer_label:{
			for (int y = height - 1 ; y >= 0; y--) {
				for (int x = width - 1; x >= 0; x--){
					if (indices[y][x] >=0){
						maxIndex = indices[y][x];
						break outer_label;
					}
				}
			}
		}
		double [][] textureCoordinate = new double [maxIndex+1][2];
		int indx = 0;
		for (int y = 0;  indx <= maxIndex; y++) {
			for (int x = 0; (x < width) && (indx <= maxIndex); x++){
				if (indices[y][x] >=0){
					textureCoordinate[indx][0] = (x + 0.5)/width;
					textureCoordinate[indx][1] = (height - y - 0.5) / height; // y is up
					indx ++;
				}
			}
		}
		return textureCoordinate;
	}
	public double [] getIndexedDisparities( // get disparity for each index
			double [] disparity,
			double min_disparity,
			double max_disparity,
			Rectangle bounds,
			int [][]  indices,
			int       tile_size)
	{
		//		  int height = indices.length;
		int width = indices[0].length;
		int maxIndex = getMaxIndex(indices);
		double [] indexedDisparity = new double [maxIndex+1];
		int indx = 0;
		if (disparity.length > (bounds.height * bounds.width)) { // old version - selected is full size
			for (int y = 0;  indx <= maxIndex; y++) {
				for (int x = 0; (x < width) && (indx <= maxIndex); x++){
					if (indices[y][x] >=0){
						// center coordinates for 8*8 tile is [3.5,3.5]
						double disp = (disparity == null)? min_disparity:( disparity[(bounds.y + y) * tilesX + (bounds.x + x)]);
						if      (disp < min_disparity) disp = min_disparity;
						else if (disp > max_disparity) disp = max_disparity;
						indexedDisparity[indx] =disp;
						indx ++;
					}
				}
			} 
		} else { // 09.18.2022
			for (int y = 0;  indx <= maxIndex; y++) {
				for (int x = 0; (x < width) && (indx <= maxIndex); x++){
					if (indices[y][x] >=0){
						// center coordinates for 8*8 tile is [3.5,3.5]
						double disp = (disparity == null)? min_disparity:( disparity[bounds.width *y + x]);
						if      (disp < min_disparity) disp = min_disparity;
						else if (disp > max_disparity) disp = max_disparity;
						indexedDisparity[indx] =disp;
						indx ++;
					}
				}
			} 
		}
		return indexedDisparity;
	}
	
	// preparing to move to TriMesh

	public double [][] getCoords( // get world XYZ in meters for indices
			double [] disparity, // null - use min_disparity
			double min_disparity,
			double max_disparity,
			Rectangle bounds,
			int [][]  indices,
			int       tile_size,
			boolean   correctDistortions, // requires backdrop image to be corrected also
			GeometryCorrection geometryCorrection)
	{
		//		  int height = indices.length;
		int width = indices[0].length;
		int maxIndex = getMaxIndex(indices);
		double [][] coordinate = new double [maxIndex+1][];
		int indx = 0;
		if (disparity.length > (bounds.height * bounds.width)) { // old version - selected is full size
			for (int y = 0;  indx <= maxIndex; y++) {
				for (int x = 0; (x < width) && (indx <= maxIndex); x++){
					if (indices[y][x] >=0){
						// center coordinates for 8*8 tile is [3.5,3.5]
						double px = (bounds.x + x + 0.5) * tile_size - 0.5;
						double py = (bounds.y + y + 0.5) * tile_size - 0.5;
						double disp = (disparity == null)? min_disparity:( disparity[(bounds.y + y) * tilesX + (bounds.x + x)]);
						if      (disp < min_disparity) disp = min_disparity;
						else if (disp > max_disparity) disp = max_disparity;
						coordinate[indx] = geometryCorrection.getWorldCoordinates(
								px,
								py,
								disp,
								correctDistortions);
						indx ++;
					}
				}
			}
		} else { // 09.18.2022
			for (int y = 0;  indx <= maxIndex; y++) {
				for (int x = 0; (x < width) && (indx <= maxIndex); x++){
					if (indices[y][x] >=0){
						// center coordinates for 8*8 tile is [3.5,3.5]
						double px = (bounds.x + x + 0.5) * tile_size - 0.5;
						double py = (bounds.y + y + 0.5) * tile_size - 0.5;
						double disp = (disparity == null)? min_disparity:( disparity[bounds.width * y + x]);
						if      (disp < min_disparity) disp = min_disparity;
						else if (disp > max_disparity) disp = max_disparity;
						coordinate[indx] = geometryCorrection.getWorldCoordinates(
								px,
								py,
								disp,
								correctDistortions);
						indx ++;
					}
				}
			}

		}
		return coordinate;
	}

	static int getMaxIndex(int [][] indices)
	{
@@ -8795,292 +8637,6 @@ ImageDtt.startAndJoin(threads);
		return -1;
	}

	public static int [][] filterTriangles(
			int  [][] triangles,
			double [] disparity, // disparities per vertex index
			double    maxDispDiff, // maximal relative disparity difference in a triangle
			int       debug_level)
	{
		final double min_avg = 3.0; // 0.5; // minimal average disparity to normalize triangle
		class Triangle {
			int [] points = new int [3];
			Triangle (int i1, int i2, int i3){
				points[0] = i1;
				points[1] = i2;
				points[2] = i3;
			}
		}
		ArrayList<Triangle> triList = new ArrayList<Triangle>();
		for (int i = 0; i < triangles.length; i++){
			double disp_avg = (disparity[triangles[i][0]] + disparity[triangles[i][1]]+ disparity[triangles[i][2]])/3.0; // fixed 09.18.2022!
			if (disp_avg < min_avg) disp_avg = min_avg;
			loop:{
				for (int j = 0; j < 3; j++){
					int j1 = (j + 1) % 3;
					if (Math.abs(disparity[triangles[i][j]] - disparity[triangles[i][j1]]) > (disp_avg* maxDispDiff)) {
						if (debug_level > 1) {
							System.out.println("removed triangle "+i+": "+
									disparity[triangles[i][0]]+". "+disparity[triangles[i][1]]+". "+disparity[triangles[i][2]]+
									". Avg = "+disp_avg);
						}
						break loop;
					}
				}
				triList.add(new Triangle(
						triangles[i][0],
						triangles[i][1],
						triangles[i][2]));
			}
		}
		int [][] filteredTriangles = new int [triList.size()][3];
		for (int i = 0; i < filteredTriangles.length; i++){
			filteredTriangles[i] = triList.get(i).points;
		}
		return filteredTriangles;
	}

	public static int [][] filterTrianglesWorld(
			int  [][] triangles,
			double [][] worldXYZ,  // world per vertex index
			double      maxZtoXY,
			double maxZ) 
	{
		final double maxZtoXY2 = maxZtoXY * maxZtoXY;
		class Triangle {
			int [] points = new int [3];
			Triangle (int i1, int i2, int i3){
				points[0] = i1;
				points[1] = i2;
				points[2] = i3;
			}
		}
		ArrayList<Triangle> triList = new ArrayList<Triangle>();
		for (int i = 0; i < triangles.length; i++){
			double [][] min_max = new double[3][2];
			boolean not_too_far = true;
			for (int di = 0; di < 3; di++) {
				min_max[di][0] = worldXYZ[triangles[i][0]][di];
				min_max[di][1] = min_max[di][0]; // both min and max to the same vertex 0
			}
			if (maxZ != 0) {
				not_too_far &=  worldXYZ[triangles[i][0]][2] > -maxZ; 
			}
			for (int vi = 1; vi < 3; vi++) {
				for (int di = 0; di < 3; di++) {
					min_max[di][0] = Math.min(min_max[di][0], worldXYZ[triangles[i][vi]][di]);
					min_max[di][1] = Math.max(min_max[di][1], worldXYZ[triangles[i][vi]][di]);
				}
			}
			double dx = min_max[0][1]-min_max[0][0];
			double dy = min_max[1][1]-min_max[1][0];
			double dz = min_max[2][1]-min_max[2][0];
			double ratio2 = dz*dz/(dx*dx+dy*dy + 0.001);
			if (not_too_far && ((maxZtoXY == 0) || (ratio2 < maxZtoXY2))) {
				triList.add(new Triangle(
						triangles[i][0],
						triangles[i][1],
						triangles[i][2]));
			}
		}
		int [][] filteredTriangles = new int [triList.size()][3];
		for (int i = 0; i < filteredTriangles.length; i++){
			filteredTriangles[i] = triList.get(i).points;
		}
		return filteredTriangles;
	}

	public static int [] reIndex(
			int [][]  indices,
			int [][] triangles) {
		int last_index = -1;
		for (int i = 0; i < indices.length; i++) {
			for (int j = 0; j < indices[i].length; j++) {
				if (indices[i][j] > last_index) {
					last_index = indices[i][j]; 
				}
			}
		}
		boolean [] used_indices = new boolean[last_index+1];
		for (int i = 0; i < triangles.length; i++) {
			for (int j = 0; j < triangles[i].length; j++) { // always 3
				used_indices[triangles[i][j]] = true;
			}
		}
		int new_len = 0;
		for (int i = 0; i < used_indices.length; i++) if (used_indices[i]) {
			new_len++;
		}
		if (new_len == used_indices.length) {
			return null; // no re-indexing is needed
		}
		int [] re_index = new int [new_len];
		int indx = 0;
		for (int i = 0; i < indices.length; i++) {
			for (int j = 0; j < indices[i].length; j++) {
				int old_index=indices[i][j];
				if (old_index >= 0) {
					if (used_indices[old_index]) { // keep
						re_index[indx] = old_index;
						indices[i][j] = indx++;
					} else {
						indices[i][j] = -1;
					}
				}
			}
		}
		return re_index;
	}
	
	

	public static int [][] triangulateCluster(
			int [][]  indices)
	{
		int height = indices.length;
		int width = indices[0].length;
		class Triangle {
			int [] points = new int [3];
			Triangle (int i1, int i2, int i3){
				points[0] = i1;
				points[1] = i2;
				points[2] = i3;
			}
		}
		ArrayList<Triangle> triList = new ArrayList<Triangle>();
		for (int y = 0;  y < (height - 1); y++){
			for (int x = 0; x < width; x++){
				if (indices[y][x] >= 0){
					if ((x > 0) && (indices[y + 1][x - 1] >= 0) && (indices[y + 1][x] >= 0)){
						triList.add(new Triangle(
								indices[y][x],
								indices[y + 1][x],
								indices[y + 1][x - 1]));
					}
					if (x < (width - 1)) {
						if (indices[y + 1][x] >= 0){
							if (indices[y][x + 1] >= 0){
								triList.add(new Triangle(
										indices[y][x],
										indices[y][x + 1],
										indices[y + 1][x]));

							} else if (indices[y + 1][x + 1] >= 0){
								triList.add(new Triangle(
										indices[y][x],
										indices[y + 1][x + 1],
										indices[y + 1][x]));

							}
						} else if ((indices[y][x + 1] >= 0) && (indices[y + 1][x + 1] >= 0)) {
							triList.add(new Triangle(
									indices[y][x],
									indices[y][x + 1],
									indices[y + 1][x + 1]));
						}
					}
				}
			}
		}
		int [][] triangles = new int [triList.size()][3];
		for (int i = 0; i < triangles.length; i++){
			triangles[i] = triList.get(i).points;
		}
		return triangles;
	}

	static int iSign (int a) {return (a > 0) ? 1 : ((a < 0)? -1 : 0);}

	public void testTriangles(
			String     texturePath, // if not null - will show
			Rectangle  bounds,
			boolean [] selected,
			double []  disparity,
			int        tile_size,
			int [][]  indices,
			int [][]  triangles,
			double [][] debug_triangles) // if not null - should be [2][width* height], will mark disparity and triangles
	{
		String [] titles = {"disparity","triangles"};
		double [][] dbg_img = new double [titles.length][tilesX*tilesY*tile_size*tile_size];
		Arrays.fill(dbg_img[0], Double.NaN);
		if (selected.length > (bounds.height * bounds.width)) { // old version - selected is full size
			for (int i = 0; i < selected.length; i++ ){
				double d = selected[i]? ((disparity.length >1) ? disparity[i] : disparity[0]):Double.NaN;
				int y = i / tilesX;
				int x = i % tilesX;
				for (int dy = 0; dy <tile_size; dy ++){
					for (int dx = 0; dx <tile_size; dx ++){
						dbg_img[0][(y * tile_size + dy)*(tile_size*tilesX) + (x * tile_size + dx)] = d;
					}
				}
			}
		} else { // 09.18.2022
			for (int i = 0; i < selected.length; i++ ){
				double d = selected[i]? ((disparity.length > 1) ? disparity[i] : disparity[0]):Double.NaN;
				int y = i / bounds.width + bounds.y;
				int x = i % bounds.width + bounds.x;
				for (int dy = 0; dy <tile_size; dy ++){
					for (int dx = 0; dx <tile_size; dx ++){
						dbg_img[0][(y * tile_size + dy)*(tile_size*tilesX) + (x * tile_size + dx)] = d;
					}
				}
			}
		}
		int maxIndex = getMaxIndex(indices);
		int [][] pxy = new int [maxIndex+1][2];
		int height = indices.length;
		int width = indices[0].length;

		for (int y = 0; y < height; y++){
			for (int x = 0; x < width; x++){
				if (indices[y][x] >= 0){
					pxy[indices[y][x]][0] =  (bounds.x + x)*tile_size + (tile_size/2);
					pxy[indices[y][x]][1] =  (bounds.y + y)*tile_size + (tile_size/2);
				}
			}
		}

		for (int i = 0; i < triangles.length; i++ ){
			for (int side = 0; side < triangles[i].length; side++){
				int [] pntIndx = {
						triangles[i][side],
						(side == (triangles[i].length -1)? triangles[i][0]:triangles[i][side+1])};
				int dx = iSign(pxy[pntIndx[1]][0] - pxy[pntIndx[0]][0]);
				int dy = iSign(pxy[pntIndx[1]][1] - pxy[pntIndx[0]][1]);
				for (int j = 0; j < tile_size; j++){
					int x = pxy[pntIndx[0]][0] + dx*j;
					int y = pxy[pntIndx[0]][1] + dy*j;
					dbg_img[1][y * tile_size * tilesX + x] = 10.0; //1711748
				}
			}
		}
		if (texturePath != null) {
			ShowDoubleFloatArrays.showArrays(
					dbg_img,
					tilesX * tile_size,
					tilesY * tile_size,
					true,
					"triangles-"+texturePath,
					titles);
		}
		if (debug_triangles != null) {
			int indx_tri = (debug_triangles.length>1) ? 1 : 0;
			for (int i = 0; i < debug_triangles[indx_tri].length; i++) {
				if (dbg_img[1][i] > 0) {
					debug_triangles[indx_tri][i] = dbg_img[1][i]; // 10.0 to have the same scale as disparity
				}
			}
			if (indx_tri > 0) {
				for (int i = 0; i < debug_triangles[indx_tri].length; i++) {
					if (!Double.isNaN(dbg_img[0][i])) {
						debug_triangles[0][i] = dbg_img[0][i]; // disparity if not NaN
					}
				}
			}
		}
	}

	
	public static double [] fillNaNs(
			final double [] data,
			int       width,
+1877 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading