Search in sources :

Example 21 with RouteSegment

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

the class RoutingContext method loadRouteSegment.

public RouteSegment loadRouteSegment(int x31, int y31, int memoryLimit) {
    long tileId = getRoutingTile(x31, y31, memoryLimit, OPTION_SMART_LOAD);
    TLongObjectHashMap<RouteDataObject> excludeDuplications = new TLongObjectHashMap<RouteDataObject>();
    RouteSegment original = null;
    if (tileRoutes.containsKey(tileId)) {
        List<RouteDataObject> routes = tileRoutes.get(tileId);
        if (routes != null) {
            for (RouteDataObject ro : routes) {
                for (int i = 0; i < ro.pointsX.length; i++) {
                    if (ro.getPoint31XTile(i) == x31 && ro.getPoint31YTile(i) == y31) {
                        long id = calcRouteId(ro, i);
                        if (excludeDuplications.contains(id)) {
                            continue;
                        }
                        excludeDuplications.put(id, ro);
                        RouteSegment segment = new RouteSegment(ro, i);
                        segment.next = original;
                        original = segment;
                    }
                }
            }
        }
    }
    List<RoutingSubregionTile> subregions = indexedSubregions.get(tileId);
    if (subregions != null) {
        for (RoutingSubregionTile rs : subregions) {
            original = rs.loadRouteSegment(x31, y31, this, excludeDuplications, original);
        }
    }
    return original;
}
Also used : TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) FinalRouteSegment(net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)

Example 22 with RouteSegment

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

the class RouteResultPreparation method attachRoadSegments.

private void attachRoadSegments(RoutingContext ctx, List<RouteSegmentResult> result, int routeInd, int pointInd, boolean plus) throws IOException {
    RouteSegmentResult rr = result.get(routeInd);
    RouteDataObject road = rr.getObject();
    long nextL = pointInd < road.getPointsLength() - 1 ? getPoint(road, pointInd + 1) : 0;
    long prevL = pointInd > 0 ? getPoint(road, pointInd - 1) : 0;
    // attach additional roads to represent more information about the route
    RouteSegmentResult previousResult = null;
    // by default make same as this road id
    long previousRoadId = road.getId();
    if (pointInd == rr.getStartPointIndex() && routeInd > 0) {
        previousResult = result.get(routeInd - 1);
        previousRoadId = previousResult.getObject().getId();
        if (previousRoadId != road.getId()) {
            if (previousResult.getStartPointIndex() < previousResult.getEndPointIndex() && previousResult.getEndPointIndex() < previousResult.getObject().getPointsLength() - 1) {
                rr.attachRoute(pointInd, new RouteSegmentResult(previousResult.getObject(), previousResult.getEndPointIndex(), previousResult.getObject().getPointsLength() - 1));
            } else if (previousResult.getStartPointIndex() > previousResult.getEndPointIndex() && previousResult.getEndPointIndex() > 0) {
                rr.attachRoute(pointInd, new RouteSegmentResult(previousResult.getObject(), previousResult.getEndPointIndex(), 0));
            }
        }
    }
    Iterator<RouteSegment> it;
    if (rr.getPreAttachedRoutes(pointInd) != null) {
        final RouteSegmentResult[] list = rr.getPreAttachedRoutes(pointInd);
        it = new Iterator<BinaryRoutePlanner.RouteSegment>() {

            int i = 0;

            @Override
            public boolean hasNext() {
                return i < list.length;
            }

            @Override
            public RouteSegment next() {
                RouteSegmentResult r = list[i++];
                return new RouteSegment(r.getObject(), r.getStartPointIndex());
            }

            @Override
            public void remove() {
            }
        };
    } else {
        RouteSegment rt = ctx.loadRouteSegment(road.getPoint31XTile(pointInd), road.getPoint31YTile(pointInd), ctx.config.memoryLimitation);
        it = rt == null ? null : rt.getIterator();
    }
    // try to attach all segments except with current id
    while (it != null && it.hasNext()) {
        RouteSegment routeSegment = it.next();
        if (routeSegment.road.getId() != road.getId() && routeSegment.road.getId() != previousRoadId) {
            RouteDataObject addRoad = routeSegment.road;
            checkAndInitRouteRegion(ctx, addRoad);
            // TODO restrictions can be considered as well
            int oneWay = ctx.getRouter().isOneWay(addRoad);
            if (oneWay >= 0 && routeSegment.getSegmentStart() < addRoad.getPointsLength() - 1) {
                long pointL = getPoint(addRoad, routeSegment.getSegmentStart() + 1);
                if (pointL != nextL && pointL != prevL) {
                    // if way contains same segment (nodes) as different way (do not attach it)
                    rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.getSegmentStart(), addRoad.getPointsLength() - 1));
                }
            }
            if (oneWay <= 0 && routeSegment.getSegmentStart() > 0) {
                long pointL = getPoint(addRoad, routeSegment.getSegmentStart() - 1);
                // if way contains same segment (nodes) as different way (do not attach it)
                if (pointL != nextL && pointL != prevL) {
                    rr.attachRoute(pointInd, new RouteSegmentResult(addRoad, routeSegment.getSegmentStart(), 0));
                }
            }
        }
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment) FinalRouteSegment(net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)

Aggregations

RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)22 ArrayList (java.util.ArrayList)10 FinalRouteSegment (net.osmand.router.BinaryRoutePlanner.FinalRouteSegment)9 RouteDataObject (net.osmand.binary.RouteDataObject)8 Point (java.awt.Point)5 LatLon (net.osmand.data.LatLon)5 PriorityQueue (java.util.PriorityQueue)3 Way (net.osmand.osm.edit.Way)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 TLongHashSet (gnu.trove.set.hash.TLongHashSet)2 DataTileManager (net.osmand.data.DataTileManager)2 QuadPoint (net.osmand.data.QuadPoint)2 RouteSegmentPoint (net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint)2 RouteSegmentVisitor (net.osmand.router.BinaryRoutePlanner.RouteSegmentVisitor)2 Builder (net.osmand.router.RoutingConfiguration.Builder)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 File (java.io.File)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1