2022-04-07 18:43:21 +02:00

50 lines
1.7 KiB
Java

package ch.epfl.alpano.dem;
import static java.lang.Math.max;
import static java.lang.Math.min;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import ch.epfl.alpano.GeoPoint;
import static java.lang.Math.toRadians;
final class DrawHgtDEM2 {
final static double ORIGIN_LON = toRadians(6.0);
final static double ORIGIN_LAT = toRadians(45.0);
final static double WIDTH = toRadians(0.1);
final static int IMAGE_SIZE = 1200;
final static double MIN_ELEVATION = 00;
final static double MAX_ELEVATION = 500;
public static void main(String[] as) throws Exception {
DiscreteElevationModel dDEM = new HgtDiscreteElevationModel(null);
ContinuousElevationModel cDEM =
new ContinuousElevationModel(dDEM);
double step = WIDTH / (IMAGE_SIZE - 1);
BufferedImage i = new BufferedImage(IMAGE_SIZE,
IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < IMAGE_SIZE; ++x) {
double lon = ORIGIN_LON + x * step;
for (int y = 0; y < IMAGE_SIZE; ++y) {
double lat = ORIGIN_LAT + y * step;
GeoPoint p = new GeoPoint(lon, lat);
double el =
(cDEM.elevationAt(p) - MIN_ELEVATION)
/ (MAX_ELEVATION - MIN_ELEVATION);
i.setRGB(x, IMAGE_SIZE - 1 - y, gray(el));
}
}
dDEM.close();
ImageIO.write(i, "png", new File("tests/ch/epfl/alpano/dem/dem2.png"));
}
private static int gray(double v) {
double clampedV = max(0, min(v, 1));
int gray = (int) (255.9999 * clampedV);
return (gray << 16) | (gray << 8) | gray;
}
}