76 lines
1.7 KiB
Java
76 lines
1.7 KiB
Java
package sparseviewer.interp;
|
|
|
|
public class InterpolationResult {
|
|
|
|
private final Grid2D grid;
|
|
private final float[] pixels;
|
|
private final double zmin;
|
|
private final double zmax;
|
|
|
|
public InterpolationResult(Grid2D grid, float[] pixels) {
|
|
this.grid = grid;
|
|
this.pixels = pixels;
|
|
|
|
double min = Double.POSITIVE_INFINITY;
|
|
double max = Double.NEGATIVE_INFINITY;
|
|
|
|
for (int i = 0; i < pixels.length; i++) {
|
|
float v = pixels[i];
|
|
|
|
if (Float.isNaN(v) || Float.isInfinite(v)) {
|
|
continue;
|
|
}
|
|
|
|
if (v < min) {
|
|
min = v;
|
|
}
|
|
|
|
if (v > max) {
|
|
max = v;
|
|
}
|
|
}
|
|
|
|
if (min == Double.POSITIVE_INFINITY || max == Double.NEGATIVE_INFINITY) {
|
|
min = 0.0;
|
|
max = 1.0;
|
|
}
|
|
|
|
if (min == max) {
|
|
min -= 1.0;
|
|
max += 1.0;
|
|
}
|
|
|
|
this.zmin = min;
|
|
this.zmax = max;
|
|
}
|
|
|
|
public Grid2D getGrid() {
|
|
return grid;
|
|
}
|
|
|
|
public float[] getPixels() {
|
|
return pixels;
|
|
}
|
|
|
|
public double getZMin() {
|
|
return zmin;
|
|
}
|
|
|
|
public double getZMax() {
|
|
return zmax;
|
|
}
|
|
|
|
public float getValueAtIndex(int ix, int iy) {
|
|
if (ix < 0 || iy < 0 || ix >= grid.getWidth() || iy >= grid.getHeight()) {
|
|
return Float.NaN;
|
|
}
|
|
|
|
return pixels[iy * grid.getWidth() + ix];
|
|
}
|
|
|
|
public float getNearestValue(double x, double y) {
|
|
int ix = grid.xToIndex(x);
|
|
int iy = grid.yToIndex(y);
|
|
return getValueAtIndex(ix, iy);
|
|
}
|
|
} |