void fitSpline() { Roi roi = imp.getRoi(); if (roi == null) { noRoi("Spline"); return; } int type = roi.getType(); boolean segmentedSelection = type == Roi.POLYGON || type == Roi.POLYLINE; if (!(segmentedSelection || type == Roi.FREEROI || type == Roi.TRACED_ROI || type == Roi.FREELINE)) { IJ.error("Spline", "Polygon or polyline selection required"); return; } if (roi instanceof EllipseRoi) return; PolygonRoi p = (PolygonRoi) roi; if (!segmentedSelection) { if (p.subPixelResolution()) p = trimFloatPolygon(p, p.getUncalibratedLength()); else p = trimPolygon(p, p.getUncalibratedLength()); } String options = Macro.getOptions(); if (options != null && options.indexOf("straighten") != -1) p.fitSplineForStraightening(); else if (options != null && options.indexOf("remove") != -1) p.removeSplineFit(); else p.fitSpline(); imp.draw(); LineWidthAdjuster.update(); }
public void run(String arg) { imp = WindowManager.getCurrentImage(); if (arg.equals("add")) { addToRoiManager(imp); return; } if (imp == null) { IJ.noImage(); return; } if (arg.equals("all")) imp.setRoi(0, 0, imp.getWidth(), imp.getHeight()); else if (arg.equals("none")) imp.killRoi(); else if (arg.equals("restore")) imp.restoreRoi(); else if (arg.equals("spline")) fitSpline(); else if (arg.equals("circle")) fitCircle(imp); else if (arg.equals("ellipse")) createEllipse(imp); else if (arg.equals("hull")) convexHull(imp); else if (arg.equals("mask")) createMask(imp); else if (arg.equals("from")) createSelectionFromMask(imp); else if (arg.equals("inverse")) invert(imp); else if (arg.equals("toarea")) lineToArea(imp); else if (arg.equals("toline")) areaToLine(imp); else if (arg.equals("properties")) { setProperties("Properties ", imp.getRoi()); imp.draw(); } else if (arg.equals("band")) makeBand(imp); else if (arg.equals("tobox")) toBoundingBox(imp); else runMacro(arg); }
void runMacro(String arg, ImagePlus imp) { boolean rotate = arg.equals("rotate"); Roi roi = imp.getRoi(); if (rotate && IJ.macroRunning()) { String options = Macro.getOptions(); if (options != null && (options.indexOf("grid=") != -1 || options.indexOf("interpolat") != -1)) { IJ.run("Rotate... ", options); // run Image>Transform>Rotate return; } } if (roi == null) { noRoi(rotate ? "Rotate" : "Enlarge"); return; } double dangle = Tools.parseDouble(angle); if (Double.isNaN(dangle)) { dangle = 15; angle = "" + dangle; } if (rotate && (roi instanceof ImageRoi)) { dangle = IJ.getNumber("Angle (degrees):", dangle); ((ImageRoi) roi).rotate(dangle); imp.draw(); angle = "" + dangle; return; } Undo.setup(Undo.ROI, imp); roi = (Roi) roi.clone(); if (rotate) { String value = IJ.runMacroFile("ij.jar:RotateSelection", angle); Roi roi2 = imp.getRoi(); transferProperties(roi, roi2); imp.setRoi(roi2); if (value != null) angle = value; } else if (arg.equals("enlarge")) (new RoiEnlarger()).run(""); }