Search in sources :

Example 1 with Environment

use of org.opentripplanner.visibility.Environment in project OpenTripPlanner by opentripplanner.

the class TestVisibilityGraph method testConcavePolygon.

public void testConcavePolygon() {
    VLPolygon poly = poly(1, 1, 5, 1, 5, 5, 3, 5, 3, 4, 4, 4, 4, 2, 2, 2, 2, 3, 1, 3);
    if (poly.area() < 0) {
        poly.reverse();
    }
    Environment environment = new Environment(Arrays.asList(poly));
    environment.enforce_standard_form();
    VisibilityGraph vg = new VisibilityGraph(environment, 0.01);
    boolean[][] expected = { { true, true, false, false, false, false, true, true, true, true }, { true, true, true, false, false, true, true, true, false, false }, { false, true, true, true, true, true, true, false, false, false }, { false, false, true, true, true, true, false, false, false, false }, { false, false, true, true, true, true, false, false, false, false }, { false, true, true, true, true, true, true, false, false, false }, { true, true, true, false, false, true, true, true, false, false }, { true, true, false, false, false, false, true, true, true, true }, { true, false, false, false, false, false, false, true, true, true }, { true, false, false, false, false, false, false, true, true, true } };
    for (int i = 0; i < expected.length; ++i) {
        for (int j = 0; j < expected[i].length; ++j) {
            assertEquals(expected[i][j], vg.get(i, j));
        }
    }
}
Also used : VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) VisibilityGraph(org.opentripplanner.visibility.VisibilityGraph) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 2 with Environment

use of org.opentripplanner.visibility.Environment in project OpenTripPlanner by opentripplanner.

the class TestVisibilityGraph method testConcavePolygon2.

// A massively reduced version of the Piazza San Marco, which
// caused problems when the code was buggy
public void testConcavePolygon2() {
    VLPolygon poly = poly(17.0, 14.0, 70.0, 18.0, 69.0, 26.0, 39.0, 20.0, 13.0, 78.0, -111.0, 24.0);
    Environment environment = new Environment(Arrays.asList(poly));
    environment.enforce_standard_form();
    VisibilityGraph vg = new VisibilityGraph(environment, 0.0000001);
    boolean[][] expected = { { true, true, true, false, true, true }, { true, true, true, true, true, true }, { true, true, true, true, true, false }, { false, true, true, true, true, false }, { true, true, true, true, true, true }, { true, true, false, false, true, true } };
    for (int i = 0; i < expected.length; ++i) {
        for (int j = 0; j < expected[i].length; ++j) {
            assertEquals(" at " + i + ", " + j, expected[i][j], vg.get(i, j));
        }
    }
}
Also used : VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) VisibilityGraph(org.opentripplanner.visibility.VisibilityGraph) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 3 with Environment

use of org.opentripplanner.visibility.Environment in project OpenTripPlanner by opentripplanner.

the class TestVisibilityGraph method testSanMarco.

