Refactor native parameters for routing

This commit is contained in:
Victor Shcherb 2020-07-10 23:12:29 +02:00
parent 46703209ff
commit 1433eb0ca9
3 changed files with 22 additions and 26 deletions

View file

@ -26,10 +26,9 @@ import net.osmand.data.QuadRect;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.NativeTransportRoutingResult;
import net.osmand.router.PrecalculatedRouteDirection;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.RoutingConfiguration;
import net.osmand.router.RoutingContext;
import net.osmand.router.TransportRoutingConfiguration;
import net.osmand.util.Algorithms;
@ -135,12 +134,10 @@ public class NativeLibrary {
return nativeTransportRouting(new int[] { sx31, sy31, ex31, ey31 }, cfg, progress);
}
public RouteSegmentResult[] runNativeRouting(int sx31, int sy31, int ex31, int ey31, RoutingConfiguration config,
RouteRegion[] regions, RouteCalculationProgress progress, PrecalculatedRouteDirection precalculatedRouteDirection,
boolean basemap, boolean publicTransport, boolean startTransportStop, boolean targetTransportStop) {
public RouteSegmentResult[] runNativeRouting(RoutingContext c, RouteRegion[] regions, boolean basemap) {
// config.router.printRules(System.out);
return nativeRouting(new int[] { sx31, sy31, ex31, ey31 }, config, config.initialDirection == null ? -360 : config.initialDirection.floatValue(),
regions, progress, precalculatedRouteDirection, basemap, publicTransport, startTransportStop, targetTransportStop);
return nativeRouting(c, c.config.initialDirection == null ? -360 : c.config.initialDirection.floatValue(),
regions, basemap);
}
@ -162,10 +159,7 @@ public class NativeLibrary {
protected static native RouteDataObject[] getRouteDataObjects(RouteRegion reg, long rs, int x31, int y31);
protected static native RouteSegmentResult[] nativeRouting(int[] coordinates, RoutingConfiguration r,
float initDirection, RouteRegion[] regions, RouteCalculationProgress progress,
PrecalculatedRouteDirection precalculatedRouteDirection, boolean basemap,
boolean publicTransport, boolean startTransportStop, boolean targetTransportStop);
protected static native RouteSegmentResult[] nativeRouting(RoutingContext c, float initDirection, RouteRegion[] regions, boolean basemap);
protected static native NativeTransportRoutingResult[] nativeTransportRouting(int[] coordinates, TransportRoutingConfiguration cfg,
RouteCalculationProgress progress);

View file

@ -349,8 +349,8 @@ public class RoutePlannerFrontEnd {
}
if (gctx.distFromLastPoint(startPoint) > 1) {
gctx.routeGapDistance += gctx.distFromLastPoint(startPoint);
System.out.println(String.format("????? gap of route point = %f, gap of actual gpxPoint = %f ",
gctx.distFromLastPoint(startPoint), gctx.distFromLastPoint(pnt.loc)));
System.out.println(String.format("????? gap of route point = %f, gap of actual gpxPoint = %f, %s ",
gctx.distFromLastPoint(startPoint), gctx.distFromLastPoint(pnt.loc), pnt.loc));
}
gctx.res.addAll(pnt.routeToTarget);
i = pnt.targetInd;
@ -784,8 +784,12 @@ public class RoutePlannerFrontEnd {
if (ctx.nativeLib != null) {
ctx.startX = start.preciseX;
ctx.startY = start.preciseY;
ctx.startRoadId = start.road.id;
ctx.startSegmentInd = start.segStart;
ctx.targetX = end.preciseX;
ctx.targetY = end.preciseY;
ctx.targetRoadId = end.road.id;
ctx.targetSegmentInd = end.segStart;
return runNativeRouting(ctx, recalculationEnd);
} else {
refreshProgressDistance(ctx);
@ -850,9 +854,7 @@ public class RoutePlannerFrontEnd {
ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY);
// long time = System.currentTimeMillis();
RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY,
ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE,
ctx.publicTransport, ctx.startTransportStop, ctx.targetTransportStop);
RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx, regions, ctx.calculationMode == RouteCalculationMode.BASE);
// log.info("Native routing took " + (System.currentTimeMillis() - time) / 1000f + " seconds");
ArrayList<RouteSegmentResult> result = new ArrayList<RouteSegmentResult>(Arrays.asList(res));
if (recalculationEnd != null) {
@ -924,13 +926,7 @@ public class RoutePlannerFrontEnd {
List<RouteSegmentResult> res = searchRouteInternalPrepare(local, points.get(i), points.get(i + 1), routeDirection);
makeStartEndPointsPrecise(res, points.get(i).getPreciseLatLon(), points.get(i + 1).getPreciseLatLon(), null);
results.addAll(res);
if(ctx.calculationProgress != null) {
ctx.calculationProgress.distinctLoadedTiles += local.calculationProgress.distinctLoadedTiles;
ctx.calculationProgress.loadedTiles += local.calculationProgress.loadedTiles;
ctx.calculationProgress.loadedPrevUnloadedTiles += local.calculationProgress.loadedPrevUnloadedTiles;
}
ctx.routingTime += local.routingTime;
// local.unloadAllData(ctx);
if (restPartRecalculatedRoute != null) {
results.addAll(restPartRecalculatedRoute);

View file

@ -51,14 +51,16 @@ public class RoutingContext {
// 1. Initial variables
public int startX;
public int startY;
public long startRoadId;
public int startSegmentInd;
public boolean startTransportStop;
public int targetX;
public int targetY;
public long targetRoadId;
public int targetSegmentInd;
public boolean targetTransportStop;
public boolean publicTransport;
// deprecated
public long firstRoadId;
public int firstRoadDirection;
public RouteCalculationProgress calculationProgress;
public boolean leftSideNavigation;
@ -187,12 +189,16 @@ public class RoutingContext {
public void initStartAndTargetPoints(RouteSegment start, RouteSegment end) {
initTargetPoint(end);
startX = start.road.getPoint31XTile(start.getSegmentStart());
startY = start.road.getPoint31YTile(start.getSegmentStart());
startY = start.road.getPoint31YTile(start.getSegmentStart());
startRoadId = start.road.getId();
startSegmentInd = start.getSegmentStart();
}
public void initTargetPoint(RouteSegment end) {
targetX = end.road.getPoint31XTile(end.getSegmentStart());
targetY = end.road.getPoint31YTile(end.getSegmentStart());
targetRoadId = end.road.getId();
targetSegmentInd = end.getSegmentStart();
}
public void unloadAllData() {