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; ...@@ -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.social.SocialView;
import de.tud.kom.p2psim.api.topology.views.TopologyView; import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; 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.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.visualization.world.SocialViewComponentVis; import de.tud.kom.p2psim.impl.topology.views.visualization.world.SocialViewComponentVis;
...@@ -63,6 +64,8 @@ public class DefaultTopology implements Topology { ...@@ -63,6 +64,8 @@ public class DefaultTopology implements Topology {
public DefaultTopology(PositionVector worldDimensions) { public DefaultTopology(PositionVector worldDimensions) {
this.worldDimensions = worldDimensions; this.worldDimensions = worldDimensions;
components = new LinkedList<TopologyComponent>(); components = new LinkedList<TopologyComponent>();
// obstacles = new LinkedList<Obstacle>(); // obstacles = new LinkedList<Obstacle>();
topoListeners = new LinkedList<TopologyListener>(); topoListeners = new LinkedList<TopologyListener>();
......
...@@ -31,6 +31,7 @@ import de.tud.kom.p2psim.api.topology.Topology; ...@@ -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.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector; 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.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.Either;
import de.tud.kom.p2psim.impl.util.Left; import de.tud.kom.p2psim.impl.util.Left;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
...@@ -44,7 +45,7 @@ import java.util.UUID; ...@@ -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 * 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. * top right corner and not, as intended, straight to their destination.
* *
* @author Martin Hellwig * @author Martin Hellwig
...@@ -63,8 +64,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -63,8 +64,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private String movementType; //car, bike or foot private String movementType; //car, bike or foot
private String defaultMovement; private String defaultMovement;
private String navigationalType; //fastest, private String navigationalType; //fastest,
private double latLeft; //Values from -90 to 90; always smaller than latRight private double latLower; //Values from -90 to 90; always smaller than latUpper
private double latRight; //Values from -90 to 90 private double latUpper; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180 private double lonRight; //Values from -180 to 180
private boolean uniqueFolders; private boolean uniqueFolders;
...@@ -78,8 +79,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -78,8 +79,8 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public RealWorldStreetsMovement() { public RealWorldStreetsMovement() {
this.worldDimensions = Binder.getComponentOrNull(Topology.class) this.worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions(); .getWorldDimensions();
latLeft = GPSCalculation.getLatLower(); latLower = GPSCalculation.getLatLower();
latRight = GPSCalculation.getLatUpper(); latUpper = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft(); lonLeft = GPSCalculation.getLonLeft();
lonRight = GPSCalculation.getLonRight(); lonRight = GPSCalculation.getLonRight();
} }
...@@ -178,7 +179,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -178,7 +179,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
*/ */
private double[] transformOwnWorldWindowToGPS(double x, double y) { private double[] transformOwnWorldWindowToGPS(double x, double y) {
double[] gps_coordinates = new double[2]; 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(); gps_coordinates[1] = lonLeft + (lonRight - lonLeft) * x/worldDimensions.getX();
return gps_coordinates; return gps_coordinates;
} }
...@@ -190,8 +191,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy { ...@@ -190,8 +191,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
* @return The projected position in world-dimensions * @return The projected position in world-dimensions
*/ */
private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) { private PositionVector transformGPSWindowToOwnWorld(double lat, double lon) {
VisualizationTopologyView.VisualizationInjector.getWorldX();
double x = worldDimensions.getX() * (lon - lonLeft)/(lonRight - lonLeft); 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.max(0, x);
x = Math.min(worldDimensions.getX(), x); x = Math.min(worldDimensions.getX(), x);
y = Math.max(0, y); y = Math.max(0, y);
......
...@@ -25,7 +25,15 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza ...@@ -25,7 +25,15 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
import de.tudarmstadt.maki.simonstrator.api.Binder; 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 * @author Martin Hellwig
* @version 1.0, Nov 3, 2015 * @version 1.0, Nov 3, 2015
*/ */
...@@ -37,7 +45,9 @@ public class GPSCalculation { ...@@ -37,7 +45,9 @@ public class GPSCalculation {
private static int zoom; 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- * http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-
...@@ -64,7 +74,8 @@ public class GPSCalculation { ...@@ -64,7 +74,8 @@ public class GPSCalculation {
* is valid on all zoom levels. * is valid on all zoom levels.
*/ */
// 17: 2, 16: 1, 15: 0.5, 14: 0.25 // 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() { public static double getLatCenter() {
...@@ -79,46 +90,34 @@ public class GPSCalculation { ...@@ -79,46 +90,34 @@ public class GPSCalculation {
return zoom; return zoom;
} }
public static double getLatUpper() { public static double getMetersPerPixel()
return latCenter + (Binder.getComponentOrNull(Topology.class) {
.getWorldDimensions().getY() / 111111d) * scaleFactor; return metersPerPixel;
}
// return latCenter + scaleFactor * 0.027613 * Binder public static double getLatUpper() {
// .getComponentOrNull(Topology.class).getWorldDimensions().getY() return latCenter + ((Binder.getComponentOrNull(Topology.class)
// / 1000; .getWorldDimensions().getY()/2) / 111111d);
} }
public static double getLatLower() { public static double getLatLower() {
return latCenter - (Binder.getComponentOrNull(Topology.class) return latCenter - ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getY() / 111111d) * scaleFactor; .getWorldDimensions().getY()/2) / 111111d);
// return latCenter - scaleFactor * 0.027613 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getY()
// / 1000;
} }
public static double getLonLeft() { public static double getLonLeft() {
return lonCenter - (Binder.getComponentOrNull(Topology.class) return lonCenter - ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() / 111111d / scaleLon) * scaleFactor; .getWorldDimensions().getX()/2) / (111111d * scaleLon));
// return lonCenter - scaleFactor * 0.043 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getX()
// / 1000;
} }
public static double getLonRight() { public static double getLonRight() {
return lonCenter + (Binder.getComponentOrNull(Topology.class) return lonCenter + ((Binder.getComponentOrNull(Topology.class)
.getWorldDimensions().getX() / 111111d / scaleLon) * scaleFactor; .getWorldDimensions().getX()/2) / (111111d * scaleLon));
// return lonCenter + scaleFactor * 0.043 * Binder
// .getComponentOrNull(Topology.class).getWorldDimensions().getX()
// / 1000;
} }
public void setLatCenter(double latCenter) { public void setLatCenter(double latCenter) {
this.latCenter = latCenter; this.latCenter = latCenter;
this.scaleLon = Math.cos(Math.toRadians(latCenter)); this.scaleLon = Math.cos(Math.toRadians(latCenter));
this.scaleFactor = 0.38d;
} }
public void setLonCenter(double lonCenter) { public void setLonCenter(double lonCenter) {
...@@ -126,7 +125,8 @@ public class GPSCalculation { ...@@ -126,7 +125,8 @@ public class GPSCalculation {
} }
public void setZoom(int zoom) { 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(); setScaleFactor();
} }
} }
...@@ -185,8 +185,8 @@ public class ModularMovementModelViz extends JComponent ...@@ -185,8 +185,8 @@ public class ModularMovementModelViz extends JComponent
{ {
Point2D pt = comp.getRealPosition().asPoint(); Point2D pt = comp.getRealPosition().asPoint();
g2.setColor(Color.GRAY); g2.setColor(Color.GRAY);
g2.fillOval((int) pt.getX() - NODE_PAD, g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_PAD,
(int) pt.getY() - NODE_PAD, NODE_PAD * 2 + 1, VisualizationInjector.scaleValue(pt.getY()) - NODE_PAD, NODE_PAD * 2 + 1,
NODE_PAD * 2 + 1); NODE_PAD * 2 + 1);
} }
......
...@@ -70,25 +70,33 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -70,25 +70,33 @@ public class ShowMapQuestMapViz extends JComponent
private void initializeImage() { private void initializeImage() {
if (!initialized) { if (!initialized) {
PositionVector worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
tempImageFilePath = tempImageFilePath + "mapquest" tempImageFilePath = tempImageFilePath + "mapquest"
+ GPSCalculation.getLatCenter() + "_" + GPSCalculation.getLatCenter() + "_"
+ GPSCalculation.getLonCenter() + "_" + GPSCalculation.getZoom() + "_" + GPSCalculation.getLonCenter() + "_" + GPSCalculation.getZoom() + "_"
+ VisualizationInjector.getWorldX() + "_" + worldDimensions.getX() + "_"
+ VisualizationInjector.getWorldY() + mapType + ".jpg"; + worldDimensions.getY() + mapType + ".jpg";
// Check if the file with same properties (same location) already // Check if the file with same properties (same location) already
// exists // exists
File f = new File(tempImageFilePath); File f = new File(tempImageFilePath);
if (!f.exists()) { if (!f.exists()) {
try { 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=" String imageUrl = "http://www.mapquestapi.com/staticmap/v4/getmap?key="
+ mapQuestKey + "&type=" + mapType + mapQuestKey + "&type=" + mapType
+ "&imagetype=jpeg&center=" + "&imagetype=jpeg&center="
+ GPSCalculation.getLatCenter() + "," + GPSCalculation.getLatCenter() + ","
+ GPSCalculation.getLonCenter() + "&zoom=" + GPSCalculation.getLonCenter() + "&zoom="
+ ((GPSCalculation.getZoom()) + 1) + "&size=" + ((GPSCalculation.getZoom())) + "&size="
+ VisualizationInjector.getWorldX() + "," + pxx + ","
+ VisualizationInjector.getWorldY(); + pxy;
URL url = new URL(imageUrl); URL url = new URL(imageUrl);
InputStream is = url.openStream(); InputStream is = url.openStream();
OutputStream os = new FileOutputStream(tempImageFilePath); OutputStream os = new FileOutputStream(tempImageFilePath);
......
...@@ -123,6 +123,7 @@ public class ModularMovementIconVis extends ModularMovementModelViz implements E ...@@ -123,6 +123,7 @@ public class ModularMovementIconVis extends ModularMovementModelViz implements E
boolean iconNotFound = true; boolean iconNotFound = true;
Host host = comp.getHost(); Host host = comp.getHost();
Point2D pt = comp.getRealPosition().asPoint(); Point2D pt = comp.getRealPosition().asPoint();
pt = new Point2D.Double(VisualizationTopologyView.VisualizationInjector.scaleValue(pt.getX()), VisualizationTopologyView.VisualizationInjector.scaleValue(pt.getY()));
g2.setColor(Color.GRAY); g2.setColor(Color.GRAY);
// Check if the component has a specified state, as this would have precedence over the classIcon. // 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 ...@@ -263,7 +263,7 @@ public class NodeInfoComponentVis extends JComponent
// Draw active (green) over underlay vis. // Draw active (green) over underlay vis.
g2.setColor(nodeInfo.isActive() ? activeGreen : Color.LIGHT_GRAY); g2.setColor(nodeInfo.isActive() ? activeGreen : Color.LIGHT_GRAY);
int radius = 3; 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); radius * 2);
if (!nodeInfo.isActive()) { if (!nodeInfo.isActive()) {
...@@ -285,7 +285,7 @@ public class NodeInfoComponentVis extends JComponent ...@@ -285,7 +285,7 @@ public class NodeInfoComponentVis extends JComponent
continue; continue;
} }
g2.setColor(colors[dim][value]); 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)); 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