Ticket #13124: josm_ticket_13124_gpx_heat_map_by_kidelo_v4.patch

File josm_ticket_13124_gpx_heat_map_by_kidelo_v4.patch, 4.6 KB (added by kidelo, 7 years ago)

GPX Heat Map Extension by kidelo, version 4

  • src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

     
    10081008        // use basic stroke for outlines and default transparency
    10091009        g.setStroke(new BasicStroke(outlineWidth));
    10101010
    1011         int lastPixelY = 0;
     1011        int lastPixelX = 0;
    10121012        int lastPixelColor = 0;
    10131013
    10141014        // resample gray scale image with line linear weight of next sample in line
    10151015        // process each line and draw pixels / rectangles with same color with one operations
    1016         for (int x = 0; x < maxPixelX; x += offX) {
    1017             for (int y = 0; y < maxPixelY; y += offY) {
     1016        for (int y = 0; y < maxPixelY; y += offY) {
    10181017
    1019                 int thePixelColor = 0;
     1018            // the lines offsets
     1019            final int lastLineOffset = maxPixelX * (y+0);
     1020            final int nextLineOffset = maxPixelX * (y+1);
    10201021
     1022            for (int x = 0; x < maxPixelX; x += offX) {
     1023
     1024                int thePixelColor = 0; int thePixelCount = 0;
     1025
    10211026                // sample the image (it is gray scale)
    1022                 int offset = (x * maxPixelX) + y;
     1027                int offset = lastLineOffset + x;
    10231028
    10241029                // merge next pixels of window of line
    1025                 for (int k = 0; k < offX && offset + k < imgPixels.length; k++) {
     1030                for (int k = 0; k < offX && (offset + k) < nextLineOffset; k++) {
    10261031                    thePixelColor += imgPixels[offset+k] & 0xFF;
     1032                    thePixelCount++;
    10271033                }
    10281034
    10291035                // mean value
    1030                 thePixelColor /= offX;
     1036                thePixelColor = thePixelCount > 0 ? (thePixelColor / thePixelCount) : 0;
    10311037
    10321038                // restart -> use initial sample
    1033                 if (0 == y) {
    1034                     lastPixelY = 0; lastPixelColor = thePixelColor - 1;
     1039                if (0 == x) {
     1040                    lastPixelX = 0; lastPixelColor = thePixelColor - 1;
    10351041                }
    10361042
    10371043                boolean bDrawIt = false;
     
    10551061
    10561062                        // box from from last Y pixel to current pixel
    10571063                        if (drawOutlines) {
    1058                             g.drawRect(lastPixelY, x, offY + y - lastPixelY, offX);
     1064                            g.drawRect(lastPixelX, y, offX + x - lastPixelX, offY);
    10591065                        } else {
    1060                             g.fillRect(lastPixelY, x, offY + y - lastPixelY, offX);
     1066                            g.fillRect(lastPixelX, y, offX + x - lastPixelX, offY);
    10611067                        }
    10621068                    }
    10631069
    10641070                    // restart detection
    1065                     lastPixelY = y; lastPixelColor = thePixelColor;
     1071                    lastPixelX = x; lastPixelColor = thePixelColor;
    10661072                }
    10671073            }
    10681074        }
     
    10801086    private void drawHeatMap(Graphics2D g, MapView mv, List<WayPoint> visibleSegments) {
    10811087
    10821088        // get bounds of screen image and projection, zoom and adjust input parameters
    1083         final Rectangle screenBounds = g.getDeviceConfiguration().getBounds();
     1089        final Rectangle screenBounds = new Rectangle(mv.getWidth(), mv.getHeight());
    10841090        final double zoomScale = mv.getScale();
    10851091
    10861092        // adjust global settings ( zero = default line width )
     
    10881094
    10891095        // 1st setup virtual paint area ----------------------------------------
    10901096
    1091         // HACK: sometime screen bounds does not return valid values when picture is shifted
    1092         // therefore we use a bigger area to avoid missing parts of image
    1093         screenBounds.width = screenBounds.width * 3 / 2;
    1094         screenBounds.height = screenBounds.height * 3 / 2;
    1095 
    10961097        // new image buffer needed
    10971098        final boolean imageSetup = null == heatMapImgGray || !heatMapCacheScreenBounds.equals(screenBounds);
    10981099
     
    11411142            // remember draw parameters
    11421143            heatMapCacheVisibleSegments = visibleSegments.size();
    11431144            heatMapCacheZoomScale = zoomScale;
    1144             heatMapCacheLineWith = lineWidth;
     1145            heatMapCacheLineWith = globalLineWidth;
    11451146        }
    11461147
    11471148        // 4th. Draw data on target layer, map data via color lookup table --------------
    1148         drawHeatMapGrayMap(g, heatMapImgGray,
    1149                 lineWidthB > 2 ? (lineWidthB / 2) : 1,
    1150                 lineWidth > 2 ? (lineWidth - 2) : 1);
     1149        drawHeatMapGrayMap(g, heatMapImgGray, lineWidthB > 2 ? (lineWidthB / 2) : 1, lineWidth > 2 ? (lineWidth - 2) : 1);
    11511150    }
    11521151
    11531152    /**