private Pair<Point2D, Point2D> getAPointInReachblePartEdges(Area area, Edge relatedEdge) { Point2D point = null; Edge rEdge = null; if (area instanceof Road) { Road road = (Road) area; FOR: for (SOSArea reachablePart : road.getReachableParts()) { for (Edge edge : reachablePart.getEdges()) { if (edge.getReachablityIndex() >= 0 && area.getEdges().get(edge.getReachablityIndex()).equals(relatedEdge)) { point = edge.getMidPoint(); rEdge = edge; break FOR; } } } } if (point == null) { point = relatedEdge.getMidPoint(); rEdge = relatedEdge; } ArrayList<Point2D> twoPointForCheckContain = Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 10); ArrayList<Point2D> twoPoint = Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 3000); if (area.getShape().contains(twoPointForCheckContain.get(0).toGeomPoint())) return new Pair<Point2D, Point2D>(twoPoint.get(0), twoPoint.get(1)); else return new Pair<Point2D, Point2D>(twoPoint.get(1), twoPoint.get(0)); }
// Morteza2011***************************************************************** public static Pair<ArrayList<Edge>, ArrayList<Edge>> splitEdges( ArrayList<Edge> edgeList1, List<Edge> edgeList2) { ArrayList<ArrayList<Pair<Point2D, Point2D>>> pointList1 = new ArrayList<ArrayList<Pair<Point2D, Point2D>>>(); ArrayList<ArrayList<Pair<Point2D, Point2D>>> pointList2 = new ArrayList<ArrayList<Pair<Point2D, Point2D>>>(); for (short i = 0; i < edgeList1.size(); i++) { pointList1.add(new ArrayList<Pair<Point2D, Point2D>>()); pointList1 .get(i) .add( new Pair<Point2D, Point2D>(edgeList1.get(i).getStart(), edgeList1.get(i).getStart())); pointList1 .get(i) .add(new Pair<Point2D, Point2D>(edgeList1.get(i).getStart(), edgeList1.get(i).getEnd())); } for (short i = 0; i < edgeList2.size(); i++) { pointList2.add(new ArrayList<Pair<Point2D, Point2D>>()); pointList2 .get(i) .add( new Pair<Point2D, Point2D>(edgeList2.get(i).getStart(), edgeList2.get(i).getStart())); pointList2 .get(i) .add(new Pair<Point2D, Point2D>(edgeList2.get(i).getStart(), edgeList2.get(i).getEnd())); } for (short i = 0; i < edgeList1.size(); i++) { for (short j = 0; j < edgeList2.size(); j++) { Point2D intersect = Utility.getIntersect(edgeList1.get(i), edgeList2.get(j)); if (intersect != null) { pointList1.get(i).add(new Pair<Point2D, Point2D>(edgeList1.get(i).getStart(), intersect)); pointList2.get(j).add(new Pair<Point2D, Point2D>(edgeList2.get(j).getStart(), intersect)); } } } for (short i = 0; i < edgeList1.size(); i++) { sortPoints(pointList1.get(i)); } for (short i = 0; i < edgeList2.size(); i++) { sortPoints(pointList2.get(i)); } ArrayList<Edge> newEdges1 = new ArrayList<Edge>(); ArrayList<Edge> newEdges2 = new ArrayList<Edge>(); for (short i = 0; i < pointList1.size(); i++) { for (short j = 0; j < pointList1.get(i).size() - 1; j++) { Edge e = new Edge(pointList1.get(i).get(j).second(), pointList1.get(i).get(j + 1).second()); newEdges1.add(e); } } for (short i = 0; i < pointList2.size(); i++) { for (short j = 0; j < pointList2.get(i).size() - 1; j++) { Edge e = new Edge(pointList2.get(i).get(j).second(), pointList2.get(i).get(j + 1).second()); newEdges2.add(e); } } return new Pair<ArrayList<Edge>, ArrayList<Edge>>(newEdges1, newEdges2); }
private void computeCenter(int[] apexes) { rescuecore2.geometry.Point2D p = SOSGeometryTools.computeCentroid(apexes); centerX = (int) p.getX(); centerY = (int) p.getY(); if (apexes.length < 6) return; try { Point2D point1 = null, point2 = null, middlePoint = null; ArrayList<rescuecore2.geometry.Point2D> twoPointOutOfLine = null; if (!contains(centerX, centerY)) { // if the point is not inside the polygon /////////////////////// finding a point inside polygon//////////////// FOR: for (int i = 0; i < apexes.length - 2; i += 2) { point1 = new rescuecore2.geometry.Point2D(apexes[i], apexes[i + 1]); point2 = new rescuecore2.geometry.Point2D(apexes[i + 2], apexes[i + 3]); middlePoint = new rescuecore2.geometry.Point2D( (apexes[i] + apexes[i + 2]) / 2, (apexes[i + 1] + apexes[i + 3]) / 2); twoPointOutOfLine = Utility.get2PointsAroundAPointOutOfLine(point1, point2, middlePoint, 2); for (rescuecore2.geometry.Point2D point2d : twoPointOutOfLine) { if (contains(point2d.getX(), point2d.getY())) { centerX = (int) point2d.getX(); centerY = (int) point2d.getY(); break FOR; } } } /* if (!contains(centerX, centerY)) { debug.show("SOS Shape", new ShapeDebugFrame.AWTShapeInfo(this, "apexes=" + Arrays.toString(apexes), Color.blue, false), new ShapeDebugFrame.Point2DShapeInfo(point1, "Point 1", Color.red, true), new ShapeDebugFrame.Point2DShapeInfo(point2, "Point 2", Color.green, true), new ShapeDebugFrame.Point2DShapeInfo(middlePoint, "middlePoint", Color.pink, true), new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(0), "twoPointOutOfLine 1", Color.magenta, true), new ShapeDebugFrame.Point2DShapeInfo(twoPointOutOfLine.get(1), "twoPointOutOfLine 2", Color.black, true), new ShapeDebugFrame.DetailInfo("area:" + SOSGeometryTools.computeAreaUnsigned(apexes)) ); } */ /////////////////////////////////////////////////////////////////////// } } catch (Exception e) { e.printStackTrace(); System.err.println(this.getClass().getSimpleName() + " have error" + e.getMessage()); } }
// Morteza2012***************************************************************** public ArrayList<Road> checkNeighborRoads() { ArrayList<Road> rs = new ArrayList<Road>(); for (Area a : position.getNeighbours()) { if (a instanceof Road) { Road r = ((Road) a); if (Utility.hasIntersect(expandedBlock, r.getExpandedArea())) { if (!r.getNeighborBlockades().contains(this)) { rs.add(r); r.getNeighborBlockades().remove(this); r.getNeighborBlockades().add(this); } } else if (r.getNeighborBlockades().contains(this)) { r.getNeighborBlockades().remove(this); rs.add(r); } } } rs.add(position); return rs; }
// Morteza2011***************************************************************** public static ArrayList<SOSArea> mergeBlockades(Road road, ArrayList<SOSArea> blockades) { // log(road).logln("RoadID:" + road.getID()); // for (SOSArea b : blockades) { // log(road).logln(b.getReachablityBlockades()); // } for (short i = 0; i < blockades.size(); i++) { for (short j = (short) (i + 1); j < blockades.size(); j++) { if (Utility.hasIntersect(blockades.get(i), blockades.get(j))) { SOSArea a1 = blockades.get(i); SOSArea a2 = blockades.get(j); SOSArea a3; try { a3 = merge(road, a1, a2, (short) (0)); } catch (Exception e) { a3 = reMerge(a1, a2); e.printStackTrace(); } blockades.remove(j--); if (!a3.getEdges().isEmpty()) { blockades.set(i, a3); } i--; break; } else { try { if (blockades .get(i) .getShape() .contains( blockades.get(j).getEdges().get(0).getStart().getX(), blockades.get(j).getEdges().get(0).getStart().getY())) { // log(road).logln(blockades.get(j)+" has included in "+blockades.get(i)); blockades.get(i).addReachablityBlockades(blockades.get(j).getReachablityBlockades()); blockades.remove(j--); } else { if (blockades .get(j) .getShape() .contains( blockades.get(i).getEdges().get(0).getStart().getX(), blockades.get(i).getEdges().get(0).getStart().getY())) { // log(road).logln(blockades.get(i)+" has included in "+blockades.get(j)); blockades .get(j) .addReachablityBlockades(blockades.get(i).getReachablityBlockades()); blockades.remove(i--); break; } // else // log(road).logln("intersect:no and included:no!"); } } catch (Exception e) { try { e.printStackTrace(); SOSArea a1 = blockades.get(i); SOSArea a2 = blockades.get(j); SOSArea a3; a3 = reMerge(a1, a2); blockades.remove(j--); if (!a3.getEdges().isEmpty()) { blockades.set(i, a3); } i--; break; } catch (Exception e1) { } } } } } return blockades; }