// Generates a new polygon by dragging a polygon by a vector and taking all the points it // touched. public static Polygon stroke(double x, double y, Polygon poly) { Polygon polyTrans = mul(Mat.translation(x, y), poly); ArrayList<Mat> vertices = new ArrayList<Mat>(); ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>(); int size = poly.vertices.size(); // The list of possible vertices of the extrusion vertices.addAll(poly.vertices); vertices.addAll(polyTrans.vertices); // pre-compute some information that will make it easy to find the actual perimeter of the // extrusion for (int i = 0; i < 2 * size; i++) { edgesTo.add(new TreeSet<Integer>()); } for (int i = 0; i < size; i++) { edgesTo.get(i).add(new Integer((i + 1) % size)); edgesTo.get((i + 1) % size).add(new Integer(i)); edgesTo.get(i + size).add(new Integer(((i + 1) % size) + size)); edgesTo.get(((i + 1) % size) + size).add(new Integer(i + size)); edgesTo.get(i).add(new Integer(i + size)); edgesTo.get(i + size).add(new Integer(i)); } return perimeter(vertices, edgesTo); }
public ArrayList getILSModels() { ArrayList arrayList = new ArrayList(); for (int i = runwayAL.size() - 1; i >= 0; i--) arrayList.addAll(((RunwayModel) runwayAL.get(i)).getILSAL()); return arrayList; }
public static SymbolAxis getBLMAxis( final String param, final Map<String, TypeDataSet> typeSeries, Map<String, NumberAxis> typeAxes) { final ArrayList<LossDetector> detectors = new ArrayList<LossDetector>(); for (TypeDataSet v : typeSeries.values()) { if (v.isVisible()) { detectors.addAll(v.getDetectors()); } } if (detectors.size() > 0) { Collections.sort(detectors, LossDetector.getComparator()); } String[] names = new String[detectors.size()]; final LossDetector[] dets = new LossDetector[detectors.size()]; final ValueAxis[] axes = new ValueAxis[detectors.size()]; int index = 0; for (LossDetector det : detectors) { names[index] = det.getShortName(); dets[index] = det; axes[index] = typeAxes.get(det.getType()); index++; } @SuppressWarnings("rawtypes") SymbolAxis axis = new SymbolAxis("", names) { private static final long serialVersionUID = -2911592900608877261L; protected void drawGridBandsHorizontal( Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, boolean firstGridBandIsDark, List ticks) { boolean currentGridBandIsDark = firstGridBandIsDark; double yy = dataArea.getY(); double xx1, xx2; // gets the outline stroke width of the plot double outlineStrokeWidth; if (getPlot().getOutlineStroke() != null) { outlineStrokeWidth = ((BasicStroke) getPlot().getOutlineStroke()).getLineWidth(); } else { outlineStrokeWidth = 1d; } Iterator iterator = ticks.iterator(); ValueTick tick; Rectangle2D band; while (iterator.hasNext()) { tick = (ValueTick) iterator.next(); int index = (int) tick.getValue(); xx1 = valueToJava2D(tick.getValue() - 0.5d, dataArea, RectangleEdge.BOTTOM); xx2 = valueToJava2D(tick.getValue() + 0.5d, dataArea, RectangleEdge.BOTTOM); currentGridBandIsDark = !currentGridBandIsDark; if (dets.length > 0) { LossDetector detector = dets[index]; Set<String> normalization = typeSeries.get(detector.getType()).getNormalization(); boolean limitVisibility = typeSeries.get(detector.getType()).isLimitVisible(); if (limitVisibility) { ScalarSignalValue limit = (ScalarSignalValue) detector.getValue(param, normalization); if (limit != null) { ValueAxis ax = axes[index]; double losslimit = Math.abs(limit.getValue()); double zz = ax.valueToJava2D(losslimit, dataArea, RectangleEdge.RIGHT); g2.setPaint(Color.red); Rectangle2D.Double zRect = new Rectangle2D.Double( xx1, yy + outlineStrokeWidth, xx2 - xx1, zz - yy - outlineStrokeWidth); g2.fill(zRect); } } if (STATUS_DECORATION) { int status = detectors.get((int) tick.getValue()).getStatus(); Color color = statusColors.get(status); if (color == null || status == LossDetector.STATUS_OK) { } else { g2.setPaint(color); double x, y, w, h; x = xx1; y = yy + outlineStrokeWidth; w = xx2 - xx1; h = 10; band = new Rectangle2D.Double(x, y, w, 10); g2.fill(band); } } } } g2.setPaintMode(); } protected AxisState drawTickMarksAndLabels( Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge) { AxisState state = new AxisState(cursor); if (isAxisLineVisible()) { drawAxisLine(g2, cursor, dataArea, edge); } double ol = getTickMarkOutsideLength(); double il = getTickMarkInsideLength(); List ticks = refreshTicks(g2, state, dataArea, edge); state.setTicks(ticks); g2.setFont(getTickLabelFont()); Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); if (isTickLabelsVisible()) { /// status decorations if (STATUS_DECORATION && dets.length > 0) { int status = detectors.get((int) tick.getValue()).getStatus(); Color color = statusColors.get(status); if (color == null) { g2.setPaint(getTickLabelPaint()); } else { g2.setPaint(color); } } else { g2.setPaint(getTickLabelPaint()); } float[] anchorPoint = calculateAnchorPoint(tick, cursor, dataArea, edge); TextUtilities.drawRotatedString( tick.getText(), g2, anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), tick.getAngle(), tick.getRotationAnchor()); } if (isTickMarksVisible()) { float xx = (float) valueToJava2D(tick.getValue(), dataArea, edge); Line2D mark = null; g2.setStroke(getTickMarkStroke()); g2.setPaint(getTickMarkPaint()); if (edge == RectangleEdge.LEFT) { mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx); } else if (edge == RectangleEdge.RIGHT) { mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx); } else if (edge == RectangleEdge.TOP) { mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il); } else if (edge == RectangleEdge.BOTTOM) { mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il); } g2.draw(mark); } } // need to work out the space used by the tick labels... // so we can update the cursor... double used = 0.0; if (isTickLabelsVisible()) { if (edge == RectangleEdge.LEFT) { used += findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorLeft(used); } else if (edge == RectangleEdge.RIGHT) { used = findMaximumTickLabelWidth(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorRight(used); } else if (edge == RectangleEdge.TOP) { used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorUp(used); } else if (edge == RectangleEdge.BOTTOM) { used = findMaximumTickLabelHeight(ticks, g2, plotArea, isVerticalTickLabels()); state.cursorDown(used); } } return state; } }; // axis.setTickLabelFont(axis.getTickLabelFont().deriveFont(Font.BOLD, 14.0f)); return axis; }
// take the union of two polygons, assuming no enclosed empty spaces, and that the result will // be contiguous. public static Polygon combine(Polygon poly1, Polygon poly2) { ArrayList<Mat> vertices = new ArrayList<Mat>(); ArrayList<TreeSet<Integer>> edgesTo = new ArrayList<TreeSet<Integer>>(); int sizePoly1 = poly1.vertices.size(); int sizePoly2 = poly2.vertices.size(); int size = sizePoly1 + sizePoly2; boolean done; Publisher<GUISegmentMsg> segmentPub = node.newPublisher("/gui/Segment", "lab5_msgs/GUISegmentMsg"); Publisher<GUIEraseMsg> erasePub = node.newPublisher("/gui/Erase", "lab5_msgs/GUIEraseMsg"); // erasePub.publish(new GUIEraseMsg()); GUISegmentMsg segmentPlot = new GUISegmentMsg(); ColorMsg segmentPlotColor = new ColorMsg(); // add all the vertices in both polygons vertices.addAll(poly1.vertices); vertices.addAll(poly2.vertices); for (int i = 0; i < size; i++) { edgesTo.add(new TreeSet<Integer>()); } // add all the edges in both polygons for (int i = 0; i < sizePoly1; i++) { edgesTo.get(i).add(new Integer((i + 1) % sizePoly1)); edgesTo.get((i + 1) % sizePoly1).add(new Integer(i)); } for (int i = 0; i < sizePoly2; i++) { edgesTo.get(i + sizePoly1).add(new Integer(((i + 1) % sizePoly2) + sizePoly1)); edgesTo.get(((i + 1) % sizePoly2) + sizePoly1).add(new Integer(i + sizePoly1)); } System.err.println(vertices); System.err.println(edgesTo); segmentPlotColor.r = 255; segmentPlotColor.g = 0; segmentPlotColor.b = 0; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } } // find and merge colocated points done = false; while (!done) { done = true; checkFMCP: { for (int p0 = 0; p0 < size; p0++) { for (int p1 = 0; p1 < size; p1++) { if (p0 != p1) { if (ptsEqual(vertices.get(p0), vertices.get(p1))) { // System.err.println("found two colocated: " + p0 + " " + p1); // System.err.println(edgesTo); edgesTo.get(p0).addAll(edgesTo.get(p1)); edgesTo.get(p0).remove(p0); vertices.remove(p1); edgesTo.remove(p1); size--; for (int e0 = 0; e0 < size; e0++) { if (edgesTo.get(e0).contains(new Integer(p1))) { edgesTo.get(e0).remove(new Integer(p1)); edgesTo.get(e0).add(new Integer(p0)); } // System.err.println("e0: " + e0); // System.err.println(edgesTo.get(e0)); TreeSet<Integer> head = new TreeSet(edgesTo.get(e0).headSet(new Integer(p1))); // System.err.println(head); for (Integer e1 : edgesTo.get(e0).tailSet(new Integer(p1))) { head.add(e1 - 1); } head.remove(e0); // System.err.println(head); edgesTo.set(e0, head); // System.err.println(edgesTo.get(e0)); } done = false; // System.err.println(edgesTo); break checkFMCP; } } } } } } System.err.println("merged points"); System.err.println(edgesTo); /*segmentPlotColor.r = 0; segmentPlotColor.g = 0; segmentPlotColor.b = 255; segmentPlot.color = segmentPlotColor; for (int e0 = 0; e0 < size; e0++){ for (int e1 : edgesTo.get(e0)) { double[] xyStart = Mat.decodePoint(vertices.get(e0)); double[] xyEnd = Mat.decodePoint(vertices.get(e1)); segmentPlot.startX = xyStart[0]; segmentPlot.startY = xyStart[1]; segmentPlot.endX = xyEnd[0]; segmentPlot.endY = xyEnd[1]; segmentPub.publish(segmentPlot); } }*/ // find and split edges bisected by points done = false; while (!done) { done = true; checkFSEBP: { for (int e0 = 0; e0 < size; e0++) { for (int e1 : edgesTo.get(e0)) { for (int p = 0; p < size; p++) { if (e0 != p && e1 != p) { if (ptSegIntersect(vertices.get(e0), vertices.get(e1), vertices.get(p))) { edgesTo.get(p).add(new Integer(e0)); edgesTo.get(p).add(new Integer(e1)); edgesTo.get(e0).remove(new Integer(e1)); edgesTo.get(e0).add(new Integer(p)); edgesTo.get(e1).remove(new Integer(e0)); edgesTo.get(e1).add(new Integer(p)); done = false; break checkFSEBP; } } } } } } } System.err.println("split edges on points"); System.err.println(edgesTo); System.err.println("GOT HERE!"); int iters = 0; done = false; while (!done) { // find and split intersecting edges System.err.println("size: " + size); done = true; checkFSIE: { for (int e00 = 0; e00 < size; e00++) { for (int e10 = 0; e10 < size; e10++) { if (e00 != e10) { for (int e01 : new TreeSet<Integer>(edgesTo.get(e00))) { if (e01 != e10 && e01 != e00) { for (int e11 : new TreeSet<Integer>(edgesTo.get(e10))) { if (e11 != e00 && e11 != e01 && e11 != e10) { if (lineSegIntersect( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11))) { // System.err.println("intersectors for iter " + iters); // System.err.println(e00); // System.err.println(edgesTo.get(e00)); // Mat.print(System.err, vertices.get(e00)); // System.err.println(e01); // System.err.println(edgesTo.get(e01)); // Mat.print(System.err, vertices.get(e01)); // System.err.println(e10); // System.err.println(edgesTo.get(e10)); // Mat.print(System.err, vertices.get(e10)); // System.err.println(e11); // System.err.println(edgesTo.get(e11)); // Mat.print(System.err, vertices.get(e11)); if (iters > 10000) { // F**K! try { throw new Exception(); } catch (Exception e) { e.printStackTrace(); System.err.println("hey there"); System.exit(1); } } iters++; Mat newVertex = lineSegIntersection( vertices.get(e00), vertices.get(e01), vertices.get(e10), vertices.get(e11)); if (ptsEqual(newVertex, vertices.get(e00))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e00).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e01))) { edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(e01)); edgesTo.get(e01).add(new Integer(e11)); } else if (ptsEqual(newVertex, vertices.get(e10))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e10)); edgesTo.get(e10).add(new Integer(e01)); } else if (ptsEqual(newVertex, vertices.get(e11))) { edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e00)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(e11)); edgesTo.get(e11).add(new Integer(e01)); } else { vertices.add(newVertex); edgesTo.add(new TreeSet<Integer>()); edgesTo.get(size).add(new Integer(e00)); edgesTo.get(size).add(new Integer(e01)); edgesTo.get(size).add(new Integer(e10)); edgesTo.get(size).add(new Integer(e11)); edgesTo.get(e00).remove(new Integer(e01)); edgesTo.get(e00).add(new Integer(size)); edgesTo.get(e01).remove(new Integer(e00)); edgesTo.get(e01).add(new Integer(size)); edgesTo.get(e10).remove(new Integer(e11)); edgesTo.get(e10).add(new Integer(size)); edgesTo.get(e11).remove(new Integer(e10)); edgesTo.get(e11).add(new Integer(size)); size++; } done = false; break checkFSIE; } } } } } } } } } System.err.println("split edges on edges"); System.err.println(edgesTo); } System.err.println("GOT HERE TOO!"); System.err.println("begin vertices"); for (Mat vertex : vertices) { Mat.print(System.err, vertex); } System.err.println("end vertices"); System.err.println(edgesTo); return perimeter(vertices, edgesTo); }