Search in sources :

Example 6 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method searchRoute.

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();
    List<LatLon> targets = new ArrayList<>();
    targets.add(end);
    if (!intermediatesEmpty) {
        targets.addAll(intermediates);
    }
    if (needRequestPrivateAccessRouting(ctx, targets)) {
        ctx.calculationProgress.requestPrivateAccessRouting = true;
    }
    double maxDistance = MapUtils.getDistance(start, end);
    if (!intermediatesEmpty) {
        LatLon b = start;
        for (LatLon l : intermediates) {
            maxDistance = Math.max(MapUtils.getDistance(b, l), maxDistance);
            b = l;
        }
    }
    if (ctx.calculationMode == RouteCalculationMode.COMPLEX && routeDirection == null && maxDistance > ctx.config.DEVIATION_RADIUS * 6) {
        RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE);
        nctx.calculationProgress = ctx.calculationProgress;
        List<RouteSegmentResult> ls = searchRoute(nctx, start, end, intermediates);
        routeDirection = PrecalculatedRouteDirection.build(ls, ctx.config.DEVIATION_RADIUS, ctx.getRouter().getMaxDefaultSpeed());
    }
    if (intermediatesEmpty && ctx.nativeLib != null) {
        ctx.startX = MapUtils.get31TileNumberX(start.getLongitude());
        ctx.startY = MapUtils.get31TileNumberY(start.getLatitude());
        ctx.targetX = MapUtils.get31TileNumberX(end.getLongitude());
        ctx.targetY = MapUtils.get31TileNumberY(end.getLatitude());
        RouteSegment recalculationEnd = getRecalculationEnd(ctx);
        if (recalculationEnd != null) {
            ctx.initTargetPoint(recalculationEnd);
        }
        if (routeDirection != null) {
            ctx.precalculatedRouteDirection = routeDirection.adopt(ctx);
        }
        List<RouteSegmentResult> res = runNativeRouting(ctx, recalculationEnd);
        if (res != null) {
            new RouteResultPreparation().printResults(ctx, start, end, res);
        }
        makeStartEndPointsPrecise(res, start, end, intermediates);
        return res;
    }
    int indexNotFound = 0;
    List<RouteSegmentPoint> points = new ArrayList<RouteSegmentPoint>();
    if (!addSegment(start, ctx, indexNotFound++, points)) {
        return null;
    }
    if (intermediates != null) {
        for (LatLon l : intermediates) {
            if (!addSegment(l, ctx, indexNotFound++, points)) {
                return null;
            }
        }
    }
    if (!addSegment(end, ctx, indexNotFound++, points)) {
        return null;
    }
    List<RouteSegmentResult> res = searchRoute(ctx, points, routeDirection);
    // make start and end more precise
    makeStartEndPointsPrecise(res, start, end, intermediates);
    if (res != null) {
        new RouteResultPreparation().printResults(ctx, start, end, res);
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint) LatLon(net.osmand.data.LatLon) RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 7 with RouteSegmentPoint

use of net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint in project Osmand by osmandapp.

the class RoutePlannerFrontEnd method searchRoute.

@SuppressWarnings("static-access")
private List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegmentPoint start, RouteSegmentPoint end, PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException {
    if (ctx.SHOW_GC_SIZE) {
        long h1 = ctx.runGCUsedMemory();
        float mb = (1 << 20);
        log.warn("Used before routing " + h1 / mb + " actual");
    }
    List<RouteSegmentResult> result = searchRouteInternalPrepare(ctx, start, end, routeDirection);
    if (RoutingContext.SHOW_GC_SIZE) {
        int sz = ctx.global.size;
        log.warn("Subregion size " + ctx.subregionTiles.size() + " " + " tiles " + ctx.indexedSubregions.size());
        ctx.runGCUsedMemory();
        long h1 = ctx.runGCUsedMemory();
        ctx.unloadAllData();
        ctx.runGCUsedMemory();
        long h2 = ctx.runGCUsedMemory();
        float mb = (1 << 20);
        log.warn("Unload context :  estimated " + sz / mb + " ?= " + (h1 - h2) / mb + " actual");
    }
    return result;
}
Also used : RouteSegmentPoint(net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)7 ArrayList (java.util.ArrayList)4 QuadPoint (net.osmand.data.QuadPoint)4 LatLon (net.osmand.data.LatLon)3 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 BinaryRoutePlanner (net.osmand.router.BinaryRoutePlanner)1 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)1 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)1