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();
// float devDistance = ctx.precalculatedRouteDirection.getDeviationDistance(x, y);
// // 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
// segmentDist = segmentDist * (float) Math.pow(1.5, devDistance / 500);
// 3. next by method
// segmentDist = devDistance ;
// ctx.timeNanoToCalcDeviation += (System.nanoTime() - nt);
}
// could be expensive calculation
// 3. get intersected ways
final RouteSegment roadNext = ctx.loadRouteSegment(x, y, ctx.config.memoryLimitation - ctx.memoryOverhead);
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
previous = processIntersections(ctx, graphSegments, visitedSegments, distStartObstacles,
@ -557,7 +565,7 @@ public class BinaryRoutePlanner {
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,
boolean[] processFurther) {
boolean thereAreRestrictions ;

View file

@ -19,6 +19,7 @@ public class PrecalculatedRouteDirection {
private float minSpeed;
private float maxSpeed;
private float[] tms;
private boolean followNext;
private static final int SHIFT = (1 << (31 - 17));
private static final int[] SHIFTS = new int[]{1 << (31 - 15), 1 << (31 - 13), 1 << (31 - 12),
1 << (31 - 11), 1 << (31 - 7)};
@ -240,6 +241,15 @@ public class PrecalculatedRouteDirection {
return ((long) x31) << 32l + ((long)y31);
}
public void setFollowNext(boolean followNext) {
this.followNext = followNext;
}
public boolean isFollowNext() {
return followNext;
}
public PrecalculatedRouteDirection adopt(RoutingContext ctx) {
int ind1 = getIndex(ctx.startX, ctx.startY);
int ind2 = getIndex(ctx.targetX, ctx.targetY);
@ -258,6 +268,7 @@ public class PrecalculatedRouteDirection {
// routeDirection.startY31 = ctx.startY;
routeDirection.endPoint = calc(ctx.targetX, ctx.targetX);
routeDirection.endFinishTime = (float) BinaryRoutePlanner.squareRootDist(pointsX[ind2], pointsY[ind2], ctx.targetX, ctx.targetY) / maxSpeed;
routeDirection.followNext = followNext;
// routeDirection.endX31 = ctx.targetX;
// 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 {
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) {
ctx.calculationProgress = new RouteCalculationProgress();
}
boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty();
PrecalculatedRouteDirection routeDirection = null;
double maxDistance = MapUtils.getDistance(start, end);
if(!intermediatesEmpty) {
LatLon b = start;
@ -99,7 +103,8 @@ public class RoutePlannerFrontEnd {
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);
nctx.calculationProgress = ctx.calculationProgress ;
List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);
@ -117,7 +122,7 @@ public class RoutePlannerFrontEnd {
if(res != null) {
new RouteResultPreparation().printResults(ctx, start, end, res);
}
return res;
return res;
}
int indexNotFound = 0;
List<RouteSegment> points = new ArrayList<BinaryRoutePlanner.RouteSegment>();

View file

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

View file

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