Changeset 29977 in osm for applications


Ignore:
Timestamp:
2013-09-27T02:00:51+02:00 (11 years ago)
Author:
oliverw
Message:

[josm_elevationprofile]: Fixed bug in color interpolation; added 'exp' hint

Location:
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColorMap.java

    r29964 r29977  
    11/**
    2  * This program is free software: you can redistribute it and/or modify it under 
    3  * the terms of the GNU General Public License as published by the 
    4  * Free Software Foundation, either version 3 of the License, or 
    5  * (at your option) any later version. 
     2 * This program is free software: you can redistribute it and/or modify it under
     3 * the terms of the GNU General Public License as published by the
     4 * Free Software Foundation, either version 3 of the License, or
     5 * (at your option) any later version.
    66 *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    9  * See the GNU General Public License for more details. 
     7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
     8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     9 * See the GNU General Public License for more details.
    1010 *
    11  * You should have received a copy of the GNU General Public License along with this program. 
     11 * You should have received a copy of the GNU General Public License along with this program.
    1212 * If not, see <http://www.gnu.org/licenses/>.
    1313 */
     
    3131    private String name;
    3232    private static HashMap<String, ColorMap> colorMaps;
    33    
     33
    3434    static {
    35         colorMaps = new HashMap<String, ColorMap>();   
    36     }
    37    
     35        colorMaps = new HashMap<String, ColorMap>();
     36    }
     37
    3838    // Private ctor to enforce use of create
    39     private ColorMap() {       
    40     }
    41    
     39    private ColorMap() {
     40    }
     41
    4242    public String getName() {
    43         return name;
     43        return name;
    4444    }
    4545
    4646    public void setName(String name) {
    47         this.name = name;
    48     }
    49    
     47        this.name = name;
     48    }
     49
    5050    /**
    5151     * Gets the color according to the given elevation value.
     
    5959            return Color.white;
    6060        }
    61        
     61
    6262        // out of range?
    6363        if (elevation < colorList.get(0).ele) {
    6464            return colorList.get(0).getColor();
    6565        }
    66        
     66
    6767        int last = colorList.size() - 1;
    6868        if (elevation > colorList.get(last).ele) {
    6969            return colorList.get(last).getColor();
    7070        }
    71        
     71
    7272        // find elevation section
    7373        for (int i = 0; i < last; i++) {
    7474            ColorMapEntry e1 = colorList.get(i);
    7575            ColorMapEntry e2 = colorList.get(i + 1);
    76            
     76
    7777            // elevation within range?
    7878            if (e1.getEle() <= elevation && e2.getEle() >= elevation) {
    79                
     79
    8080                // interpolate color between both
    8181                double val = (elevation - e1.getEle()) / (double)(e2.getEle() - e1.getEle());
     
    8383            }
    8484        }
    85        
     85
    8686        // here we should never end!
    8787        throw new RuntimeException("Inconsistent color map - found no entry for elevation " + elevation);
    8888    }
    89    
    90    
     89
     90
    9191    /**
    9292     * Gets the color map with the given name.
     
    9898        if (colorMaps.containsKey(name)) {
    9999            return colorMaps.get(name);
    100         }       
     100        }
    101101        return null;
    102102    }
    103    
    104     /**
    105      * Gets the number of available color maps. 
     103
     104    /**
     105     * Gets the number of available color maps.
    106106     *
    107107     * @return the int
     
    110110        return colorMaps != null ? colorMaps.size() : 0;
    111111    }
    112    
    113    
     112
     113
    114114    /**
    115115     * Gets the available color map names.
     
    118118     * @return the map or <code>null</code>, if no such map exists
    119119     */
    120     public static String[] getNames() {         
     120    public static String[] getNames() {
    121121        return colorMaps.keySet().toArray(new String[size()]);
    122122    }
    123    
     123
    124124    private static void registerColorMap(ColorMap newMap) {
    125125        CheckParameterUtil.ensureParameterNotNull(newMap);
     
    132132        }
    133133    }
    134    
     134
    135135    public static Color interpolate(java.awt.Color c1, java.awt.Color c2, double ratio) {
    136         double r1 = ratio;
     136        double r1 = 1 -ratio;
    137137        // clip
    138138        if (r1 < 0) r1 = 0d;
     
    158158        CheckParameterUtil.ensureParameterNotNull(colors);
    159159        CheckParameterUtil.ensureParameterNotNull(ele);
    160        
     160
    161161        if (colors.length != ele.length) {
    162162            throw new IllegalArgumentException("Arrays colors and ele must have same length: " + colors.length + " vs " + ele.length);
    163163        }
    164        
     164
    165165        ColorMap map = new ColorMap();
    166         map.colorList = new ArrayList<ColorMap.ColorMapEntry>(); 
     166        map.colorList = new ArrayList<ColorMap.ColorMapEntry>();
    167167        map.name = name;
    168168        for (int i = 0; i < ele.length; i++) {
    169169            map.colorList.add(map.new ColorMapEntry(colors[i], ele[i]));
    170170        }
    171        
     171
    172172        // sort by elevation
    173173        Collections.sort(map.colorList);
    174        
     174
    175175        registerColorMap(map);
    176176        return map;
    177177    }
    178    
     178
    179179
    180180    class ColorMapEntry implements Comparable<ColorMapEntry> {
    181         private int ele; // limit       
    182         private Color color;
    183        
     181        private final int ele; // limit
     182        private final Color color;
     183
    184184        public ColorMapEntry(Color color, int ele) {
    185185            super();
     
    197197
    198198        @Override
    199         public int compareTo(ColorMapEntry o) {     
     199        public int compareTo(ColorMapEntry o) {
    200200            return this.ele - o.ele;
    201201        }
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/actions/AddElevationLayerAction.java

    r29964 r29977  
    3232
    3333    public AddElevationLayerAction() {
    34         super(tr("Elevation Grid Layer"), "elevation", tr("Shows elevation grid layer"), null, true);
     34        super(tr("Elevation Grid Layer (experimental!)"), "elevation", tr("Shows elevation grid layer"), null, true);
    3535    }
    3636
  • applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java

    r29964 r29977  
    9292        if (isLoaded()) return;
    9393       
     94        // TODO: Save
     95       
    9496        // We abuse the loadImage method to render the vertices...
    9597        //
     
    113115    }
    114116
     117    /**
     118     * See also <a href="http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_bounding_box">OSM Wiki</a>
     119     * @param x the x
     120     * @param y the y
     121     * @param zoom the zoom
     122     * @return the bounds
     123     */
    115124    private Bounds tile2Bounds(final int x, final int y, final int zoom) {
    116125        Bounds bb = new Bounds(
Note: See TracChangeset for help on using the changeset viewer.