Changeset 1254 in josm for trunk/src/org


Ignore:
Timestamp:
2009-01-11T20:11:07+01:00 (15 years ago)
Author:
ulfl
Message:

mappaint major performance improvements:

  • cache mappaint style and isArea information in OsmPrimitive
  • don't call alreadyDrawn.contains() - seems that ends up in n2 searches
Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r1214 r1254  
    1919import org.openstreetmap.josm.tools.DateParser;
    2020import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.gui.mappaint.ElemStyle;
    2122
    2223
     
    139140    private static Collection<String> directionKeys = null;
    140141
     142       
     143    /* mappaint style cache */
     144    public ElemStyle mappaintStyle = null;
     145    public boolean isMappaintArea = false;
     146       
    141147    /**
    142148     * Implementation of the visitor scheme. Subclasses have to call the correct
     
    214220        checkTagged();
    215221        checkDirectionTagged();
     222        mappaintStyle = null;
    216223    }
    217224    /**
     
    226233        checkTagged();
    227234        checkDirectionTagged();
     235        mappaintStyle = null;
    228236    }
    229237
     
    262270        tagged = osm.tagged;
    263271        incomplete = osm.incomplete;
     272        mappaintStyle = null;
    264273    }
    265274
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1240 r1254  
    5353    protected Collection<OsmPrimitive> alreadyDrawn;
    5454    protected Collection<Way> alreadyDrawnAreas;
     55    protected Boolean useStyleCache;
     56   
     57    protected int profilerVisibleNodes;
     58    protected int profilerVisibleWays;
     59    protected int profilerVisibleAreas;
    5560
    5661    protected boolean isZoomOk(ElemStyle e) {
     
    6772        // XXX - do we need a Preference setting for this (if things vary widely)?
    6873        return !(circum >= e.maxScale / 22 || circum < e.minScale / 22);
     74    }
     75
     76    public ElemStyle getPrimitiveStyle(OsmPrimitive osm) {
     77        if(!useStyleCache)
     78            return (styles != null) ? (IconElemStyle)styles.get(osm) : null;
     79
     80        if(osm.mappaintStyle == null) {
     81            osm.mappaintStyle =  styles.get(osm);
     82            osm.isMappaintArea = styles.isArea(osm);
     83        }
     84        return osm.mappaintStyle;
     85    }
     86
     87    public boolean isPrimitiveArea(OsmPrimitive osm) {
     88        if(!useStyleCache)
     89            return styles.isArea((Way)osm);
     90
     91        if(osm.mappaintStyle == null) {
     92            osm.mappaintStyle = styles.get(osm);
     93            osm.isMappaintArea = styles.isArea(osm);
     94        }
     95        return osm.isMappaintArea;
    6996    }
    7097
     
    80107        if ((!selectedCall && n.selected) || (p.x < 0) || (p.y < 0)
    81108        || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
    82 
    83         IconElemStyle nodeStyle = styles != null ? (IconElemStyle)styles.get(n) : null;
     109       
     110        profilerVisibleNodes++;
     111       
     112        IconElemStyle nodeStyle = (IconElemStyle)getPrimitiveStyle(n);
    84113        if (nodeStyle != null && isZoomOk(nodeStyle))
    85114            drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected);
     
    104133        if(!isPolygonVisible(polygon))
    105134            return;
    106 
    107         ElemStyle wayStyle = styles != null ? styles.get(w) : null;
     135           
     136        ElemStyle wayStyle = getPrimitiveStyle(w);
    108137
    109138        if(!isZoomOk(wayStyle))
    110139            return;
    111140
    112         LineElemStyle l = null;
    113         Color areacolor = untaggedColor;
    114         if(wayStyle!=null)
    115         {
    116             if(wayStyle instanceof LineElemStyle)
    117                 l = (LineElemStyle)wayStyle;
    118             else if (wayStyle instanceof AreaElemStyle)
    119             {
    120                 areacolor = ((AreaElemStyle)wayStyle).color;
    121                 l = ((AreaElemStyle)wayStyle).line;
    122                 if (fillAreas)
    123                     drawArea(polygon, w.selected ? selectedColor : areacolor);
    124             }
    125         }
    126 
    127         drawWay(w, l, areacolor, w.selected);
     141        if(wayStyle==null)
     142        {
     143            // way without style
     144            profilerVisibleWays++;
     145            drawWay(w, null, untaggedColor, w.selected);
     146        }
     147        else if(wayStyle instanceof LineElemStyle)
     148        {
     149            // way with line style
     150            profilerVisibleWays++;
     151            drawWay(w, (LineElemStyle)wayStyle, untaggedColor, w.selected);
     152        }
     153        else if (wayStyle instanceof AreaElemStyle)
     154        {
     155            // way with area style
     156            if (fillAreas)
     157            {
     158                profilerVisibleAreas++;
     159                drawArea(polygon, w.selected ? selectedColor : ((AreaElemStyle)wayStyle).color);
     160            }
     161            drawWay(w, ((AreaElemStyle)wayStyle).line, ((AreaElemStyle)wayStyle).color, w.selected);
     162        }
    128163    }
    129164
     
    785820
    786821        boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
     822        useStyleCache = Main.pref.getBoolean("mappaint.cache",true);
     823        fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);
     824        fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     825
    787826        long profilerStart = java.lang.System.currentTimeMillis();
    788827        long profilerLast = profilerStart;
    789828        int profilerN;
    790829        if(profiler)
    791         {
    792             System.out.println("Mappaint Profiler");
    793         }
     830            System.out.println("Mappaint Profiler (" +
     831                (useStyleCache ? "cache=true, " : "cache=false, ") +
     832                (fillAreas ? "fillareas=true, " : "fillareas=false, ") +
     833                "fillalpha=" + fillAlpha + "%)");
    794834
    795835        getSettings(virtual);
    796836        useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false);
    797837        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false);
    798         fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);
    799         fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
    800838        circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
    801839        styles = MapPaintStyles.getStyles().getStyleSet();
     
    808846        alreadyDrawnAreas = new LinkedList<Way>();
    809847        selectedCall = false;
     848       
     849        profilerVisibleNodes = 0;
     850        profilerVisibleWays = 0;
     851        profilerVisibleAreas = 0;
    810852
    811853        if(profiler)
     
    831873            if(profiler)
    832874            {
    833                 System.out.format("Relations: %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     875                System.out.format("Relations: %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    834876                profilerLast = java.lang.System.currentTimeMillis();
    835877            }
     
    839881            for (final Way osm : data.ways)
    840882            {
    841                 if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))
    842                 {
    843                     if(styles.isArea((Way)osm) && !alreadyDrawnAreas.contains(osm))
     883                //if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))
     884                if (!osm.incomplete && !osm.deleted)
     885                {
     886                    //if(styles.isArea((Way)osm) && !alreadyDrawnAreas.contains(osm))
     887                    if(isPrimitiveArea(osm))
    844888                    {
    845889                        osm.visit(this);
     
    853897            if(profiler)
    854898            {
    855                 System.out.format("Areas    : %4dms, n=%d\n",  (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     899                System.out.format("Areas    : %4dms, n=%5d, visible=%d\n",
     900                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleAreas);
    856901                profilerLast = java.lang.System.currentTimeMillis();
    857902            }
     
    868913            if(profiler)
    869914            {
    870                 System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     915                System.out.format("Ways     : %4dms, n=%5d, visible=%d\n",
     916                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays);
    871917                profilerLast = java.lang.System.currentTimeMillis();
    872918            }
     
    885931            if(profiler)
    886932            {
    887                 System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     933                System.out.format("Ways     : %4dms, n=%5d, visible=%d\n",
     934                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays);
    888935                profilerLast = java.lang.System.currentTimeMillis();
    889936            }
     
    895942        for (final OsmPrimitive osm : data.getSelected()) {
    896943            if (!osm.incomplete && !osm.deleted
    897             && !(osm instanceof Node) && !alreadyDrawn.contains(osm))
     944            //&& !(osm instanceof Node) && !alreadyDrawn.contains(osm))
     945            && !(osm instanceof Node))
    898946            {
    899947                osm.visit(this);
     
    904952        if(profiler)
    905953        {
    906             System.out.format("Selected : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     954            System.out.format("Selected : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    907955            profilerLast = java.lang.System.currentTimeMillis();
    908956        }
     
    910958        /*** DISPLAY CACHED SEGMENTS (WAYS) NOW ***/
    911959        displaySegments();
    912         /*System.out.println("display segments " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
    913         profilerLast = java.lang.System.currentTimeMillis();*/
     960        /*if(profiler)
     961        {
     962            System.out.format("DS       : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
     963            profilerLast = java.lang.System.currentTimeMillis();
     964        }*/
    914965
    915966        /*** NODES ***/
    916967        profilerN = 0;
    917968        for (final OsmPrimitive osm : data.nodes)
    918             if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))
     969            //if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))
     970            if (!osm.incomplete && !osm.deleted)
    919971            {
    920972                osm.visit(this);
     
    924976        if(profiler)
    925977        {
    926             System.out.format("Nodes    : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     978            System.out.format("Nodes    : %4dms, n=%5d, visible=%d\n",
     979                (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleNodes);
    927980            profilerLast = java.lang.System.currentTimeMillis();
    928981        }
     
    944997            if(profiler)
    945998            {
    946                 System.out.format("Virtual  : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     999                System.out.format("Virtual  : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    9471000                profilerLast = java.lang.System.currentTimeMillis();
    9481001            }
    9491002
    9501003            displaySegments(null);
    951             /*System.out.println("display segments virtual " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
    952             profilerLast = java.lang.System.currentTimeMillis();*/
     1004            /*if(profiler)
     1005            {
     1006                System.out.format("VirtualDS: %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
     1007                profilerLast = java.lang.System.currentTimeMillis();
     1008            }*/
    9531009        }
    9541010
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1196 r1254  
    9898               osm.checkTagged();
    9999               osm.checkDirectionTagged();
     100               osm.mappaintStyle = null;
    100101          }
    101102     }
Note: See TracChangeset for help on using the changeset viewer.