Changeset 1235 in josm


Ignore:
Timestamp:
2009-01-10T20:51:48+01:00 (15 years ago)
Author:
ulfl
Message:

first set of performance optimizations:

  • don't call Main.pref.get() when getting a style name, cache the name and only update once for each visitAll
  • check first, if a Way/Node to display is visible at all
Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1221 r1235  
    7676     */
    7777    public void visit(Node n) {
     78        // check, if the node is visible at all
     79        Point p = nc.getPoint(n.eastNorth);
     80        if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
     81       
    7882        IconElemStyle nodeStyle = (IconElemStyle)styles.get(n);
    7983        if (nodeStyle != null && isZoomOk(nodeStyle))
     
    9599            return;
    96100
     101        // check, if the way is visible at all
     102        Polygon polygon = new Polygon();
     103        for (Node n : w.nodes)
     104        {
     105            Point p = nc.getPoint(n.eastNorth);
     106            polygon.addPoint(p.x,p.y);
     107        }
     108        if(!isPolygonVisible(polygon))
     109            return;
     110       
    97111        ElemStyle wayStyle = styles.get(w);
    98112
     
    104118        if(wayStyle!=null)
    105119        {
    106             boolean area = false;
    107120            if(wayStyle instanceof LineElemStyle)
    108121                l = (LineElemStyle)wayStyle;
     
    111124                areacolor = ((AreaElemStyle)wayStyle).color;
    112125                l = ((AreaElemStyle)wayStyle).line;
    113                 area = true;
    114             }
    115             if (area && fillAreas)
    116                 drawWayAsArea(w, areacolor);
     126                if (fillAreas)
     127                    drawWayAsArea(w, areacolor);
     128            }
    117129        }
    118130
     
    129141        int realWidth = 0; //the real width of the element in meters
    130142        boolean dashed = false;
     143        Node lastN;
    131144
    132145        if(l != null)
     
    147160            color = selectedColor;
    148161
    149         Node lastN;
     162        // draw overlays under the way
    150163        if(l != null && l.overlays != null)
    151164        {
     
    168181        }
    169182
     183        // draw the way
    170184        lastN = null;
    171185        for(Node n : w.nodes)
     
    176190        }
    177191
     192        // draw overlays above the way
    178193        if(l != null && l.overlays != null)
    179194        {
     
    799814        alreadyDrawnAreas = new LinkedList<Way>();
    800815        selectedCall = false;
    801 
     816       
     817        // update the style name, just in case the user changed it in the meantime
     818        styles.updateStyleName();
     819       
    802820        if(profiler)
    803821        {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1223 r1235  
    99import java.awt.Graphics2D;
    1010import java.awt.Point;
     11import java.awt.Polygon;
    1112import java.awt.Rectangle;
    1213import java.awt.RenderingHints;
     
    357358    }
    358359
     360    protected boolean isPolygonVisible(Polygon polygon) {
     361        Rectangle bounds = polygon.getBounds();
     362                if (bounds.x > nc.getWidth()) return false;
     363                else if (bounds.y > nc.getHeight()) return false;
     364                else if (bounds.x + polygon.getBounds().width < 0) return false;
     365                else if (bounds.y + polygon.getBounds().height < 0) return false;
     366       
     367        return true;
     368    }
     369       
    359370    public void setGraphics(Graphics g) {
    360371        this.g = g;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r1195 r1235  
    3131    }
    3232    HashMap<String, StyleSet> styleSet;
     33    String styleName;
    3334
    3435    public ElemStyles()
    3536    {
    3637        styleSet = new HashMap<String, StyleSet>();
     38        updateStyleName();
     39    }
     40
     41    public void updateStyleName() {
     42        // Main.pref.get() is slow when done thousands of times, do it once here and cache it
     43        styleName = Main.pref.get("mappaint.style", "standard");
    3744    }
    3845
     
    7885    {
    7986        if(name == null)
    80             name = Main.pref.get("mappaint.style", "standard");
     87            name = styleName;
    8188        StyleSet s = styleSet.get(name);
    8289        if(create && s == null)
Note: See TracChangeset for help on using the changeset viewer.