Refactor S3DB layer (#452)
This commit is contained in:
98
vtm/src/org/oscim/layers/tile/buildings/S3DBTileLayer.java
Normal file
98
vtm/src/org/oscim/layers/tile/buildings/S3DBTileLayer.java
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.layers.tile.buildings;
|
||||
|
||||
import org.oscim.layers.tile.TileLayer;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.layers.tile.TileRenderer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
import org.oscim.renderer.OffscreenRenderer;
|
||||
import org.oscim.renderer.OffscreenRenderer.Mode;
|
||||
import org.oscim.tiling.TileSource;
|
||||
|
||||
public class S3DBTileLayer extends TileLayer {
|
||||
|
||||
private final static int MAX_CACHE = 32;
|
||||
|
||||
private final static int MIN_ZOOM = 16;
|
||||
private final static int MAX_ZOOM = 16;
|
||||
|
||||
private final TileSource mTileSource;
|
||||
|
||||
public S3DBTileLayer(Map map, TileSource tileSource) {
|
||||
this(map, tileSource, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple-3D-Buildings OSCIM4 Tile Layer
|
||||
*
|
||||
* @param map Stored map workaround
|
||||
* @param tileSource Source of loaded tiles in {@link org.oscim.layers.tile.vector.VectorTileLayer}
|
||||
* @param fxaa Switch on Fast Approximate Anti-Aliasing
|
||||
* @param ssao Switch on Screen Space Ambient Occlusion
|
||||
*/
|
||||
public S3DBTileLayer(Map map, TileSource tileSource, boolean fxaa, boolean ssao) {
|
||||
super(map, new TileManager(map, MAX_CACHE));
|
||||
setRenderer(new S3DBTileRenderer(fxaa, ssao));
|
||||
|
||||
mTileManager.setZoomLevel(MIN_ZOOM, MAX_ZOOM);
|
||||
mTileSource = tileSource;
|
||||
initLoader(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3DBTileLoader createLoader() {
|
||||
return new S3DBTileLoader(getManager(), mTileSource);
|
||||
}
|
||||
|
||||
public static class S3DBTileRenderer extends TileRenderer {
|
||||
LayerRenderer mRenderer;
|
||||
|
||||
public S3DBTileRenderer(boolean fxaa, boolean ssao) {
|
||||
mRenderer = new BuildingRenderer(this, MIN_ZOOM, MAX_ZOOM, true, false);
|
||||
|
||||
if (fxaa || ssao) {
|
||||
Mode mode = Mode.FXAA;
|
||||
if (fxaa && ssao)
|
||||
mode = Mode.SSAO_FXAA;
|
||||
else if (ssao)
|
||||
mode = Mode.SSAO;
|
||||
mRenderer = new OffscreenRenderer(mode, mRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(GLViewport v) {
|
||||
super.update(v);
|
||||
mRenderer.update(v);
|
||||
setReady(mRenderer.isReady());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void render(GLViewport v) {
|
||||
mRenderer.render(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setup() {
|
||||
mRenderer.setup();
|
||||
return super.setup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,11 +128,11 @@ class S3DBTileLoader extends TileLoader {
|
||||
|
||||
int c = 0;
|
||||
if (element.tags.containsKey(OSCIM4_KEY_COLOR)) {
|
||||
c = S3DBLayer.getColor(element.tags.getValue(OSCIM4_KEY_COLOR), isRoof);
|
||||
c = S3DBUtils.getColor(element.tags.getValue(OSCIM4_KEY_COLOR), isRoof);
|
||||
}
|
||||
|
||||
if (c == 0 && element.tags.containsKey(OSCIM4_KEY_MATERIAL)) {
|
||||
c = S3DBLayer.getMaterialColor(element.tags.getValue(OSCIM4_KEY_MATERIAL), isRoof);
|
||||
c = S3DBUtils.getMaterialColor(element.tags.getValue(OSCIM4_KEY_MATERIAL), isRoof);
|
||||
}
|
||||
|
||||
if (c == 0) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2017 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -17,96 +18,27 @@
|
||||
package org.oscim.layers.tile.buildings;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.layers.tile.TileLayer;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.layers.tile.TileRenderer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
import org.oscim.renderer.OffscreenRenderer;
|
||||
import org.oscim.renderer.OffscreenRenderer.Mode;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.utils.ColorUtil;
|
||||
import org.oscim.utils.ColorsCSS;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class S3DBLayer extends TileLayer {
|
||||
static final Logger log = LoggerFactory.getLogger(S3DBLayer.class);
|
||||
|
||||
private final static int MAX_CACHE = 32;
|
||||
|
||||
private final static int MIN_ZOOM = 16;
|
||||
private final static int MAX_ZOOM = 16;
|
||||
/**
|
||||
* Provides utils for S3DB layers.
|
||||
*/
|
||||
public final class S3DBUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(S3DBUtils.class);
|
||||
|
||||
/* TODO get from theme */
|
||||
private final static double HSV_S = 0.7;
|
||||
private final static double HSV_V = 1.2;
|
||||
|
||||
private final TileSource mTileSource;
|
||||
|
||||
public S3DBLayer(Map map, TileSource tileSource) {
|
||||
this(map, tileSource, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple-3D-Buildings OSCIM4 Tile Layer
|
||||
*
|
||||
* @param map Stored map workaround
|
||||
* @param tileSource Source of loaded tiles in {@link org.oscim.layers.tile.vector.VectorTileLayer}
|
||||
* @param fxaa Switch on Fast Approximate Anti-Aliasing
|
||||
* @param ssao Switch on Screen Space Ambient Occlusion
|
||||
* @param color the color as string (see http://wiki.openstreetmap.org/wiki/Key:colour)
|
||||
* @param roof declare if color is used for roofs
|
||||
* @return the color as integer (8 bit each a, r, g, b)
|
||||
*/
|
||||
public S3DBLayer(Map map, TileSource tileSource, boolean fxaa, boolean ssao) {
|
||||
super(map, new TileManager(map, MAX_CACHE));
|
||||
setRenderer(new S3DBRenderer(fxaa, ssao));
|
||||
|
||||
mTileManager.setZoomLevel(MIN_ZOOM, MAX_ZOOM);
|
||||
mTileSource = tileSource;
|
||||
initLoader(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected S3DBTileLoader createLoader() {
|
||||
return new S3DBTileLoader(getManager(), mTileSource);
|
||||
}
|
||||
|
||||
public static class S3DBRenderer extends TileRenderer {
|
||||
LayerRenderer mRenderer;
|
||||
|
||||
public S3DBRenderer(boolean fxaa, boolean ssao) {
|
||||
mRenderer = new BuildingRenderer(this, MIN_ZOOM, MAX_ZOOM, true, false);
|
||||
|
||||
if (fxaa || ssao) {
|
||||
Mode mode = Mode.FXAA;
|
||||
if (fxaa && ssao)
|
||||
mode = Mode.SSAO_FXAA;
|
||||
else if (ssao)
|
||||
mode = Mode.SSAO;
|
||||
mRenderer = new OffscreenRenderer(mode, mRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update(GLViewport v) {
|
||||
super.update(v);
|
||||
mRenderer.update(v);
|
||||
setReady(mRenderer.isReady());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void render(GLViewport v) {
|
||||
mRenderer.render(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setup() {
|
||||
mRenderer.setup();
|
||||
return super.setup();
|
||||
}
|
||||
}
|
||||
|
||||
static int getColor(String color, boolean roof) {
|
||||
public static int getColor(String color, boolean roof) {
|
||||
|
||||
if (color.charAt(0) == '#') {
|
||||
int c = Color.parseColor(color, Color.CYAN);
|
||||
@@ -155,7 +87,12 @@ public class S3DBLayer extends TileLayer {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getMaterialColor(String material, boolean roof) {
|
||||
/**
|
||||
* @param material the material as string (see http://wiki.openstreetmap.org/wiki/Key:material and following pages)
|
||||
* @param roof declare if material is used for roofs
|
||||
* @return the color as integer (8 bit each a, r, g, b)
|
||||
*/
|
||||
public static int getMaterialColor(String material, boolean roof) {
|
||||
|
||||
if (roof) {
|
||||
if ("glass".equals(material))
|
||||
@@ -210,4 +147,7 @@ public class S3DBLayer extends TileLayer {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private S3DBUtils() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user