Search in sources :

Example 71 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method initVertexInfoSubpanel.

private void initVertexInfoSubpanel() {
    JPanel vertexDataPanel = new JPanel();
    vertexDataPanel.setLayout(new BoxLayout(vertexDataPanel, BoxLayout.PAGE_AXIS));
    vertexDataPanel.setPreferredSize(new Dimension(300, 600));
    leftPanel.add(vertexDataPanel, BorderLayout.CENTER);
    // nearby vertices
    JLabel nvLabel = new JLabel("Vertices");
    vertexDataPanel.add(nvLabel);
    nearbyVertices = new JList<DisplayVertex>();
    nearbyVertices.setVisibleRowCount(4);
    JScrollPane nvScrollPane = new JScrollPane(nearbyVertices);
    vertexDataPanel.add(nvScrollPane);
    nearbyVertices.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            outgoingEdges.removeAll();
            incomingEdges.removeAll();
            DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
            if (selected != null) {
                Vertex nowSelected = selected.vertex;
                showGraph.highlightVertex(nowSelected);
                outgoingEdges.setModel(new EdgeListModel(nowSelected.getOutgoing()));
                incomingEdges.setModel(new EdgeListModel(nowSelected.getIncoming()));
            }
        }
    });
    // listener useful for both incoming and outgoing edge list panes
    // when a different edge is selected, change up the pattern pane and list of nearby nodes
    ListSelectionListener edgeChanged = new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            @SuppressWarnings("unchecked") JList<Edge> edgeList = (JList<Edge>) e.getSource();
            Edge selected = (Edge) edgeList.getSelectedValue();
            boolean outgoing = (edgeList == outgoingEdges);
            reactToEdgeSelection(selected, outgoing);
        }
    };
    // outgoing edges
    JLabel ogeLabel = new JLabel("Outgoing edges");
    vertexDataPanel.add(ogeLabel);
    outgoingEdges = new JList<Edge>();
    outgoingEdges.setVisibleRowCount(4);
    JScrollPane ogeScrollPane = new JScrollPane(outgoingEdges);
    vertexDataPanel.add(ogeScrollPane);
    outgoingEdges.addListSelectionListener(edgeChanged);
    // incoming edges
    JLabel iceLabel = new JLabel("Incoming edges");
    vertexDataPanel.add(iceLabel);
    incomingEdges = new JList<Edge>();
    JScrollPane iceScrollPane = new JScrollPane(incomingEdges);
    vertexDataPanel.add(iceScrollPane);
    incomingEdges.addListSelectionListener(edgeChanged);
    // paths list
    JLabel pathsLabel = new JLabel("Paths");
    vertexDataPanel.add(pathsLabel);
    pathsList = new JList<PathPrinter>();
    popup = new JPopupMenu();
    JMenuItem compareMenuItem = new JMenuItem("compare");
    compareMenuItem.addActionListener(new OnPopupMenuClickListener());
    popup.add(compareMenuItem);
    // make paths list right-clickable
    pathsList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                @SuppressWarnings("unchecked") JList<PathPrinter> list = (JList<PathPrinter>) e.getSource();
                int row = list.locationToIndex(e.getPoint());
                list.setSelectedIndex(row);
                popup.show(list, e.getX(), e.getY());
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    pathsList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent ev) {
            PathPrinter pp = ((PathPrinter) pathsList.getSelectedValue());
            if (pp == null) {
                return;
            }
            GraphPath path = pp.gp;
            DefaultListModel<State> pathModel = new DefaultListModel<State>();
            for (State st : path.states) {
                pathModel.addElement(st);
            }
            pathStates.setModel(pathModel);
            showGraph.highlightGraphPath(path);
        }
    });
    JScrollPane pathsScrollPane = new JScrollPane(pathsList);
    vertexDataPanel.add(pathsScrollPane);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ListSelectionEvent(javax.swing.event.ListSelectionEvent) GraphPath(org.opentripplanner.routing.spt.GraphPath) ListSelectionListener(javax.swing.event.ListSelectionListener) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 72 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class ShowGraph method drawHighlighted.

