Commit 79f5c2d5 authored by Clemens Krug's avatar Clemens Krug
Browse files

Fixed some issues with world dimensioning and position calculation

~ Settings of the world size were not employed correctly. Furthermore, setting a different zoom for the visualisation / map would fuck up the positioning.
Now the specified world size is used correctly. Zoom is used to specify the zoom level (detail) on the map. Positioning now works with different zoom levels, however, when visualising positions they now need to be scaled to be drawn correctly.
parent d3ffc239
......@@ -32,6 +32,7 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.visualization.world.SocialViewComponentVis;
......@@ -63,6 +64,8 @@ public class DefaultTopology implements Topology {
public DefaultTopology(PositionVector worldDimensions) {
this.worldDimensions = worldDimensions;
components = new LinkedList<TopologyComponent>();
// obstacles = new LinkedList<Obstacle>();
topoListeners = new LinkedList<TopologyListener>();
......
......@@ -31,6 +31,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView;
import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.Left;
import de.tudarmstadt.maki.simonstrator.api.Binder;
......@@ -44,7 +45,7 @@ import java.util.UUID;
/**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
*
* 13.03.2017 Clemens Krug: Fixed an bug. When the GraphHopper routing had errors the nodes would move to the
* 13.03.2017 Clemens Krug: Fixed a bug. When the GraphHopper routing had errors the nodes would move to the
* top right corner and not, as intended, straight to their destination.
*
* @author Martin Hellwig
......@@ -63,8 +64,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private String movementType; //car, bike or foot
private String defaultMovement;
private String navigationalType; //fastest,
private double latLeft; //Values from -90 to 90; always smaller than latRight
private double latRight; //Values from -90 to 90
private double latLower; //Values from -90 to 90; always smaller than latUpper
private double latUpper; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180
private boolean uniqueFolders;
......@@ -78,8 +79,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public RealWorldStreetsMovement() {
this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
latLeft = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper();
latLower = GPSCalculation.getLatLower();
latUpper = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft();
lonRight = GPSCalculation.getLonRight();
}
......@@ -178,7 +179,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
*/
private double[] transformOwnWorldWindowToGPS(double x, double y) {
double[] gps_coordinates = new double[2];
gps_coordinates[0] = latLeft + (latRight - latLeft) * (worldDimensions.getY() - y)/worldDimensions.getY();
gps_coordinates[0] = latLower + (latUpper - latLower) * (worldDimensions.getY() - y)/worldDimensions.getY();
gps_coordinates[1] = lonLeft + (lonRight - lonLeft) * x/worldDimensions.getX();
return gps_coordinates;
}
......@@ -190,8 +191,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
* @return The projected position in world-dimensions
*/
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
VisualizationTopologyView.VisualizationInjector.getWorldX();
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft);
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLeft)/(latRight - latLeft);
double y = worldDimensions.getY() - worldDimensions.getY() * (lat - latLower)/(latUpper - latLower);
x = Math.max(0, x);
x = Math.min(worldDimensions.getX(), x);
y = Math.max(0, y);
......
......@@ -25,7 +25,15 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
import de.tudarmstadt.maki.simonstrator.api.Binder;
/**
*
*
* CHANGELOG
* - 26.06.2017 Clemens Krug:
* Change some calculations that used numbers that were not comprehensible and not documented.
* In the previous version, changing the zoom of the visualisation / map would fuck up the whole
* positioning calculations. This has been fixed now.
*
*
*
* @author Martin Hellwig
* @version 1.0, Nov 3, 2015
*/
......@@ -37,7 +45,9 @@ public class GPSCalculation {
private static int zoom;
private static double scaleFactor;
private static double metersPerPixel;
private static int EARTH_CIRCUMFERENCE = 40030173;
/*
* http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-
......@@ -64,7 +74,8 @@ public class GPSCalculation {
* is valid on all zoom levels.
*/
// 17: 2, 16: 1, 15: 0.5, 14: 0.25
VisualizationInjector.setScale(Math.pow(2.0d, (zoom - 16)));
// VisualizationInjector.setScale(Math.pow(2.0d, (zoom - 16)));
VisualizationInjector.setScale(1/metersPerPixel);
}
public static double getLatCenter() {
......@@ -79,46 +90,34 @@ public class GPSCalculation {
return zoom;
}
public static double getLatUpper() {
return latCenter + (Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY() / 111111d) * scaleFactor;
public static double getMetersPerPixel()
{
return metersPerPixel;
}
// return latCenter + scaleFactor * 0.027613 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getY()
// / 1000;
public static double getLatUpper() {
return latCenter + ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY()/2) / 111111d);
}
public static double getLatLower() {
return latCenter - (Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY() / 111111d) * scaleFactor;
// return latCenter - scaleFactor * 0.027613 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getY()
// / 1000;
return latCenter - ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY()/2) / 111111d);
}
public static double getLonLeft() {
return lonCenter - (Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() / 111111d / scaleLon) * scaleFactor;
// return lonCenter - scaleFactor * 0.043 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getX()
// / 1000;
return lonCenter - ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX()/2) / (111111d * scaleLon));
}
public static double getLonRight() {
return lonCenter + (Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() / 111111d / scaleLon) * scaleFactor;
// return lonCenter + scaleFactor * 0.043 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getX()
// / 1000;
return lonCenter + ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX()/2) / (111111d * scaleLon));
}
public void setLatCenter(double latCenter) {
this.latCenter = latCenter;
this.scaleLon = Math.cos(Math.toRadians(latCenter));
this.scaleFactor = 0.38d;
}
public void setLonCenter(double lonCenter) {
......@@ -126,7 +125,8 @@ public class GPSCalculation {
}
public void setZoom(int zoom) {
this.zoom = zoom;
GPSCalculation.zoom = zoom;
GPSCalculation.metersPerPixel = EARTH_CIRCUMFERENCE * Math.cos(Math.toRadians(GPSCalculation.getLatCenter())) / Math.pow(2, GPSCalculation.getZoom() + 8);
setScaleFactor();
}
}
......@@ -185,8 +185,8 @@ public class ModularMovementModelViz extends JComponent
{
Point2D pt = comp.getRealPosition().asPoint();
g2.setColor(Color.GRAY);
g2.fillOval((int) pt.getX() - NODE_PAD,
(int) pt.getY() - NODE_PAD, NODE_PAD * 2 + 1,
g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_PAD,
VisualizationInjector.scaleValue(pt.getY()) - NODE_PAD, NODE_PAD * 2 + 1,
NODE_PAD * 2 + 1);
}
......
......@@ -70,25 +70,33 @@ public class ShowMapQuestMapViz extends JComponent
private void initializeImage() {
if (!initialized) {
PositionVector worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
tempImageFilePath = tempImageFilePath + "mapquest"
+ GPSCalculation.getLatCenter() + "_"
+ GPSCalculation.getLonCenter() + "_" + GPSCalculation.getZoom() + "_"
+ VisualizationInjector.getWorldX() + "_"
+ VisualizationInjector.getWorldY() + mapType + ".jpg";
+ worldDimensions.getX() + "_"
+ worldDimensions.getY() + mapType + ".jpg";
// Check if the file with same properties (same location) already
// exists
File f = new File(tempImageFilePath);
if (!f.exists()) {
try {
//Based on the meters per pixel, the needed height and width in pixels can be determined.
int pxx = (int) (worldDimensions.getX() / GPSCalculation.getMetersPerPixel());
int pxy = (int) (worldDimensions.getY() / GPSCalculation.getMetersPerPixel());
String imageUrl = "http://www.mapquestapi.com/staticmap/v4/getmap?key="
+ mapQuestKey + "&type=" + mapType
+ "&imagetype=jpeg&center="
+ GPSCalculation.getLatCenter() + ","
+ GPSCalculation.getLonCenter() + "&zoom="
+ ((GPSCalculation.getZoom()) + 1) + "&size="
+ VisualizationInjector.getWorldX() + ","
+ VisualizationInjector.getWorldY();
+ ((GPSCalculation.getZoom())) + "&size="
+ pxx + ","
+ pxy;
URL url = new URL(imageUrl);
InputStream is = url.openStream();
OutputStream os = new FileOutputStream(tempImageFilePath);
......
......@@ -123,6 +123,7 @@ public class ModularMovementIconVis extends ModularMovementModelViz implements E
boolean iconNotFound = true;
Host host = comp.getHost();
Point2D pt = comp.getRealPosition().asPoint();
pt = new Point2D.Double(VisualizationTopologyView.VisualizationInjector.scaleValue(pt.getX()), VisualizationTopologyView.VisualizationInjector.scaleValue(pt.getY()));
g2.setColor(Color.GRAY);
// Check if the component has a specified state, as this would have precedence over the classIcon.
......
......@@ -263,7 +263,7 @@ public class NodeInfoComponentVis extends JComponent
// Draw active (green) over underlay vis.
g2.setColor(nodeInfo.isActive() ? activeGreen : Color.LIGHT_GRAY);
int radius = 3;
g2.drawOval(center.x - radius, center.y - radius, radius * 2,
g2.drawOval(VisualizationInjector.scaleValue(center.x) - radius, VisualizationInjector.scaleValue(center.y) - radius, radius * 2,
radius * 2);
if (!nodeInfo.isActive()) {
......@@ -285,7 +285,7 @@ public class NodeInfoComponentVis extends JComponent
continue;
}
g2.setColor(colors[dim][value]);
g2.drawArc(center.x-arcSize, center.y-arcSize, 2*arcSize, 2*arcSize, dim*segmentDegrees, segmentDegrees);
g2.drawArc(VisualizationInjector.scaleValue(center.x)-arcSize, VisualizationInjector.scaleValue(center.y)-arcSize, 2*arcSize, 2*arcSize, dim*segmentDegrees, segmentDegrees);
}
g2.setStroke(new BasicStroke(1));
......
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