From f7272dcdcd16d286d57275eda3058f87f1690ce7 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Wed, 6 Mar 2019 21:12:52 +0100 Subject: [PATCH] Render themes: allow HSV colors for S3DB (#695) --- resources/rendertheme.xsd | 3 ++ vtm-themes/resources/assets/vtm/default.xml | 3 +- vtm-themes/resources/assets/vtm/newtron.xml | 3 +- vtm-themes/resources/assets/vtm/osmagray.xml | 3 +- .../resources/assets/vtm/osmarender.xml | 3 +- .../resources/assets/vtm/tronrender.xml | 3 +- .../layers/tile/buildings/S3DBLayer.java | 28 ++++++------- .../layers/tile/buildings/S3DBTileLoader.java | 6 ++- .../layers/tile/buildings/S3DBUtils.java | 41 ++++++++----------- vtm/src/org/oscim/theme/XmlThemeBuilder.java | 9 ++++ .../oscim/theme/styles/ExtrusionStyle.java | 31 +++++++++++++- 11 files changed, 87 insertions(+), 46 deletions(-) diff --git a/resources/rendertheme.xsd b/resources/rendertheme.xsd index 05030d3d..12093a0d 100644 --- a/resources/rendertheme.xsd +++ b/resources/rendertheme.xsd @@ -245,6 +245,9 @@ + + + diff --git a/vtm-themes/resources/assets/vtm/default.xml b/vtm-themes/resources/assets/vtm/default.xml index 78e8fe84..661c5ce7 100644 --- a/vtm-themes/resources/assets/vtm/default.xml +++ b/vtm-themes/resources/assets/vtm/default.xml @@ -647,7 +647,8 @@ - + diff --git a/vtm-themes/resources/assets/vtm/newtron.xml b/vtm-themes/resources/assets/vtm/newtron.xml index 94ad27f1..80173cc6 100644 --- a/vtm-themes/resources/assets/vtm/newtron.xml +++ b/vtm-themes/resources/assets/vtm/newtron.xml @@ -569,7 +569,8 @@ --> - + diff --git a/vtm-themes/resources/assets/vtm/osmagray.xml b/vtm-themes/resources/assets/vtm/osmagray.xml index 5f75f02b..3bb49784 100644 --- a/vtm-themes/resources/assets/vtm/osmagray.xml +++ b/vtm-themes/resources/assets/vtm/osmagray.xml @@ -560,7 +560,8 @@ - + diff --git a/vtm-themes/resources/assets/vtm/osmarender.xml b/vtm-themes/resources/assets/vtm/osmarender.xml index aa25e611..b982cd15 100644 --- a/vtm-themes/resources/assets/vtm/osmarender.xml +++ b/vtm-themes/resources/assets/vtm/osmarender.xml @@ -560,7 +560,8 @@ - + diff --git a/vtm-themes/resources/assets/vtm/tronrender.xml b/vtm-themes/resources/assets/vtm/tronrender.xml index c009506f..b7339c65 100644 --- a/vtm-themes/resources/assets/vtm/tronrender.xml +++ b/vtm-themes/resources/assets/vtm/tronrender.xml @@ -569,7 +569,8 @@ --> - + diff --git a/vtm/src/org/oscim/layers/tile/buildings/S3DBLayer.java b/vtm/src/org/oscim/layers/tile/buildings/S3DBLayer.java index 7cf58eb0..d8a9d97e 100644 --- a/vtm/src/org/oscim/layers/tile/buildings/S3DBLayer.java +++ b/vtm/src/org/oscim/layers/tile/buildings/S3DBLayer.java @@ -159,9 +159,9 @@ public class S3DBLayer extends BuildingLayer { Integer bColor = null; if (mColored) { if ((v = getTransformedValue(element, Tag.KEY_BUILDING_COLOR)) != null) { - bColor = S3DBUtils.getColor(v, false); + bColor = S3DBUtils.getColor(v, extrusion.hsv, false); } else if ((v = getTransformedValue(element, Tag.KEY_BUILDING_MATERIAL)) != null) { - bColor = S3DBUtils.getMaterialColor(v); + bColor = S3DBUtils.getMaterialColor(v, extrusion.hsv, false); } } @@ -179,7 +179,7 @@ public class S3DBLayer extends BuildingLayer { float minRoofHeightS = ExtrusionUtils.mapGroundScale(maxHeight - roofHeight, groundScale) * TILE_SCALE; // Process building and roof - processRoof(element, tile, minRoofHeightS, maxHeightS, bColor, extrusion.colorTop); + processRoof(element, tile, minRoofHeightS, maxHeightS, bColor, extrusion); if (S3DBUtils.calcOutlines(element, minHeightS, minRoofHeightS)) { get(tile).addMeshElement(element, groundScale, bColor); } @@ -248,24 +248,24 @@ public class S3DBLayer extends BuildingLayer { /** * Process the roof parts of building. * - * @param element the MapElement which needs a roof - * @param tile the tile which contains map element - * @param minHeight the height of the underlying building - * @param maxHeight the height of the roof + minHeight (whole building) - * @param buildingColor the color of main building - * @param defaultRoofColor the default color of roof + * @param element the MapElement which needs a roof + * @param tile the tile which contains map element + * @param minHeight the height of the underlying building + * @param maxHeight the height of the roof + minHeight (whole building) + * @param buildingColor the color of main building + * @param extrusion the extrusion style */ private void processRoof(MapElement element, MapTile tile, float minHeight, float maxHeight, - int buildingColor, int defaultRoofColor) { - int roofColor = defaultRoofColor; + int buildingColor, ExtrusionStyle extrusion) { + int roofColor = extrusion.colorTop; String v; if (mColored) { v = getTransformedValue(element, Tag.KEY_ROOF_COLOR); if (v != null) - roofColor = S3DBUtils.getColor(v, false); + roofColor = S3DBUtils.getColor(v, extrusion.hsv, false); else if ((v = getTransformedValue(element, Tag.KEY_ROOF_MATERIAL)) != null) - roofColor = S3DBUtils.getMaterialColor(v); + roofColor = S3DBUtils.getMaterialColor(v, extrusion.hsv, false); } boolean roofOrientationAcross = false; @@ -288,7 +288,7 @@ public class S3DBLayer extends BuildingLayer { if (mTransparent) { // Use transparency of default roof color - roofColor = ExtrusionStyle.blendAlpha(roofColor, Color.aToFloat(defaultRoofColor)); + roofColor = ExtrusionStyle.blendAlpha(roofColor, Color.aToFloat(extrusion.colorTop)); } boolean success; diff --git a/vtm/src/org/oscim/layers/tile/buildings/S3DBTileLoader.java b/vtm/src/org/oscim/layers/tile/buildings/S3DBTileLoader.java index 77064a6e..b57d9cce 100644 --- a/vtm/src/org/oscim/layers/tile/buildings/S3DBTileLoader.java +++ b/vtm/src/org/oscim/layers/tile/buildings/S3DBTileLoader.java @@ -35,6 +35,8 @@ import org.slf4j.LoggerFactory; class S3DBTileLoader extends TileLoader { static final Logger log = LoggerFactory.getLogger(S3DBTileLoader.class); + private static final Color.HSV HSV = new Color.HSV(0f, 0.5f, 1.2f); + private static final String OSCIM4_KEY_COLOR = "c"; private static final String OSCIM4_KEY_MATERIAL = "m"; @@ -125,11 +127,11 @@ class S3DBTileLoader extends TileLoader { int c = 0; if (element.tags.containsKey(OSCIM4_KEY_COLOR)) { - c = S3DBUtils.getColor(element.tags.getValue(OSCIM4_KEY_COLOR), true); + c = S3DBUtils.getColor(element.tags.getValue(OSCIM4_KEY_COLOR), HSV, true); } if (c == 0 && element.tags.containsKey(OSCIM4_KEY_MATERIAL)) { - c = S3DBUtils.getMaterialColor(element.tags.getValue(OSCIM4_KEY_MATERIAL)); + c = S3DBUtils.getMaterialColor(element.tags.getValue(OSCIM4_KEY_MATERIAL), HSV, true); } if (c == 0) { diff --git a/vtm/src/org/oscim/layers/tile/buildings/S3DBUtils.java b/vtm/src/org/oscim/layers/tile/buildings/S3DBUtils.java index e1544082..2de2f934 100644 --- a/vtm/src/org/oscim/layers/tile/buildings/S3DBUtils.java +++ b/vtm/src/org/oscim/layers/tile/buildings/S3DBUtils.java @@ -20,7 +20,6 @@ package org.oscim.layers.tile.buildings; import org.oscim.backend.canvas.Color; import org.oscim.core.GeometryBuffer; import org.oscim.core.Tag; -import org.oscim.utils.ColorUtil; import org.oscim.utils.ColorsCSS; import org.oscim.utils.Tessellator; import org.oscim.utils.geom.GeometryUtils; @@ -42,10 +41,6 @@ import java.util.TreeMap; public final class S3DBUtils { private static final Logger log = LoggerFactory.getLogger(S3DBUtils.class); - /* TODO get from theme */ - private static final double HSV_S = 0.5; - private static final double HSV_V = 1.2; - // Toggle this to debug and improve ridge calculation, you can see the faults in map then. private static final boolean IMPROVE_RIDGE_CALCULATION = false; private static final int SNAP_THRESHOLD = 70; // Threshold for ridge snap calculation (maybe should depend on map scale) @@ -1062,27 +1057,27 @@ public final class S3DBUtils { /** * @param color the color as string (see http://wiki.openstreetmap.org/wiki/Key:colour) + * @param hsv the HSV color values to modify given color * @param relative declare if colors are modified relative to their values * @return the color as integer (8 bit each a, r, g, b) */ - public static int getColor(String color, boolean relative) { - - if (color.charAt(0) == '#') { - int c = Color.parseColor(color, Color.CYAN); - /* hardcoded colors are way too saturated for my taste */ - return ColorUtil.modHsv(c, 1.0, HSV_S, HSV_V, relative); - } - + public static int getColor(String color, Color.HSV hsv, boolean relative) { if ("transparent".equals(color)) return Color.get(0, 1, 1, 1); - Integer css = ColorsCSS.get(color); + int c; + if (color.charAt(0) == '#') + c = Color.parseColor(color, Color.CYAN); + else { + Integer css = ColorsCSS.get(color); + if (css == null) { + log.debug("unknown color:{}", color); + c = Color.CYAN; + } else + c = css; + } - if (css != null) - return ColorUtil.modHsv(css, 1.0, HSV_S, HSV_V, relative); - - log.debug("unknown color:{}", color); - return 0; + return hsv.mod(c, relative); } /** @@ -1221,9 +1216,10 @@ public final class S3DBUtils { /** * @param material the material as string (see http://wiki.openstreetmap.org/wiki/Key:material and following pages) + * @param hsv the HSV color values to modify given material * @return the color as integer (8 bit each a, r, g, b) */ - public static int getMaterialColor(String material) { + public static int getMaterialColor(String material, Color.HSV hsv, boolean relative) { int c; if (material.charAt(0) == '#') { @@ -1295,12 +1291,11 @@ public final class S3DBUtils { default: c = Color.CYAN; log.debug("unknown material:{}", material); + break; } } - // TODO option to mod color c with hsv - - return c; + return hsv.mod(c, relative); } /** diff --git a/vtm/src/org/oscim/theme/XmlThemeBuilder.java b/vtm/src/org/oscim/theme/XmlThemeBuilder.java index 6f1801fe..6842b22a 100644 --- a/vtm/src/org/oscim/theme/XmlThemeBuilder.java +++ b/vtm/src/org/oscim/theme/XmlThemeBuilder.java @@ -1223,6 +1223,15 @@ public class XmlThemeBuilder extends DefaultHandler { else if ("line-color".equals(name)) b.colorLine(Color.parseColor(value)); + else if ("hsv-h".equals(name)) + b.hsvHue(Double.parseDouble(value)); + + else if ("hsv-s".equals(name)) + b.hsvSaturation(Double.parseDouble(value)); + + else if ("hsv-v".equals(name)) + b.hsvValue(Double.parseDouble(value)); + else if ("default-height".equals(name)) b.defaultHeight(Integer.parseInt(value)); diff --git a/vtm/src/org/oscim/theme/styles/ExtrusionStyle.java b/vtm/src/org/oscim/theme/styles/ExtrusionStyle.java index 2a3573a1..e7457776 100644 --- a/vtm/src/org/oscim/theme/styles/ExtrusionStyle.java +++ b/vtm/src/org/oscim/theme/styles/ExtrusionStyle.java @@ -1,7 +1,7 @@ /* * Copyright 2013 Hannes Janetzek * Copyright 2016-2017 devemux86 - * Copyright 2018 Gustl22 + * Copyright 2018-2019 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -27,12 +27,13 @@ public class ExtrusionStyle extends RenderStyle { public final int colorLine; public final int colorSide; public final int colorTop; + public final Color.HSV hsv; public final int defaultHeight; private final int level; public final float[] colors; - public ExtrusionStyle(int level, int colorSide, int colorTop, int colorLine, int defaultHeight) { + public ExtrusionStyle(int level, int colorSide, int colorTop, int colorLine, Color.HSV hsv, int defaultHeight) { this.level = level; this.colorSide = colorSide; @@ -41,6 +42,7 @@ public class ExtrusionStyle extends RenderStyle { this.colors = new float[16]; fillColors(colorSide, colorTop, colorLine, colors); + this.hsv = hsv; this.defaultHeight = defaultHeight; } @@ -54,6 +56,7 @@ public class ExtrusionStyle extends RenderStyle { this.colors = new float[16]; fillColors(colorSide, colorTop, colorLine, colors); + this.hsv = new Color.HSV(b.hsvHue, b.hsvSaturation, b.hsvValue); this.defaultHeight = b.defaultHeight; } @@ -112,6 +115,9 @@ public class ExtrusionStyle extends RenderStyle { public int colorSide; public int colorTop; public int colorLine; + public double hsvHue; + public double hsvSaturation; + public double hsvValue; public int defaultHeight; public ExtrusionBuilder() { @@ -126,6 +132,9 @@ public class ExtrusionStyle extends RenderStyle { this.colorSide = themeCallback != null ? themeCallback.getColor(extrusion.colorSide) : extrusion.colorSide; this.colorTop = themeCallback != null ? themeCallback.getColor(extrusion.colorTop) : extrusion.colorTop; this.colorLine = themeCallback != null ? themeCallback.getColor(extrusion.colorLine) : extrusion.colorLine; + this.hsvHue = extrusion.hsv.hue; + this.hsvSaturation = extrusion.hsv.saturation; + this.hsvValue = extrusion.hsv.value; this.defaultHeight = extrusion.defaultHeight; return self(); @@ -161,6 +170,21 @@ public class ExtrusionStyle extends RenderStyle { return self(); } + public T hsvHue(double hsvHue) { + this.hsvHue = hsvHue; + return self(); + } + + public T hsvSaturation(double hsvSaturation) { + this.hsvSaturation = hsvSaturation; + return self(); + } + + public T hsvValue(double hsvValue) { + this.hsvValue = hsvValue; + return self(); + } + public T defaultHeight(int defaultHeight) { this.defaultHeight = defaultHeight; return self(); @@ -172,6 +196,9 @@ public class ExtrusionStyle extends RenderStyle { colorSide = Color.TRANSPARENT; colorTop = Color.TRANSPARENT; colorLine = Color.TRANSPARENT; + hsvHue = 0; + hsvSaturation = 1; + hsvValue = 1; defaultHeight = 12; // 12m default return self(); }