private void drawHighlighted() {
    /* Draw highlighted edges in another color */
    noFill();
    // yellow transparent edge highlight
    stroke(200, 200, 000, 16);
    strokeWeight(8);
    if (drawHighlighted && highlightedEdges != null) {
        try {
            for (Edge e : highlightedEdges) {
                drawEdge(e);
            }
        } catch (ConcurrentModificationException cme) {
        // The edge list was cleared or added to while it was being drawn, no harm done.
        }
    }
    /* Draw highlighted graph path in another color */
    if (highlightedGraphPath != null) {
        drawGraphPath(highlightedGraphPath);
    }
    /* Draw (single) highlighted edge in highlight color */
    if (highlightedEdge != null && highlightedEdge.getGeometry() != null) {
        stroke(10, 200, 10, 128);
        strokeWeight(12);
        drawEdge(highlightedEdge);
    }
    /* Draw highlighted vertices */
    // orange fill
    fill(255, 127, 0);
    noStroke();
    if (highlightedVertices != null) {
        for (Vertex v : highlightedVertices) {
            drawVertex(v, 8);
        }
    }
    /* Draw (single) highlighed coordinate in a different color */
    if (highlightedCoordinate != null) {
        fill(255, 255, 30);
        drawCoordinate(highlightedCoordinate, 7);
    }
    noFill();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 73 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class ShowGraph method findVisibleElements.

@SuppressWarnings("unchecked")
private synchronized void findVisibleElements() {
    visibleVertices = (List<Vertex>) vertexIndex.query(modelBounds);
    visibleStreetEdges.clear();
    visibleLinkEdges.clear();
    visibleTransitEdges.clear();
    for (Edge de : (Iterable<Edge>) edgeIndex.query(modelBounds)) {
        if (de instanceof PatternEdge) {
            visibleTransitEdges.add(de);
        } else if (de instanceof PathwayEdge || de instanceof StreetTransitLink || de instanceof SimpleTransfer) {
            visibleLinkEdges.add(de);
        } else if (de instanceof StreetEdge) {
            visibleStreetEdges.add(de);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) SimpleTransfer(org.opentripplanner.routing.edgetype.SimpleTransfer) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge)

Example 74 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class TestStreetMatcher method testStreetMatcher.

@Test
public void testStreetMatcher() {
    LineString geometry = geometry(-122.385689, 47.669484, -122.387384, 47.669470);
    StreetMatcher matcher = new StreetMatcher(_graph);
    List<Edge> match = matcher.match(geometry);
    assertNotNull(match);
    assertEquals(1, match.size());
    assertEquals("56th_24th", match.get(0).getToVertex().getLabel());
    geometry = geometry(-122.385689, 47.669484, -122.387384, 47.669470, -122.387588, 47.669325);
    match = matcher.match(geometry);
    assertNotNull(match);
    assertEquals(2, match.size());
    geometry = geometry(-122.385689, 47.669484, -122.387384, 47.669470, -122.387588, 47.669325, -122.387255, 47.668675);
    match = matcher.match(geometry);
    assertNotNull(match);
    assertEquals(3, match.size());
    geometry = geometry(-122.384756, 47.669260, -122.384777, 47.667454, -122.383554, 47.666789, -122.3825, 47.666);
    match = matcher.match(geometry);
    assertNotNull(match);
    System.out.println(match);
    assertEquals(4, match.size());
    assertEquals("ballard_20th", match.get(3).getToVertex().getLabel());
}
Also used : LineString(com.vividsolutions.jts.geom.LineString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 75 with Edge

use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.

the class TestUnconnectedAreas method testUnconnectedParkAndRide.

/**
 * The P+R.osm.gz file contains 2 park and ride, one a single way area and the other a
 * multipolygon with a hole. Both are not linked to any street, apart from three roads that
 * crosses the P+R with w/o common nodes.
 *
 * This test just make sure we correctly link those P+R with the street network by creating
 * virtual nodes at the place where the street intersects the P+R areas. See ticket #1562.
 */
@Test
public void testUnconnectedParkAndRide() throws Exception {
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(getClass().getResource("P+R.osm.gz").getFile());
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, new HashMap<Class<?>, Object>());
    assertEquals(1, gg.getBuilderAnnotations().size());
    int nParkAndRide = 0;
    int nParkAndRideLink = 0;
    for (Vertex v : gg.getVertices()) {
        if (v instanceof ParkAndRideVertex) {
            nParkAndRide++;
        }
    }
    for (Edge e : gg.getEdges()) {
        if (e instanceof ParkAndRideLinkEdge) {
            nParkAndRideLink++;
        }
    }
    assertEquals(2, nParkAndRide);
    assertEquals(10, nParkAndRideLink);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) Graph(org.opentripplanner.routing.graph.Graph) ParkAndRideVertex(org.opentripplanner.routing.vertextype.ParkAndRideVertex) File(java.io.File) ParkAndRideLinkEdge(org.opentripplanner.routing.edgetype.ParkAndRideLinkEdge) ParkAndRideEdge(org.opentripplanner.routing.edgetype.ParkAndRideEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.opentripplanner.routing.graph.Edge)113 Vertex (org.opentripplanner.routing.graph.Vertex)61 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)53 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)26 HashSet (java.util.HashSet)23 State (org.opentripplanner.routing.core.State)22 Coordinate (com.vividsolutions.jts.geom.Coordinate)19 Graph (org.opentripplanner.routing.graph.Graph)19 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)18 Test (org.junit.Test)17 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)17 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)17 ArrayList (java.util.ArrayList)16 LineString (com.vividsolutions.jts.geom.LineString)15 GraphPath (org.opentripplanner.routing.spt.GraphPath)15 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)12 PathwayEdge (org.opentripplanner.routing.edgetype.PathwayEdge)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Stop (org.onebusaway.gtfs.model.Stop)9 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)9