Commit 5d6289e3 authored by Andrey Filippov's avatar Andrey Filippov

adding support for ortho-ortho-diagonal conflicts

parent 8a2df8e5
/**
**
** Conflict - Represent a "conflit" between connected supertiles
**
** Copyright (C) 2017 Elphel, Inc.
**
** -----------------------------------------------------------------------------**
**
** Conflict.java is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
** -----------------------------------------------------------------------------**
**
*/
public class Conflict{
int start_layer;
int end_layer;
boolean [] start_dirs = new boolean[24];
// 0 ... 7 - ortho-diagonal-ortho
// 0 ... 3 from start_layer to end_layer: 0 - start_layer->N->SE->W->end_layer, 1 - start_layer->E->SW->N->end_layer, ...
// 4 ... 7 from end_layer to start_layer: 4 - end_layer->N->SE->W->start_layer, 7 - end_layer->E->SW->N->start_layer, ...
// 8 ... 15 - ortho-ortho-diagonal (turn right)
// 8 ... 11 : 8 - start_layer->N->E->SW->end_layer, 9 - start_layer->E->S->NW->end_layer, ...
// 12 ... 15 : 12 - end_layer->N->E->SW->start_layer, 13 - end_layer->E->S->NW->start_layer, ...
// 16 ... 23 - ortho-ortho-diagonal (turn left)
// 16 ... 19 : 16 - start_layer->N->W->SE->end_layer, 17 - start_layer->E->N->SW->end_layer, ...
// 20 ... 23 : 20 - end_layer->N->W->SE->start_layer, 21 - end_layer->E->N->SW->start_layer, ...
Conflict(int start_layer, int end_layer, int start_dir) // for ortho-diag-ortho
{
if (end_layer > start_layer) {
this.start_layer = start_layer;
this.end_layer = end_layer;
this.start_dirs[start_dir] = true;
} else {
this.start_layer = end_layer;
this.end_layer = start_layer;
this.start_dirs[start_dir + 4] = true;
}
}
Conflict(int start_layer, int end_layer, int start_dir, boolean right) // for ortho-ortho-diag
{
if (end_layer > start_layer) {
this.start_layer = start_layer;
this.end_layer = end_layer;
this.start_dirs[(right? 8 : 12) + start_dir] = true;
} else {
this.start_layer = end_layer;
this.end_layer = start_layer;
this.start_dirs[(right? 16 : 20) + start_dir] = true;
}
}
Conflict(int [] arr)
{
this.start_layer = arr[0];
this.end_layer = arr[1];
for (int i = 0; i < start_dirs.length; i++){
start_dirs[i] = (arr[2] & (1 << i)) != 0;
}
}
Conflict(int bits)
{
this.start_layer = -1;
this.end_layer = -1;
for (int i = 0; i < start_dirs.length; i++){
start_dirs[i] = (bits & (1 << i)) != 0;
}
}
boolean combine (Conflict other_conflict)
{
if ((other_conflict.start_layer == this.start_layer) && (other_conflict.end_layer == this.end_layer)) {
for (int i = 0; i < start_dirs.length; i++) start_dirs[i] |= other_conflict.start_dirs[i];
return true;
}
return false;
}
int getStartLayer(){
return start_layer;
}
int getEndLayer(){
return end_layer;
}
int getDirBits(){
int dirs_bits = 0;
for (int i = 0; i < start_dirs.length; i++){
if (start_dirs[i]) dirs_bits |= (1 << i);
}
return dirs_bits;
}
int getDirBitsOrthoDiagOrtho(){
int dirs_bits = 0;
for (int i = 0; i < 8; i++){
if (start_dirs[i]) dirs_bits |= (1 << i);
}
return dirs_bits;
}
int getDirBitsOrthoOrthoDiag(boolean right){
int dirs_bits = 0;
if (right) {
for (int i = 0; i < 8; i++){
if (start_dirs[i]) dirs_bits |= (1 << (i + 8));
}
} else {
for (int i = 0; i < 8; i++){
if (start_dirs[i]) dirs_bits |= (1 << (i + 16));
}
}
return dirs_bits;
}
int [] toArray()
{
int dirs_bits = 0;
for (int i = 0; i < start_dirs.length; i++){
if (start_dirs[i]) dirs_bits |= (1 << i);
}
int [] rslt = {start_layer, end_layer, dirs_bits};
return rslt;
}
int getNumConflicts(){
int numbits = 0;
for (int i = 0; i < start_dirs.length; i++){
if (start_dirs[i]) numbits++;
}
return numbits;
}
int getNumOrthoDiagOrthoConflicts(){
int numbits = 0;
for (int i = 0; i < 8; i++){
if (start_dirs[i]) numbits++;
}
return numbits;
}
int getNumOrthoOrthoDiagConflicts(){
int numbits = 0;
for (int i = 8; i < 24; i++){
if (start_dirs[i]) numbits++;
}
return numbits;
}
int getIncompatibleOrthoDiagOrthoConflicts(){
int num_incompat = 0;
for (int i = 0; i < 8; i++){
if (start_dirs[i]) {
int [] incomp_bits= {
i ^ 4,
(i & 4) | ((i + 1) & 3),
(i & 4) | ((i - 1) & 3)};
for (int j = 1; j < 3; j++){ // skip dual triangles
int i1 = incomp_bits[j];
if (start_dirs[i1]){
num_incompat ++;
}
}
}
}
return num_incompat / 2;
}
public int getDualTriOrthoDiagOrthoConflicts()
{
int num_dual = 0;
for (int i = 0; i < 4; i++) if (start_dirs[i] && start_dirs[i + 4]) num_dual++;
return num_dual;
}
}
This diff is collapsed.
This diff is collapsed.
...@@ -3428,10 +3428,19 @@ public class TileProcessor { ...@@ -3428,10 +3428,19 @@ public class TileProcessor {
0, // final int debugLevel) 0, // final int debugLevel)
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
Conflicts iconflicts0 = new Conflicts(st);
/*
int [][][] conflicts0 = st.detectTriangularConflicts( int [][][] conflicts0 = st.detectTriangularConflicts(
1); // final int debugLevel) 1); // final int debugLevel)
int [] conflicts0_stats = st.getNumConflicts( int [] conflicts0_stats = st.getNumConflicts(
conflicts0, conflicts0,
*/
int [][][] conflicts0 = iconflicts0.detectTriangularConflicts(
1); // final int debugLevel)
Conflicts conflicts0_stats = new Conflicts(
conflicts0,
st,
-1); // debugLevel); -1); // debugLevel);
// just testing // just testing
...@@ -3479,11 +3488,20 @@ public class TileProcessor { ...@@ -3479,11 +3488,20 @@ public class TileProcessor {
System.out.println("Pass "+(pass+1)+": multi_tri_results (success/failures) = "+conflict_resoultion_results[0]+" / "+conflict_resoultion_results[1]); System.out.println("Pass "+(pass+1)+": multi_tri_results (success/failures) = "+conflict_resoultion_results[0]+" / "+conflict_resoultion_results[1]);
if ((dual_tri_results[0] == 0) &&(conflict_resoultion_results[0] == 0)) break; if ((dual_tri_results[0] == 0) &&(conflict_resoultion_results[0] == 0)) break;
} }
/*
int [] conflicts1_stats = st.getNumConflicts( int [] conflicts1_stats = st.getNumConflicts(
conflicts0, conflicts0,
1); // -1); // debugLevel); 1); // -1); // debugLevel);
st.printConflictSummary(conflicts1_stats); st.printConflictSummary(conflicts1_stats);
*/
Conflicts conflicts1_stats = new Conflicts(
conflicts0,
st,
-1); // debugLevel);
conflicts1_stats.printConflictSummary("Detected conflicts (all):", true,false,false);
conflicts1_stats.printConflictSummary("Detected conflicts (ortho-diag-ortho):", false, true,false);
conflicts1_stats.printConflictSummary("Detected conflicts(ortho-ortho-diag):", false, false, true);
/* /*
for (int pass = 0; pass < 10; pass ++) { for (int pass = 0; pass < 10; pass ++) {
int [] dual_tri_results = st. resolveDualTriangularConflicts( int [] dual_tri_results = st. resolveDualTriangularConflicts(
...@@ -3623,8 +3641,11 @@ public class TileProcessor { ...@@ -3623,8 +3641,11 @@ public class TileProcessor {
0, // final int debugLevel) 0, // final int debugLevel)
clt_parameters.tileX, clt_parameters.tileX,
clt_parameters.tileY); clt_parameters.tileY);
st.detectTriangularConflicts(
1); // final int debugLevel) System.out.println("********* Put here conflict resolution again ! *********");
// st.detectTriangularConflicts(
// 1); // 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