Commit 686eca40 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Modular Movement model segment calculation

parent cff5d31b
......@@ -31,12 +31,16 @@ import java.util.UUID;
import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
import com.graphhopper.GraphHopper;
import com.graphhopper.PathWrapper;
import com.graphhopper.routing.util.EdgeFilter;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.storage.index.LocationIndex;
import com.graphhopper.storage.index.QueryResult;
import com.graphhopper.util.DistanceCalc2D;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.Instruction;
import com.graphhopper.util.InstructionList;
import com.graphhopper.util.PointList;
import com.graphhopper.util.shapes.GHPoint;
......@@ -186,7 +190,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
trajectory = new RouteImpl(comp.getRealPosition(),
destination, pointList,
routeSensor.getSegmentListeners(), routeSensor,
calculateSegments(pointList));
calculateSegments(rsp.getBest()));
} else {
trajectory = new RouteImpl(comp.getRealPosition(),
destination, pointList);
......@@ -204,6 +208,45 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
return new Left<PositionVector, Boolean>(newPosition);
}
/**
* Calculate RouteSegments using the PathWrapper
* @param pathWrapper
* @return
*/
private List<RouteSegmentImpl> calculateSegments(PathWrapper pathWrapper) {
InstructionList instructions = pathWrapper.getInstructions();
int ptIdx = 0;
List<RouteSegmentImpl> segments = new LinkedList<>();
RouteSegmentImpl lastSegment = null;
for (Instruction instr : instructions) {
RouteSegmentImpl segment = null;
PointList points = instr.getPoints();
String name = instr.getName();
if (name.isEmpty()) {
name = Integer.toString(instr.getPoints().toGHPoint(0).hashCode());
}
for (GHPoint point : points) {
if (segment == null) {
if (lastSegment != null) {
lastSegment.addRouteLocation(transformGPSWindowToOwnWorld(
point.getLat(), point.getLon()));
}
segment = new RouteSegmentImpl(name, ptIdx, transformGPSWindowToOwnWorld(point.getLat(),
point.getLon()));
} else {
segment.addRouteLocation(transformGPSWindowToOwnWorld(
point.getLat(), point.getLon()));
}
ptIdx++;
}
lastSegment = segment;
segments.add(segment);
}
return segments;
}
/**
* Calculate the route segments along the given point list.
*
......
......@@ -207,7 +207,7 @@ public class ModularMovementModelViz extends JComponent
private class TrajectoryVis {
private final RouteSensor routeSensor;
public TrajectoryVis(RouteSensor routeSensor) {
this.routeSensor = routeSensor;
}
......@@ -217,14 +217,24 @@ public class ModularMovementModelViz extends JComponent
if (!rt.hasSegmentInformation()) {
return;
}
boolean alt = false;
for (RouteSegment segment : rt.getSegmentsAhead()) {
Location lastLoc = null;
g2.setColor(Color.MAGENTA);
if (alt) {
g2.setColor(Color.ORANGE);
}
alt = !alt;
for (Location loc : segment.getSegmentLocations()) {
if (lastLoc == null) {
lastLoc = loc;
g2.drawString(segment.getSegmentId(),
VisualizationInjector
.scaleValue(lastLoc.getLongitude()),
VisualizationInjector
.scaleValue(lastLoc.getLatitude()));
continue;
}
g2.setColor(Color.MAGENTA);
g2.setStroke(new BasicStroke(3.0f));
g2.drawLine(
VisualizationInjector
......
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