Render themes: allow HSV colors for S3DB (#695)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
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<ExtrusionStyle> {
|
||||
colorSide = Color.TRANSPARENT;
|
||||
colorTop = Color.TRANSPARENT;
|
||||
colorLine = Color.TRANSPARENT;
|
||||
hsvHue = 0;
|
||||
hsvSaturation = 1;
|
||||
hsvValue = 1;
|
||||
defaultHeight = 12; // 12m default
|
||||
return self();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user