Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-03-03 18:47:54 +01:00
commit a1799a2607
5 changed files with 41 additions and 19 deletions

View file

@ -371,15 +371,23 @@ public class BinaryRoutePlanner {
// long nt = System.nanoTime(); // long nt = System.nanoTime();
// float devDistance = ctx.precalculatedRouteDirection.getDeviationDistance(x, y); // float devDistance = ctx.precalculatedRouteDirection.getDeviationDistance(x, y);
// // 1. linear method // // 1. linear method
// // segmentDist = segmentDist * (1 + ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.config.DEVIATION_RADIUS); // segmentDist = segmentDist * (1 + devDistance / ctx.config.DEVIATION_RADIUS);
// // 2. exponential method // // 2. exponential method
// segmentDist = segmentDist * (float) Math.pow(1.5, devDistance / 500); // segmentDist = segmentDist * (float) Math.pow(1.5, devDistance / 500);
// 3. next by method
// segmentDist = devDistance ;
// ctx.timeNanoToCalcDeviation += (System.nanoTime() - nt); // ctx.timeNanoToCalcDeviation += (System.nanoTime() - nt);
} }
// could be expensive calculation // could be expensive calculation
// 3. get intersected ways // 3. get intersected ways
final RouteSegment roadNext = ctx.loadRouteSegment(x, y, ctx.config.memoryLimitation - ctx.memoryOverhead); final RouteSegment roadNext = ctx.loadRouteSegment(x, y, ctx.config.memoryLimitation - ctx.memoryOverhead);
float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime); float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime);
if(ctx.precalculatedRouteDirection != null && ctx.precalculatedRouteDirection.isFollowNext()) {
// reset to f
// distStartObstacles = 0;
// more precise but slower
distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMaxDefaultSpeed();
}
// We don't check if there are outgoing connections // We don't check if there are outgoing connections
previous = processIntersections(ctx, graphSegments, visitedSegments, distStartObstacles, previous = processIntersections(ctx, graphSegments, visitedSegments, distStartObstacles,
@ -557,7 +565,7 @@ public class BinaryRoutePlanner {
private RouteSegment processIntersections(RoutingContext ctx, PriorityQueue<RouteSegment> graphSegments, private RouteSegment processIntersections(RoutingContext ctx, PriorityQueue<RouteSegment> graphSegments,
TLongObjectHashMap<RouteSegment> visitedSegments, float distFromStart, RouteSegment segment, TLongObjectHashMap<RouteSegment> visitedSegments, float distFromStart, RouteSegment segment,
short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections, short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections,
boolean[] processFurther) { boolean[] processFurther) {
boolean thereAreRestrictions ; boolean thereAreRestrictions ;

View file

@ -19,6 +19,7 @@ public class PrecalculatedRouteDirection {
private float minSpeed; private float minSpeed;
private float maxSpeed; private float maxSpeed;
private float[] tms; private float[] tms;
private boolean followNext;
private static final int SHIFT = (1 << (31 - 17)); private static final int SHIFT = (1 << (31 - 17));
private static final int[] SHIFTS = new int[]{1 << (31 - 15), 1 << (31 - 13), 1 << (31 - 12), private static final int[] SHIFTS = new int[]{1 << (31 - 15), 1 << (31 - 13), 1 << (31 - 12),
1 << (31 - 11), 1 << (31 - 7)}; 1 << (31 - 11), 1 << (31 - 7)};
@ -240,6 +241,15 @@ public class PrecalculatedRouteDirection {
return ((long) x31) << 32l + ((long)y31); return ((long) x31) << 32l + ((long)y31);
} }
public void setFollowNext(boolean followNext) {
this.followNext = followNext;
}
public boolean isFollowNext() {
return followNext;
}
public PrecalculatedRouteDirection adopt(RoutingContext ctx) { public PrecalculatedRouteDirection adopt(RoutingContext ctx) {
int ind1 = getIndex(ctx.startX, ctx.startY); int ind1 = getIndex(ctx.startX, ctx.startY);
int ind2 = getIndex(ctx.targetX, ctx.targetY); int ind2 = getIndex(ctx.targetX, ctx.targetY);
@ -258,6 +268,7 @@ public class PrecalculatedRouteDirection {
// routeDirection.startY31 = ctx.startY; // routeDirection.startY31 = ctx.startY;
routeDirection.endPoint = calc(ctx.targetX, ctx.targetX); routeDirection.endPoint = calc(ctx.targetX, ctx.targetX);
routeDirection.endFinishTime = (float) BinaryRoutePlanner.squareRootDist(pointsX[ind2], pointsY[ind2], ctx.targetX, ctx.targetY) / maxSpeed; routeDirection.endFinishTime = (float) BinaryRoutePlanner.squareRootDist(pointsX[ind2], pointsY[ind2], ctx.targetX, ctx.targetY) / maxSpeed;
routeDirection.followNext = followNext;
// routeDirection.endX31 = ctx.targetX; // routeDirection.endX31 = ctx.targetX;
// routeDirection.endY31 = ctx.targetY; // routeDirection.endY31 = ctx.targetY;

View file

@ -84,13 +84,17 @@ public class RoutePlannerFrontEnd {
} }
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List<LatLon> intermediates) throws IOException, InterruptedException { public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List<LatLon> intermediates) throws IOException, InterruptedException {
return searchRoute(ctx, start, end, intermediates, null);
}
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List<LatLon> intermediates,
PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException {
if(ctx.calculationProgress == null) { if(ctx.calculationProgress == null) {
ctx.calculationProgress = new RouteCalculationProgress(); ctx.calculationProgress = new RouteCalculationProgress();
} }
boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty(); boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty();
PrecalculatedRouteDirection routeDirection = null;
double maxDistance = MapUtils.getDistance(start, end); double maxDistance = MapUtils.getDistance(start, end);
if(!intermediatesEmpty) { if(!intermediatesEmpty) {
LatLon b = start; LatLon b = start;
@ -99,7 +103,8 @@ public class RoutePlannerFrontEnd {
b = l; b = l;
} }
} }
if(ctx.calculationMode == RouteCalculationMode.COMPLEX && maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) { if(ctx.calculationMode == RouteCalculationMode.COMPLEX && routeDirection == null
&& maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) {
RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE); RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
nctx.calculationProgress = ctx.calculationProgress ; nctx.calculationProgress = ctx.calculationProgress ;
List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates); List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);

View file

@ -71,7 +71,7 @@ public class MapRenderRepositories {
private final static Log log = PlatformUtil.getLog(MapRenderRepositories.class); private final static Log log = PlatformUtil.getLog(MapRenderRepositories.class);
private final OsmandApplication context; private final OsmandApplication context;
private final static int BASEMAP_ZOOM = 11; private final static int zoomOnlyForBasemaps = 11;
static int zoomForBaseRouteRendering = 14; static int zoomForBaseRouteRendering = 14;
private Handler handler; private Handler handler;
private Map<String, BinaryMapIndexReader> files = new ConcurrentHashMap<String, BinaryMapIndexReader>(); private Map<String, BinaryMapIndexReader> files = new ConcurrentHashMap<String, BinaryMapIndexReader>();
@ -376,7 +376,7 @@ public class MapRenderRepositories {
if (checkWhetherInterrupted()) { if (checkWhetherInterrupted()) {
return false; return false;
} }
if (renderRouteDataFile >= 0 && zoom >= BASEMAP_ZOOM ) { if (renderRouteDataFile >= 0 && zoom >= zoomOnlyForBasemaps ) {
searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, null); searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, null);
for (BinaryMapIndexReader c : files.values()) { for (BinaryMapIndexReader c : files.values()) {
// false positive case when we have 2 sep maps Country-roads & Country // false positive case when we have 2 sep maps Country-roads & Country
@ -389,14 +389,14 @@ public class MapRenderRepositories {
String coastlineTime = ""; String coastlineTime = "";
boolean addBasemapCoastlines = true; boolean addBasemapCoastlines = true;
boolean emptyData = zoom > BASEMAP_ZOOM && tempResult.isEmpty() && coastLines.isEmpty(); boolean emptyData = zoom > zoomOnlyForBasemaps && tempResult.isEmpty() && coastLines.isEmpty();
boolean basemapMissing = zoom <= BASEMAP_ZOOM && basemapCoastLines.isEmpty() && mi == null; boolean basemapMissing = zoom <= zoomOnlyForBasemaps && basemapCoastLines.isEmpty() && mi == null;
boolean detailedLandData = zoom >= zoomForBaseRouteRendering && tempResult.size() > 0 && renderRouteDataFile < 0; boolean detailedLandData = zoom >= zoomForBaseRouteRendering && tempResult.size() > 0 && renderRouteDataFile < 0;
if (!coastLines.isEmpty()) { if (!coastLines.isEmpty()) {
long ms = System.currentTimeMillis(); long ms = System.currentTimeMillis();
boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom, boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom,
basemapCoastLines.isEmpty(), true, tempResult); basemapCoastLines.isEmpty(), true, tempResult);
addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= BASEMAP_ZOOM; addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= zoomOnlyForBasemaps;
coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )";
} else { } else {
addBasemapCoastlines = !detailedLandData; addBasemapCoastlines = !detailedLandData;
@ -425,7 +425,7 @@ public class MapRenderRepositories {
mapIndex.initMapEncodingRule(0, 2, "name", ""); mapIndex.initMapEncodingRule(0, 2, "name", "");
} }
} }
if (zoom <= BASEMAP_ZOOM || emptyData) { if (zoom <= zoomOnlyForBasemaps || emptyData) {
tempResult.addAll(basemapResult); tempResult.addAll(basemapResult);
} }

View file

@ -451,7 +451,8 @@ public class RouteProvider {
latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude()); latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude());
} }
precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed()); precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed());
cf.planRoadDirection = 1; precalculated.setFollowNext(true);
//cf.planRoadDirection = 1;
} }
// BUILD context // BUILD context
RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files,
@ -466,9 +467,6 @@ public class RouteProvider {
complexCtx.calculationProgress = params.calculationProgress; complexCtx.calculationProgress = params.calculationProgress;
complexCtx.leftSideNavigation = params.leftSide; complexCtx.leftSideNavigation = params.leftSide;
} }
if(precalculated != null) {
ctx.precalculatedRouteDirection = precalculated.adopt(ctx);
}
ctx.leftSideNavigation = params.leftSide; ctx.leftSideNavigation = params.leftSide;
ctx.calculationProgress = params.calculationProgress; ctx.calculationProgress = params.calculationProgress;
if(params.previousToRecalculate != null) { if(params.previousToRecalculate != null) {
@ -481,7 +479,7 @@ public class RouteProvider {
if (params.intermediates != null) { if (params.intermediates != null) {
inters = new ArrayList<LatLon>(params.intermediates); inters = new ArrayList<LatLon>(params.intermediates);
} }
return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters); return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated);
} }
@ -547,12 +545,12 @@ public class RouteProvider {
private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params, private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params,
RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en, RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en,
List<LatLon> inters) throws IOException { List<LatLon> inters, PrecalculatedRouteDirection precalculated) throws IOException {
try { try {
List<RouteSegmentResult> result ; List<RouteSegmentResult> result ;
if(complexCtx != null) { if(complexCtx != null) {
try { try {
result = router.searchRoute(complexCtx, st, en, inters); result = router.searchRoute(complexCtx, st, en, inters, precalculated);
// discard ctx and replace with calculated // discard ctx and replace with calculated
ctx = complexCtx; ctx = complexCtx;
} catch(final RuntimeException e) { } catch(final RuntimeException e) {