Commit 98697bf6 authored by hengwen's avatar hengwen
Browse files

Add heightmap

parent 9b0603a3
......@@ -164,15 +164,65 @@ public class MapModel {
}
}
public static class HeightMap {
private double[][] data;
private double heightMapDeltaX;
private double heightMapDeltaY;
private double heightMapMinX;
private double heightMapMinY;
private double heightMapMaxX;
private double heightMapMaxY;
public HeightMap(double[][] data, double heightMapDeltaX, double heightMapDeltaY, double heightMapMinX, double heightMapMinY, double heightMapMaxX, double heightMapMaxY) {
this.data = data;
this.heightMapDeltaX = heightMapDeltaX;
this.heightMapDeltaY = heightMapDeltaY;
this.heightMapMinX = heightMapMinX;
this.heightMapMinY = heightMapMinY;
this.heightMapMaxX = heightMapMaxX;
this.heightMapMaxY = heightMapMaxY;
}
public double[][] getData() {
return data;
}
public double getHeightMapDeltaX() {
return heightMapDeltaX;
}
public double getHeightMapDeltaY() {
return heightMapDeltaY;
}
public double getHeightMapMinX() {
return heightMapMinX;
}
public double getHeightMapMinY() {
return heightMapMinY;
}
public double getHeightMapMaxX() {
return heightMapMaxX;
}
public double getHeightMapMaxY() {
return heightMapMaxY;
}
}
private int id;
private String name;
private String path;
private List<Street> streets;
private List<Building> buildings;
private List<Waterway> waterways;
private Bound bounds;
private HeightMap heightMap;
public int getId() {
return id;
}
......@@ -228,4 +278,12 @@ public class MapModel {
public void setBounds(Bound bounds) {
this.bounds = bounds;
}
public HeightMap getHeightMap() {
return heightMap;
}
public void setHeightMap(HeightMap heightMap) {
this.heightMap = heightMap;
}
}
package server.restful.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.restful.model.MapModel;
import simulation.environment.World;
import simulation.environment.WorldModel;
......@@ -16,6 +18,7 @@ public class WorldBuilderService {
World world;
MapModel mapModel;
ApproximateConverter converter;
private Logger logger = LoggerFactory.getLogger(WorldBuilderService.class);
public WorldBuilderService(String mapPath) throws Exception {
mapModel = new MapModel();
......@@ -32,16 +35,16 @@ public class WorldBuilderService {
addBuildings();
addBound();
addWaterWays();
// addHeightMap();
addHeightMap();
} catch (Exception e) {
e.printStackTrace();
}
return mapModel;
};
}
private void addStreets() throws Exception {
List<MapModel.Street> streets = new ArrayList<>();
for (EnvStreet street: world.getContainer().getStreets()){
for (EnvStreet street : world.getContainer().getStreets()) {
List<MapModel.Node> nodes = getLonLatNodesFromXYNodes(street.getNodes());
List<MapModel.Node> intersections = getLonLatNodesFromXYNodes((List<EnvNode>) street.getIntersections());
streets.add(new MapModel.Street(
......@@ -58,16 +61,15 @@ public class WorldBuilderService {
mapModel.setStreets(streets);
}
private List<MapModel.Node> getLonLatNodesFromXYNodes(List<EnvNode> nodes){
private List<MapModel.Node> getLonLatNodesFromXYNodes(List<EnvNode> nodes) {
List<MapModel.Node> result = new ArrayList<>();
for (EnvNode node: nodes){
for (EnvNode node : nodes) {
double x = node.getX().doubleValue(), y = node.getY().doubleValue();
result.add(new MapModel.Node(
node.getOsmId(),
x,y,
// (float) converter.convertXToLong(x, y),
// (float) converter.convertYToLat(y),
(float) converter.convertXToLong(x, y),
(float) converter.convertYToLat(y),
node.getZ().floatValue()
));
}
......@@ -75,27 +77,26 @@ public class WorldBuilderService {
}
private void addBound() throws Exception {
EnvBounds bound = world.getContainer().getBounds();
double minX = bound.getMinX(), minY = bound.getMinY(),
maxX = bound.getMaxX(), maxY = bound.getMaxY();
mapModel.setBounds(new MapModel.Bound(
minX, minY,0, maxX, maxY, 0
// (float) converter.convertXToLong(minX, minY),
// (float) converter.convertYToLat(minY),
// (float) bound.getMinZ(),
// (float) converter.convertXToLong(maxX, maxY),
// (float) converter.convertYToLat(maxY),
// (float) bound.getMaxZ()
));
EnvBounds bound = world.getContainer().getBounds();
double minX = bound.getMinX(), minY = bound.getMinY(),
maxX = bound.getMaxX(), maxY = bound.getMaxY();
mapModel.setBounds(new MapModel.Bound(
(float) converter.convertXToLong(minX, minY),
(float) converter.convertYToLat(minY),
(float) bound.getMinZ(),
(float) converter.convertXToLong(maxX, maxY),
(float) converter.convertYToLat(maxY),
(float) bound.getMaxZ()
));
}
private void addBuildings() throws Exception {
List<MapModel.Building> buildings = new ArrayList<>();
for (Building building: world.getContainer().getBuildings()){
for (Building building : world.getContainer().getBuildings()) {
Building.BuildingTypes buildingTypes = building.getBuildingTypes();
buildings.add(new MapModel.Building(
getLonLatNodesFromXYNodes(building.getNodes()),
buildingTypes == null ? "" : buildingTypes.toString()
getLonLatNodesFromXYNodes(building.getNodes()),
buildingTypes == null ? "" : buildingTypes.toString()
));
}
mapModel.setBuildings(buildings);
......@@ -103,7 +104,7 @@ public class WorldBuilderService {
private void addWaterWays() throws Exception {
List<MapModel.Waterway> waterways = new ArrayList<>();
for (Waterway waterway: world.getContainer().getWaterway()){
for (Waterway waterway : world.getContainer().getWaterway()) {
Waterway.WaterTypes waterwayTypes = waterway.getWaterType();
waterways.add(new MapModel.Waterway(
getLonLatNodesFromXYNodes(waterway.getNodes()),
......@@ -112,4 +113,24 @@ public class WorldBuilderService {
}
mapModel.setWaterways(waterways);
}
private void addHeightMap() {
VisualisationEnvironmentContainer container;
try {
container = world.getContainer();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return;
}
mapModel.setHeightMap(new MapModel.HeightMap(
container.getHeightMap(),
container.getHeightMapDeltaX(),
container.getHeightMapDeltaY(),
container.getHeightMapMinPoint().getX(),
container.getHeightMapMinPoint().getY(),
container.getHeightMapMaxPoint().getX(),
container.getHeightMapMaxPoint().getY()
));
}
}
......@@ -12,7 +12,13 @@ public class WorldBuilderServiceTest {
MapModel result = wb.buildWorld();
assertTrue(result.getStreets().size() > 0);
assertTrue(result.getBuildings().size() > 0);
assertTrue(result.getWaterways().size() >= 0); // Aachen.osm has no waterway
// assertTrue(result.getWaterways().size() > 0); // Aachen.osm has no waterway
assertTrue(result.getBounds() != null);
assertTrue(result.getHeightMap().getHeightMapDeltaX() != 0);
assertTrue(result.getHeightMap().getHeightMapDeltaY() != 0);
assertTrue(result.getHeightMap().getHeightMapMinX() != 0);
assertTrue(result.getHeightMap().getHeightMapMinY() != 0);
assertTrue(result.getHeightMap().getHeightMapMaxX() != 0);
assertTrue(result.getHeightMap().getHeightMapMaxY() != 0);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment