void lineToArea(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null || !roi.isLine()) { IJ.error("Line to Area", "Line selection required"); return; } Undo.setup(Undo.ROI, imp); Roi roi2 = null; if (roi.getType() == Roi.LINE) { double width = roi.getStrokeWidth(); if (width <= 1.0) roi.setStrokeWidth(1.0000001); FloatPolygon p = roi.getFloatPolygon(); roi.setStrokeWidth(width); roi2 = new PolygonRoi(p, Roi.POLYGON); roi2.setDrawOffset(roi.getDrawOffset()); } else { ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight()); ip2.setColor(255); roi.drawPixels(ip2); // new ImagePlus("ip2", ip2.duplicate()).show(); ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); roi2 = tts.convert(ip2); } transferProperties(roi, roi2); roi2.setStrokeWidth(0); Color c = roi2.getStrokeColor(); if (c != null) // remove any transparency roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue())); imp.setRoi(roi2); Roi.previousRoi = (Roi) roi.clone(); }
public void deleteHandle(double ox, double oy) { if (imp == null) return; if (nPoints <= 1) { imp.deleteRoi(); return; } boolean splineFit = xSpline != null; xSpline = null; FloatPolygon points = getFloatPolygon(); modState = NO_MODS; if (previousRoi != null) previousRoi.modState = NO_MODS; int pointToDelete = getClosestPoint(ox, oy, points); FloatPolygon points2 = new FloatPolygon(); for (int i = 0; i < points.npoints; i++) { if (i != pointToDelete) points2.addPoint(points.xpoints[i], points.ypoints[i]); } if (type == POINT) imp.setRoi(new PointRoi(points2.xpoints, points2.ypoints, points2.npoints)); else { if (subPixelResolution()) { Roi roi2 = new PolygonRoi(points2, type); roi2.setDrawOffset(getDrawOffset()); imp.setRoi(roi2); } else imp.setRoi( new PolygonRoi(toInt(points2.xpoints), toInt(points2.ypoints), points2.npoints, type)); if (splineFit) ((PolygonRoi) imp.getRoi()).fitSpline(splinePoints); } }
void addHandle(double ox, double oy) { if (imp == null || type == ANGLE) return; boolean splineFit = xSpline != null; xSpline = null; FloatPolygon points = getFloatPolygon(); int n = points.npoints; modState = NO_MODS; if (previousRoi != null) previousRoi.modState = NO_MODS; int pointToDuplicate = getClosestPoint(ox, oy, points); FloatPolygon points2 = new FloatPolygon(); for (int i2 = 0; i2 < n; i2++) { if (i2 == pointToDuplicate) { int i1 = i2 - 1; if (i1 == -1) i1 = isLine() ? i2 : n - 1; int i3 = i2 + 1; if (i3 == n) i3 = isLine() ? i2 : 0; double x1 = points.xpoints[i1] + 2 * (points.xpoints[i2] - points.xpoints[i1]) / 3; double y1 = points.ypoints[i1] + 2 * (points.ypoints[i2] - points.ypoints[i1]) / 3; double x2 = points.xpoints[i2] + (points.xpoints[i3] - points.xpoints[i2]) / 3; double y2 = points.ypoints[i2] + (points.ypoints[i3] - points.ypoints[i2]) / 3; points2.addPoint(x1, y1); points2.addPoint(x2, y2); } else points2.addPoint(points.xpoints[i2], points.ypoints[i2]); } if (type == POINT) imp.setRoi(new PointRoi(points2)); else { if (subPixelResolution()) { Roi roi2 = new PolygonRoi(points2, type); roi2.setDrawOffset(getDrawOffset()); imp.setRoi(roi2); } else imp.setRoi( new PolygonRoi(toInt(points2.xpoints), toInt(points2.ypoints), points2.npoints, type)); if (splineFit) ((PolygonRoi) imp.getRoi()).fitSpline(splinePoints); } }
private void transferProperties(Roi roi1, Roi roi2) { if (roi1 == null || roi2 == null) return; roi2.setStrokeColor(roi1.getStrokeColor()); if (roi1.getStroke() != null) roi2.setStroke(roi1.getStroke()); roi2.setDrawOffset(roi1.getDrawOffset()); }