// The Piazza San Marco in Venice, from OSM.
public void testSanMarco() {
    VLPolygon poly = poly(12.3389861, 45.4339415, 12.3389153, 45.4340763, 12.3390769, 45.4341172, 12.3391694, 45.4341388, 12.3392136, 45.4340533, 12.3397036, 45.434177, 12.339797, 45.4341939, 12.3397873, 45.4342286, 12.339706, 45.4342158, 12.3396866, 45.4342575, 12.3393905, 45.434195, 12.3391779, 45.4346848, 12.3391272, 45.4347845, 12.3390937, 45.4347676, 12.3389625, 45.4347071, 12.3386095, 45.4345509, 12.3379792, 45.4342771, 12.3378901, 45.4342367, 12.3376881, 45.4341478, 12.337471, 45.4340513, 12.3373322, 45.4339869, 12.3371759, 45.4339216, 12.3372951, 45.4336885, 12.3374061, 45.4334649, 12.3374185, 45.4334486, 12.3391652, 45.4339348, 12.3391453, 45.4339861);
    Environment environment = new Environment(Arrays.asList(poly));
    environment.enforce_standard_form();
    VisibilityGraph vg = new VisibilityGraph(environment, 0.0000001);
    boolean[][] expected = { { true, true, false, true, true, false, true, true, true, true, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, true }, { true, true, true, true, true, false, true, true, true, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true }, { false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true }, { true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true }, { true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true }, { false, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }, { true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, true }, { true, true, true, true, false, false, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true }, { true, true, false, false, false, false, false, true, true, true, false, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true }, { true, false, false, false, false, false, false, false, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true }, { false, false, false, false, false, false, false, false, false, true, true, true, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false }, { false, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, false }, { false, false, false, false, false, false, false, false, false, true, false, true, true, true, true, false, true, false, false, false, false, false, false, false, true, true, true }, { false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false }, { true, false, false, false, false, false, false, false, false, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true }, { false, false, false, false, false, false, false, false, false, true, true, true, false, false, true, true, true, false, false, false, false, false, false, false, false, false, false }, { true, true, false, false, false, false, false, false, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true }, { true, true, true, true, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, true, true, true }, { false, true, true, true, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, false, false, false, false, false, false, false }, { false, true, true, true, false, false, false, true, true, true, true, false, false, false, false, false, true, true, true, true, true, false, false, false, false, false, false }, { false, true, true, true, false, false, false, true, true, true, true, false, false, false, false, false, true, true, false, true, true, true, false, false, false, false, false }, { false, true, true, true, false, false, true, true, true, true, false, false, false, false, false, false, true, true, false, false, true, true, true, true, true, true, true }, { false, true, true, true, false, false, true, true, true, true, false, false, false, false, false, false, true, true, false, false, false, true, true, true, false, false, false }, { false, true, true, true, false, false, true, true, true, true, false, true, false, false, false, false, true, true, false, false, false, true, true, true, true, true, true }, { false, true, true, true, false, false, true, true, true, true, false, true, true, false, false, false, true, true, false, false, false, true, false, true, true, true, true }, { false, true, true, true, false, false, true, true, true, true, false, true, true, false, true, false, true, true, false, false, false, true, false, true, true, true, true }, { true, true, true, true, true, false, true, true, true, true, false, false, true, false, true, false, true, true, false, false, false, true, false, true, true, true, true } };
    for (int i = 0; i < expected.length; ++i) {
        for (int j = 0; j < expected[i].length; ++j) {
            assertEquals(" at " + i + ", " + j, expected[i][j], vg.get(i, j));
        }
    }
}
Also used : VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) VisibilityGraph(org.opentripplanner.visibility.VisibilityGraph) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 4 with Environment

use of org.opentripplanner.visibility.Environment in project OpenTripPlanner by opentripplanner.

the class TestVisibilityGraph method testSquareOffCenterInSquare.

public void testSquareOffCenterInSquare() {
    Environment environment = new Environment(Arrays.asList(poly(1, 1, 5, 1, 5, 5, 1, 5), poly(2, 2, 2, 3, 3, 3, 3, 2)));
    environment.enforce_standard_form();
    VisibilityGraph vg = new VisibilityGraph(environment, 0.01);
    boolean[][] expected = { { true, true, false, true, true, true, false, true }, { true, true, true, true, true, false, true, true }, { false, true, true, true, false, true, true, true }, { true, true, true, true, true, true, true, false }, { true, true, false, true, true, true, false, true }, { true, false, true, true, true, true, true, false }, { false, true, true, true, false, true, true, true }, { true, true, true, false, true, false, true, true } };
    for (int i = 0; i < expected.length; ++i) {
        for (int j = 0; j < expected[i].length; ++j) {
            assertEquals(expected[i][j], vg.get(i, j));
        }
    }
}
Also used : Environment(org.opentripplanner.visibility.Environment) VisibilityGraph(org.opentripplanner.visibility.VisibilityGraph) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 5 with Environment

use of org.opentripplanner.visibility.Environment in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method buildWithVisibility.

