Commit 164444fe authored by Andrey Filippov's avatar Andrey Filippov

still working on textures

parent 433c7f7f
...@@ -8044,7 +8044,7 @@ public class OpticalFlow { ...@@ -8044,7 +8044,7 @@ public class OpticalFlow {
payload_blue_sky = new double[tiles]; payload_blue_sky = new double[tiles];
Arrays.fill(payload_blue_sky,Double.NaN); Arrays.fill(payload_blue_sky,Double.NaN);
} }
combo_dsn_final[COMBO_DSN_INDX_BLUE_SKY] = payload_blue_sky;
// restore modified parameters // restore modified parameters
clt_parameters.img_dtt.bimax_combine_mode = save_bimax_combine_mode; clt_parameters.img_dtt.bimax_combine_mode = save_bimax_combine_mode;
......
...@@ -1788,7 +1788,9 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -1788,7 +1788,9 @@ public class QuadCLT extends QuadCLTCPU {
final boolean filter_bg, // remove bg tiles (possibly occluded) final boolean filter_bg, // remove bg tiles (possibly occluded)
final double max_distortion, // maximal neighbor tiles offset as a fraction of tile size (8) final double max_distortion, // maximal neighbor tiles offset as a fraction of tile size (8)
final int [] cluster_index, // [tilesX*tilesY] final int [] cluster_index, // [tilesX*tilesY]
final boolean [] border, // border tiles final boolean [] border, // border tiles for clusters?
final int discard_frame_edges, // do not use tiles that have pixels closer to the frame margins
final int keep_frame_tiles, // do not discard pixels for border tiles in reference frame
final boolean keep_channels, final boolean keep_channels,
final int debugLevel){ final int debugLevel){
// FIXME: Move to clt_parameters; // FIXME: Move to clt_parameters;
...@@ -1990,8 +1992,12 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -1990,8 +1992,12 @@ public class QuadCLT extends QuadCLTCPU {
final int tilesX = scene.getTileProcessor().getTilesX(); final int tilesX = scene.getTileProcessor().getTilesX();
final int tilesY = scene.getTileProcessor().getTilesY(); final int tilesY = scene.getTileProcessor().getTilesY();
final int tiles = tilesX*tilesY; final int tiles = tilesX*tilesY;
int tile_size = scene.getTileProcessor().getTileSize(); final int tile_size = scene.getTileProcessor().getTileSize();
int tile_len = tile_size*tile_size; int tile_len = tile_size*tile_size;
// final int transform_size = clt_parameters.transform_size;
final int full_width = tilesX * tile_size;
final int full_height = tilesY * tile_size;
final double [][][][] texture_tiles88 = new double [tilesY][tilesX][][]; // here - non-overlapped! final double [][][][] texture_tiles88 = new double [tilesY][tilesX][][]; // here - non-overlapped!
// copy from windowed output to // copy from windowed output to
final TpTask[] ftp_tasks = tp_tasks[0]; final TpTask[] ftp_tasks = tp_tasks[0];
...@@ -2033,7 +2039,7 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -2033,7 +2039,7 @@ public class QuadCLT extends QuadCLTCPU {
} }
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
if (max_distortion > 0) {// remove distorted tiles if ((max_distortion > 0) || (discard_frame_edges > 0)) {// remove distorted tiles
double max_distortion2 = max_distortion * max_distortion; double max_distortion2 = max_distortion * max_distortion;
final TileNeibs tn = new TileNeibs(tilesX, tilesY); final TileNeibs tn = new TileNeibs(tilesX, tilesY);
final boolean [] distorted = new boolean [tiles]; final boolean [] distorted = new boolean [tiles];
...@@ -2078,6 +2084,19 @@ public class QuadCLT extends QuadCLTCPU { ...@@ -2078,6 +2084,19 @@ public class QuadCLT extends QuadCLTCPU {
} }
} }
} }
// see if the tile should be removed because it is too close to the edge of the scene frame
if (!distorted[nTile] && (discard_frame_edges > 0)) {
if ((tileX >= keep_frame_tiles) && (tileY >= keep_frame_tiles) &&
(tileX < (tilesX - keep_frame_tiles)) && (tileY < (tilesY - keep_frame_tiles))) {
if (
(centerXY[0] < discard_frame_edges) ||
(centerXY[1] < discard_frame_edges) ||
(centerXY[0] > (full_width - discard_frame_edges-1)) ||
(centerXY[1] > (full_height - discard_frame_edges-1))) {
distorted[nTile] = true;
}
}
}
} else { } else {
if (debugLevel > -3) { if (debugLevel > -3) {
System.out.println("Non-null texture for no-cluster, nTile="+nTile+ System.out.println("Non-null texture for no-cluster, nTile="+nTile+
......
...@@ -12056,6 +12056,7 @@ public class QuadCLTCPU { ...@@ -12056,6 +12056,7 @@ public class QuadCLTCPU {
clt_parameters.maxZtoXY, // double maxZtoXY, // 10.0. <=0 - do not use clt_parameters.maxZtoXY, // double maxZtoXY, // 10.0. <=0 - do not use
clt_parameters.maxZ, clt_parameters.maxZ,
clt_parameters.limitZ, clt_parameters.limitZ,
null, // dbg_disp_tri_slice, // double [][] dbg_disp_tri_slice,
debugLevel + 1); // int debug_level) > 0 debugLevel + 1); // int debug_level) > 0
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
...@@ -12155,6 +12156,7 @@ public class QuadCLTCPU { ...@@ -12155,6 +12156,7 @@ public class QuadCLTCPU {
clt_parameters.maxZtoXY, // double maxZtoXY, // 10.0. <=0 - do not use clt_parameters.maxZtoXY, // double maxZtoXY, // 10.0. <=0 - do not use
clt_parameters.maxZ, clt_parameters.maxZ,
clt_parameters.limitZ, clt_parameters.limitZ,
null, // double [][] dbg_disp_tri_slice,
debugLevel + 1); // int debug_level) > 0 debugLevel + 1); // int debug_level) > 0
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -12203,7 +12205,8 @@ public class QuadCLTCPU { ...@@ -12203,7 +12205,8 @@ public class QuadCLTCPU {
double maxDispTriangle, // relative <=0 - do not use double maxDispTriangle, // relative <=0 - do not use
double maxZtoXY, // 10.0. <=0 - do not use double maxZtoXY, // 10.0. <=0 - do not use
double maxZ, // far clip (0 - do not clip). Negative - limit by max double maxZ, // far clip (0 - do not clip). Negative - limit by max
boolean limitZ, boolean limitZ,
double [][] dbg_disp_tri_slice,
int debug_level int debug_level
) throws IOException ) throws IOException
{ {
...@@ -12315,19 +12318,20 @@ public class QuadCLTCPU { ...@@ -12315,19 +12318,20 @@ public class QuadCLTCPU {
} }
} }
if (show_triangles) { if (show_triangles || (dbg_disp_tri_slice != null)) {
double [] ddisp = (disparity == null)?(new double[1]):disparity; double [] ddisp = (disparity == null)?(new double[1]):disparity;
if (disparity == null) { if (disparity == null) {
ddisp[0] = min_disparity; ddisp[0] = min_disparity;
} }
tp.testTriangles( tp.testTriangles(
texturePath, (show_triangles? texturePath: null),
bounds, bounds,
selected, selected,
ddisp, // disparity, // if disparity.length == 1 - use for all ddisp, // disparity, // if disparity.length == 1 - use for all
tile_size, tile_size,
indices, indices,
triangles); triangles,
dbg_disp_tri_slice); // double [][] debug_triangles);
} }
if (x3dOutput != null) { if (x3dOutput != null) {
x3dOutput.addCluster( x3dOutput.addCluster(
......
...@@ -32,15 +32,19 @@ class TileCluster{ ...@@ -32,15 +32,19 @@ class TileCluster{
double [] disparity; // all and only unused - NaN double [] disparity; // all and only unused - NaN
int [] cluster_index = null; // for debug purposes, index of the source cluster int [] cluster_index = null; // for debug purposes, index of the source cluster
int index = -1; int index = -1;
boolean is_sky = false;
ArrayList<IndexedRectanle> clust_list; ArrayList<IndexedRectanle> clust_list;
class IndexedRectanle{ class IndexedRectanle{
int index; int index;
Rectangle bounds; Rectangle bounds;
boolean is_sky;
IndexedRectanle ( IndexedRectanle (
int index, int index,
Rectangle bounds){ Rectangle bounds,
boolean is_sky){
this.index = index; this.index = index;
this.bounds = bounds; this.bounds = bounds;
this.is_sky = is_sky;
} }
} }
// to use cluster_index - set index >= 0, <0 - do not use. // to use cluster_index - set index >= 0, <0 - do not use.
...@@ -48,9 +52,11 @@ class TileCluster{ ...@@ -48,9 +52,11 @@ class TileCluster{
Rectangle bounds, Rectangle bounds,
int index, // <0 to skip int index, // <0 to skip
boolean [] border, boolean [] border,
double [] disparity){ double [] disparity,
boolean is_sky){
this.bounds = bounds; this.bounds = bounds;
this.index = index; this.index = index;
this.is_sky = is_sky;
/** /**
if (index >= 0) { if (index >= 0) {
this.cluster_index = new int [bounds.width * bounds.height]; this.cluster_index = new int [bounds.width * bounds.height];
...@@ -72,10 +78,31 @@ class TileCluster{ ...@@ -72,10 +78,31 @@ class TileCluster{
} }
this.disparity = disparity; this.disparity = disparity;
} }
public boolean isSky() {
return is_sky;
}
public int getSkyClusterIndex() {
if (clust_list == null) {
return -2;
}
for (int i = 0; i < clust_list.size(); i++) {
if (clust_list.get(i).is_sky) {
return i;
}
}
return -1;
}
public Rectangle getBounds() {return bounds;} public Rectangle getBounds() {
return bounds;
}
public Rectangle getBounds(int gap) {
return new Rectangle (bounds.x - gap, bounds.y - gap, bounds.width + 2* gap, bounds.height + 2* gap);
}
public boolean [] getBorder() {return border;} public boolean [] getBorder() {return border;}
public double [] getDisparity() {return disparity;} public double [] getDisparity() {return disparity;}
public void setDisparity(double [] disparity) {this.disparity = disparity;}
public double [] getSubDisparity(int indx) { // disparity should be NaN for unused ! public double [] getSubDisparity(int indx) { // disparity should be NaN for unused !
if (clust_list == null) { if (clust_list == null) {
return null; return null;
...@@ -94,6 +121,32 @@ class TileCluster{ ...@@ -94,6 +121,32 @@ class TileCluster{
} }
return sub_disparity; return sub_disparity;
} }
public void setSubDisparity(int indx, double [] sub_disparity) { // disparity should be NaN for unused !
if (clust_list == null) {
return;
}
Rectangle sub_bounds = clust_list.get(indx).bounds;
int src_x = sub_bounds.x - bounds.x;
for (int dst_y = 0; dst_y < sub_bounds.height; dst_y++) {
int src_y = dst_y + sub_bounds.y - bounds.y;
System.arraycopy(
sub_disparity,
dst_y * sub_bounds.width,
disparity,
src_y * bounds.width + src_x,
sub_bounds.width);
}
}
public boolean isSubSky(int indx) {
if (clust_list == null) {
return false;
}
return clust_list.get(indx).is_sky;
}
public boolean [] getSubBorder(int indx) { // disparity should be NaN for unused ! public boolean [] getSubBorder(int indx) { // disparity should be NaN for unused !
if (clust_list == null) { if (clust_list == null) {
...@@ -113,7 +166,7 @@ class TileCluster{ ...@@ -113,7 +166,7 @@ class TileCluster{
} }
return sub_border; return sub_border;
} }
// returns selected for all non-NAN, so it is possible to use NEGATIVE_INFINITY for non-NaN
public boolean [] getSubSelected(int indx) { // disparity should be NaN for unused ! public boolean [] getSubSelected(int indx) { // disparity should be NaN for unused !
if (clust_list == null) { if (clust_list == null) {
return null; return null;
...@@ -141,6 +194,15 @@ class TileCluster{ ...@@ -141,6 +194,15 @@ class TileCluster{
return selected; return selected;
} }
public Rectangle getSubBounds (int indx) {
if (clust_list == null) {
return null;
} else {
Rectangle sub_bounds = clust_list.get(indx).bounds;
return sub_bounds;
}
}
public Rectangle [] getSubBounds() { public Rectangle [] getSubBounds() {
if (clust_list == null) { if (clust_list == null) {
return null; return null;
...@@ -163,6 +225,9 @@ class TileCluster{ ...@@ -163,6 +225,9 @@ class TileCluster{
return sub_indices; return sub_indices;
} }
} }
public void resetClusterIndex() { // to rebuild cluster index from disparity
this.cluster_index = null;
}
public int [] getClusterIndex() { // (Now not) just a debug feature, no need to optimize? public int [] getClusterIndex() { // (Now not) just a debug feature, no need to optimize?
if (clust_list == null) { if (clust_list == null) {
return null; return null;
...@@ -183,6 +248,36 @@ class TileCluster{ ...@@ -183,6 +248,36 @@ class TileCluster{
} }
} }
return cluster_index; return cluster_index;
}
public void increaseBounds() {
int num_subs = getSubBounds().length;
for (int indx = 0; indx < num_subs; indx++) {
increaseBounds(indx);
}
}
public void increaseBounds(int sub_index) {
Rectangle bounds = getSubBounds(sub_index);
Rectangle ext_bounds = new Rectangle (bounds.x - 1, bounds.y - 1, bounds.width + 2, bounds.height + 2);
if (ext_bounds.x < 0) {
ext_bounds.width += ext_bounds.x;
ext_bounds.x = 0;
}
if ((ext_bounds.x + ext_bounds.width) > this.bounds.width) {
ext_bounds.width = this.bounds.width - ext_bounds.x;
}
if (ext_bounds.y < 0) {
ext_bounds.height += ext_bounds.y;
ext_bounds.y = 0;
}
if ((ext_bounds.y + ext_bounds.height) > this.bounds.height) {
ext_bounds.height = this.bounds.height - ext_bounds.y;
}
bounds.x = ext_bounds.x;
bounds.y = ext_bounds.y;
bounds.width = ext_bounds.width;
bounds.height = ext_bounds.height;
} }
...@@ -194,7 +289,7 @@ class TileCluster{ ...@@ -194,7 +289,7 @@ class TileCluster{
if (clust_list == null) { if (clust_list == null) {
clust_list = new ArrayList<IndexedRectanle>(); clust_list = new ArrayList<IndexedRectanle>();
} }
clust_list.add(new IndexedRectanle(tileCluster.index, tileCluster.bounds)); clust_list.add(new IndexedRectanle(tileCluster.index, tileCluster.bounds, tileCluster.isSky()));
int dst_x = tileCluster.bounds.x - bounds.x; int dst_x = tileCluster.bounds.x - bounds.x;
for (int src_y = 0; src_y < tileCluster.bounds.height; src_y++) { for (int src_y = 0; src_y < tileCluster.bounds.height; src_y++) {
......
package com.elphel.imagej.tileprocessor; package com.elphel.imagej.tileprocessor;
import java.awt.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -526,6 +527,37 @@ public class TileNeibs{ ...@@ -526,6 +527,37 @@ public class TileNeibs{
return bound_shape; return bound_shape;
} }
public static double[] getDoubleWindow(
Rectangle window,
double [] data,
int data_width) {
double [] window_data = new double [window.width * window.height];
for (int row = 0; row < window.height; row++) {
System.arraycopy(
data,
(window.y + row) * data_width + window.x,
window_data,
row * window.width,
window.width);
}
return window_data;
}
public static void setDoubleWindow(
Rectangle window,
double [] window_data,
double [] data,
int data_width) {
for (int row = 0; row < window.height; row++) {
System.arraycopy(
window_data,
row * window.width,
data,
(window.y + row) * data_width + window.x,
window.width);
}
}
public int [] distanceFromEdge( public int [] distanceFromEdge(
boolean [] tiles) { boolean [] tiles) {
......
...@@ -8991,13 +8991,14 @@ ImageDtt.startAndJoin(threads); ...@@ -8991,13 +8991,14 @@ ImageDtt.startAndJoin(threads);
static int iSign (int a) {return (a > 0) ? 1 : ((a < 0)? -1 : 0);} static int iSign (int a) {return (a > 0) ? 1 : ((a < 0)? -1 : 0);}
public void testTriangles( public void testTriangles(
String texturePath, String texturePath, // if not null - will show
Rectangle bounds, Rectangle bounds,
boolean [] selected, boolean [] selected,
double [] disparity, double [] disparity,
int tile_size, int tile_size,
int [][] indices, int [][] indices,
int [][] triangles) int [][] triangles,
double [][] debug_triangles) // if not null - should be [2][width* height], will mark disparity and triangles
{ {
String [] titles = {"disparity","triangles"}; String [] titles = {"disparity","triangles"};
double [][] dbg_img = new double [titles.length][tilesX*tilesY*tile_size*tile_size]; double [][] dbg_img = new double [titles.length][tilesX*tilesY*tile_size*tile_size];
...@@ -9053,12 +9054,30 @@ ImageDtt.startAndJoin(threads); ...@@ -9053,12 +9054,30 @@ ImageDtt.startAndJoin(threads);
} }
} }
} }
ShowDoubleFloatArrays.showArrays(dbg_img, if (texturePath != null) {
tilesX * tile_size, ShowDoubleFloatArrays.showArrays(
tilesY * tile_size, dbg_img,
true, tilesX * tile_size,
"triangles-"+texturePath, tilesY * tile_size,
titles); 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
}
}
}
}
} }
......
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