Changeset 11451 in josm
 Timestamp:
 20170111T20:06:51+01:00 (7 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r11436 r11451 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 … … 834 834 835 835 // alpha with preoffset, 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 … … 852 852 // transform into lookup table 853 853 return colorTable; 854 } 855 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); 854 869 } 855 870 … … 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 … … 925 945 gB.setStroke(backStroke); gB.setComposite(backComp); 926 946 927 // for all points, draw single lines by using optimize drawing 947 // get last point in list 948 final WayPoint lastPnt = !listSegm.isEmpty() ? listSegm.get(listSegm.size()  1) : null; 949 950 // for all points, draw single lines by using optimized 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()); 955 956 // end of line segment or end of list reached 957 if (!trkPnt.drawLine  (lastPnt == trkPnt)) { 932 958 933 959 // convert to primitive type … … 946 972 } 947 973 948 // drop used p ints974 // drop used points 949 975 heatMapPolyX.clear(); heatMapPolyY.clear(); 950 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 } 976 } 977 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 } … … 966 987 * @param imgGray gray scale input image 967 988 * @param sampleRaster the line with for drawing 968 */ 969 private void drawHeatMapGrayMap(Graphics2D g, BufferedImage imgGray, int sampleRaster) { 989 * @param outlineWidth line width for outlines 990 */ 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(); 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)); 979 1010 980 1011 int lastPixelY = 0; … … 1001 1032 // restart > use initial sample 1002 1033 if (0 == y) { 1003 lastPixelY = 0; lastPixelColor = thePixelColor; 1004 } 1005 1006 // different color to last one ? 1007 if (Math.abs(lastPixelColor  thePixelColor) > 1) { 1008 1009 // draw only foreground pixels, skip small variations 1010 if (lastPixelColor > 1+1) { 1034 lastPixelY = 0; lastPixelColor = thePixelColor  1; 1035 } 1036 1037 boolean bDrawIt = false; 1038 1039 // when one of segment is mapped to black 1040 bDrawIt = bDrawIt  (lastPixelColor == 0)  (thePixelColor == 0); 1041 1042 // different color 1043 bDrawIt = bDrawIt  (Math.abs(lastPixelColorthePixelColor) > 0); 1044 1045 // when line is finished draw always 1046 bDrawIt = bDrawIt  (y >= (maxPixelYoffY)); 1047 1048 if (bDrawIt) { 1049 1050 // draw only foreground pixels 1051 if (lastPixelColor > 0) { 1011 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; … … 1028 1067 } 1029 1068 } 1069 1070 // recover 1071 g.setStroke(oldStroke); 1030 1072 } 1031 1073 … … 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  … … 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 … … 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 … … 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, 1149 lineWidthB > 2 ? (lineWidthB / 2) : 1, 1150 lineWidth > 2 ? (lineWidth  2) : 1); 1107 1151 } 1108 1152
Note: See TracChangeset
for help on using the changeset viewer.