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 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(); }
/** Sets the color used used for the ROI Manager "Show All" mode. */ public static void setShowAllColor(Color c) { if (c == null) return; showAllColor = c; labelColor = null; ImagePlus img = WindowManager.getCurrentImage(); if (img != null) { ImageCanvas ic = img.getCanvas(); if (ic != null && ic.getShowAllROIs()) img.draw(); } }
void lineWidth() { int width = (int) IJ.getNumber("Line Width:", Line.getWidth()); if (width == IJ.CANCELED) return; Line.setWidth(width); LineWidthAdjuster.update(); ImagePlus imp = WindowManager.getCurrentImage(); if (imp != null && imp.isProcessor()) { ImageProcessor ip = imp.getProcessor(); ip.setLineWidth(Line.getWidth()); Roi roi = imp.getRoi(); if (roi != null && roi.isLine()) imp.draw(); } }
protected void scroll(int sx, int sy) { int ox = xSrcStart + (int) (sx / magnification); // convert to offscreen coordinates int oy = ySrcStart + (int) (sy / magnification); // IJ.log("scroll: "+ox+" "+oy+" "+xMouseStart+" "+yMouseStart); int newx = xSrcStart + (xMouseStart - ox); int newy = ySrcStart + (yMouseStart - oy); if (newx < 0) newx = 0; if (newy < 0) newy = 0; if ((newx + srcRect.width) > imageWidth) newx = imageWidth - srcRect.width; if ((newy + srcRect.height) > imageHeight) newy = imageHeight - srcRect.height; srcRect.x = newx; srcRect.y = newy; // IJ.log(sx+" "+sy+" "+newx+" "+newy+" "+srcRect); imp.draw(); Thread.yield(); }
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(""); }