use of org.opentripplanner.visibility.VLPolygon in project OpenTripPlanner by opentripplanner.
the class WalkableAreaBuilder method toJTSPolygon.
private Polygon toJTSPolygon(VLPolygon visibilityPolygon) {
if (visibilityPolygon.vertices.isEmpty()) {
return null;
}
// incomprehensibly, visilibity's routines for figuring out point-polygon containment are
// too broken
// to use here, so we have to fall back to JTS.
Coordinate[] coordinates = new Coordinate[visibilityPolygon.n() + 1];
for (int p = 0; p < coordinates.length; ++p) {
VLPoint vlPoint = visibilityPolygon.get(p);
coordinates[p] = new Coordinate(vlPoint.x, vlPoint.y);
}
LinearRing shell = GeometryUtils.getGeometryFactory().createLinearRing(coordinates);
Polygon poly = GeometryUtils.getGeometryFactory().createPolygon(shell, new LinearRing[0]);
return poly;
}
use of org.opentripplanner.visibility.VLPolygon in project OpenTripPlanner by opentripplanner.
the class WalkableAreaBuilder method makeStandardizedVLPolygon.
private VLPolygon makeStandardizedVLPolygon(List<VLPoint> vertices, List<OSMNode> nodes, boolean reversed) {
VLPolygon polygon = new VLPolygon(vertices);
if ((reversed && polygon.area() > 0) || (!reversed && polygon.area() < 0)) {
polygon.reverse();
// need to reverse nodes as well
reversePolygonOfOSMNodes(nodes);
}
if (!polygon.is_in_standard_form()) {
standardize(polygon.vertices, nodes);
}
return polygon;
}
use of org.opentripplanner.visibility.VLPolygon 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);
}
use of org.opentripplanner.visibility.VLPolygon in project OpenTripPlanner by opentripplanner.
the class TestVisibilityGraph method testPalazzo.
// Another Venice test case
public void testPalazzo() {
VLPolygon poly = poly(12.3402039, 45.4342526, 12.339956, 45.43421, 12.3401159, 45.4338161, 12.3404923, 45.4338996, 12.3402845, 45.4344296, 12.3402433, 45.4344174, 12.3401433, 45.4343973, 12.3401691, 45.4343433);
Environment environment = new Environment(Arrays.asList(poly));
environment.enforce_standard_form();
VisibilityGraph vg = new VisibilityGraph(environment, 0.0000001);
boolean[][] expected = { { true, true, true, false, false, false, false, true }, { true, true, true, true, true, false, false, true }, { true, true, true, true, true, true, true, true }, { false, true, true, true, true, false, true, true }, { false, true, true, true, true, true, true, true }, { false, false, true, false, true, true, true, false }, { false, false, true, true, true, true, true, true }, { true, true, true, true, true, 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));
}
}
}
Aggregations