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;
}
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;
}
Aggregations