Ticket #13124: josm_ticket_13124_gpx_heat_map_by_kidelo_v3.patch
File josm_ticket_13124_gpx_heat_map_by_kidelo_v3.patch, 9.7 KB (added by , 7 years ago) |
---|
-
src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
742 742 // 3rd. determine current paint parameters ----------------------------- 743 743 744 744 // alpha value is based on zoom and line with combined with global layer alpha 745 float theLineAlpha = Math.min(Math.max((0.50f/(float) zoomScale)/(globalLineWidth + 1), 0.0 01f), 0.50f) * layerAlpha;745 float theLineAlpha = Math.min(Math.max((0.50f/(float) zoomScale)/(globalLineWidth + 1), 0.01f), 0.50f) * layerAlpha; 746 746 final int theLineWith = (int) (lineWidth / zoomScale) + 1; 747 747 748 748 // 4th setup virtual paint area ---------------------------------------- … … 833 833 int alpha = (int) (Math.sin(i * mapTo90Deg) * 255); 834 834 835 835 // alpha with pre-offset, first color -> full transparent 836 alpha = i > 0 ? ( 75+ alpha) : 0;836 alpha = i > 0 ? (10 + alpha) : 0; 837 837 838 838 // shrink to maximum bound 839 839 if (alpha > 255) { … … 854 854 } 855 855 856 856 /** 857 * Creates a darker color 858 * @param in Color object 859 * @param adjust darker adjustment amount 860 * @return new Color 861 */ 862 protected static Color darkerColor(Color in, float adjust) { 863 864 final float r = ((float) in.getRed()/255); 865 final float g = ((float) in.getGreen()/255); 866 final float b = ((float) in.getBlue()/255); 867 868 return new Color(r*adjust, g*adjust, b*adjust); 869 } 870 871 /** 857 872 * Creates a colormap by using a static color map with 1..n colors (RGB 0.0 ..1.0) 858 873 * @param str the filename (without extension) to look for into data/gpx 859 874 * @return the parsed colormap … … 899 914 if (colorList.isEmpty()) { 900 915 colorList.add(Color.BLACK); 901 916 colorList.add(Color.WHITE); 917 } else { 918 // add additional darker elements to end of list 919 final Color lastColor = colorList.get(colorList.size() - 1); 920 colorList.add(darkerColor(lastColor, 0.975f)); 921 colorList.add(darkerColor(lastColor, 0.950f)); 902 922 } 903 923 904 924 return createColorLut(colorList.toArray(new Color[ colorList.size() ])); … … 924 944 // set initial values 925 945 gB.setStroke(backStroke); gB.setComposite(backComp); 926 946 947 // get last point in list 948 final WayPoint lastPnt = !listSegm.isEmpty() ? listSegm.get(listSegm.size() - 1) : null; 949 927 950 // for all points, draw single lines by using optimize drawing 928 951 for (WayPoint trkPnt : listSegm) { 929 952 930 // something to paint or color changed (new segment needed, decrease performance ;-()931 if (!trkPnt.drawLine && !heatMapPolyX.isEmpty()) {953 // get transformed coordinates 954 final Point paintPnt = mv.getPoint(trkPnt.getEastNorth()); 932 955 956 // end of line segment or end of list reached 957 if (!trkPnt.drawLine || (lastPnt == trkPnt)) { 958 933 959 // convert to primitive type 934 960 final int[] polyXArr = heatMapPolyX.stream().mapToInt(Integer::intValue).toArray(); 935 961 final int[] polyYArr = heatMapPolyY.stream().mapToInt(Integer::intValue).toArray(); … … 945 971 gB.setStroke(backStroke); gB.setComposite(backComp); 946 972 } 947 973 948 // drop used p ints974 // drop used points 949 975 heatMapPolyX.clear(); heatMapPolyY.clear(); 976 } 950 977 951 } else { 952 953 // get transformed coordinates 954 final Point paintPnt = mv.getPoint(trkPnt.getEastNorth()); 955 956 // store only the integer part (make sense because pixel is 1:1 here) 957 heatMapPolyX.add((int) paintPnt.getX()); 958 heatMapPolyY.add((int) paintPnt.getY()); 959 } 978 // store only the integer part (make sense because pixel is 1:1 here) 979 heatMapPolyX.add((int) paintPnt.getX()); 980 heatMapPolyY.add((int) paintPnt.getY()); 960 981 } 961 982 } 962 983 … … 965 986 * @param g the common draw object to use 966 987 * @param imgGray gray scale input image 967 988 * @param sampleRaster the line with for drawing 989 * @param outlineWidth line width for outlines 968 990 */ 969 private void drawHeatMapGrayMap(Graphics2D g, BufferedImage imgGray, int sampleRaster ) {991 private void drawHeatMapGrayMap(Graphics2D g, BufferedImage imgGray, int sampleRaster, int outlineWidth) { 970 992 971 993 final int[] imgPixels = ((DataBufferInt) imgGray.getRaster().getDataBuffer()).getData(); 972 994 973 995 // samples offset and bounds are scaled with line width derived from zoom level 974 final int offX = Math.max(1, sampleRaster / 2);975 final int offY = Math.max(1, sampleRaster / 2);996 final int offX = Math.max(1, sampleRaster); 997 final int offY = Math.max(1, sampleRaster); 976 998 977 999 final int maxPixelX = imgGray.getWidth(); 978 1000 final int maxPixelY = imgGray.getHeight(); 979 1001 1002 // always full or outlines at big samples rasters 1003 final boolean drawOutlines = (outlineWidth > 0) && ((0 == sampleRaster) || (sampleRaster > 8)); 1004 1005 // backup stroke 1006 final Stroke oldStroke = g.getStroke(); 1007 1008 // use basic stroke for outlines and default transparency 1009 g.setStroke(new BasicStroke(outlineWidth)); 1010 980 1011 int lastPixelY = 0; 981 1012 int lastPixelColor = 0; 982 1013 … … 1000 1031 1001 1032 // restart -> use initial sample 1002 1033 if (0 == y) { 1003 lastPixelY = 0; lastPixelColor = thePixelColor ;1034 lastPixelY = 0; lastPixelColor = thePixelColor - 1; 1004 1035 } 1005 1036 1006 // different color to last one ? 1007 if (Math.abs(lastPixelColor - thePixelColor) > 1) { 1037 boolean bDrawIt = false; 1008 1038 1009 // draw only foreground pixels, skip small variations1010 if (lastPixelColor > 1+1) {1039 // when one of segment is mapped to black 1040 bDrawIt = bDrawIt || (lastPixelColor == 0) || (thePixelColor == 0); 1011 1041 1042 // different color 1043 bDrawIt = bDrawIt || (Math.abs(lastPixelColor-thePixelColor) > 0); 1044 1045 // when line is finished draw always 1046 bDrawIt = bDrawIt || (y >= (maxPixelY-offY)); 1047 1048 if (bDrawIt) { 1049 1050 // draw only foreground pixels 1051 if (lastPixelColor > 0) { 1052 1012 1053 // gray to RGB mapping 1013 1054 g.setColor(heatMapLutColor[ lastPixelColor ]); 1014 1055 1015 // start point for draw (1016 int yN = lastPixelY > 0 ? lastPixelY : y;1017 1018 1056 // box from from last Y pixel to current pixel 1019 if ( offX < sampleRaster) {1020 g. fillRect(yN, x, offY + y - yN, offX);1057 if (drawOutlines) { 1058 g.drawRect(lastPixelY, x, offY + y - lastPixelY, offX); 1021 1059 } else { 1022 g. drawRect(yN, x, offY + y - yN, offX);1060 g.fillRect(lastPixelY, x, offY + y - lastPixelY, offX); 1023 1061 } 1024 1062 } 1063 1025 1064 // restart detection 1026 1065 lastPixelY = y; lastPixelColor = thePixelColor; 1027 1066 } 1028 1067 } 1029 1068 } 1069 1070 // recover 1071 g.setStroke(oldStroke); 1030 1072 } 1031 1073 1032 1074 /** … … 1041 1083 final Rectangle screenBounds = g.getDeviceConfiguration().getBounds(); 1042 1084 final double zoomScale = mv.getScale(); 1043 1085 1044 // adjust global settings 1045 final int globalLineWidth = Math.min(Math.max(lineWidth, 1), 20);1086 // adjust global settings ( zero = default line width ) 1087 final int globalLineWidth = (0 == lineWidth) ? 1 : Math.min(Math.max(lineWidth, 1), 20); 1046 1088 1047 1089 // 1st setup virtual paint area ---------------------------------------- 1048 1090 … … 1069 1111 // 2nd. determine current scale factors ------------------------------- 1070 1112 1071 1113 // the line width (foreground: draw extra small footprint line of track) 1072 final int lineWidthB = Math.max((int)(globalLineWidth / zoomScale) + 1, 2);1114 final int lineWidthB = (int) Math.max(1.5f * (globalLineWidth / zoomScale) + 1, 2); 1073 1115 final int lineWidthF = lineWidthB > 2 ? (globalLineWidth - 1) : 0; 1074 1116 1075 1117 // recalculation of image needed … … 1086 1128 heatMapGraph2d.clearRect(0, 0, heatMapImgGray.getWidth(), heatMapImgGray.getHeight()); 1087 1129 1088 1130 // alpha combines both values, therefore the foreground shall be lighter 1089 final float lineAlphaB = Math.min(Math.max((0.40f/(float) zoomScale)/(globalLineWidth + 1), 0.0 01f), 0.50f);1131 final float lineAlphaB = Math.min(Math.max((0.40f/(float) zoomScale)/(globalLineWidth + 1), 0.01f), 0.40f); 1090 1132 final float lineAlphaF = lineAlphaB / 1.5f; 1091 1133 1092 1134 // derive draw parameters and draw … … 1103 1145 } 1104 1146 1105 1147 // 4th. Draw data on target layer, map data via color lookup table -------------- 1106 drawHeatMapGrayMap(g, heatMapImgGray, lineWidthB );1148 drawHeatMapGrayMap(g, heatMapImgGray, lineWidthB > 2 ? lineWidthB / 2 : 1, lineWidth > 2 ? lineWidth-2 : 1); 1107 1149 } 1108 1150 1109 1151 /**