public void buildWithVisibility(AreaGroup group, boolean platformEntriesLinking) {
    Set<OSMNode> startingNodes = new HashSet<OSMNode>();
    Set<Vertex> startingVertices = new HashSet<Vertex>();
    Set<Edge> edges = new HashSet<Edge>();
    // create polygon and accumulate nodes for area
    for (Ring ring : group.outermostRings) {
        AreaEdgeList edgeList = new AreaEdgeList();
        // the points corresponding to concave or hole vertices
        // or those linked to ways
        ArrayList<VLPoint> visibilityPoints = new ArrayList<VLPoint>();
        ArrayList<OSMNode> visibilityNodes = new ArrayList<OSMNode>();
        HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
        // and to avoid the numerical problems that they tend to cause
        for (Area area : group.areas) {
            // parameter is true
            if (platformEntriesLinking && "platform".equals(area.parent.getTag("public_transport"))) {
                continue;
            }
            if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
                continue;
            }
            // Add stops from public transit relations into the area
            Collection<OSMNode> nodes = osmdb.getStopsInArea(area.parent);
            if (nodes != null) {
                for (OSMNode node : nodes) {
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
            }
            for (Ring outerRing : area.outermostRings) {
                for (int i = 0; i < outerRing.nodes.size(); ++i) {
                    OSMNode node = outerRing.nodes.get(i);
                    createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
                for (Ring innerRing : outerRing.holes) {
                    for (int j = 0; j < innerRing.nodes.size(); ++j) {
                        OSMNode node = innerRing.nodes.get(j);
                        createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
                        addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                    }
                }
            }
        }
        List<OSMNode> nodes = new ArrayList<OSMNode>();
        List<VLPoint> vertices = new ArrayList<VLPoint>();
        accumulateRingNodes(ring, nodes, vertices);
        VLPolygon polygon = makeStandardizedVLPolygon(vertices, nodes, false);
        accumulateVisibilityPoints(ring.nodes, polygon, visibilityPoints, visibilityNodes, false);
        ArrayList<VLPolygon> polygons = new ArrayList<VLPolygon>();
        polygons.add(polygon);
        // holes
        for (Ring innerRing : ring.holes) {
            ArrayList<OSMNode> holeNodes = new ArrayList<OSMNode>();
            vertices = new ArrayList<VLPoint>();
            accumulateRingNodes(innerRing, holeNodes, vertices);
            VLPolygon hole = makeStandardizedVLPolygon(vertices, holeNodes, true);
            accumulateVisibilityPoints(innerRing.nodes, hole, visibilityPoints, visibilityNodes, true);
            nodes.addAll(holeNodes);
            polygons.add(hole);
        }
        Environment areaEnv = new Environment(polygons);
        // areas to prevent way explosion
        if (visibilityPoints.size() > MAX_AREA_NODES) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is too complicated (" + visibilityPoints.size() + " > " + MAX_AREA_NODES);
            continue;
        }
        if (!areaEnv.is_valid(VISIBILITY_EPSILON)) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is not epsilon-valid (epsilon = " + VISIBILITY_EPSILON + ")");
            continue;
        }
        edgeList.setOriginalEdges(ring.toJtsPolygon());
        createNamedAreas(edgeList, ring, group.areas);
        OSMWithTags areaEntity = group.getSomeOSMObject();
        for (int i = 0; i < visibilityNodes.size(); ++i) {
            OSMNode nodeI = visibilityNodes.get(i);
            VisibilityPolygon visibilityPolygon = new VisibilityPolygon(visibilityPoints.get(i), areaEnv, VISIBILITY_EPSILON);
            Polygon poly = toJTSPolygon(visibilityPolygon);
            for (int j = 0; j < visibilityNodes.size(); ++j) {
                OSMNode nodeJ = visibilityNodes.get(j);
                P2<OSMNode> nodePair = new P2<OSMNode>(nodeI, nodeJ);
                if (alreadyAddedEdges.contains(nodePair))
                    continue;
                IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(nodeI, areaEntity);
                IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nodeJ, areaEntity);
                Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
                GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
                LineString line = geometryFactory.createLineString(coordinates);
                if (poly != null && poly.contains(line)) {
                    createSegments(nodeI, nodeJ, startEndpoint, endEndpoint, group.areas, edgeList, edges);
                    if (startingNodes.contains(nodeI)) {
                        startingVertices.add(startEndpoint);
                    }
                    if (startingNodes.contains(nodeJ)) {
                        startingVertices.add(endEndpoint);
                    }
                }
            }
        }
    }
    pruneAreaEdges(startingVertices, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) VLPolygon(org.opentripplanner.visibility.VLPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) HashSet(java.util.HashSet) P2(org.opentripplanner.common.model.P2) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LinearRing(com.vividsolutions.jts.geom.LinearRing) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

Environment (org.opentripplanner.visibility.Environment)7 VLPoint (org.opentripplanner.visibility.VLPoint)7 VisibilityGraph (org.opentripplanner.visibility.VisibilityGraph)6 VLPolygon (org.opentripplanner.visibility.VLPolygon)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 LinearRing (com.vividsolutions.jts.geom.LinearRing)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 P2 (org.opentripplanner.common.model.P2)1 OSMNode (org.opentripplanner.openstreetmap.model.OSMNode)1 OSMWithTags (org.opentripplanner.openstreetmap.model.OSMWithTags)1 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)1 AreaEdgeList (org.opentripplanner.routing.edgetype.AreaEdgeList)1 NamedArea (org.opentripplanner.routing.edgetype.NamedArea)1