Search in sources :

Example 1 with GpxPoint

use of net.osmand.router.RoutePlannerFrontEnd.GpxPoint in project OsmAnd-tools by osmandapp.

the class OsmAndMapsService method approximate.

private List<RouteSegmentResult> approximate(RoutingContext ctx, RoutePlannerFrontEnd router, Map<String, Object> props, List<LatLon> polyline) throws IOException, InterruptedException {
    GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
    List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(polyline));
    GpxRouteApproximation r = router.searchGpxRoute(gctx, gpxPoints, null);
    List<RouteSegmentResult> route = new ArrayList<RouteSegmentResult>();
    for (GpxPoint pnt : r.finalPoints) {
        route.addAll(pnt.routeToTarget);
    }
    if (router.useNativeApproximation) {
        RouteResultPreparation preparation = new RouteResultPreparation();
        // preparation.prepareTurnResults(gctx.ctx, route);
        preparation.addTurnInfoDescriptions(route);
    }
    putResultProps(ctx, route, props);
    return route;
}
Also used : LocationsHolder(net.osmand.LocationsHolder) ArrayList(java.util.ArrayList) GpxRouteApproximation(net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation) RouteResultPreparation(net.osmand.router.RouteResultPreparation) RouteSegmentResult(net.osmand.router.RouteSegmentResult) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint)

Example 2 with GpxPoint

use of net.osmand.router.RoutePlannerFrontEnd.GpxPoint in project OsmAnd-tools by osmandapp.

the class MapRouterLayer method getGpxAproximation.

private List<RouteSegmentResult> getGpxAproximation(RoutePlannerFrontEnd router, GpxRouteApproximation gctx, List<GpxPoint> gpxPoints) throws IOException, InterruptedException {
    GpxRouteApproximation r = router.searchGpxRoute(gctx, gpxPoints, null);
    if (TEST_INTERMEDIATE_POINTS) {
        return r.result;
    }
    List<RouteSegmentResult> rsr = new ArrayList<RouteSegmentResult>();
    for (GpxPoint pnt : r.finalPoints) {
        rsr.addAll(pnt.routeToTarget);
    }
    return rsr;
}
Also used : ArrayList(java.util.ArrayList) GpxRouteApproximation(net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation) RouteSegmentResult(net.osmand.router.RouteSegmentResult) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint)

Example 3 with GpxPoint

use of net.osmand.router.RoutePlannerFrontEnd.GpxPoint in project OsmAnd-tools by osmandapp.

the class MapRouterLayer method createSegmentVisitor.

