Skip to content

Commit 6d66205

Browse files
committed
Merge remote-tracking branch 'origin/feature/geopackage' into develop
2 parents 625953b + 6d01bab commit 6d66205

14 files changed

Lines changed: 107 additions & 103 deletions

File tree

worldwind/src/main/java/gov/nasa/worldwind/globe/BasicTessellator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class BasicTessellator implements Tessellator, TileFactory {
3434

3535
// ~0.6 meter resolution
36-
protected LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), new Location(-90, -180), 90, 20, 32, 32);
36+
protected LevelSet levelSet = new LevelSet(new Sector().setFullSphere(), new Location(-90, -180), new Location(90, 90), 20, 32, 32);
3737

3838
protected double detailControl = 80;
3939

worldwind/src/main/java/gov/nasa/worldwind/layer/BlueMarbleLandsatLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public BlueMarbleLandsatLayer(String serviceAddress) {
8585

8686
@Override
8787
public Tile createTile(Sector sector, Level level, int row, int column) {
88-
double radiansPerPixel = Math.toRadians(level.tileDelta) / level.tileHeight;
88+
double radiansPerPixel = Math.toRadians(level.tileDelta.latitude) / level.tileHeight;
8989
double metersPerPixel = radiansPerPixel * WorldWind.WGS84_SEMI_MAJOR_AXIS;
9090

9191
if (metersPerPixel < 2.0e3) { // switch to Landsat at 2km resolution

worldwind/src/main/java/gov/nasa/worldwind/layer/LayerFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ protected void createFromGeoPackageAsync(String pathName, Layer layer, Callback
279279
tileMatrixSet.getMaxY() - tileMatrixSet.getMinY(),
280280
tileMatrixSet.getMaxX() - tileMatrixSet.getMinX());
281281
config.tileOrigin.set(tileMatrixSet.getMinY(), tileMatrixSet.getMinX());
282-
config.firstLevelDelta = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / tileMatrix.valueAt(0).getMatrixHeight();
282+
config.firstLevelDelta.set(
283+
(tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / tileMatrix.valueAt(0).getMatrixHeight(),
284+
(tileMatrixSet.getMaxX() - tileMatrixSet.getMinX()) / tileMatrix.valueAt(0).getMatrixWidth()
285+
);
283286
config.numLevels = tileMatrix.keyAt(tileMatrix.size() - 1) - tileMatrix.keyAt(0) + 1;
284287

285288
TiledSurfaceImage surfaceImage = new TiledSurfaceImage();
@@ -665,7 +668,7 @@ protected LevelSet createWmtsLevelSet(WmtsLayer wmtsLayer, CompatibleTileMatrixS
665668
}
666669
int imageSize = tileMatrixSet.getTileMatrices().get(0).getTileHeight();
667670

668-
return new LevelSet(boundingBox, new Location(-90, -180), 90, compatibleTileMatrixSet.tileMatrices.size(), imageSize, imageSize);
671+
return new LevelSet(boundingBox, new Location(-90, -180), new Location(90, 90), compatibleTileMatrixSet.tileMatrices.size(), imageSize, imageSize);
669672
}
670673

671674
protected String buildWmtsKvpTemplate(String kvpServiceAddress, String layer, String format, String styleIdentifier, String tileMatrixSet) {

worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorImageTile.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import java.util.Collection;
66

77
import gov.nasa.worldwind.geom.Location;
8-
import gov.nasa.worldwind.render.ImageSource;
98
import gov.nasa.worldwind.render.ImageTile;
9+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1010
import gov.nasa.worldwind.util.Level;
1111
import gov.nasa.worldwind.util.LevelSet;
1212
import gov.nasa.worldwind.util.Logger;
1313
import gov.nasa.worldwind.util.Tile;
1414
import gov.nasa.worldwind.util.TileFactory;
1515

16-
class MercatorImageTile extends ImageTile implements ImageSource.Transformer {
16+
class MercatorImageTile extends ImageTile implements DownloadPostprocessor<Bitmap> {
1717

1818
/**
1919
* Constructs a tile with a specified sector, level, row and column.
@@ -53,23 +53,25 @@ static void assembleMercatorTilesForLevel(Level level, TileFactory tileFactory,
5353
// NOTE LevelSet.sector is final Sector attribute and thus can not be cast to MercatorSector!
5454
MercatorSector sector = MercatorSector.fromSector(level.parent.sector);
5555
Location tileOrigin = level.parent.tileOrigin;
56-
double dLat = level.tileDelta / 2;
57-
double dLon = level.tileDelta;
56+
double dLat = level.tileDelta.latitude;
57+
double dLon = level.tileDelta.longitude;
5858

5959
int firstRow = Tile.computeRow(dLat, sector.minLatitude(), tileOrigin.latitude);
6060
int lastRow = Tile.computeLastRow(dLat, sector.maxLatitude(), tileOrigin.latitude);
6161
int firstCol = Tile.computeColumn(dLon, sector.minLongitude(), tileOrigin.longitude);
6262
int lastCol = Tile.computeLastColumn(dLon, sector.maxLongitude(), tileOrigin.longitude);
6363

64-
double deltaLat = dLat / 90;
65-
double d1 = sector.minLatPercent() + deltaLat * firstRow;
64+
double dLatPercent = dLat / sector.deltaLatitude() * (sector.maxLatPercent() - sector.minLatPercent());
65+
double firstRowPercent = MercatorSector.gudermannianInverse(tileOrigin.latitude) + firstRow * dLatPercent;
66+
double firstColLon = tileOrigin.longitude + firstCol * dLon;
67+
68+
double d1 = firstRowPercent;
6669
for (int row = firstRow; row <= lastRow; row++) {
67-
double d2 = d1 + deltaLat;
68-
double t1 = tileOrigin.longitude + (firstCol * dLon);
70+
double d2 = d1 + dLatPercent;
71+
double t1 = firstColLon;
6972
for (int col = firstCol; col <= lastCol; col++) {
70-
double t2;
71-
t2 = t1 + dLon;
72-
result.add(tileFactory.createTile(MercatorSector.fromDegrees(d1, d2, t1, t2), level, row, col));
73+
double t2 = t1 + dLon;
74+
result.add(tileFactory.createTile(new MercatorSector(d1, d2, t1, t2), level, row, col));
7375
t1 = t2;
7476
}
7577
d1 = d2;
@@ -114,31 +116,33 @@ public Tile[] subdivide(TileFactory tileFactory) {
114116
int eastCol = westCol + 1;
115117

116118
Tile[] children = new Tile[4];
117-
children[0] = tileFactory.createTile(MercatorSector.fromDegrees(d0, d1, t0, t1), childLevel, northRow, westCol);
118-
children[1] = tileFactory.createTile(MercatorSector.fromDegrees(d0, d1, t1, t2), childLevel, northRow, eastCol);
119-
children[2] = tileFactory.createTile(MercatorSector.fromDegrees(d1, d2, t0, t1), childLevel, southRow, westCol);
120-
children[3] = tileFactory.createTile(MercatorSector.fromDegrees(d1, d2, t1, t2), childLevel, southRow, eastCol);
119+
children[0] = tileFactory.createTile(new MercatorSector(d0, d1, t0, t1), childLevel, northRow, westCol);
120+
children[1] = tileFactory.createTile(new MercatorSector(d0, d1, t1, t2), childLevel, northRow, eastCol);
121+
children[2] = tileFactory.createTile(new MercatorSector(d1, d2, t0, t1), childLevel, southRow, westCol);
122+
children[3] = tileFactory.createTile(new MercatorSector(d1, d2, t1, t2), childLevel, southRow, eastCol);
121123

122124
return children;
123125
}
124126

125127
@Override
126-
public Bitmap transform(Bitmap bitmap) {
128+
public Bitmap process(Bitmap resource) {
127129
// Re-project mercator tile to equirectangular
128-
Bitmap trans = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
130+
int[] pixels = new int[resource.getWidth() * resource.getHeight()];
131+
int[] result = new int[resource.getWidth() * resource.getHeight()];
132+
resource.getPixels(pixels, 0, resource.getWidth(), 0, 0, resource.getWidth(), resource.getHeight());
129133
double miny = ((MercatorSector) sector).minLatPercent();
130134
double maxy = ((MercatorSector) sector).maxLatPercent();
131-
for (int y = 0; y < bitmap.getHeight(); y++) {
132-
double sy = 1.0 - y / (double) (bitmap.getHeight() - 1);
135+
for (int y = 0; y < resource.getHeight(); y++) {
136+
double sy = 1.0 - y / (double) (resource.getHeight() - 1);
133137
double lat = sy * (sector.maxLatitude() - sector.minLatitude()) + sector.minLatitude();
134138
double dy = 1.0 - (MercatorSector.gudermannianInverse(lat) - miny) / (maxy - miny);
135139
dy = Math.max(0.0, Math.min(1.0, dy));
136-
int iy = (int) (dy * (bitmap.getHeight() - 1));
137-
for (int x = 0; x < bitmap.getWidth(); x++) {
138-
trans.setPixel(x, y, bitmap.getPixel(x, iy));
140+
int iy = (int) (dy * (resource.getHeight() - 1));
141+
for (int x = 0; x < resource.getWidth(); x++) {
142+
result[x + y * resource.getWidth()] = pixels[x + iy * resource.getWidth()];
139143
}
140144
}
141-
return trans;
145+
return Bitmap.createBitmap(result, resource.getWidth(), resource.getHeight(), resource.getConfig());
142146
}
143147

144148
}

worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorSector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ public class MercatorSector extends Sector {
66

77
private final double minLatPercent, maxLatPercent;
88

9-
private MercatorSector(double minLatPercent, double maxLatPercent,
10-
double minLongitude, double maxLongitude) {
9+
public MercatorSector(double minLatPercent, double maxLatPercent, double minLongitude, double maxLongitude) {
1110
this.minLatPercent = minLatPercent;
1211
this.maxLatPercent = maxLatPercent;
1312
this.minLatitude = gudermannian(minLatPercent);

worldwind/src/main/java/gov/nasa/worldwind/layer/mercator/MercatorTiledImageLayer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313

1414
public abstract class MercatorTiledImageLayer extends RenderableLayer implements TileFactory {
1515

16-
private static final double FULL_SPHERE = 360;
17-
1816
private final int firstLevelOffset;
1917

2018
public MercatorTiledImageLayer(String name, int numLevels, int firstLevelOffset, int tileSize, boolean overlay) {
2119
super(name);
2220
this.setPickEnabled(false);
2321
this.firstLevelOffset = firstLevelOffset;
2422

23+
MercatorSector sector = new MercatorSector(-1.0, 1.0, -180.0, 180.0);
24+
Location tileOrigin = new Location(sector.minLatitude(), sector.minLongitude());
25+
int n = 1 << firstLevelOffset;
26+
Location firstLevelDelta = new Location(sector.deltaLatitude() / n, sector.deltaLongitude() / n);
2527
MercatorTiledSurfaceImage surfaceImage = new MercatorTiledSurfaceImage();
26-
surfaceImage.setLevelSet(new LevelSet(
27-
MercatorSector.fromDegrees(-1.0, 1.0, - FULL_SPHERE / 2, FULL_SPHERE / 2), new Location(-90, -180),
28-
FULL_SPHERE / (1 << firstLevelOffset), numLevels - firstLevelOffset, tileSize, tileSize));
28+
surfaceImage.setLevelSet(new LevelSet(sector, tileOrigin, firstLevelDelta, numLevels - firstLevelOffset, tileSize, tileSize));
2929
surfaceImage.setTileFactory(this);
3030
if(!overlay) {
3131
surfaceImage.setImageOptions(new ImageOptions(WorldWind.RGB_565)); // reduce memory usage by using a 16-bit configuration with no alpha

worldwind/src/main/java/gov/nasa/worldwind/render/ImageRetriever.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.net.URL;
1717

1818
import gov.nasa.worldwind.WorldWind;
19+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1920
import gov.nasa.worldwind.util.Logger;
2021
import gov.nasa.worldwind.util.Retriever;
2122

@@ -71,7 +72,7 @@ protected Bitmap decodeImage(ImageSource imageSource, ImageOptions imageOptions)
7172
}
7273

7374
if (imageSource.isUrl()) {
74-
return this.decodeUrl(imageSource.asUrl(), imageOptions, imageSource.transformer);
75+
return this.decodeUrl(imageSource.asUrl(), imageOptions, imageSource.postprocessor);
7576
}
7677

7778
return this.decodeUnrecognized(imageSource);
@@ -87,7 +88,7 @@ protected Bitmap decodeFilePath(String pathName, ImageOptions imageOptions) {
8788
return BitmapFactory.decodeFile(pathName, factoryOptions);
8889
}
8990

90-
protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, ImageSource.Transformer transformer) throws IOException {
91+
protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, DownloadPostprocessor<Bitmap> postprocessor) throws IOException {
9192
// TODO establish a file caching service for remote resources
9293
// TODO retry absent resources, they are currently handled but suppressed entirely after the first failure
9394
// TODO configurable connect and read timeouts
@@ -104,8 +105,8 @@ protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions, ImageSou
104105
Bitmap bitmap = BitmapFactory.decodeStream(stream, null, factoryOptions);
105106

106107
// Apply bitmap transformation if required
107-
if (transformer != null && bitmap != null) {
108-
bitmap = transformer.transform(bitmap);
108+
if (postprocessor != null && bitmap != null) {
109+
bitmap = postprocessor.process(bitmap);
109110
}
110111

111112
return bitmap;

worldwind/src/main/java/gov/nasa/worldwind/render/ImageSource.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Arrays;
1515
import java.util.HashMap;
1616

17+
import gov.nasa.worldwind.util.DownloadPostprocessor;
1718
import gov.nasa.worldwind.util.Logger;
1819
import gov.nasa.worldwind.util.WWUtil;
1920

@@ -52,18 +53,6 @@ public interface BitmapFactory {
5253
Bitmap createBitmap();
5354
}
5455

55-
/**
56-
* Interface for remote image source post-transformation
57-
*/
58-
public interface Transformer {
59-
/**
60-
* Transforms image according to specified algorithm implementation
61-
* @param bitmap original bitmap
62-
* @return transformed bitmap
63-
*/
64-
Bitmap transform(Bitmap bitmap);
65-
}
66-
6756
protected static final HashMap<Object, BitmapFactory> lineStippleFactories = new HashMap<>();
6857

6958
protected static final int TYPE_UNRECOGNIZED = 0;
@@ -82,7 +71,7 @@ public interface Transformer {
8271

8372
protected Object source;
8473

85-
protected Transformer transformer;
74+
protected DownloadPostprocessor<Bitmap> postprocessor;
8675

8776
protected ImageSource() {
8877
}
@@ -194,15 +183,15 @@ public static ImageSource fromUrl(String urlString) {
194183
* application's manifest must include the permissions that allow network connections.
195184
*
196185
* @param urlString complete URL string
197-
* @param transformer implementation of image post-transformation routine
186+
* @param postprocessor implementation of image post-transformation routine
198187
*
199188
* @return the new image source
200189
*
201190
* @throws IllegalArgumentException If the URL string is null
202191
*/
203-
public static ImageSource fromUrl(String urlString, Transformer transformer) {
192+
public static ImageSource fromUrl(String urlString, DownloadPostprocessor<Bitmap> postprocessor) {
204193
ImageSource imageSource = fromUrl(urlString);
205-
imageSource.transformer = transformer;
194+
imageSource.postprocessor = postprocessor;
206195
return imageSource;
207196
}
208197

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gov.nasa.worldwind.util;
2+
3+
/**
4+
* Interface for resource download post-processing
5+
*/
6+
public interface DownloadPostprocessor<T> {
7+
/**
8+
* Process resource according to specified algorithm implementation
9+
*
10+
* @param resource original resource
11+
* @return processed resource
12+
*/
13+
T process(T resource);
14+
}

worldwind/src/main/java/gov/nasa/worldwind/util/Level.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package gov.nasa.worldwind.util;
77

8+
import gov.nasa.worldwind.geom.Location;
9+
810
/**
911
* Represents a level of a specific resolution in a {@link LevelSet}.
1012
*/
@@ -35,7 +37,7 @@ public class Level {
3537
/**
3638
* The geographic width and height in degrees of tiles within this level.
3739
*/
38-
public final double tileDelta;
40+
public final Location tileDelta;
3941

4042
/**
4143
* The parent LevelSet's tileWidth.
@@ -54,21 +56,21 @@ public class Level {
5456
* @param levelNumber the level's ordinal within its parent level set
5557
* @param tileDelta the geographic width and height in degrees of tiles within this level
5658
*/
57-
public Level(LevelSet parent, int levelNumber, double tileDelta) {
59+
public Level(LevelSet parent, int levelNumber, Location tileDelta) {
5860
if (parent == null) {
5961
throw new IllegalArgumentException(
6062
Logger.logMessage(Logger.ERROR, "Level", "constructor", "The parent level set is null"));
6163
}
6264

63-
if (tileDelta <= 0) {
65+
if (tileDelta == null || tileDelta.latitude <= 0 || tileDelta.longitude <= 0) {
6466
throw new IllegalArgumentException(
6567
Logger.logMessage(Logger.ERROR, "Level", "constructor", "The tile delta is zero"));
6668
}
6769

6870
this.parent = parent;
6971
this.levelNumber = levelNumber;
70-
this.levelWidth = (int) Math.round(parent.tileWidth * parent.sector.deltaLongitude() / tileDelta);
71-
this.levelHeight = (int) Math.round(parent.tileHeight * parent.sector.deltaLatitude() / tileDelta);
72+
this.levelWidth = (int) Math.round(parent.tileWidth * parent.sector.deltaLongitude() / tileDelta.longitude);
73+
this.levelHeight = (int) Math.round(parent.tileHeight * parent.sector.deltaLatitude() / tileDelta.latitude);
7274
this.tileDelta = tileDelta;
7375
this.tileWidth = parent.tileWidth;
7476
this.tileHeight = parent.tileHeight;

0 commit comments

Comments
 (0)