From 159dc51197dbec48768f4fc563601c78d73a4292 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 15:01:29 +0200 Subject: [PATCH 1/3] Consolidate rendering with native --- .../osmand/plus/render/MapRenderRepositories.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 18d4f3e7ae..e7e9bc1b6d 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -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 files = new ConcurrentHashMap(); @@ -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); } From 05e763f60c791e79e8111134fea48c8f054bd2c3 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 15:55:32 +0200 Subject: [PATCH 2/3] Improve gpx route calculation --- .../src/net/osmand/router/BinaryRoutePlanner.java | 12 ++++++++++-- .../osmand/router/PrecalculatedRouteDirection.java | 11 +++++++++++ .../src/net/osmand/router/RoutePlannerFrontEnd.java | 11 ++++++++--- .../src/net/osmand/plus/routing/RouteProvider.java | 12 +++++------- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index b798c78fca..4a222c8acb 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -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().getMinDefaultSpeed(); + } // 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 graphSegments, - TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, + TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections, boolean[] processFurther) { boolean thereAreRestrictions ; diff --git a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java index 68bcc8195e..17a5eb5314 100644 --- a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java +++ b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java @@ -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; diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index b466cb0dcf..8d7f61e3ae 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -84,13 +84,17 @@ public class RoutePlannerFrontEnd { } - public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates) throws IOException, InterruptedException { + return searchRoute(ctx, start, end, intermediates, null); + } + + + public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List 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 ls = searchRoute(nctx, start, end, intermediates); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index e8cbf61d0e..61cc068e36 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -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(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 inters) throws IOException { + List inters, PrecalculatedRouteDirection precalculated) throws IOException { try { List 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) { From 3c1104b1d0c431925f04765355fa852fe3509578 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 18:44:17 +0100 Subject: [PATCH 3/3] Improve gpx route calculation --- OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java | 4 ++-- OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index 4a222c8acb..e8091b06a4 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -384,9 +384,9 @@ public class BinaryRoutePlanner { float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime); if(ctx.precalculatedRouteDirection != null && ctx.precalculatedRouteDirection.isFollowNext()) { // reset to f - distStartObstacles = 0; +// distStartObstacles = 0; // more precise but slower - //distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMinDefaultSpeed(); + distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMaxDefaultSpeed(); } // We don't check if there are outgoing connections diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index 8d7f61e3ae..1e2bfd5ac9 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -122,7 +122,7 @@ public class RoutePlannerFrontEnd { if(res != null) { new RouteResultPreparation().printResults(ctx, start, end, res); } - return res; + return res; } int indexNotFound = 0; List points = new ArrayList();