private RouteSegmentVisitor createSegmentVisitor(final boolean animateRoutingCalculation, final DataTileManager<Entity> points) {
    return new RouteSegmentVisitor() {

        private List<RouteSegment> cache = new ArrayList<RouteSegment>();

        private List<RouteSegment> pollCache = new ArrayList<RouteSegment>();

        private List<Integer> cacheInt = new ArrayList<Integer>();

        @Override
        public void visitSegment(RouteSegment s, int endSegment, boolean poll) {
            if (gpx) {
                return;
            }
            if (stop) {
                throw new RuntimeException("Interrupted");
            }
            if (!animateRoutingCalculation) {
                return;
            }
            if (!poll && pause) {
                pollCache.add(s);
                return;
            }
            cache.add(s);
            cacheInt.add(endSegment);
            if (cache.size() < steps) {
                return;
            }
            if (pause) {
                registerObjects(points, poll, pollCache, null);
                pollCache.clear();
            }
            registerObjects(points, !poll, cache, cacheInt);
            cache.clear();
            cacheInt.clear();
            redraw();
            if (pause) {
                waitNextPress();
            }
        }

        @Override
        public void visitApproximatedSegments(List<RouteSegmentResult> segment, GpxPoint start, GpxPoint target) {
            if (stop) {
                throw new RuntimeException("Interrupted");
            }
            if (!animateRoutingCalculation) {
                return;
            }
            // points.clear();
            for (List<Entity> list : points.getAllEditObjects()) {
                Iterator<Entity> it = list.iterator();
                while (it.hasNext()) {
                    Entity e = it.next();
                    if (!"yes".equals(e.getTag("gpx"))) {
                        it.remove();
                    }
                }
            }
            startRoute = start.loc;
            endRoute = target.loc;
            for (int i = 0; i < segment.size(); i++) {
                cache.add(new RouteSegment(segment.get(i).getObject(), segment.get(i).getStartPointIndex()));
                cacheInt.add(segment.get(i).getEndPointIndex());
            }
            if (cache.size() < steps) {
                return;
            }
            if (pause) {
                registerObjects(points, false, pollCache, null);
                pollCache.clear();
            }
            registerObjects(points, false, cache, cacheInt);
            cache.clear();
            cacheInt.clear();
            redraw();
            if (pause) {
                waitNextPress();
            }
        }

        private void registerObjects(final DataTileManager<Entity> points, boolean white, List<RouteSegment> registerCache, List<Integer> cacheInt) {
            for (int l = 0; l < registerCache.size(); l++) {
                RouteSegment segment = registerCache.get(l);
                Way way = new Way(-1);
                way.putTag(OSMTagKey.NAME.getValue(), segment.getTestName());
                if (white) {
                    way.putTag("color", "white");
                }
                int from = cacheInt != null ? segment.getSegmentStart() : segment.getSegmentStart() - 2;
                int to = cacheInt != null ? cacheInt.get(l) : segment.getSegmentStart() + 2;
                if (from > to) {
                    int x = from;
                    from = to;
                    to = x;
                }
                for (int i = from; i <= to; i++) {
                    if (i >= 0 && i < segment.getRoad().getPointsLength()) {
                        net.osmand.osm.edit.Node n = createNode(segment, i);
                        way.addNode(n);
                        if (i == from || i == to) {
                            n.putTag("colour", "red");
                        }
                        points.registerObject(n.getLatitude(), n.getLongitude(), n);
                    }
                }
                LatLon n = way.getLatLon();
                points.registerObject(n.getLatitude(), n.getLongitude(), way);
            }
        }
    };
}
Also used : Entity(net.osmand.osm.edit.Entity) RouteSegmentVisitor(net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor) Point(java.awt.Point) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) Way(net.osmand.osm.edit.Way) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) LatLon(net.osmand.data.LatLon) DataTileManager(net.osmand.data.DataTileManager) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 4 with GpxPoint

use of net.osmand.router.RoutePlannerFrontEnd.GpxPoint in project OsmAnd-tools by osmandapp.

the class MapRouterLayer method selfRoute.

