epfl-archive/Alpano/tests/ch/epfl/alpano/DrawPanoramaNew2.java
2022-04-07 18:43:21 +02:00

63 lines
2.2 KiB
Java

package ch.epfl.alpano;
import java.io.File;
import java.util.Locale;
import javax.imageio.ImageIO;
import ch.epfl.alpano.dem.ContinuousElevationModel;
import ch.epfl.alpano.dem.DiscreteElevationModel;
import ch.epfl.alpano.dem.HgtDiscreteElevationModel;
import ch.epfl.alpano.gui.ChannelPainter;
import ch.epfl.alpano.gui.ImagePainter;
import ch.epfl.alpano.gui.PanoramaRenderer;
import ch.epfl.alpano.gui.PanoramaUserParameters;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
import ch.epfl.alpano.gui.PredefinedPanoramas;
final class DrawPanoramaNew2 {
public static void main(String[] as) throws Exception {
PanoramaUserParameters pano = PredefinedPanoramas.JURA_ALPS.get();
ContinuousElevationModel cDEM =generatePredefinedCDEM("./HGT/");
Panorama p = new PanoramaComputer(cDEM)
.computePanorama(pano.panoramaComputeParameters());
ChannelPainter d = p::distanceAt;
ChannelPainter sl = p::slopeAt;
ChannelPainter h = d.div(100000).cycling().mul(360);
ChannelPainter s = d.div(200000).clamped().inverted();
ChannelPainter b = sl.mul(2).div(Math.PI).inverted().mul(0.7).add(0.3);
ChannelPainter o =
d.map(dist -> dist == Float.POSITIVE_INFINITY ? 0 : 1);
ImagePainter l = ImagePainter.hsb(h, s, b, o);
Image i = PanoramaRenderer.renderPanorama(p, l);
ImageIO.write(SwingFXUtils.fromFXImage(i, null),
"png",
new File("tests/ch/epfl/alpano/niesen-profile.png"));
}
private static final ContinuousElevationModel generatePredefinedCDEM(String path){
DiscreteElevationModel DEM1=null;
DiscreteElevationModel DEM2=null;
File file;
for(int i=6;i<=11;++i){
for(int j=45;j<=47;++j){
file = new File(String.format((Locale) null, path+"N%02dE%03d.hgt",j,i));
if(DEM1==null)
DEM1 = new HgtDiscreteElevationModel(file);
DEM1 = new HgtDiscreteElevationModel(file).union(DEM1);
}
if(DEM2==null)
DEM2=DEM1;
DEM2=DEM1.union(DEM2);
DEM1=null;
}
return new ContinuousElevationModel(DEM2);
}
}