Commit 21c0a3c4 authored by Andrey Filippov's avatar Andrey Filippov

generating multi-leaf tile surfaces

parent eabd962e
...@@ -449,7 +449,7 @@ public class TileSurface { ...@@ -449,7 +449,7 @@ public class TileSurface {
double [] wnd = new double [size * size]; double [] wnd = new double [size * size];
int indx = 0; int indx = 0;
for (int i = 0; i < size; i++){ for (int i = 0; i < size; i++){
for (int j = 0; i < size; i++){ for (int j = 0; j < size; j++){
wnd[indx++] = wnd1d[i]*wnd1d[j]; wnd[indx++] = wnd1d[i]*wnd1d[j];
} }
} }
...@@ -953,13 +953,6 @@ public class TileSurface { ...@@ -953,13 +953,6 @@ public class TileSurface {
int stileY = nsTile / stilesX; int stileY = nsTile / stilesX;
int stileX = nsTile % stilesX; int stileX = nsTile % stilesX;
for (int np = 0; np < planes[nsTile].length; np++) if (planes[nsTile][np] != null){ for (int np = 0; np < planes[nsTile].length; np++) if (planes[nsTile][np] != null){
/*
int surf_number = getTileSurfaceNumber ( // maximal number of surfaces in this supertile
nsTile, // int nsTile,
-1, // int dir, // direction, or -1 (same)
np, // 0, // int np,
planes); // TilePlanes.PlaneData [][] planes)
*/
int [][][] src_mesh = lappingMeshes[nsTile][np]; int [][][] src_mesh = lappingMeshes[nsTile][np];
double [][] disp_strength = fusedSupertilePlanes[nsTile][np]; double [][] disp_strength = fusedSupertilePlanes[nsTile][np];
TileData [] dual_mesh = new TileData [len2]; // full overlapping dual-sized mesh TileData [] dual_mesh = new TileData [len2]; // full overlapping dual-sized mesh
...@@ -967,28 +960,6 @@ public class TileSurface { ...@@ -967,28 +960,6 @@ public class TileSurface {
System.out.println("createTileShells():2, *** NULL here*** nsTile = "+nsTile+" np="+np); System.out.println("createTileShells():2, *** NULL here*** nsTile = "+nsTile+" np="+np);
continue; continue;
} }
/*
int [] sNeibs = planes[nsTile][np].getNeibBest();
int [] surface_numbers = new int [8];
for (int dir = 0; dir < 8; dir++){
int nsTile1 = getNStileDir(nsTile, dir);
if (sNeibs[dir] >= 0){
surface_numbers[dir] = getTileSurfaceNumber ( // maximal number of surfaces in this supertile
nsTile1, // int nsTile,
-1, // int dir, // direction, or -1 (same)
sNeibs[dir], // int np,
planes);
} else if (nsTile1 >= 0){
surface_numbers[dir] = getTileSurfaceNumber ( // maximal number of surfaces in this supertile
nsTile1, // int nsTile,
((dir + 4) % 8), // int dir, // direction, or -1 (same)
np, // 0, // int np,
planes);
} else { // out of the picture
surface_numbers[dir] = -1; // out of the picture
}
}
*/
for (int indx = 0 ; indx < len2; indx++){ for (int indx = 0 ; indx < len2; indx++){
// src_mesh non-null elements can only be generated by this supertile, while // src_mesh non-null elements can only be generated by this supertile, while
// neighbor links can point to others (connected). // neighbor links can point to others (connected).
...@@ -1001,32 +972,12 @@ public class TileSurface { ...@@ -1001,32 +972,12 @@ public class TileSurface {
if (src_neibs != null){ if (src_neibs != null){
int tsegm = tileNeibs.getSegment(indx); int tsegm = tileNeibs.getSegment(indx);
int nsTile0 = getNStileDir(nsTile, tsegm); // supertile over which this tile is int nsTile0 = getNStileDir(nsTile, tsegm); // supertile over which this tile is
// if ( (tsegm < 0) || // own tile (center square)
// (surface_numbers[tsegm] >= 0)) { // <0 - out of picture area
if ( (tsegm < 0) || // own tile (center square) if ( (tsegm < 0) || // own tile (center square)
(nsTile0 >= 0)) { // <0 - out of picture area (nsTile0 >= 0)) { // <0 - out of picture area
dual_mesh[indx] = new TileData( // now sets neighbors to -1 dual_mesh[indx] = new TileData( // now sets neighbors to -1
disp_strength[0][indx], // disparity disp_strength[0][indx], // disparity
disp_strength[1][indx]); // strength disp_strength[1][indx]); // strength
dual_mesh[indx].setDbgNsTile(nsTile); dual_mesh[indx].setDbgNsTile(nsTile);
/*
if (tsegm < 0) { // own (center)
dual_mesh[indx].setIndex(surf_number);
} else {
// dual_mesh[indx].setIndex(surface_numbers[tsegm]);
// the cell is generated byh this supertile, so if the segment is outside
// of the home area (tsegm >= 0), surface will be numbered as destinatination
// supertile coming from this
// int nsTile2 = getNStileDir(nsTile, tsegm); // negative segm 1 is OK ?
int dir1from2 = getDirToStile(nsTile0, nsTile); // can be -1;
int surf = getTileSurfaceNumber ( // maximal number of surfaces in this supertile
nsTile0, // int nsTile,
dir1from2, // int dir, // direction, or -1 (same)
np, // int np,
planes);
dual_mesh[indx].setIndex(surf);
}
*/
int dirThisfrom0 = getDirToStile(nsTile0, nsTile); // can be -1; int dirThisfrom0 = getDirToStile(nsTile0, nsTile); // can be -1;
int surf0 = getTileSurfaceNumber ( // Number of the surface for the tile itself int surf0 = getTileSurfaceNumber ( // Number of the surface for the tile itself
nsTile0, // int nsTile, nsTile0, // int nsTile,
...@@ -1048,7 +999,6 @@ public class TileSurface { ...@@ -1048,7 +999,6 @@ public class TileSurface {
// nsTile2 - non-overlapping supertile where the destination tile belongs // nsTile2 - non-overlapping supertile where the destination tile belongs
// Unique surface number should be determined for nsTile2, generated by nsTile1, // Unique surface number should be determined for nsTile2, generated by nsTile1,
// for direction how nsTile1 is visible from the nsTile2 // for direction how nsTile1 is visible from the nsTile2
// int dir1from2 = getDirToStile(nsTile2, nsTile1); // can be -1;
int dir1from2 = getDirToStile(nsTile2, nsTile1); // can be -1; int dir1from2 = getDirToStile(nsTile2, nsTile1); // can be -1;
int surf = getTileSurfaceNumber ( // maximal number of surfaces in this supertile int surf = getTileSurfaceNumber ( // maximal number of surfaces in this supertile
nsTile2, // int nsTile, nsTile2, // int nsTile,
...@@ -1064,38 +1014,16 @@ public class TileSurface { ...@@ -1064,38 +1014,16 @@ public class TileSurface {
} }
// Now we have a double-sized surface with all tiles set with correct absolute indices, now just split it // Now we have a double-sized surface with all tiles set with correct absolute indices, now just split it
//surf_number = //surf_number =
int sh3 = 3 * sh;
for (int ty = 0; ty < ss2; ty++ ){ for (int ty = 0; ty < ss2; ty++ ){
for (int tx = 0; tx < ss2; tx++ ){ for (int tx = 0; tx < ss2; tx++ ){
int indx = ty * ss2 + tx; int indx = ty * ss2 + tx;
if (dual_mesh[indx] != null) { // some cells may be missing after merge if (dual_mesh[indx] != null) { // some cells may be missing after merge
int tsegm = tileNeibs.getSegment(indx);
// int nsTile1 = getNStileDir(nsTile,tsegm);
int ix, iy; int ix, iy;
/*
switch (tsegm){
case -1 : ix = tx - sh ; iy = ty - sh ; break;
case 0 : ix = tx - sh ; iy = ty + sh ; break;
case 1 : ix = tx - sh3; iy = ty + sh ; break;
case 2 : ix = tx - sh3; iy = ty - sh ; break;
case 3 : ix = tx - sh3; iy = ty + sh3; break;
case 4 : ix = tx - sh ; iy = ty + sh3; break;
case 5 : ix = tx + sh ; iy = ty + sh3; break;
case 6 : ix = tx + sh ; iy = ty - sh ; break;
case 7 : ix = tx + sh ; iy = ty + sh ; break;
default:
ix = tx -sh; iy = ty -sh;
}
*/
ix = (stileX * superTileSize) + tx -sh; iy = (stileY * superTileSize) + ty -sh; ix = (stileX * superTileSize) + tx -sh; iy = (stileY * superTileSize) + ty -sh;
// if ((ix >= 0) && (ix < superTileSize) && (iy >= 0) && (iy < superTileSize)) {
// int tindx = ((stileY * superTileSize) + iy) * tilesX + ((stileX * superTileSize) + ix);
if ((ix >= 0) && (ix < tilesX) && (iy >= 0) && (iy < tilesX)) { if ((ix >= 0) && (ix < tilesX) && (iy >= 0) && (iy < tilesX)) {
int tindx = iy * tilesX + ix; int tindx = iy * tilesX + ix;
// if ()
tile_data[tindx][dual_mesh[indx].getIndex()] = dual_mesh[indx]; //oob tile_data[tindx][dual_mesh[indx].getIndex()] = dual_mesh[indx]; //oob
// tile_data[nsTile1][iy * superTileSize + ix][dual_mesh[indx].getIndex()] = dual_mesh[indx];
} }
} }
} }
...@@ -1221,6 +1149,195 @@ public class TileSurface { ...@@ -1221,6 +1149,195 @@ public class TileSurface {
ImageDtt.startAndJoin(threads); ImageDtt.startAndJoin(threads);
return tile_data; return tile_data;
} }
public void checkShellsConnections (
final TileData [][] tileData,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int nStiles = stilesX * stilesY;
final int nTiles = nStiles * superTileSize * superTileSize;
// final TileData [][] tile_data = new TileData [nTiles][];
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_stile = (dbg_Y * superTileSize) * (stilesX * superTileSize) + (dbg_X * superTileSize);
// final int dbg_tile = dbg_Y * stilesX + dbg_X;
final int dbg_tilesX = stilesX * superTileSize;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
int dbg_stX = nTile % dbg_tilesX;
int dbg_stY = nTile / dbg_tilesX;
int dbg_st = (dbg_stY / superTileSize) * stilesX + (dbg_stX / superTileSize);
int dl = ((debugLevel > -1) && (dbg_st == dbg_stile)) ? 3:0;
if (dl > 0){
System.out.println("checkShellsConnections(), nTile = "+nTile+ ", nsTile = "+dbg_st);
}
if (tileData[nTile] != null){
for (int nl = 0; nl < tileData[nTile].length; nl++){
if (tileData[nTile][nl] != null){
int [] neibs = tileData[nTile][nl].getNeighbors();
for (int dir = 0; dir < neibs.length; dir++){
if (neibs[dir] >= 0){
int nTile1 = getNtileDir(nTile, dir);
if (nTile1 >= 0) {
if ((tileData[nTile1] == null) || (tileData[nTile1][neibs[dir]] == null)){
if (debugLevel > -1) {
int dbg_sstile = tileData[nTile][nl].getDbgNsTile();
int dbg_stileX = dbg_sstile % stilesX;
int dbg_stileY = dbg_sstile / stilesX;
int dbg_tx = nTile % dbg_tilesX;
int dbg_ty = nTile / dbg_tilesX;
int dbg_dx = dbg_tx - (superTileSize * dbg_stileX + superTileSize/2);
int dbg_dy = dbg_ty - (superTileSize * dbg_stileY + superTileSize/2);
System.out.println("Broken link: "+nTile1+ " from "+nTile+", nl="+nl+", dir = "+dir+
", dbg_stX="+dbg_stX+", dbg_stY="+dbg_stY+", dbg_st="+dbg_st+", neibs[dir]="+neibs[dir]+
" dbg_nsTile = "+dbg_sstile +" ("+dbg_stileX+":"+dbg_stileY+")"+
" nTile="+nTile+" ("+dbg_tx+":"+dbg_ty+")"+
", deltas from src center: "+dbg_dx+":"+dbg_dy);
}
neibs[dir] = -2; // was broken link
} else { // check if link is mutual
int [] neibs_other = tileData[nTile1][neibs[dir]].getNeighbors();
if (neibs_other[(dir + 4) % 8] != nl){
if (debugLevel > -1) {
int dbg_sstile = tileData[nTile][nl].getDbgNsTile();
int dbg_stileX = dbg_sstile % stilesX;
int dbg_stileY = dbg_sstile / stilesX;
int dbg_tx = nTile % dbg_tilesX;
int dbg_ty = nTile / dbg_tilesX;
int dbg_dx = dbg_tx - (superTileSize * dbg_stileX + superTileSize/2);
int dbg_dy = dbg_ty - (superTileSize * dbg_stileY + superTileSize/2);
System.out.println("Link not mutual: "+nTile1+ " from "+nTile+", nl="+nl+", dir = "+dir+
", dbg_stX="+dbg_stX+", dbg_stY="+dbg_stY+", dbg_st="+dbg_st+", neibs[dir]="+neibs[dir]+
" dbg_nsTile = "+dbg_sstile +" ("+dbg_stileX+":"+dbg_stileY+")"+
" nTile="+nTile+" ("+dbg_tx+":"+dbg_ty+")"+
", deltas from src center: "+dbg_dx+":"+dbg_dy+
", neibs_other["+((dir + 4) % 8)+"]="+neibs_other[(dir + 4) % 8]+
", dbg_nsTile other="+tileData[nTile1][neibs[dir]].getDbgNsTile());
}
neibs[dir] = -3; // not a mutual link (break only this side here)
}
}
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
public void addBackShellsConnections (
final TileData [][] tileData,
final int debugLevel,
final int dbg_X,
final int dbg_Y)
{
final int nStiles = stilesX * stilesY;
final int nTiles = nStiles * superTileSize * superTileSize;
// final TileData [][] tile_data = new TileData [nTiles][];
final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0);
final int dbg_stile = (dbg_Y * superTileSize) * (stilesX * superTileSize) + (dbg_X * superTileSize);
// final int dbg_tile = dbg_Y * stilesX + dbg_X;
final int dbg_tilesX = stilesX * superTileSize;
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
public void run() {
for (int nTile = ai.getAndIncrement(); nTile < nTiles; nTile = ai.getAndIncrement()) {
int dbg_stX = nTile % dbg_tilesX;
int dbg_stY = nTile / dbg_tilesX;
int dbg_st = (dbg_stY / superTileSize) * stilesX + (dbg_stX / superTileSize);
int dl = ((debugLevel > -1) && (dbg_st == dbg_stile)) ? 3:0;
if (dl > 0){
System.out.println("checkShellsConnections(), nTile = "+nTile+ ", nsTile = "+dbg_st);
}
if (tileData[nTile] != null){
for (int nl = 0; nl < tileData[nTile].length; nl++){
if (tileData[nTile][nl] != null){
int [] neibs = tileData[nTile][nl].getNeighbors();
for (int dir = 0; dir < neibs.length; dir++){
if (neibs[dir] >= 0){
int nTile1 = getNtileDir(nTile, dir);
if (nTile1 >= 0) {
if ((tileData[nTile1] == null) || (tileData[nTile1][neibs[dir]] == null)){
if (debugLevel > 0) {
int dbg_sstile = tileData[nTile][nl].getDbgNsTile();
int dbg_stileX = dbg_sstile % stilesX;
int dbg_stileY = dbg_sstile / stilesX;
int dbg_tx = nTile % dbg_tilesX;
int dbg_ty = nTile / dbg_tilesX;
int dbg_dx = dbg_tx - (superTileSize * dbg_stileX + superTileSize/2);
int dbg_dy = dbg_ty - (superTileSize * dbg_stileY + superTileSize/2);
System.out.println("Broken link: "+nTile1+ " from "+nTile+", nl="+nl+", dir = "+dir+
", dbg_stX="+dbg_stX+", dbg_stY="+dbg_stY+", dbg_st="+dbg_st+", neibs[dir]="+neibs[dir]+
" dbg_nsTile = "+dbg_sstile +" ("+dbg_stileX+":"+dbg_stileY+")"+
" nTile="+nTile+" ("+dbg_tx+":"+dbg_ty+")"+
", deltas from src center: "+dbg_dx+":"+dbg_dy);
}
// neibs[dir] = -2; // was broken link
} else { // check if link is mutual
int [] neibs_other = tileData[nTile1][neibs[dir]].getNeighbors();
if (neibs_other[(dir + 4) % 8] != nl){
if (debugLevel > 0) {
int dbg_sstile = tileData[nTile][nl].getDbgNsTile();
int dbg_stileX = dbg_sstile % stilesX;
int dbg_stileY = dbg_sstile / stilesX;
int dbg_tx = nTile % dbg_tilesX;
int dbg_ty = nTile / dbg_tilesX;
int dbg_dx = dbg_tx - (superTileSize * dbg_stileX + superTileSize/2);
int dbg_dy = dbg_ty - (superTileSize * dbg_stileY + superTileSize/2);
System.out.println("Link not mutual: "+nTile1+ " from "+nTile+", nl="+nl+", dir = "+dir+
", dbg_stX="+dbg_stX+", dbg_stY="+dbg_stY+", dbg_st="+dbg_st+", neibs[dir]="+neibs[dir]+
" dbg_nsTile = "+dbg_sstile +" ("+dbg_stileX+":"+dbg_stileY+")"+
" nTile="+nTile+" ("+dbg_tx+":"+dbg_ty+")"+
", deltas from src center: "+dbg_dx+":"+dbg_dy+
", neibs_other["+((dir + 4) % 8)+"]="+neibs_other[(dir + 4) % 8]+
", dbg_nsTile other="+tileData[nTile1][neibs[dir]].getDbgNsTile());
}
if (neibs_other[(dir + 4) % 8] < 0 ){
neibs_other[(dir + 4) % 8] = nl; // adding back link instead of missing one
} else {
int nTile2 = getNtileDir(nTile1, (dir + 4) % 8);
if ( (nTile2 < 0) ||
(tileData[nTile2] == null) ||
(tileData[nTile2][neibs_other[(dir + 4) % 8]] == null)) {
neibs_other[(dir + 4) % 8] = nl; // adding back link instead of broken one
}
}
}
}
}
}
}
}
}
}
}
}
};
}
ImageDtt.startAndJoin(threads);
}
public int getTileLayersNumber ( public int getTileLayersNumber (
final TileData [][] tileData) final TileData [][] tileData)
...@@ -1279,7 +1396,6 @@ public class TileSurface { ...@@ -1279,7 +1396,6 @@ public class TileSurface {
final Thread[] threads = ImageDtt.newThreadArray(threadsMax); final Thread[] threads = ImageDtt.newThreadArray(threadsMax);
final AtomicInteger ai = new AtomicInteger(0); final AtomicInteger ai = new AtomicInteger(0);
final int numLayers = getTileLayersNumber(tileData); final int numLayers = getTileLayersNumber(tileData);
// final double [][][] disp_strength = new double [numLayers][2][tileData.length];
final int [][][] connections = new int [numLayers][tileData.length][8]; final int [][][] connections = new int [numLayers][tileData.length][8];
for (int ithread = 0; ithread < threads.length; ithread++) { for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() { threads[ithread] = new Thread() {
...@@ -1351,7 +1467,27 @@ public class TileSurface { ...@@ -1351,7 +1467,27 @@ public class TileSurface {
debugLevel, // final int debugLevel, debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X, dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y); dbg_Y); // final int dbg_Y);
System.out.println("addBackShellsConnections()");
addBackShellsConnections (
tileData, // final TileData [][] tileData_src,
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y);
//
System.out.println("checkShellsConnections()");
checkShellsConnections (
tileData, // final TileData [][] tileData_src,
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y);
/*
System.out.println("checkShellsConnections() - 2");
checkShellsConnections (
tileData, // final TileData [][] tileData_src,
debugLevel, // final int debugLevel,
dbg_X, // final int dbg_X,
dbg_Y); // final int dbg_Y);
*/
tileData = compactSortShells ( tileData = compactSortShells (
tileData, // final TileData [][] tileData_src, tileData, // final TileData [][] tileData_src,
debugLevel, // final int debugLevel, debugLevel, // final int debugLevel,
......
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