Commit 6a57b1fc authored by Andrey Filippov's avatar Andrey Filippov

Working, but unfinished

parent 8d0998f2
...@@ -144,7 +144,7 @@ public class TexturedModel { ...@@ -144,7 +144,7 @@ public class TexturedModel {
final int tiles_wnd_ext2 = (bounds_ext2 == null) ? tiles_wnd : (bounds_ext2.width * bounds_ext2.height); final int tiles_wnd_ext2 = (bounds_ext2 == null) ? tiles_wnd : (bounds_ext2.width * bounds_ext2.height);
// calculate "connections - per tile, per layer, per direction (1 of the first 4), per target layer - normalized difference difference // calculate "connections - per tile, per layer, per direction (1 of the first 4), per target layer - normalized difference difference
// final int dbg_tile = (debugLevel > 0)? 1090:-1; // 977 : -1; // final int dbg_tile = (debugLevel > 0)? 1090:-1; // 977 : -1;
final int dbg_tile = (debugLevel > -2)? 3661:-1; // 977 : -1; final int dbg_tile = -1; // (debugLevel > -2)? 3661:-1; // 977 : -1;
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
...@@ -563,6 +563,7 @@ public class TexturedModel { ...@@ -563,6 +563,7 @@ public class TexturedModel {
null, // int [] stitch_stitched, // +1 - stitch, +2 - stitched null, // int [] stitch_stitched, // +1 - stitch, +2 - stitched
null, // int [] no_connect, // bit mask of prohibited directions null, // int [] no_connect, // bit mask of prohibited directions
disparity_crop, disparity_crop,
null, // int [] class_conn, // 1 - disconnected from, 2 - disconnected (not only for stitch)
true)); // boolean is_sky)); true)); // boolean is_sky));
cluster_list.add(tileCluster); cluster_list.add(tileCluster);
} // if (anum.get() > 0) { - Blue Sky exists } // if (anum.get() > 0) { - Blue Sky exists
...@@ -881,7 +882,7 @@ public class TexturedModel { ...@@ -881,7 +882,7 @@ public class TexturedModel {
System.out.println("buildTileCluster(): processing sky cluster, cluster_list.size()="+cluster_list.size()); System.out.println("buildTileCluster(): processing sky cluster, cluster_list.size()="+cluster_list.size());
} }
final int dbg_tile = 2445; // 2337; // 3298; // 3297; // 3146; // 3661; // 3648; // 3661; // 3264; // 858; // -3868; // 28+48*80; final int dbg_tile = 2580; // 2580; // -1; // 2445; // 2337; // 3298; // 3297; // 3146; // 3661; // 3648; // 3661; // 3264; // 858; // -3868; // 28+48*80;
// final int num_layers = disparity_layers.length; // final int num_layers = disparity_layers.length;
final int tiles = source_disparity.length; final int tiles = source_disparity.length;
final int tilesY = tiles/tilesX; final int tilesY = tiles/tilesX;
...@@ -894,6 +895,11 @@ public class TexturedModel { ...@@ -894,6 +895,11 @@ public class TexturedModel {
final boolean [] new_seam = new boolean [tiles]; final boolean [] new_seam = new boolean [tiles];
final double [] disparity = new double[tiles]; // current cluster disparities final double [] disparity = new double[tiles]; // current cluster disparities
final double [] max_neib = new double[tiles]; // maximal disparity of neibs final double [] max_neib = new double[tiles]; // maximal disparity of neibs
final int [] class_conn = new int [tiles]; // 0 other, 1 was "max_neib", 2- max_neib+1 (modified)
final boolean [] clas_conn_from = new boolean [tiles]; // temporary - disconnected from
final double delta_disp = 1E-6;
final boolean keep_stitched_only = true; final boolean keep_stitched_only = true;
if ((dbg_tile >= 0) && !Double.isNaN(source_disparity[dbg_tile])) { if ((dbg_tile >= 0) && !Double.isNaN(source_disparity[dbg_tile])) {
System.out.println("buildTileCluster(): source_disparity["+dbg_tile+"] is not NaN"); System.out.println("buildTileCluster(): source_disparity["+dbg_tile+"] is not NaN");
...@@ -1019,6 +1025,9 @@ public class TexturedModel { ...@@ -1019,6 +1025,9 @@ public class TexturedModel {
// lower disparity but lower neib_level if both conflict? // lower disparity but lower neib_level if both conflict?
double [] max_n = new double [max_neib_lev]; double [] max_n = new double [max_neib_lev];
Arrays.fill(max_n, Double.NaN); Arrays.fill(max_n, Double.NaN);
if (tile == dbg_tile) {
System.out.println("buildTileCluster().011: tile="+tile);
}
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
int tile1 = tn.getNeibIndex(tile, dir); int tile1 = tn.getNeibIndex(tile, dir);
if (tile1 >= 0) { // && (neib_lev[tile1] >= 0) && (neib_lev[tile1] < max_neib_lev)){ // has defined neighbor if (tile1 >= 0) { // && (neib_lev[tile1] >= 0) && (neib_lev[tile1] < max_neib_lev)){ // has defined neighbor
...@@ -1041,21 +1050,73 @@ public class TexturedModel { ...@@ -1041,21 +1050,73 @@ public class TexturedModel {
break; break;
} }
} else { // old one, find the lowest neighbor conflict } else { // old one, find the lowest neighbor conflict
for (int i = 0; i < max_n.length; i ++) if (!Double.isNaN(max_n[i]) && (disparity[tile] < max_n[i])) { if (Double.isNaN(source_disparity[tile])) {// original disparity was NaN, may re-select
double max_diff = disp_adiff + disp_rdiff * Math.max(0.0, max_n[i]); double swd = 0;
if (disparity[tile] < (max_n[i] - max_diff)) { // it is a conflict int nn = 0;
disparity[tile] = max_n[i]; for (int dir = 0; dir < 8; dir++) {
neib_lev[tile] = i + 1; // was -1 int tile1 = tn.getNeibIndex(tile, dir);
lor_list.add(tile); if (tile1 >= 0) { // && (neib_lev[tile1] >= 0) && (neib_lev[tile1] < max_neib_lev)){ // has defined neighbor
break; if (!Double.isNaN(disparity[tile]) && (neib_lev[tile] >= 0)) { // no need to check disparity[]
nn++;
swd += disparity[tile];
}
}
}
if (nn>0) { // has neibs
double disp = swd / nn + delta_disp;
l_replace:
{
for (int i = 0; i < max_n.length; i ++) if (!Double.isNaN(max_n[i]) && (disp < max_n[i])) {
double max_diff = disp_adiff + disp_rdiff * Math.max(0.0, max_n[i]);
if (disp < (max_n[i] - max_diff)) { // it is a conflict
if (max_n[i] != disparity[tile]) {
disparity[tile] = max_n[i];
neib_lev[tile] = i + 1; // max = 2
lor_list.add(tile);
}
break l_replace;
}
}
// no conflicts; use lowest available level
for (int i = 0; i < max_n.length; i ++) if (!Double.isNaN(max_n[i]) && (disp < max_n[i])) {
disparity[tile] = max_n[i]; // increase only, bo back-and-forth
neib_lev[tile] = i + 1; // max = 2
lor_list.add(tile);
break l_replace;
}
// keep current
disparity[tile] = disparity[tile]; // Double.NaN; // should not happen!
// neib_lev[tile] = -1;
}
} else { // should not happen!
disparity[tile] = Double.NaN;
neib_lev[tile] = -1;
} }
} } else {
for (int i = 0; i < max_n.length; i ++) if (!Double.isNaN(max_n[i]) && (disparity[tile] < max_n[i])) {
double max_diff = disp_adiff + disp_rdiff * Math.max(0.0, max_n[i]);
if (disparity[tile] < (max_n[i] - max_diff)) { // it is a conflict
disparity[tile] = max_n[i];
neib_lev[tile] = i + 1; // was -1
lor_list.add(tile);
break;
}
}
}
} }
} // while (!loc_list.isEmpty()) { finished with loc_list, created lor_list } // while (!loc_list.isEmpty()) { finished with loc_list, created lor_list
loc_list.clear(); // restarting building new list of conflicts loc_list.clear(); // restarting building new list of conflicts
while (!lor_list.isEmpty()) { // may be already empty while (!lor_list.isEmpty()) { // may be already empty
int tile0 = lor_list.remove(0); int tile0 = lor_list.remove(0);
if (tile0 == dbg_tile) {
System.out.println("buildTileCluster().012: tile="+tile0);
}
if (Double.isNaN(source_disparity[tile0]) && !loc_list.contains(tile0)) {
max_neib[tile0] = disparity[tile0]; // is it needed? Yes, for ordering
loc_list.add(tile0); // put it back for re-check
}
// look around, for conflicts, add if was not already there (consider using additional array?) // look around, for conflicts, add if was not already there (consider using additional array?)
for (int dir0 = 0; dir0 < 8; dir0++) { for (int dir0 = 0; dir0 < 8; dir0++) {
int tile = tn.getNeibIndex(tile0, dir0); int tile = tn.getNeibIndex(tile0, dir0);
...@@ -1064,8 +1125,11 @@ public class TexturedModel { ...@@ -1064,8 +1125,11 @@ public class TexturedModel {
// System.out.println(); // System.out.println();
// } // }
// tries many times as it does not qualify to be added // tries many times as it does not qualify to be added
if (tile == dbg_tile) {
System.out.println("buildTileCluster().013: tile="+tile);
}
if ((tile >= 0) && !loc_list.contains(tile)) { // Do not check+add same tile if ((tile >= 0) && !loc_list.contains(tile)) { // Do not check+add same tile
double disp = disparity[tile]; // double disp = disparity[tile];
// See if there is a conflict // See if there is a conflict
double max_n = Double.NaN; double max_n = Double.NaN;
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
...@@ -1155,19 +1219,23 @@ public class TexturedModel { ...@@ -1155,19 +1219,23 @@ public class TexturedModel {
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
removed_multi.add(new ArrayList<Integer>()); removed_multi.add(new ArrayList<Integer>());
} //////////////////////////// } ////////////////////////////
final boolean [] removed_steep = new boolean [tiles];
for (int nlev = 1; nlev <= max_neib_lev; nlev++) { for (int nlev = 1; nlev <= max_neib_lev; nlev++) {
final int fnlev = nlev; final int fnlev = nlev;
ai.set(0); ai.set(0);
ati.set(0); ati.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
// removed_multi.add(new ArrayList<Integer>());
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
ArrayList<Integer> removed_this = removed_multi.get(ati.getAndIncrement()); ArrayList<Integer> removed_this = removed_multi.get(ati.getAndIncrement());
int nlev_m1 = fnlev - 1; int nlev_m1 = fnlev - 1;
for (int tile = ai.getAndIncrement(); tile < tiles; tile = ai.getAndIncrement()) { for (int tile = ai.getAndIncrement(); tile < tiles; tile = ai.getAndIncrement()) {
// do not modify border tiles that have original disparity (stitched to previous cluster) - not here! // do not modify border tiles that have original disparity (stitched to previous cluster) - not here!
if ((neib_lev[tile] == fnlev) && (seams[tile] == 0)){ // keep seams // try - do not modify flaps
if ((neib_lev[tile] == fnlev) &&
(seams[tile] == 0) // keep seams
// && !Double.isNaN(source_disparity[tile])
){ // this is not a flap (keep flaps)
look_for_master: look_for_master:
{ {
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
...@@ -1194,6 +1262,7 @@ public class TexturedModel { ...@@ -1194,6 +1262,7 @@ public class TexturedModel {
} }
neib_lev[tile] = -1; neib_lev[tile] = -1;
removed_this.add(tile); removed_this.add(tile);
removed_steep[tile] = true;
// strange - neib_lev was set to -1, but disparity - to original? // strange - neib_lev was set to -1, but disparity - to original?
// keep it for now // keep it for now
/// disparity[tile] = source_disparity[tile]; /// disparity[tile] = source_disparity[tile];
...@@ -1272,7 +1341,25 @@ public class TexturedModel { ...@@ -1272,7 +1341,25 @@ public class TexturedModel {
if (tile == dbg_tile) { if (tile == dbg_tile) {
System.out.println("buildTileCluster().015: tile="+tile); System.out.println("buildTileCluster().015: tile="+tile);
} }
if ((neib_lev[tile] >= 0) && (neib_lev[tile] < max_neib_lev)) { // allow disconnected over previously removed/replaced tiles (removed_steep[])
if ((neib_lev[tile] >= 0) &&
((neib_lev[tile] < max_neib_lev)
|| removed_steep[tile]
|| Double.isNaN(source_disparity[tile]))) {
// if removed_steep[tile] - make sure tile is not on the edge
if (removed_steep[tile]) {
boolean edge_tile = false;
for (int dir3 = 0; dir3 < 8; dir3++) {
int tile3 = tn.getNeibIndex(tile, dir3);
if ((tile3 >= 0) && (neib_lev[tile3] < 0)) {
edge_tile = true;
break;
}
}
if (edge_tile) {
continue; // wrong place for discontinued[]
}
}
double max_n = Double.NaN; double max_n = Double.NaN;
Arrays.fill(disconnected_from, false); Arrays.fill(disconnected_from, false);
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
...@@ -1298,27 +1385,33 @@ public class TexturedModel { ...@@ -1298,27 +1385,33 @@ public class TexturedModel {
} }
} }
} }
if (disparity[tile] < max_n) { // works with Double.isNaN(max_n) if (disparity[tile] < max_n) { // works with Double.isNaN(max_n)
double max_diff = disp_adiff + disp_rdiff * Math.max(0.0, max_n); double max_diff = disp_adiff + disp_rdiff * Math.max(0.0, max_n);
double threshold_disp = disparity[tile] + max_diff; double threshold_disp = disparity[tile] + max_diff;
// if (disparity[tile] < (max_n - max_diff)) {
if (threshold_disp < max_n) { if (threshold_disp < max_n) {
// calculate prohibited directions // calculate prohibited directions
for (int dir = 0; dir < 8; dir++) { for (int dir = 0; dir < 8; dir++) {
if (disconnected_from[dir]) { // already assumes (neib_lev[tile1] == max_neib_lev) if (disconnected_from[dir]) { // already assumes (neib_lev[tile1] == max_neib_lev)
no_connect[tile] |= (1 << dir); no_connect[tile] |= (1 << dir);
clas_conn_from[tn.getNeibIndex(tile, dir)] = true; // is it OK with threads?
}
}
// remove leaks between
for (int dir = 1; dir < 8; dir += 2) {
if ((((no_connect[tile] & (1 << (dir-1))) != 0)) &&
(((no_connect[tile] & (1 << ((dir+1) % 8))) != 0))){
no_connect[tile] |= (1 << dir);
} }
} }
// only count as discontinued if it is original disparity, not added flap // only count as discontinued if it is original disparity, not added flap
// enabling flaps, will re-filter later // enabling flaps, will re-filter later
// alternatively to disparity may test (initial_seam[tile] || (neib_lev[tile] == 0)) // alternatively to disparity may test (initial_seam[tile] || (neib_lev[tile] == 0))
// if (disparity[tile] == source_disparity[tile]) { loc_this.add(tile);
loc_this.add(tile); discontinued[tile] = true;
discontinued[tile] = true; if (dbg_over_conflicts != null) {
if (dbg_over_conflicts != null) { dbg_over_conflicts[tile] = 10*(max_n-disparity[tile])/max_diff;
dbg_over_conflicts[tile] = 10*(max_n-disparity[tile])/max_diff; }
}
// }
} }
} }
} }
...@@ -1335,7 +1428,6 @@ public class TexturedModel { ...@@ -1335,7 +1428,6 @@ public class TexturedModel {
// Maybe it is now (after removing modified disparity ones) not needed? // Maybe it is now (after removing modified disparity ones) not needed?
ati.set(0); ati.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
/// loc_multi.add(new ArrayList<Integer>()); they are already there
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
ArrayList<Integer> loc_this = loc_multi.get(ati.getAndIncrement()); ArrayList<Integer> loc_this = loc_multi.get(ati.getAndIncrement());
...@@ -1362,9 +1454,7 @@ public class TexturedModel { ...@@ -1362,9 +1454,7 @@ public class TexturedModel {
Arrays.fill(discontinued, false); Arrays.fill(discontinued, false);
ati.set(0); ati.set(0);
// Rebuild disconnected[] w/o isolated, mark them as max_neib_lev+1 // Rebuild disconnected[] w/o isolated, mark them as max_neib_lev+1
// loc_multi.clear();
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
/// loc_multi.add(new ArrayList<Integer>()); they are already there
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
public void run() { public void run() {
ArrayList<Integer> loc_this = loc_multi.get(ati.getAndIncrement()); ArrayList<Integer> loc_this = loc_multi.get(ati.getAndIncrement());
...@@ -1386,7 +1476,21 @@ public class TexturedModel { ...@@ -1386,7 +1476,21 @@ public class TexturedModel {
for (ArrayList<Integer> part_loc: loc_multi) { for (ArrayList<Integer> part_loc: loc_multi) {
loc_list.addAll(part_loc); // seems OK as there are no duplicates loc_list.addAll(part_loc); // seems OK as there are no duplicates
} }
for (int tile:loc_list) {
class_conn[tile] |= 2;
for (int dir = 0; dir < 8; dir++) {
int tile1 = tn.getNeibIndex(tile, dir);
if ((tile1 >= 0) && (clas_conn_from[tile1])) { // only conflicts with max_neib_lev
class_conn[tile1] |= 1;
}
}
}
// TODO: improve class_conn[]
final int [] dbg_neib_new_conflicts = (debugLevel > 0)? neib_lev.clone() : null; final int [] dbg_neib_new_conflicts = (debugLevel > 0)? neib_lev.clone() : null;
// there may be some orphans left neib_lev >0 that do not have neighbors with neib_lev one less // there may be some orphans left neib_lev >0 that do not have neighbors with neib_lev one less
...@@ -1538,12 +1642,14 @@ public class TexturedModel { ...@@ -1538,12 +1642,14 @@ public class TexturedModel {
String [] dbg_titles = {"Source","Intermediate","Final", "neib_lev0", String [] dbg_titles = {"Source","Intermediate","Final", "neib_lev0",
"neib_prebreak", "neib_preterm", "neib_prebreak", "neib_preterm",
"neib_noorph", "neib_noorph",
"discontinued_filtered", "new_conflicts", "discontinued_filtered",
"class_conn",
"new_conflicts",
"over_conflicts", "neib_lev1", "neib_lev2", "over_conflicts", "neib_lev1", "neib_lev2",
"seams", "seams_layers_0", "seams_layers_1", "newseam_discontinued", "seams", "seams_layers_0", "seams_layers_1", "newseam_discontinued",
"stitch_stitched", "stitch_stitched",
"disparity_layers_0", "disparity_layers_1"}; "disparity_layers_0", "disparity_layers_1"};
double [][] dbg_neib_lev = new double [13][tiles]; double [][] dbg_neib_lev = new double [14][tiles];
for (int i = 0; i < tiles; i++) { for (int i = 0; i < tiles; i++) {
if (dbg_neib_lev_preisol != null) dbg_neib_lev[0][i] = 10*dbg_neib_lev_preisol[i]; if (dbg_neib_lev_preisol != null) dbg_neib_lev[0][i] = 10*dbg_neib_lev_preisol[i];
...@@ -1551,14 +1657,15 @@ public class TexturedModel { ...@@ -1551,14 +1657,15 @@ public class TexturedModel {
if (dbg_neib_lev_pre_term != null) dbg_neib_lev[2][i] = 10*dbg_neib_lev_pre_term[i]; if (dbg_neib_lev_pre_term != null) dbg_neib_lev[2][i] = 10*dbg_neib_lev_pre_term[i];
if (dbg_neib_lev_orphaned != null) dbg_neib_lev[3][i] = 10*dbg_neib_lev_orphaned[i]; if (dbg_neib_lev_orphaned != null) dbg_neib_lev[3][i] = 10*dbg_neib_lev_orphaned[i];
if ((dbg_discontinued_full != null) && (dbg_discontinued_notisolated != null)) dbg_neib_lev[4][i] = 10*(dbg_discontinued_full[i]? 1:0) + 20*(dbg_discontinued_notisolated[i]? 1:0); if ((dbg_discontinued_full != null) && (dbg_discontinued_notisolated != null)) dbg_neib_lev[4][i] = 10*(dbg_discontinued_full[i]? 1:0) + 20*(dbg_discontinued_notisolated[i]? 1:0);
if (dbg_neib_new_conflicts != null) dbg_neib_lev[5][i] = 10*dbg_neib_new_conflicts[i]; dbg_neib_lev[5][i] = 10*class_conn[i];
if (dbg_neib_lev_predefined != null) dbg_neib_lev[6][i] = 10*dbg_neib_lev_predefined[i]; if (dbg_neib_new_conflicts != null) dbg_neib_lev[6][i] = 10*dbg_neib_new_conflicts[i];
dbg_neib_lev[ 7][i] = 10*neib_lev[i]; if (dbg_neib_lev_predefined != null) dbg_neib_lev[7][i] = 10*dbg_neib_lev_predefined[i];
dbg_neib_lev[ 8][i] = 10*seams[i]; dbg_neib_lev[ 8][i] = 10*neib_lev[i];
dbg_neib_lev[ 9][i] = 10*seams_layers[0][i]; dbg_neib_lev[ 9][i] = 10*seams[i];
dbg_neib_lev[10][i] = 10*seams_layers[1][i]; dbg_neib_lev[10][i] = 10*seams_layers[0][i];
dbg_neib_lev[11][i] = 10*(new_seam[i]?1:0) + 20*(discontinued[i]? 1:0); dbg_neib_lev[11][i] = 10*seams_layers[1][i];
dbg_neib_lev[12][i] = 10 * stitch_stitched[i]; dbg_neib_lev[12][i] = 10*(new_seam[i]?1:0) + 20*(discontinued[i]? 1:0);
dbg_neib_lev[13][i] = 10 * stitch_stitched[i];
} }
double [][] dbg_img = { double [][] dbg_img = {
...@@ -1570,15 +1677,16 @@ public class TexturedModel { ...@@ -1570,15 +1677,16 @@ public class TexturedModel {
dbg_neib_lev[2], // "neib_preterm", dbg_neib_lev[2], // "neib_preterm",
dbg_neib_lev[3], // "neib_noorph", dbg_neib_lev[3], // "neib_noorph",
dbg_neib_lev[4], // "discontinued_filtered" dbg_neib_lev[4], // "discontinued_filtered"
dbg_neib_lev[5], // "new_conflicts", dbg_neib_lev[5], // "class_conn",
dbg_neib_lev[6], // "new_conflicts",
dbg_over_conflicts, // "over_conflicts" dbg_over_conflicts, // "over_conflicts"
dbg_neib_lev[6], // "neib_lev1" dbg_neib_lev[7], // "neib_lev1"
dbg_neib_lev[7], // "neib_lev2" dbg_neib_lev[8], // "neib_lev2"
dbg_neib_lev[8], // "seams" dbg_neib_lev[9], // "seams"
dbg_neib_lev[9], // "seams_layers_0" dbg_neib_lev[10], // "seams_layers_0"
dbg_neib_lev[10], // "seams_layers_1" dbg_neib_lev[11], // "seams_layers_1"
dbg_neib_lev[11], // "newseam_discontinued", dbg_neib_lev[12], // "newseam_discontinued",
dbg_neib_lev[12], // "stitch_stitched", dbg_neib_lev[13], // "stitch_stitched",
disparity_layers[0], // "disparity_layers_0" disparity_layers[0], // "disparity_layers_0"
disparity_layers[1]};// "disparity_layers_1" disparity_layers[1]};// "disparity_layers_1"
ShowDoubleFloatArrays.showArrays( ShowDoubleFloatArrays.showArrays(
...@@ -1616,17 +1724,11 @@ public class TexturedModel { ...@@ -1616,17 +1724,11 @@ public class TexturedModel {
TileCluster [] tileClusters = new TileCluster[num_sub]; TileCluster [] tileClusters = new TileCluster[num_sub];
for (int nsub = 0; nsub < num_sub; nsub++) { for (int nsub = 0; nsub < num_sub; nsub++) {
int [] neib_lev_sub = (num_sub > 1) ? (new int [tiles]): neib_lev; int [] neib_lev_sub = (num_sub > 1) ? (new int [tiles]): neib_lev;
int [] stitch_stitched_sub = (num_sub > 1) ? (new int [tiles]): stitch_stitched;
int [] no_connect_sub = (num_sub > 1) ? (new int [tiles]): no_connect;
double [] disparity_sub = (num_sub > 1) ? (new double [tiles]): disparity;
if (num_sub > 1) { if (num_sub > 1) {
Arrays.fill(neib_lev_sub, -1); Arrays.fill(neib_lev_sub, -1);
Arrays.fill(disparity_sub, Double.NaN);
final int indx = nsub+1; final int indx = nsub+1;
for (int tile = 0; tile < tiles; tile++) if (enum_clusters[tile] == indx){ for (int tile = 0; tile < tiles; tile++) if (enum_clusters[tile] == indx){
neib_lev_sub[tile] = neib_lev[tile]; neib_lev_sub[tile] = neib_lev[tile];
disparity_sub[tile] = disparity[tile];
stitch_stitched_sub[tile] = stitch_stitched[tile];
} }
ai.set(0); ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
...@@ -1634,9 +1736,6 @@ public class TexturedModel { ...@@ -1634,9 +1736,6 @@ public class TexturedModel {
public void run() { public void run() {
for (int tile = ai.getAndIncrement(); tile < tiles; tile = ai.getAndIncrement())if (enum_clusters[tile] == indx){ for (int tile = ai.getAndIncrement(); tile < tiles; tile = ai.getAndIncrement())if (enum_clusters[tile] == indx){
neib_lev_sub[tile] = neib_lev[tile]; neib_lev_sub[tile] = neib_lev[tile];
disparity_sub[tile] = disparity[tile];
stitch_stitched_sub[tile] = stitch_stitched[tile];
no_connect_sub[tile] = no_connect[tile];
} }
} }
}; };
...@@ -1660,7 +1759,7 @@ public class TexturedModel { ...@@ -1660,7 +1759,7 @@ public class TexturedModel {
max_y.getAndAccumulate(tileY, Math::max); max_y.getAndAccumulate(tileY, Math::max);
min_x.getAndAccumulate(tileX, Math::min); min_x.getAndAccumulate(tileX, Math::min);
max_x.getAndAccumulate(tileX, Math::max); max_x.getAndAccumulate(tileX, Math::max);
if (stitch_stitched_sub[tile] != 2) { if (stitch_stitched[tile] != 2) {
anum_new.getAndIncrement(); anum_new.getAndIncrement();
} }
} }
...@@ -1668,8 +1767,7 @@ public class TexturedModel { ...@@ -1668,8 +1767,7 @@ public class TexturedModel {
}; };
} }
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
// final boolean sky_cluster = blue_sky_below >=0;
if (is_sky_cluster && (blue_sky_below >= 0)) { // increase bounding box for sky cluster if (is_sky_cluster && (blue_sky_below >= 0)) { // increase bounding box for sky cluster
min_y.set(0); min_y.set(0);
max_y.addAndGet(blue_sky_below); max_y.addAndGet(blue_sky_below);
...@@ -1698,6 +1796,7 @@ public class TexturedModel { ...@@ -1698,6 +1796,7 @@ public class TexturedModel {
final int [] border_int_crop = new int [disparity_crop.length]; final int [] border_int_crop = new int [disparity_crop.length];
final int [] stitch_stitched_crop = new int [disparity_crop.length]; final int [] stitch_stitched_crop = new int [disparity_crop.length];
final int [] no_connect_crop = new int [disparity_crop.length]; final int [] no_connect_crop = new int [disparity_crop.length];
final int [] class_conn_crop = new int [disparity_crop.length];
ai.set(0); ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
...@@ -1706,10 +1805,16 @@ public class TexturedModel { ...@@ -1706,10 +1805,16 @@ public class TexturedModel {
int tileY = tile_crop / width + bounds.y ; int tileY = tile_crop / width + bounds.y ;
int tileX = tile_crop % width + bounds.x; int tileX = tile_crop % width + bounds.x;
int tile = tileX + tileY * tilesX; int tile = tileX + tileY * tilesX;
disparity_crop[tile_crop] = disparity_sub[tile]; if (neib_lev_sub[tile] >= 0) {
border_int_crop[tile_crop] = neib_lev_sub[tile]; disparity_crop[tile_crop] = disparity[tile];
stitch_stitched_crop[tile_crop] = stitch_stitched_sub[tile]; border_int_crop[tile_crop] = neib_lev_sub[tile];
no_connect_crop[tile_crop] = no_connect_sub[tile]; stitch_stitched_crop[tile_crop] = stitch_stitched[tile];
no_connect_crop[tile_crop] = no_connect[tile];
class_conn_crop[tile_crop] = class_conn[tile];
} else {
disparity_crop[tile_crop] = Double.NaN;
border_int_crop[tile_crop] = -1;
}
} }
} }
}; };
...@@ -1742,55 +1847,6 @@ public class TexturedModel { ...@@ -1742,55 +1847,6 @@ public class TexturedModel {
} }
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
/*
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int x = ai.getAndIncrement(); x < width; x = ai.getAndIncrement()) {
for (int y = 0; y < height; y+= (height -1)) {
int tile = x + y * width;
if (border_int_crop[tile] >= 0) {
for (int dir = 0; dir < 8; dir++) {
if (tnc.getNeibIndex(tile, dir) < 0) {
no_connect_crop[tile] |= 1 << dir;
}
}
}
if (height < 2) {
break;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int y = ai.getAndIncrement(); y < height; y = ai.getAndIncrement()) {
for (int x = 0; x < width; x += (width -1)) {
int tile = x + y * width;
if (border_int_crop[tile] >= 0) {
for (int dir = 0; dir < 8; dir++) {
if (tnc.getNeibIndex(tile, dir) < 0) {
no_connect_crop[tile] |= 1 << dir;
}
}
}
if (width < 2) {
break;
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
*/
// Create new TileCluster // Create new TileCluster
tileClusters[nsub] = (new TileCluster( tileClusters[nsub] = (new TileCluster(
bounds, bounds,
...@@ -1801,6 +1857,7 @@ public class TexturedModel { ...@@ -1801,6 +1857,7 @@ public class TexturedModel {
stitch_stitched_crop, // int [] stitch_stitched, // +1 - stitch, +2 - stitched stitch_stitched_crop, // int [] stitch_stitched, // +1 - stitch, +2 - stitched
no_connect_crop, // int [] no_connect, // bit mask of prohibited directions no_connect_crop, // int [] no_connect, // bit mask of prohibited directions
disparity_crop, disparity_crop,
class_conn_crop, // int [] class_conn, // 1 - disconnected from, 2 - disconnected (not only for stitch)
is_sky_cluster)); // boolean is_sky)); is_sky_cluster)); // boolean is_sky));
cluster_list.add(tileClusters[nsub]); cluster_list.add(tileClusters[nsub]);
} }
...@@ -1813,6 +1870,8 @@ public class TexturedModel { ...@@ -1813,6 +1870,8 @@ public class TexturedModel {
//num_sub //num_sub
return tileClusters; return tileClusters;
} }
/** /**
* Create texture clusters collectively covering the depth map from multi-layer * Create texture clusters collectively covering the depth map from multi-layer
* disparity arrays and optional "blue sky" binary array * disparity arrays and optional "blue sky" binary array
...@@ -2172,6 +2231,7 @@ public class TexturedModel { ...@@ -2172,6 +2231,7 @@ public class TexturedModel {
null, // int [] stitch_stitched, // +1 - stitch, +2 - stitched null, // int [] stitch_stitched, // +1 - stitch, +2 - stitched
null, // int [] no_connect, // bit mask of prohibited directions null, // int [] no_connect, // bit mask of prohibited directions
null, null,
null, // int [] class_conn, // 1 - disconnected from, 2 - disconnected (not only for stitch)
false); // boolean is_sky)); false); // boolean is_sky));
} }
for (int i = 0; i < comb_clusters.length; i++) { for (int i = 0; i < comb_clusters.length; i++) {
...@@ -2184,9 +2244,11 @@ public class TexturedModel { ...@@ -2184,9 +2244,11 @@ public class TexturedModel {
double [][] dbg_borders_int = new double[this_combo][tiles]; double [][] dbg_borders_int = new double[this_combo][tiles];
double [][] dbg_stitch_stitched = new double[this_combo][tiles]; double [][] dbg_stitch_stitched = new double[this_combo][tiles];
double [][] dbg_no_connect = new double[this_combo][tiles]; double [][] dbg_no_connect = new double[this_combo][tiles];
double [][] dbg_class_conn = new double[this_combo][tiles];
double [][] dbg_index = null; double [][] dbg_index = null;
int [][] borders_int = new int [this_combo][]; int [][] borders_int = new int [this_combo][];
int [][] no_connect = new int [this_combo][]; int [][] no_connect = new int [this_combo][];
int [][] class_conn = new int [this_combo][];
if (debug_index) { if (debug_index) {
dbg_index = new double[this_combo][tiles]; dbg_index = new double[this_combo][tiles];
...@@ -2194,6 +2256,7 @@ public class TexturedModel { ...@@ -2194,6 +2256,7 @@ public class TexturedModel {
for (int n = 0; n < dbg_img.length; n++) { for (int n = 0; n < dbg_img.length; n++) {
borders_int[n] = consolidated_clusters[n].getBorderInt(); borders_int[n] = consolidated_clusters[n].getBorderInt();
no_connect[n] = consolidated_clusters[n].getNoConnect(); no_connect[n] = consolidated_clusters[n].getNoConnect();
class_conn[n] = consolidated_clusters[n].getClassConn();
for (int i = 0; i < tiles;i++) { for (int i = 0; i < tiles;i++) {
dbg_img[n][i] = consolidated_clusters[n].getDisparity()[i]; dbg_img[n][i] = consolidated_clusters[n].getDisparity()[i];
...@@ -2201,6 +2264,7 @@ public class TexturedModel { ...@@ -2201,6 +2264,7 @@ public class TexturedModel {
dbg_borders_int[n][i] = consolidated_clusters[n].getBorderInt()[i]; dbg_borders_int[n][i] = consolidated_clusters[n].getBorderInt()[i];
dbg_stitch_stitched[n][i] = consolidated_clusters[n].getStitchStitched()[i]; dbg_stitch_stitched[n][i] = consolidated_clusters[n].getStitchStitched()[i];
dbg_no_connect[n][i] = consolidated_clusters[n].getNoConnect()[i]; dbg_no_connect[n][i] = consolidated_clusters[n].getNoConnect()[i];
dbg_class_conn[n][i] = consolidated_clusters[n].getClassConn()[i];
if (dbg_index != null) { if (dbg_index != null) {
double d = consolidated_clusters[n].getClusterIndex()[i]; double d = consolidated_clusters[n].getClusterIndex()[i];
dbg_index[n][i] = (d >=0)? d : Double.NaN; dbg_index[n][i] = (d >=0)? d : Double.NaN;
...@@ -2237,6 +2301,12 @@ public class TexturedModel { ...@@ -2237,6 +2301,12 @@ public class TexturedModel {
tilesY, tilesY,
true, true,
"cluster_no_connect"); "cluster_no_connect");
ShowDoubleFloatArrays.showArrays(
dbg_class_conn,
tilesX,
tilesY,
true,
"cluster_class_conn");
showNoConnect( showNoConnect(
no_connect, // int [][] dir_mask, no_connect, // int [][] dir_mask,
borders_int, //int [][] borders_int, // may be null borders_int, //int [][] borders_int, // may be null
......
...@@ -34,6 +34,8 @@ class TileCluster{ ...@@ -34,6 +34,8 @@ class TileCluster{
int border_int_max; // outer border value int border_int_max; // outer border value
int [] stitch_stitched; // +1 - stitch, +2 - stitched int [] stitch_stitched; // +1 - stitch, +2 - stitched
int [] no_connect; // bit mask of prohibited directions int [] no_connect; // bit mask of prohibited directions
int [] class_conn; // 1 - disconnected from, 2 - disconnected (not only for stitch)
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
...@@ -57,12 +59,12 @@ class TileCluster{ ...@@ -57,12 +59,12 @@ class TileCluster{
public TileCluster ( public TileCluster (
Rectangle bounds, Rectangle bounds,
int index, // <0 to skip int index, // <0 to skip
// boolean [] border,
int [] border_int, // will replace border? Provide on-the-fly? int [] border_int, // will replace border? Provide on-the-fly?
int border_int_max, // outer border value int border_int_max, // outer border value
int [] stitch_stitched, // +1 - stitch, +2 - stitched int [] stitch_stitched, // +1 - stitch, +2 - stitched
int [] no_connect, // bit mask of prohibited directions int [] no_connect, // bit mask of prohibited directions
double [] disparity, double [] disparity,
int [] class_conn, // 1 - disconnected from, 2 - disconnected (not only for stitch)
boolean is_sky){ boolean is_sky){
this.bounds = bounds; this.bounds = bounds;
this.index = index; this.index = index;
...@@ -101,10 +103,16 @@ class TileCluster{ ...@@ -101,10 +103,16 @@ class TileCluster{
stitch_stitched = new int [bounds.width * bounds.height]; stitch_stitched = new int [bounds.width * bounds.height];
} }
this.stitch_stitched = stitch_stitched; this.stitch_stitched = stitch_stitched;
if (no_connect == null) { if (no_connect == null) {
no_connect = new int [bounds.width * bounds.height]; no_connect = new int [bounds.width * bounds.height];
} }
this.no_connect = no_connect; this.no_connect = no_connect;
if (class_conn == null) {
class_conn = new int [bounds.width * bounds.height];
}
this.class_conn = class_conn;
} }
public boolean isSky() { public boolean isSky() {
...@@ -139,6 +147,7 @@ class TileCluster{ ...@@ -139,6 +147,7 @@ class TileCluster{
public int [] getBorderInt() {return border_int;} public int [] getBorderInt() {return border_int;}
public int [] getStitchStitched() {return stitch_stitched;} public int [] getStitchStitched() {return stitch_stitched;}
public int [] getNoConnect() {return no_connect;} public int [] getNoConnect() {return no_connect;}
public int [] getClassConn() {return class_conn;}
public int getBorderIntMax() {return border_int_max;} public int getBorderIntMax() {return border_int_max;}
public double [] getDisparity() {return disparity;} public double [] getDisparity() {return disparity;}
public void setDisparity(double [] disparity) {this.disparity = disparity;} public void setDisparity(double [] disparity) {this.disparity = disparity;}
...@@ -263,6 +272,24 @@ class TileCluster{ ...@@ -263,6 +272,24 @@ class TileCluster{
return sub_no_connect; return sub_no_connect;
} }
public int [] getSubClassConn(int indx) {
if (clust_list == null) {
return null;
}
Rectangle sub_bounds = clust_list.get(indx).bounds;
int [] sub_class_conn = new int [sub_bounds.width * sub_bounds.height];
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(
class_conn,
src_y * bounds.width + src_x,
sub_class_conn,
dst_y * sub_bounds.width,
sub_bounds.width);
}
return sub_class_conn;
}
...@@ -420,6 +447,12 @@ class TileCluster{ ...@@ -420,6 +447,12 @@ class TileCluster{
no_connect, no_connect,
dst_y * bounds.width + dst_x, dst_y * bounds.width + dst_x,
tileCluster.bounds.width); tileCluster.bounds.width);
System.arraycopy(
tileCluster.class_conn,
src_y * tileCluster.bounds.width,
class_conn,
dst_y * bounds.width + dst_x,
tileCluster.bounds.width);
} }
return; return;
} }
......
...@@ -1295,9 +1295,10 @@ public class TriMesh { ...@@ -1295,9 +1295,10 @@ public class TriMesh {
/** /**
* Triangulate all vertice indices - combine triangulation of same-size equailateral 45-degree * Triangulate all vertice indices - combine triangulation of same-size equailateral 45-degree
* large (tile size) and small (tile subdivisions) and add connections between large and small ones * large (tile size) and small (tile subdivisions) and add connections between large and small ones
* @param indices - array of [height][width]{{index}} for large tiles and [heigh][width][py][px] * @param indices array of [height][width]{{index}} for large tiles and [heigh][width][py][px]
* for small ones. This array will be modified and re-indexed if needed. * for small ones. This array will be modified and re-indexed if needed.
* @return int [][3] - array of triangles 3 vertex indices, clockwise * @param no_connect 0 - neutral 1 - max_neib_lev, 2 - max_neib_lev+1
* @return int [][3] - array of triangles 3 vertex indices, clockwise
*/ */
public static int [][] triangulateAll( public static int [][] triangulateAll(
int [][][][] indices, int [][][][] indices,
......
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