1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
private void testAndSet(double[][] output, int x, int y, double newvalue) {
if(x<0 || x>=this.width) return;
if(y<0 || y>=this.height) return;
double v = output[x][y];
if (v>=0 && v<newvalue) return;
output[x][y] = newvalue;
}
// forward
for (int y=0; y<=height-1; y++) {
for (int x=0; x<=width-1; x++) {
double v = output[x][y];
if (v<0) continue;
for(int k=0;k<chamfer.length;k++) {
int dx = chamfer[k][0];
int dy = chamfer[k][1];
int dt = chamfer[k][2];
testAndSet(output, x+dx, y+dy, v+dt);
if (dy!=0) testAndSet(output, x-dx, y+dy, v+dt);
if (dx!=dy) {
testAndSet(output, x+dy, y+dx, v+dt);
if (dy!=0) testAndSet(output, x-dy, y+dx, v+dt);
}
}
}
}
// backward
for (int y=height-1; y>=0; y--) {
for (int x=width-1; x>=0; x--) {
double v = output[x][y];
if (v<0) continue;
for(int k=0;k<chamfer.length;k++) {
int dx = chamfer[k][0];
int dy = chamfer[k][1];
int dt = chamfer[k][2];
testAndSet(output, x-dx, y-dy, v+dt);
if (dy!=0) testAndSet(output, x+dx, y-dy, v+dt);
if (dx!=dy) {
testAndSet(output, x-dy, y-dx, v+dt);
if (dy!=0) testAndSet(output, x+dy, y-dx, v+dt);
}
}
}
}
// normalize
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
output[x][y] = output[x][y]/normalizer;
return output;
}
} |
Partager