public List<Entity> selfRoute(LatLon start, LatLon end, List<LatLon> intermediates, boolean gpx, List<RouteSegmentResult> previousRoute, RouteCalculationMode rm) {
    this.gpx = gpx;
    List<Entity> res = new ArrayList<Entity>();
    long time = System.currentTimeMillis();
    final boolean animateRoutingCalculation = DataExtractionSettings.getSettings().isAnimateRouting();
    if (animateRoutingCalculation) {
        nextTurn.setVisible(true);
        playPauseButton.setVisible(true);
        stopButton.setVisible(true);
        pause = true;
        playPauseButton.setText("Play");
    }
    stop = false;
    System.out.println("Self made route from " + start + " to " + end);
    if (start != null && end != null) {
        try {
            BinaryMapIndexReader[] files = DataExtractionSettings.getSettings().getObfReaders();
            if (files.length == 0) {
                JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), "Please specify obf file in settings", "Obf file not found", JOptionPane.ERROR_MESSAGE);
                return null;
            }
            String m = DataExtractionSettings.getSettings().getRouteMode();
            String[] props = m.split("\\,");
            RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
            Map<String, String> paramsR = new LinkedHashMap<String, String>();
            for (String p : props) {
                if (p.contains("=")) {
                    paramsR.put(p.split("=")[0], p.split("=")[1]);
                } else {
                    paramsR.put(p, "true");
                }
            }
            RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(2000, DEFAULT_NATIVE_MEMORY_LIMIT * 10);
            RoutingConfiguration config = DataExtractionSettings.getSettings().getRoutingConfig().setDirectionPoints(directionPointsFile).build(props[0], /* RoutingConfiguration.DEFAULT_MEMORY_LIMIT */
            memoryLimit, paramsR);
            PrecalculatedRouteDirection precalculatedRouteDirection = null;
            // config.ZOOM_TO_LOAD_TILES = 14;
            try {
                config.routeCalculationTime = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.US).parse("19.07.2019 12:40").getTime();
            } catch (Exception e) {
            }
            config.routeCalculationTime = System.currentTimeMillis();
            final RoutingContext ctx = router.buildRoutingContext(config, DataExtractionSettings.getSettings().useNativeRouting() ? NativeSwingRendering.getDefaultFromSettings() : null, files, rm);
            ctx.leftSideNavigation = false;
            ctx.previouslyCalculatedRoute = previousRoute;
            log.info("Use " + config.routerName + " mode for routing");
            final DataTileManager<Entity> points = map.getPoints();
            map.setPoints(points);
            ctx.setVisitor(createSegmentVisitor(animateRoutingCalculation, points));
            // Choose native or not native
            long nt = System.nanoTime();
            startProgressThread(ctx);
            try {
                GpxRouteApproximation gctx = new GpxRouteApproximation(ctx);
                List<GpxPoint> gpxPoints = router.generateGpxPoints(gctx, new LocationsHolder(intermediates));
                List<RouteSegmentResult> searchRoute = gpx ? getGpxAproximation(router, gctx, gpxPoints) : router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
                throwExceptionIfRouteNotFound(ctx, searchRoute);
                System.out.println("Routing time " + (System.nanoTime() - nt) / 1.0e9f);
                if (animateRoutingCalculation) {
                    playPauseButton.setVisible(false);
                    nextTurn.setText("FINISH");
                    waitNextPress();
                    nextTurn.setText(">>");
                }
                this.previousRoute = searchRoute;
                calculateResult(res, searchRoute);
            } finally {
                if (ctx.calculationProgress != null) {
                    ctx.calculationProgress.isCancelled = true;
                }
            }
        } catch (Exception e) {
            ExceptionHandler.handle(e);
        } finally {
            playPauseButton.setVisible(false);
            nextTurn.setVisible(false);
            stopButton.setVisible(false);
            if (map.getPoints() != null) {
                map.getPoints().clear();
            }
        }
        System.out.println("!!! Finding self route: " + res.size() + " " + (System.currentTimeMillis() - time) + " ms");
    }
    return res;
}
Also used : Entity(net.osmand.osm.edit.Entity) LocationsHolder(net.osmand.LocationsHolder) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) GpxRouteApproximation(net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation) RouteSegmentResult(net.osmand.router.RouteSegmentResult) PrecalculatedRouteDirection(net.osmand.router.PrecalculatedRouteDirection) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) JSONException(org.json.JSONException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ArrayList (java.util.ArrayList)4 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)4 GpxRouteApproximation (net.osmand.router.RoutePlannerFrontEnd.GpxRouteApproximation)3 RouteSegmentResult (net.osmand.router.RouteSegmentResult)3 LocationsHolder (net.osmand.LocationsHolder)2 Entity (net.osmand.osm.edit.Entity)2 Point (java.awt.Point)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)1 DataTileManager (net.osmand.data.DataTileManager)1 LatLon (net.osmand.data.LatLon)1 Way (net.osmand.osm.edit.Way)1 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)1 RouteSegmentVisitor (net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor)1 PrecalculatedRouteDirection (net.osmand.router.PrecalculatedRouteDirection)1