/* Copyright (C) 2001, 2006 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved. */ package gov.nasa.worldwind.layers; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.avlist.AVList; import gov.nasa.worldwind.avlist.AVListImpl; import gov.nasa.worldwind.awt.WorldWindowGLCanvas; import gov.nasa.worldwind.geom.Angle; import gov.nasa.worldwind.geom.LatLon; import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.globes.ElevationModel; import gov.nasa.worldwind.globes.Globe; import gov.nasa.worldwind.util.LevelSet; import java.awt.*; import java.awt.image.BufferedImage; /** * Procedural layer example * @author Patrick Murris * @version $Id:$ */ public class ProceduralTestLayer extends ProceduralTiledImageLayer { public ProceduralTestLayer() { super(makeLevels()); this.setUseTransparentTextures(true); } private static LevelSet makeLevels() { AVList params = new AVListImpl(); params.setValue(AVKey.TILE_WIDTH, 128); params.setValue(AVKey.TILE_HEIGHT, 128); params.setValue(AVKey.DATA_CACHE_NAME, "Tests/ProceduralTests"); params.setValue(AVKey.SERVICE, "*"); params.setValue(AVKey.DATASET_NAME, "*"); params.setValue(AVKey.FORMAT_SUFFIX, ".png"); params.setValue(AVKey.NUM_LEVELS, 10); params.setValue(AVKey.NUM_EMPTY_LEVELS, 4); params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(36d), Angle.fromDegrees(36d))); params.setValue(AVKey.SECTOR, Sector.FULL_SPHERE); return new LevelSet(params); } private WorldWindowGLCanvas wwd; public void setWwd(WorldWindowGLCanvas wwd) { this.wwd = wwd; } protected BufferedImage createTileImage(TextureTile tile, BufferedImage image) { int width = tile.getLevel().getTileWidth(); int height = tile.getLevel().getTileHeight(); Graphics2D g2 = image.createGraphics(); if (this.wwd != null) { Globe globe = this.wwd.getModel().getGlobe(); double latStep = tile.getSector().getDeltaLatDegrees() / height; double lonStep = tile.getSector().getDeltaLonDegrees() / width; // Paint elevations in different colors for (int x = 0; x < width; x++) { double lon = tile.getSector().getMinLongitude().degrees + lonStep * x + lonStep / 2; for (int y = 0; y < height; y++) { double lat = tile.getSector().getMaxLatitude().degrees - latStep * y - latStep / 2; double el = globe.getElevation(Angle.fromDegrees(lat), Angle.fromDegrees(lon)); float hue = (float)((el - globe.getMinElevation()) / (globe.getMaxElevation() - globe.getMinElevation())); hue = (10 * hue) % 1; image.setRGB(x, y, Color.HSBtoRGB(hue, 1f, 1f)); } } } else { // Draw a red cross on white background g2.setPaint(Color.WHITE); g2.fillRect(0, 0, width, height); g2.setPaint(Color.RED); g2.drawLine(0, 0, width , height); g2.drawLine(0, height, width , 0); } return image; } @Override public String toString() { return "Procedural Test Layer"; } }