Search in sources :

Example 1 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class RouteCalculator method calculateRoute.

/**
	 * Template method, responsible for shortest path generation between two map
	 * nodes. It searches for way nodes in the vicinity of the given nodes which
	 * comply with the specified way selection, searches for a suitable paths,
	 * and adds the paths as tracks to the provided <code>map</code>. Various
	 * factory methods can be used to override aspects of the default behavior
	 * in subclasses if needed.
	 * 
	 * @param markers
	 *            Nodes, not necessarily way nodes. The first node is used as
	 *            start, last node as finish, all others as via nodes.
	 * @param map
	 *            The information source.
	 * @param taskSelection
	 *            Number, indicating which kinds of ways are relevant.
	 */
public List<Position> calculateRoute(List<MapNode> markers, OsmMap map, int taskSelection) {
    List<Position> result = new ArrayList<>();
    try {
        MapWayFilter wayFilter = createMapWayFilter(map, taskSelection);
        boolean ignoreOneways = (taskSelection == 0);
        List<MapNode[]> pNodeList = subdivideProblem(markers, map, wayFilter);
        MapNode prevNode = null;
        for (int i = 0; i < pNodeList.size() && !CancelableThread.currIsCanceled(); i++) {
            Problem<MapNode, OsmMoveAction> problem = createProblem(pNodeList.get(i), map, wayFilter, ignoreOneways, taskSelection);
            ToDoubleFunction<Node<MapNode, OsmMoveAction>> h = createHeuristicFunction(pNodeList.get(i), taskSelection);
            SearchForActions<MapNode, OsmMoveAction> search = createSearch(h, taskSelection);
            List<OsmMoveAction> actions = search.findActions(problem);
            if (actions.isEmpty())
                break;
            for (Object action : actions) {
                if (action instanceof OsmMoveAction) {
                    OsmMoveAction a = (OsmMoveAction) action;
                    for (MapNode node : a.getNodes()) {
                        if (prevNode != node) {
                            result.add(new Position(node.getLat(), node.getLon()));
                            prevNode = node;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : MapWayFilter(aimax.osm.data.MapWayFilter) Position(aimax.osm.data.Position) Node(aima.core.search.framework.Node) MapNode(aimax.osm.data.entities.MapNode) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Example 2 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class DefaultEntityRenderer method getViewCoords.

/**
	 * Computes the view coordinates for a list of way nodes and checks
	 * visibility with respect to a clipping rectangle. The check improves the
	 * viewing performance in large scales in which long invisible ways (e.g.
	 * coast lines) often pass the bounding box test.
	 * 
	 * @param nodes
	 *            List of way nodes.
	 * @param viewWidth
	 *            Used for clipping if > 0.
	 * @param viewHeight
	 *            Used for clipping if > 0.
	 * @param xView
	 *            Array of coordinates for the result.
	 * @param yView
	 *            Array of coordinates for the result.
	 * @return true if at least a part of the line is visible.
	 */
protected boolean getViewCoords(List<MapNode> nodes, int viewWidth, int viewHeight, int[] xView, int[] yView) {
    boolean visible = (viewWidth <= 0 || viewHeight <= 0);
    int xv;
    int yv;
    int xClipPos;
    int yClipPos;
    int xClipPosLast = 0;
    int yClipPosLast = 0;
    int i = 0;
    for (MapNode node : nodes) {
        xv = transformer.x(node.getLon());
        yv = transformer.y(node.getLat());
        // bounding box test not sufficient for large scales...
        xView[i] = xv;
        yView[i] = yv;
        if (!visible) {
            xClipPos = 0;
            if (xv < 0)
                xClipPos = 1;
            else if (xv > viewWidth)
                xClipPos = 2;
            yClipPos = 0;
            if (yv < 0)
                yClipPos = 1;
            else if (yv > viewHeight)
                yClipPos = 2;
            visible = (xClipPos == 0 || xClipPos != xClipPosLast && i > 0) && (yClipPos == 0 || yClipPos != yClipPosLast && i > 0);
            xClipPosLast = xClipPos;
            yClipPosLast = yClipPos;
        }
        ++i;
    }
    return visible;
}
Also used : MapNode(aimax.osm.data.entities.MapNode)

Example 3 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class DefaultEntityRenderer method printBufferedObjects.

// int awnodes = 0;
/** Prints all buffered entities according to their rendering informations. */
public void printBufferedObjects() {
    Collections.sort(areaBuffer, new MapAreaComparator());
    Comparator<MapEntity> comp = new MapEntityComparator();
    if (wayBuffer.size() < 10000)
        Collections.sort(wayBuffer, comp);
    if (nodeBuffer.size() < 10000)
        Collections.sort(nodeBuffer, comp);
    for (MapWay area : areaBuffer) printWay(area, (DefaultEntityViewInfo) area.getViewInfo(), true);
    for (MapWay way : wayBuffer) printWay(way, (DefaultEntityViewInfo) way.getViewInfo(), false);
    for (MapEntity node : nodeBuffer) {
        MapNode n;
        if (node instanceof MapWay) {
            List<MapNode> wayNodes = getWayNodes((MapWay) node);
            // needed to show icons for ways, whose abstraction is empty.
            if (wayNodes.isEmpty())
                wayNodes = ((MapWay) node).getNodes();
            n = wayNodes.get(0);
        } else
            n = (MapNode) node;
        printNode(n, (DefaultEntityViewInfo) node.getViewInfo());
    }
    for (Track track : trackBuffer) printTrack(track);
    // System.out.print("NamesOrg: " + nameInfoBuffer.size() + "\n");
    Collections.sort(nameInfoBuffer);
    // remove names whose positions are to close to each other
    int charSize = (int) (defaultFontSize * displayFactorSym);
    for (int i = 0; i < nameInfoBuffer.size(); ++i) {
        NameInfo info = nameInfoBuffer.get(i);
        for (int j = 0; j < i; ++j) {
            NameInfo info1 = nameInfoBuffer.get(j);
            int fac = (info.name.equals(info1.name)) ? 3 : 2;
            if (Math.abs(info.y - info1.y) < charSize * fac) {
                fac = (info.x < info1.x) ? info.name.length() : info1.name.length();
                if (Math.abs(info.x - info1.x) < charSize * fac) {
                    nameInfoBuffer.remove(i);
                    --i;
                    j = i;
                }
            }
        }
    }
    for (NameInfo textInfo : nameInfoBuffer) {
        imageBdr.setColor(textInfo.color);
        imageBdr.drawString(textInfo.name, textInfo.x, textInfo.y);
    }
// System.out.print("Areas: " + areaBuffer.size() + "  ");
// System.out.print("Ways: " + wayBuffer.size() + "  ");
// System.out.print("Nodes: " + nodeBuffer.size() + "  ");
// System.out.print("Names: " + nameInfoBuffer.size() + "\n");
}
Also used : MapWay(aimax.osm.data.entities.MapWay) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode) Track(aimax.osm.data.entities.Track)

Example 4 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class DefaultEntityRenderer method getNextNode.

/**
	 * Returns the map node which is the nearest with respect to the specified
	 * view coordinates among the currently displayed nodes.
	 */
public MapNode getNextNode(int x, int y) {
    Position pos = new Position(transformer.lat(y), transformer.lon(x));
    MapNode nextNode = null;
    MapNode tmp = null;
    for (int i = 0; i < 2; i++) {
        List<MapWay> ways = (i == 0) ? areaBuffer : wayBuffer;
        for (MapWay way : ways) {
            tmp = pos.selectNearest(way.getNodes(), null);
            if (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode)) {
                nextNode = tmp;
            }
        }
    }
    for (MapEntity node : nodeBuffer) {
        if (node instanceof MapNode) {
            tmp = (MapNode) node;
            if (tmp != null && tmp.getAttributeValue("marker") == null && (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode))) {
                nextNode = tmp;
            }
        }
    }
    return nextNode;
}
Also used : MapWay(aimax.osm.data.entities.MapWay) Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapEntity(aimax.osm.data.entities.MapEntity)

Example 5 with MapNode

use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.

the class MapAdapter method getDistance.

@Override
public Double getDistance(String fromLocation, String toLocation) {
    MapNode node1 = getWayNode(fromLocation);
    MapNode node2 = getWayNode(toLocation);
    if (node1 != null && node2 != null && getPossibleNextLocations(fromLocation).contains(toLocation))
        return new Position(node1).getDistKM(node2);
    else
        return null;
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode)

Aggregations

MapNode (aimax.osm.data.entities.MapNode)37 ArrayList (java.util.ArrayList)13 Position (aimax.osm.data.Position)12 MapWay (aimax.osm.data.entities.MapWay)6 MapEntity (aimax.osm.data.entities.MapEntity)5 BoundingBox (aimax.osm.data.BoundingBox)4 WayRef (aimax.osm.data.entities.WayRef)4 MapAdapter (aimax.osm.routing.MapAdapter)4 Point2D (aima.core.util.math.geom.shapes.Point2D)3 MapEvent (aimax.osm.data.MapEvent)3 EntityAttribute (aimax.osm.data.entities.EntityAttribute)3 Node (aima.core.search.framework.Node)2 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)2 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 HashSet (java.util.HashSet)2 Agent (aima.core.agent.Agent)1 aima.core.environment.map (aima.core.environment.map)1 MapAgent (aima.core.environment.map.MapAgent)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1