Improve ExtrusionBuckets (#459)
+ Add method addPolyElement and addMeshElement + renamed setBuckets to resetBuckets + Add method getGroundScale to MapTile
This commit is contained in:
parent
641db3ade0
commit
97cdfa119d
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.oscim.layers.tile;
|
||||
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.tile.vector.VectorTileLoader;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook;
|
||||
@ -340,6 +341,15 @@ public class MapTile extends Tile {
|
||||
return ((t.tileX % 4) + (t.tileY % 4 * 4) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the corresponding ground scale
|
||||
*/
|
||||
public float getGroundScale() {
|
||||
double lat = MercatorProjection.toLatitude(this.y);
|
||||
return (float) MercatorProjection
|
||||
.groundResolutionWithScale(lat, 1 << this.zoomLevel);
|
||||
}
|
||||
|
||||
public MapTile getProxyChild(int id, byte state) {
|
||||
if ((proxy & (1 << id)) == 0)
|
||||
return null;
|
||||
|
@ -20,7 +20,6 @@
|
||||
package org.oscim.layers.tile.buildings;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
@ -29,12 +28,10 @@ import org.oscim.layers.tile.vector.VectorTileLayer.TileLoaderThemeHook;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.OffscreenRenderer;
|
||||
import org.oscim.renderer.OffscreenRenderer.Mode;
|
||||
import org.oscim.renderer.bucket.ExtrusionBucket;
|
||||
import org.oscim.renderer.bucket.ExtrusionBuckets;
|
||||
import org.oscim.renderer.bucket.RenderBuckets;
|
||||
import org.oscim.theme.styles.ExtrusionStyle;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -157,23 +154,7 @@ public class BuildingLayer extends Layer implements TileLoaderThemeHook {
|
||||
height = extrusion.defaultHeight * 100;
|
||||
|
||||
ExtrusionBuckets ebs = get(tile);
|
||||
|
||||
for (ExtrusionBucket b = ebs.buckets; b != null; b = b.next()) {
|
||||
if (b.getColors() == extrusion.colors) {
|
||||
b.addPoly(element, height, minHeight);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
double lat = MercatorProjection.toLatitude(tile.y);
|
||||
float groundScale = (float) MercatorProjection
|
||||
.groundResolutionWithScale(lat, 1 << tile.zoomLevel);
|
||||
|
||||
ebs.buckets = Inlist.push(ebs.buckets,
|
||||
new ExtrusionBucket(0, groundScale,
|
||||
extrusion.colors));
|
||||
|
||||
ebs.buckets.addPoly(element, height, minHeight);
|
||||
ebs.addPolyElement(element, tile.getGroundScale(), extrusion.colors, height, minHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,7 +215,7 @@ public class BuildingLayer extends Layer implements TileLoaderThemeHook {
|
||||
processElements(tile);
|
||||
get(tile).prepare();
|
||||
} else
|
||||
get(tile).setBuckets(null);
|
||||
get(tile).resetBuckets(null);
|
||||
}
|
||||
|
||||
// private int multi;
|
||||
|
@ -21,7 +21,6 @@ import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
@ -96,9 +95,7 @@ class S3DBTileLoader extends TileLoader {
|
||||
}
|
||||
|
||||
private void initTile(MapTile tile) {
|
||||
double lat = MercatorProjection.toLatitude(tile.y);
|
||||
mGroundScale = (float) MercatorProjection
|
||||
.groundResolutionWithScale(lat, 1 << mTile.zoomLevel);
|
||||
mGroundScale = tile.getGroundScale();
|
||||
|
||||
mRoofs = new ExtrusionBucket(0, mGroundScale, Color.get(247, 249, 250));
|
||||
|
||||
@ -106,7 +103,7 @@ class S3DBTileLoader extends TileLoader {
|
||||
//mRoofs = new ExtrusionLayer(0, mGroundScale, Color.get(207, 209, 210));
|
||||
mRoofs.next = mParts;
|
||||
|
||||
BuildingLayer.get(tile).setBuckets(mRoofs);
|
||||
BuildingLayer.get(tile).resetBuckets(mRoofs);
|
||||
|
||||
process(mTilePlane);
|
||||
}
|
||||
@ -145,6 +142,7 @@ class S3DBTileLoader extends TileLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
// May replace with ExtrusionBucket.addMeshElement()
|
||||
for (ExtrusionBucket l = mParts; l != null; l = l.next()) {
|
||||
if (l.getColor() == c) {
|
||||
l.addMesh(element);
|
||||
|
@ -1,10 +1,29 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2017 Gustl22
|
||||
*
|
||||
* 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.renderer.bucket;
|
||||
|
||||
import org.oscim.backend.GL;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.MapTile.TileData;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.utils.pool.Inlist;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,22 +52,71 @@ public class ExtrusionBuckets extends TileData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new ExtrusionLayers and clear previous.
|
||||
* Add mesh element to corresponding ExtrusionBucket
|
||||
*
|
||||
* @param element the MapElement as mesh
|
||||
* @param groundScale the scale of ground
|
||||
* @param color the color of element
|
||||
*/
|
||||
public void setBuckets(ExtrusionBucket el) {
|
||||
public void addMeshElement(GeometryBuffer element, float groundScale, int color) {
|
||||
// Add to bucket which has same color
|
||||
for (ExtrusionBucket eb = this.buckets; eb != null; eb = eb.next()) {
|
||||
if (eb.getColor() == color) {
|
||||
eb.addMesh(element);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to new bucket with different color
|
||||
ExtrusionBucket eb = new ExtrusionBucket(0, groundScale, color);
|
||||
this.buckets = Inlist.push(this.buckets, eb);
|
||||
this.buckets.addMesh(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add poly element to corresponding ExtrusionBucket
|
||||
*
|
||||
* @param element the MapElement as polygon
|
||||
* @param groundScale the scale of ground
|
||||
* @param colors the colors (top, side, side, line) of element
|
||||
* @param height the height of extrusion
|
||||
* @param minHeight the minimum height of extrusion
|
||||
*/
|
||||
public void addPolyElement(GeometryBuffer element, float groundScale, float[] colors, int height, int minHeight) {
|
||||
// Add to bucket which has same color
|
||||
for (ExtrusionBucket eb = this.buckets; eb != null; eb = eb.next()) {
|
||||
if (eb.getColors() == colors) {
|
||||
eb.addPoly(element, height, minHeight);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to new bucket with different color
|
||||
ExtrusionBucket eb = new ExtrusionBucket(0, groundScale, colors);
|
||||
this.buckets = Inlist.push(this.buckets, eb);
|
||||
this.buckets.addPoly(element, height, minHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new ExtrusionBuckets and clear previous.
|
||||
*/
|
||||
public void resetBuckets(ExtrusionBucket el) {
|
||||
for (RenderBucket b = buckets; b != null; b = b.next)
|
||||
b.clear();
|
||||
|
||||
buckets = el;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get root bucket
|
||||
*/
|
||||
public ExtrusionBucket buckets() {
|
||||
return buckets;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispose() {
|
||||
setBuckets(null);
|
||||
resetBuckets(null);
|
||||
|
||||
if (compiled) {
|
||||
ibo = BufferObject.release(ibo);
|
||||
|
Loading…
x
Reference in New Issue
Block a user