- java.lang.Object
-
- ij.gui.Roi
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Point>
public class Roi extends Object implements Cloneable, Serializable, Iterable<Point>
A rectangular region of interest and superclass for the other ROI classes. This class implementsIterable<Point>and can thus be used to iterate over the contained coordinates. Usage example:Roi roi = ...; for (Point p : roi) { // process p }Convention for subpixel resolution and zooming in:- Area ROIs: Integer coordinates refer to the top-left corner of the pixel with these coordinates. Thus, pixel (0,0) is enclosed by the rectangle spanned between points (0,0) and (1,1), i.e., a rectangle at (0,0) with width = height = 1 pixel.
- Line and Point Rois: Integer coordinates refer to the center of a pixel. Thus, a line from (0,0) to (1,0) has its start and end points in the center of pixels (0,0) and (1,0), respectively, and drawing the line should affect both pixels. For images dispplayed at high zoom levels, this means that (open) lines and single points are displayed 0.5 pixels further to the right and bottom than the outlines of area ROIs (closed lines) with the same coordinates.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intANGLEprotected doubleasp_bkprotected booleanaspectprotected ImageProcessorcachedMaskprotected booleancenterprotected ImagePlusclipboardprotected intclipHeightprotected intclipWidthprotected intclipXprotected intclipYstatic intCOMPOSITEprotected booleanconstrainstatic intCONSTRUCTINGprotected static ColordefaultColorprotected static ColordefaultFillColorstatic intFERET_ARRAY_POINTOFFSETstatic intFERET_ARRAYSIZEprotected ColorfillColorprotected doubleflattenScalestatic intFREELINEstatic intFREEROIstatic intHANDLE_SIZEprotected ColorhandleColorprotected booleanhyperstackPositionprotected ImageCanvasicprotected booleanignoreClipRectprotected ImagePlusimpprotected ColorinstanceColorstatic intLINEprotected static intlineWidthprotected doublemagstatic intMOVINGstatic intMOVING_HANDLEprotected booleannonScalablestatic intNORMALstatic intNOT_PASTINGprotected intoldHeightprotected intoldWidthprotected intoldXprotected intoldYstatic BasicStrokeonePixelWidestatic intOVALprotected booleanoverlayprotected static intpasteModestatic intPOINTstatic intPOLYGONstatic intPOLYLINEstatic RoipreviousRoiGet using getPreviousRoi() and set using setPreviousRoi()static intRECTANGLEstatic intRESIZINGprotected static ColorROIColorprotected BasicStrokestrokeprotected ColorstrokeColorstatic intTRACED_ROIprotected inttypeprotected booleanupdateFullWindowprotected booleanwideLineprotected intxMaxprotected intyMax
-
Constructor Summary
Constructors Constructor Description Roi(double x, double y, double width, double height)Creates a rectangular ROI using double arguments.Roi(double x, double y, double width, double height, int cornerDiameter)Creates a rounded rectangular ROI using double arguments.Roi(int x, int y, int width, int height)Creates a rectangular ROI.Roi(int x, int y, int width, int height, int cornerDiameter)Creates a new rounded rectangular ROI.Roi(int x, int y, int width, int height, ImagePlus imp)Deprecated.Roi(int sx, int sy, ImagePlus imp)Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates.Roi(int sx, int sy, ImagePlus imp, int cornerDiameter)Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates.Roi(Rectangle r)Creates a new rectangular Roi.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidabortModification(ImagePlus imp)Aborts constructing or modifying the roi (called by the ImageJ class on escape)voidabortPaste()static voidaddRoiListener(RoiListener listener)protected intclipRectMargin()Objectclone()Returns a copy of this roi.booleancontains(int x, int y)Returns whether the center of pixel (x,y) is contained in the Roi.booleancontainsPoint(double x, double y)Returns whether coordinate (x,y) is contained in the Roi.static RoiconvertLineToArea(Roi line)Converts a line selection into an area (polygon or composite) selection.
Author: Michael SchmidRoiconvertToPolygon()Deprecated.voidcopyAttributes(Roi roi2)Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection.static Roicreate(double x, double y, double width, double height)Creates a rectangular ROI.static Roicreate(double x, double y, double width, double height, int cornerDiameter)Creates a rounded rectangular ROI.voiddraw(Graphics g)voiddrawOverlay(Graphics g)voiddrawPixels()Deprecated.replaced by drawPixels(ImageProcessor)voiddrawPixels(ImageProcessor ip)Draws the selection outline on the specified ImageProcessor.voidenableSubPixelResolution()voidendPaste()booleanequals(Object obj)Checks whether two rectangles are equal.doublegetAngle()Overridden by PolygonRoi (angle between first two points), TextRoi (text angle) and Line (line angle).doublegetAngle(int x1, int y1, int x2, int y2)Returns the angle in degrees between the specified line and a horizontal line.booleangetAntiAlias()RectanglegetBoundingRect()Deprecated.replaced by getBounds()RectanglegetBounds()Returns this selection's bounding rectangle.static ColorgetColor()Returns the default (global) color used for drawing ROI outlines.FloatPolygongetContainedFloatPoints()Returns the coordinates of the pixels inside this ROI as a FloatPolygon.Point[]getContainedPoints()Returns the coordinates of the pixels inside this ROI as an array of Points.double[]getContourCentroid()PolygongetConvexHull()Returns the convex hull of this Roi as a Polygon with integer coordinates by rounding the floating-point values.intgetCornerDiameter()Returns the rounded rectangle corner diameter (pixels).intgetCPosition()Returns the channel position of this ROI, or zero if this ROI is not associated with a particular channel.static intgetCurrentPasteMode()Returns the current paste transfer mode.StringgetDebugInfo()static ColorgetDefaultFillColor()static intgetDefaultGroup()Returns the group value assigned to newly created ROIs.static intgetDefaultHandleSize()Returns the default handle size.static doublegetDefaultStrokeWidth()Returns the default stroke width.booleangetDrawOffset()Deprecated.Drawoffset is not used any more.doublegetFeretsDiameter()Returns Feret's diameter, the greatest distance between any two points along the ROI boundary.double[]getFeretValues()Returns an array with the following values:
[0] "Feret" (maximum caliper width)
[1] "FeretAngle" (angle of diameter with maximum caliper width, between 0 and 180 deg)
[2] "MinFeret" (minimum caliper width)
[3][4] , "FeretX" and "FeretY", the X and Y coordinates of the starting point (leftmost point) of the maximum-caliper-width diameter.ColorgetFillColor()Returns the fill color used to display this ROI, or null if it is displayed transparently.doublegetFloatAngle(double x1, double y1, double x2, double y2)Returns the angle in degrees between the specified line and a horizontal line.Rectangle2D.DoublegetFloatBounds()Returns this selection's bounding rectangle (with subpixel accuracy).FloatPolygongetFloatConvexHull()Returns the convex hull of this Roi as a FloatPolygon.doublegetFloatHeight()FloatPolygongetFloatPolygon()Returns the outline of this selection as a FloatPolygonFloatPolygongetFloatPolygon(String options)Returns the outline in image pixel coordinates, where options may include "close" to add a point to close the outline if this is an area roi and the outline is not closed yet.doublegetFloatWidth()intgetGroup()Returns the group attribute of this ROI.static StringgetGroupName(int groupNumber)Returns the group name associtated with the specified group.static StringgetGroupNames()Returns the group names as a comma-delimeted string.intgetHandleSize()Returns the current handle size.intgetHashCode()Returns a hashcode for this Roi that typically changes if it is moved, even though it is still the same object.ImagePlusgetImage()Returns the ImagePlus associated with this ROI, or null.intgetImageID()Returns the ID of the image associated with this ROI.FloatPolygongetInterpolatedPolygon()Returns, as a FloatPolygon, an interpolated version of this selection that has points spaced 1.0 pixel apart.FloatPolygongetInterpolatedPolygon(double interval, boolean smooth)Returns, as a FloatPolygon, an interpolated version of this selection with points spaced 'interval' pixels apart.protected FloatPolygongetInterpolatedPolygon(FloatPolygon p, double interval, boolean smooth)Returns, as a FloatPolygon, an interpolated version of this selection with points spaced abs('interval') pixels apart.RoigetInverse(ImagePlus imp)Returns the inverted roi, or null if this is not an area roi or cannot be converted to a ShapeRoi.doublegetLength()Returns the perimeter length.static VectorgetListeners()protected doublegetMagnification()ImageProcessorgetMask()Always returns null for rectangular Roi'sStringgetName()Returns the name of this ROI, or null.intgetPasteMode()Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.PolygongetPolygon()Returns the outline of this selection as a Polygon.intgetPosition()Returns the stack position (image number) for displaying this ROI, in an overlay (or the RoiManager's 'Show All'.static RoigetPreviousRoi()Returns the Roi saved by setPreviousRoi().StringgetProperties()StringgetProperty(String property)intgetPropertyCount()OverlaygetPrototypeOverlay()FloatPolygongetRotationCenter()intgetRoundRectArcSize()Obsolete; replaced by getCornerDiameter().protected BasicStrokegetScaledStroke()booleangetScaleStrokeWidth()Returns 'true' if the stroke width is scaled as images are zoomed.intgetState()ImageStatisticsgetStatistics()BasicStrokegetStroke()Returns the Stroke used to draw this ROI, or null if no Stroke is used.ColorgetStrokeColor()Returns the the color used to draw the ROI outline or null if the default color is being used.floatgetStrokeWidth()Returns the line width.intgetTPosition()Returns the frame position of this ROI, or zero if this ROI is not associated with a particular frame.intgetType()StringgetTypeAsString()Convenience method that converts Roi type to a human-readable form.doublegetXBase()doublegetYBase()intgetZPosition()Returns the slice position of this ROI, or zero if this ROI is not associated with a particular slice.protected voidgrow(int sx, int sy)protected voidhandleMouseDown(int sx, int sy)protected voidhandleMouseDrag(int sx, int sy, int flags)protected voidhandleMouseUp(int screenX, int screenY)booleanhasHyperStackPosition()Returns 'true' if setPosition(C,Z,T) has been called.booleanisActiveOverlayRoi()Returns 'true' if this ROI is displayed and is also in an overlay.booleanisArea()Returns 'true' if this is an area selection.booleanisCursor()booleanisDrawingTool()Returns 'true' if this is an ROI primarily used from drawing (e.g., TextRoi or Arrow).intisHandle(int sx, int sy)Returns a handle number if the specified screen coordinates are inside or near a handle, otherwise returns -1.static booleanisInteger(double x)Returns whether a number is an integerbooleanisLine()Returns 'true' if this is a line selection.booleanisLineOrPoint()Return 'true' if this is a line or point selection.booleanisVisible()Returns true if this ROI is currently displayed on an image.Iterator<Point>iterator()Required by theIterableinterface.static double[]lineCircleIntersection(double ax, double ay, double bx, double by, double cx, double cy, double rad, boolean ignoreOutside)Calculates intersections of a line segment with a circle Author N.Vischer ax, ay, bx, by: points A and B of line segment cx, cy, rad: Circle center and radius.protected booleanmagnificationForSubPixel()Returns whether a roi created interactively should have subpixel resolution, (if the roi type supports it), i.e., whether the magnification is high enoughprotected static booleanmagnificationForSubPixel(double magnification)protected voidmouseDownInHandle(int handle, int sx, int sy)voidmouseDragged(MouseEvent e)voidmouseMoved(MouseEvent e)voidmouseReleased(MouseEvent e)protected voidmoveHandle(int sx, int sy)voidnotifyListeners(int id)voidnudge(int key)Nudge ROI one pixel on arrow key press.voidnudgeCorner(int key)Nudge lower right corner of rectangular and oval ROIs by one pixel based on arrow key press.protected intoffScreenX(int sx)Converts image canvas screen x coordinates to integer offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.protected doubleoffScreenXD(int sx)Converts image canvas screen x coordinates to floating-point offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.protected intoffScreenY(int sy)Converts image canvas screen y coordinates to integer offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.protected doubleoffScreenYD(int sy)Converts image canvas screen y coordinates to floating-point offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.static voidremoveRoiListener(RoiListener listener)static voidresetDefaultHandleSize()static voidsaveGroupNames()protected intscreenX(int ox)protected intscreenXD(double ox)Converts an image pixel x (offscreen)coordinate to a screen x coordinate, taking the the line or area convention for coordinates into accountprotected intscreenY(int oy)protected intscreenYD(double oy)Converts an image pixel y (offscreen)coordinate to a screen y coordinate, taking the the line or area convention for coordinates into accountvoidsetAntiAlias(boolean antiAlias)voidsetBounds(Rectangle2D.Double b)Sets the bounds of rectangular, oval or text selections.static voidsetColor(Color c)Sets the default (global) color used for ROI outlines.voidsetCornerDiameter(int cornerDiameter)Sets the rounded rectangle corner diameter (pixels).static voidsetDefaultColor(Color color)Sets the default stroke color.static voidsetDefaultFillColor(Color color)static voidsetDefaultGroup(int group)Sets the group value assigned to newly created ROIs, and also sets the default ROI color to the group color.static voidsetDefaultStrokeWidth(double width)Sets the default stroke width.voidsetDrawOffset(boolean drawOffset)Deprecated.This method was previously used to draw lines and polylines shifted by 0.5 pixels top the bottom and right, for better agreement with the position used by ProfilePlot, with the default taken from Prefs.subPixelResolution.voidsetFillColor(Color color)Sets the fill color used to display this ROI, or set to null to display it transparently.voidsetFlattenScale(double scale)voidsetGroup(int group)Sets the group of this Roi, and updates stroke color accordingly.static voidsetGroupName(int groupNumber, String name)static voidsetGroupNames(String names)Sets the group names from a comma-delimeted string.voidsetHandleSize(int size)Sets the current handle size.voidsetIgnoreClipRect(boolean ignoreClipRect)voidsetImage(ImagePlus imp)Sets the ImagePlus associated with this ROI.voidsetInstanceColor(Color c)Deprecated.replaced by setStrokeColor()voidsetIsCursor(boolean isCursor)voidsetLineWidth(int width)Deprecated.replaced by setStrokeWidth(int)voidsetLocation(double x, double y)Set the location of the ROI in image coordinates.voidsetLocation(int x, int y)Set the location of the ROI in image coordinates.voidsetName(String name)Sets the name of this ROI.voidsetNonScalable(boolean nonScalable)Set 'nonScalable' true to have TextRois in a display list drawn at a fixed location and size.static voidsetPasteMode(int transferMode)Sets the Paste transfer mode.voidsetPosition(int n)Sets the stack position (image number) of this ROI.voidsetPosition(int channel, int slice, int frame)Sets the hyperstack position of this ROI.voidsetPosition(ImagePlus imp)Sets the position of this ROI based on the stack position of the specified image.static voidsetPreviousRoi(Roi roi)Saves 'roi' so it can be restored later using Edit/Selection/Restore Selection.voidsetProperties(String properties)voidsetProperty(String key, String value)voidsetPrototypeOverlay(Overlay overlay)protected voidsetRenderingHint(Graphics2D g2d)voidsetRotationCenter(double x, double y)voidsetRoundRectArcSize(int cornerDiameter)Obsolete; replaced by setCornerDiameter().voidsetStroke(BasicStroke stroke)Sets the Stroke used to draw this ROI.voidsetStrokeColor(Color c)Sets the color used by this ROI to draw its outline.voidsetStrokeWidth(double strokeWidth)This is a version of setStrokeWidth() that accepts a double argument.voidsetStrokeWidth(float strokeWidth)Sets the width of the line used to draw this ROI.voidsetUnscalableStrokeWidth(double strokeWidth)Sets the width of the line used to draw this ROI and prevents the width from increasing when the image is zoomed.voidshowStatus()intsize()Returns the number of points in this selection; equivalent to getFloatPolygon().npoints.voidstartPaste(ImagePlus clipboard)booleansubPixelResolution()Returns true if this is a slection that supports sub-pixel resolution.voidtemporarilyHide()Deprecatedstatic float[]toFloat(int[] arr)Converts an int array to a float array.static int[]toInt(float[] arr)Converts a float array to an int array using truncation.static int[]toInt(float[] arr, int[] arr2, int size)static int[]toIntR(float[] arr)Converts a float array to an int array using rounding.StringtoString()voidtranslate(double dx, double dy)voidupdate(boolean add, boolean subtract)If 'add' is true, adds this selection to the previous one.protected voidupdateClipRect()voidupdateWideLine(float width)protected booleanuseLineSubpixelConvention()Returns 'true' if this ROI uses for drawing the convention for line and point ROIs, where the coordinates are with respect to the pixel center.static Roixor(Roi[] rois)-
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
CONSTRUCTING
public static final int CONSTRUCTING
- See Also:
- Constant Field Values
-
MOVING
public static final int MOVING
- See Also:
- Constant Field Values
-
RESIZING
public static final int RESIZING
- See Also:
- Constant Field Values
-
NORMAL
public static final int NORMAL
- See Also:
- Constant Field Values
-
MOVING_HANDLE
public static final int MOVING_HANDLE
- See Also:
- Constant Field Values
-
RECTANGLE
public static final int RECTANGLE
- See Also:
- Constant Field Values
-
OVAL
public static final int OVAL
- See Also:
- Constant Field Values
-
POLYGON
public static final int POLYGON
- See Also:
- Constant Field Values
-
FREEROI
public static final int FREEROI
- See Also:
- Constant Field Values
-
TRACED_ROI
public static final int TRACED_ROI
- See Also:
- Constant Field Values
-
LINE
public static final int LINE
- See Also:
- Constant Field Values
-
POLYLINE
public static final int POLYLINE
- See Also:
- Constant Field Values
-
FREELINE
public static final int FREELINE
- See Also:
- Constant Field Values
-
ANGLE
public static final int ANGLE
- See Also:
- Constant Field Values
-
COMPOSITE
public static final int COMPOSITE
- See Also:
- Constant Field Values
-
POINT
public static final int POINT
- See Also:
- Constant Field Values
-
HANDLE_SIZE
public static final int HANDLE_SIZE
- See Also:
- Constant Field Values
-
NOT_PASTING
public static final int NOT_PASTING
- See Also:
- Constant Field Values
-
FERET_ARRAYSIZE
public static final int FERET_ARRAYSIZE
- See Also:
- Constant Field Values
-
FERET_ARRAY_POINTOFFSET
public static final int FERET_ARRAY_POINTOFFSET
- See Also:
- Constant Field Values
-
onePixelWide
public static final BasicStroke onePixelWide
-
ROIColor
protected static Color ROIColor
-
pasteMode
protected static int pasteMode
-
lineWidth
protected static int lineWidth
-
defaultFillColor
protected static Color defaultFillColor
-
previousRoi
public static Roi previousRoi
Get using getPreviousRoi() and set using setPreviousRoi()
-
type
protected int type
-
xMax
protected int xMax
-
yMax
protected int yMax
-
imp
protected ImagePlus imp
-
ic
protected ImageCanvas ic
-
oldX
protected int oldX
-
oldY
protected int oldY
-
oldWidth
protected int oldWidth
-
oldHeight
protected int oldHeight
-
clipX
protected int clipX
-
clipY
protected int clipY
-
clipWidth
protected int clipWidth
-
clipHeight
protected int clipHeight
-
clipboard
protected ImagePlus clipboard
-
constrain
protected boolean constrain
-
center
protected boolean center
-
aspect
protected boolean aspect
-
updateFullWindow
protected boolean updateFullWindow
-
mag
protected double mag
-
asp_bk
protected double asp_bk
-
cachedMask
protected ImageProcessor cachedMask
-
handleColor
protected Color handleColor
-
strokeColor
protected Color strokeColor
-
instanceColor
protected Color instanceColor
-
fillColor
protected Color fillColor
-
stroke
protected BasicStroke stroke
-
nonScalable
protected boolean nonScalable
-
overlay
protected boolean overlay
-
wideLine
protected boolean wideLine
-
ignoreClipRect
protected boolean ignoreClipRect
-
flattenScale
protected double flattenScale
-
defaultColor
protected static Color defaultColor
-
hyperstackPosition
protected boolean hyperstackPosition
-
-
Constructor Detail
-
Roi
public Roi(int x, int y, int width, int height)Creates a rectangular ROI.
-
Roi
public Roi(double x, double y, double width, double height)Creates a rectangular ROI using double arguments.
-
Roi
public Roi(int x, int y, int width, int height, int cornerDiameter)Creates a new rounded rectangular ROI.
-
Roi
public Roi(double x, double y, double width, double height, int cornerDiameter)Creates a rounded rectangular ROI using double arguments.
-
Roi
public Roi(Rectangle r)
Creates a new rectangular Roi.
-
Roi
public Roi(int sx, int sy, ImagePlus imp)Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates.
-
Roi
public Roi(int sx, int sy, ImagePlus imp, int cornerDiameter)Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates. For rectangular rois, also a corner diameter may be specified to make it a rounded rectangle
-
Roi
public Roi(int x, int y, int width, int height, ImagePlus imp)Deprecated.
-
-
Method Detail
-
create
public static Roi create(double x, double y, double width, double height)
Creates a rectangular ROI.
-
create
public static Roi create(double x, double y, double width, double height, int cornerDiameter)
Creates a rounded rectangular ROI.
-
setLocation
public void setLocation(int x, int y)Set the location of the ROI in image coordinates.
-
setLocation
public void setLocation(double x, double y)Set the location of the ROI in image coordinates.
-
translate
public void translate(double dx, double dy)
-
setImage
public void setImage(ImagePlus imp)
Sets the ImagePlus associated with this ROI.impmay be null to remove the association to an image.
-
getImage
public ImagePlus getImage()
Returns the ImagePlus associated with this ROI, or null.
-
getImageID
public int getImageID()
Returns the ID of the image associated with this ROI.
-
getType
public int getType()
-
getState
public int getState()
-
getLength
public double getLength()
Returns the perimeter length.
-
getFeretsDiameter
public double getFeretsDiameter()
Returns Feret's diameter, the greatest distance between any two points along the ROI boundary.
-
getFeretValues
public double[] getFeretValues()
Returns an array with the following values:
[0] "Feret" (maximum caliper width)
[1] "FeretAngle" (angle of diameter with maximum caliper width, between 0 and 180 deg)
[2] "MinFeret" (minimum caliper width)
[3][4] , "FeretX" and "FeretY", the X and Y coordinates of the starting point (leftmost point) of the maximum-caliper-width diameter.
[5-7] reserved
All these values and point coordinates are in calibrated image coordinates.The following array elements are end points of the maximum and minimum caliper diameter, in unscaled image pixel coordinates:
[8][9] "FeretX1", "FeretY1"; unscaled versions of "FeretX" and "FeretY" (subclasses may use any end of the diameter, not necessarily the left one)
[10][11] "FeretX2", "FeretY2", end point of the maxium-caliper-width diameter. Both of these points are vertices of the convex hull.
The final four array elements are the starting and end points of the minimum caliper width,
[12],[13] "MinFeretX", "MinFeretY", and
[14],[15] "MinFeretX2", "MinFeretY2". These two pooints are not sorted by x, but the first point point (MinFeretX, MinFeretY) is guaranteed to be a vertex of the convex hull, while second point (MinFeretX2, MinFeretY2) usually is not a vertex point but at a boundary line of the convex hull.
-
getConvexHull
public Polygon getConvexHull()
Returns the convex hull of this Roi as a Polygon with integer coordinates by rounding the floating-point values. Coordinates of the convex hull are image pixel coordinates.
-
getFloatConvexHull
public FloatPolygon getFloatConvexHull()
Returns the convex hull of this Roi as a FloatPolygon. Coordinates of the convex hull are image pixel coordinates.
-
getBounds
public Rectangle getBounds()
Returns this selection's bounding rectangle.
-
getFloatBounds
public Rectangle2D.Double getFloatBounds()
Returns this selection's bounding rectangle (with subpixel accuracy).
-
setBounds
public void setBounds(Rectangle2D.Double b)
Sets the bounds of rectangular, oval or text selections. Note that for these types, subpixel resolution is ignored, and the x,y values are rounded down, the width and height values rounded up. Do not use for other ROI types since their width and height are results of a calculation. For translating ROIs, use setLocation.
-
getBoundingRect
public Rectangle getBoundingRect()
Deprecated.replaced by getBounds()
-
getPolygon
public Polygon getPolygon()
Returns the outline of this selection as a Polygon.
-
getFloatPolygon
public FloatPolygon getFloatPolygon()
Returns the outline of this selection as a FloatPolygon
-
getFloatPolygon
public FloatPolygon getFloatPolygon(String options)
Returns the outline in image pixel coordinates, where options may include "close" to add a point to close the outline if this is an area roi and the outline is not closed yet. (For ShapeRois, "separate" inserts NaN values between subpaths).
-
getInterpolatedPolygon
public FloatPolygon getInterpolatedPolygon()
Returns, as a FloatPolygon, an interpolated version of this selection that has points spaced 1.0 pixel apart.
-
getInterpolatedPolygon
public FloatPolygon getInterpolatedPolygon(double interval, boolean smooth)
Returns, as a FloatPolygon, an interpolated version of this selection with points spaced 'interval' pixels apart. If 'smooth' is true, traced and freehand selections are first smoothed using a 3 point running average.
-
getInterpolatedPolygon
protected FloatPolygon getInterpolatedPolygon(FloatPolygon p, double interval, boolean smooth)
Returns, as a FloatPolygon, an interpolated version of this selection with points spaced abs('interval') pixels apart. If 'smooth' is true, traced and freehand selections are first smoothed using a 3 point running average. If 'interval' is negative, the program is allowed to decrease abs('interval') so that the last segment will hit the end point
-
getContainedPoints
public Point[] getContainedPoints()
Returns the coordinates of the pixels inside this ROI as an array of Points.- See Also:
getContainedFloatPoints(),iterator()
-
getContainedFloatPoints
public FloatPolygon getContainedFloatPoints()
Returns the coordinates of the pixels inside this ROI as a FloatPolygon.- See Also:
getContainedPoints(),iterator()
-
lineCircleIntersection
public static double[] lineCircleIntersection(double ax, double ay, double bx, double by, double cx, double cy, double rad, boolean ignoreOutside)Calculates intersections of a line segment with a circle Author N.Vischer ax, ay, bx, by: points A and B of line segment cx, cy, rad: Circle center and radius. ignoreOutside: if true, ignores intersections outside the line segment A-B Returns an array of 0, 2 or 4 coordinates (for 0, 1, or 2 intersection points). If two intersection points are returned, they are listed in travel direction A->B
-
clone
public Object clone()
Returns a copy of this roi. See Thinking is Java by Bruce Eckel (www.eckelobjects.com) for a good description of object cloning.
-
abortModification
public void abortModification(ImagePlus imp)
Aborts constructing or modifying the roi (called by the ImageJ class on escape)
-
grow
protected void grow(int sx, int sy)
-
moveHandle
protected void moveHandle(int sx, int sy)
-
nudge
public void nudge(int key)
Nudge ROI one pixel on arrow key press.
-
nudgeCorner
public void nudgeCorner(int key)
Nudge lower right corner of rectangular and oval ROIs by one pixel based on arrow key press.
-
updateClipRect
protected void updateClipRect()
-
clipRectMargin
protected int clipRectMargin()
-
handleMouseDrag
protected void handleMouseDrag(int sx, int sy, int flags)
-
draw
public void draw(Graphics g)
-
drawOverlay
public void drawOverlay(Graphics g)
-
getHandleSize
public int getHandleSize()
Returns the current handle size.
-
setHandleSize
public void setHandleSize(int size)
Sets the current handle size.
-
getDefaultHandleSize
public static int getDefaultHandleSize()
Returns the default handle size.
-
resetDefaultHandleSize
public static void resetDefaultHandleSize()
-
drawPixels
public void drawPixels()
Deprecated.replaced by drawPixels(ImageProcessor)
-
drawPixels
public void drawPixels(ImageProcessor ip)
Draws the selection outline on the specified ImageProcessor.
-
contains
public boolean contains(int x, int y)Returns whether the center of pixel (x,y) is contained in the Roi. The position of a pixel center determines whether a pixel is selected. Points exactly at the left (right) border are considered outside (inside); points exactly on horizontal borders are considered outside (inside) at the border with the lower (higher) y. This convention is opposite to that of the java.awt.Shape class.
-
containsPoint
public boolean containsPoint(double x, double y)Returns whether coordinate (x,y) is contained in the Roi. Note that the coordinate (0,0) is the top-left corner of pixel (0,0). Use contains(int, int) to determine whether a given pixel is contained in the Roi.
-
getInverse
public Roi getInverse(ImagePlus imp)
Returns the inverted roi, or null if this is not an area roi or cannot be converted to a ShapeRoi. If imp is not given, assumes a rectangle of size 2e9*2e9 for the boundary.
-
isHandle
public int isHandle(int sx, int sy)Returns a handle number if the specified screen coordinates are inside or near a handle, otherwise returns -1.
-
mouseDownInHandle
protected void mouseDownInHandle(int handle, int sx, int sy)
-
handleMouseDown
protected void handleMouseDown(int sx, int sy)
-
handleMouseUp
protected void handleMouseUp(int screenX, int screenY)
-
update
public void update(boolean add, boolean subtract)If 'add' is true, adds this selection to the previous one. If 'subtract' is true, subtracts it from the previous selection. Called by the IJ.doWand() method, and the makeRectangle(), makeOval(), makePolygon() and makeSelection() macro functions.
-
showStatus
public void showStatus()
-
getMask
public ImageProcessor getMask()
Always returns null for rectangular Roi's
-
startPaste
public void startPaste(ImagePlus clipboard)
-
endPaste
public void endPaste()
-
abortPaste
public void abortPaste()
-
getDefaultStrokeWidth
public static double getDefaultStrokeWidth()
Returns the default stroke width.
-
setDefaultStrokeWidth
public static void setDefaultStrokeWidth(double width)
Sets the default stroke width.
-
getDefaultGroup
public static int getDefaultGroup()
Returns the group value assigned to newly created ROIs.
-
setDefaultGroup
public static void setDefaultGroup(int group)
Sets the group value assigned to newly created ROIs, and also sets the default ROI color to the group color. Set to zero to not have a default group and to use the default ROI color.- See Also:
setGroup(int),getGroup(),getGroupColor(int)
-
getGroup
public int getGroup()
Returns the group attribute of this ROI.
-
getGroupName
public static String getGroupName(int groupNumber)
Returns the group name associtated with the specified group.
-
setGroupName
public static void setGroupName(int groupNumber, String name)
-
saveGroupNames
public static void saveGroupNames()
-
getGroupNames
public static String getGroupNames()
Returns the group names as a comma-delimeted string.
-
setGroupNames
public static void setGroupNames(String names)
Sets the group names from a comma-delimeted string.
-
setGroup
public void setGroup(int group)
Sets the group of this Roi, and updates stroke color accordingly.
-
getAngle
public double getAngle(int x1, int y1, int x2, int y2)Returns the angle in degrees between the specified line and a horizontal line.
-
getFloatAngle
public double getFloatAngle(double x1, double y1, double x2, double y2)Returns the angle in degrees between the specified line and a horizontal line.
-
setColor
public static void setColor(Color c)
Sets the default (global) color used for ROI outlines.- See Also:
getColor(),setStrokeColor(Color)
-
getColor
public static Color getColor()
Returns the default (global) color used for drawing ROI outlines.- See Also:
setColor(Color),getStrokeColor()
-
setStrokeColor
public void setStrokeColor(Color c)
Sets the color used by this ROI to draw its outline. This color, if not null, overrides the global color set by the static setColor() method. Set the stroke color after setting the fill color to both fill and outline the ROI.
-
getStrokeColor
public Color getStrokeColor()
Returns the the color used to draw the ROI outline or null if the default color is being used.- See Also:
setStrokeColor(Color)
-
setDefaultColor
public static void setDefaultColor(Color color)
Sets the default stroke color.
-
setFillColor
public void setFillColor(Color color)
Sets the fill color used to display this ROI, or set to null to display it transparently.- See Also:
getFillColor(),setStrokeColor(java.awt.Color)
-
getFillColor
public Color getFillColor()
Returns the fill color used to display this ROI, or null if it is displayed transparently.- See Also:
setFillColor(java.awt.Color),getStrokeColor()
-
setDefaultFillColor
public static void setDefaultFillColor(Color color)
-
getDefaultFillColor
public static Color getDefaultFillColor()
-
setAntiAlias
public void setAntiAlias(boolean antiAlias)
-
getAntiAlias
public boolean getAntiAlias()
-
setRenderingHint
protected void setRenderingHint(Graphics2D g2d)
-
copyAttributes
public void copyAttributes(Roi roi2)
Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection.
-
setInstanceColor
public void setInstanceColor(Color c)
Deprecated.replaced by setStrokeColor()
-
setLineWidth
public void setLineWidth(int width)
Deprecated.replaced by setStrokeWidth(int)
-
updateWideLine
public void updateWideLine(float width)
-
setNonScalable
public void setNonScalable(boolean nonScalable)
Set 'nonScalable' true to have TextRois in a display list drawn at a fixed location and size.
-
setStrokeWidth
public void setStrokeWidth(float strokeWidth)
Sets the width of the line used to draw this ROI. Set the width to 0.0 and the ROI will be drawn using a a 1 pixel stroke width regardless of the magnification.
-
setStrokeWidth
public void setStrokeWidth(double strokeWidth)
This is a version of setStrokeWidth() that accepts a double argument.
-
setUnscalableStrokeWidth
public void setUnscalableStrokeWidth(double strokeWidth)
Sets the width of the line used to draw this ROI and prevents the width from increasing when the image is zoomed.
-
getStrokeWidth
public float getStrokeWidth()
Returns the line width.
-
setStroke
public void setStroke(BasicStroke stroke)
Sets the Stroke used to draw this ROI.
-
getStroke
public BasicStroke getStroke()
Returns the Stroke used to draw this ROI, or null if no Stroke is used.
-
getScaleStrokeWidth
public boolean getScaleStrokeWidth()
Returns 'true' if the stroke width is scaled as images are zoomed.
-
getScaledStroke
protected BasicStroke getScaledStroke()
-
getName
public String getName()
Returns the name of this ROI, or null.
-
setName
public void setName(String name)
Sets the name of this ROI.
-
setPasteMode
public static void setPasteMode(int transferMode)
Sets the Paste transfer mode.- See Also:
Blitter
-
setCornerDiameter
public void setCornerDiameter(int cornerDiameter)
Sets the rounded rectangle corner diameter (pixels).
-
getCornerDiameter
public int getCornerDiameter()
Returns the rounded rectangle corner diameter (pixels).
-
setRoundRectArcSize
public void setRoundRectArcSize(int cornerDiameter)
Obsolete; replaced by setCornerDiameter().
-
getRoundRectArcSize
public int getRoundRectArcSize()
Obsolete; replaced by getCornerDiameter().
-
setPosition
public void setPosition(int n)
Sets the stack position (image number) of this ROI. In an overlay, this ROI is only displayed when the stack is at the specified position. Set to zero to have the ROI displayed on all images in the stack. Clears the hyperStackPosition, if there was one.- See Also:
Overlay
-
getPosition
public int getPosition()
Returns the stack position (image number) for displaying this ROI, in an overlay (or the RoiManager's 'Show All'. Returns zero if the ROI is not associated with a particular stack image. PointRois can also return PointRoi.POINTWISE_POSITION.- See Also:
Overlay
-
setPosition
public void setPosition(int channel, int slice, int frame)Sets the hyperstack position of this ROI. In an overlay, this ROI is only displayed when the hyperstack is at the specified position.- See Also:
Overlay
-
hasHyperStackPosition
public boolean hasHyperStackPosition()
Returns 'true' if setPosition(C,Z,T) has been called.
-
setPosition
public void setPosition(ImagePlus imp)
Sets the position of this ROI based on the stack position of the specified image.
-
getCPosition
public final int getCPosition()
Returns the channel position of this ROI, or zero if this ROI is not associated with a particular channel.
-
getZPosition
public final int getZPosition()
Returns the slice position of this ROI, or zero if this ROI is not associated with a particular slice.
-
getTPosition
public final int getTPosition()
Returns the frame position of this ROI, or zero if this ROI is not associated with a particular frame.
-
setPrototypeOverlay
public void setPrototypeOverlay(Overlay overlay)
-
getPrototypeOverlay
public Overlay getPrototypeOverlay()
-
getPasteMode
public int getPasteMode()
Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.- See Also:
Blitter
-
getCurrentPasteMode
public static int getCurrentPasteMode()
Returns the current paste transfer mode.
-
isArea
public boolean isArea()
Returns 'true' if this is an area selection.
-
isLine
public boolean isLine()
Returns 'true' if this is a line selection.
-
isLineOrPoint
public boolean isLineOrPoint()
Return 'true' if this is a line or point selection.
-
isDrawingTool
public boolean isDrawingTool()
Returns 'true' if this is an ROI primarily used from drawing (e.g., TextRoi or Arrow).
-
getMagnification
protected double getMagnification()
-
getTypeAsString
public String getTypeAsString()
Convenience method that converts Roi type to a human-readable form.
-
isVisible
public boolean isVisible()
Returns true if this ROI is currently displayed on an image.
-
subPixelResolution
public boolean subPixelResolution()
Returns true if this is a slection that supports sub-pixel resolution.
-
getDrawOffset
@Deprecated public boolean getDrawOffset()
Deprecated.Drawoffset is not used any more.
-
setDrawOffset
@Deprecated public void setDrawOffset(boolean drawOffset)
Deprecated.This method was previously used to draw lines and polylines shifted by 0.5 pixels top the bottom and right, for better agreement with the position used by ProfilePlot, with the default taken from Prefs.subPixelResolution. Now the shift is independent of this setting and only depends on the ROI type (area or line/point ROI).
-
setIgnoreClipRect
public void setIgnoreClipRect(boolean ignoreClipRect)
-
isActiveOverlayRoi
public final boolean isActiveOverlayRoi()
Returns 'true' if this ROI is displayed and is also in an overlay.
-
equals
public boolean equals(Object obj)
Checks whether two rectangles are equal.
-
offScreenX
protected int offScreenX(int sx)
Converts image canvas screen x coordinates to integer offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.
-
offScreenY
protected int offScreenY(int sy)
Converts image canvas screen y coordinates to integer offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.
-
offScreenXD
protected double offScreenXD(int sx)
Converts image canvas screen x coordinates to floating-point offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.
-
offScreenYD
protected double offScreenYD(int sy)
Converts image canvas screen y coordinates to floating-point offscreen image pixel coordinates, depending on whether this roi uses the line or area convention for coordinates.
-
useLineSubpixelConvention
protected boolean useLineSubpixelConvention()
Returns 'true' if this ROI uses for drawing the convention for line and point ROIs, where the coordinates are with respect to the pixel center. Returns false for area rois, which have coordinates with respect to the upper left corners of the pixels
-
magnificationForSubPixel
protected boolean magnificationForSubPixel()
Returns whether a roi created interactively should have subpixel resolution, (if the roi type supports it), i.e., whether the magnification is high enough
-
magnificationForSubPixel
protected static boolean magnificationForSubPixel(double magnification)
-
screenXD
protected int screenXD(double ox)
Converts an image pixel x (offscreen)coordinate to a screen x coordinate, taking the the line or area convention for coordinates into account
-
screenYD
protected int screenYD(double oy)
Converts an image pixel y (offscreen)coordinate to a screen y coordinate, taking the the line or area convention for coordinates into account
-
screenX
protected int screenX(int ox)
-
screenY
protected int screenY(int oy)
-
toInt
public static int[] toInt(float[] arr)
Converts a float array to an int array using truncation.
-
toInt
public static int[] toInt(float[] arr, int[] arr2, int size)
-
toIntR
public static int[] toIntR(float[] arr)
Converts a float array to an int array using rounding.
-
toFloat
public static float[] toFloat(int[] arr)
Converts an int array to a float array.
-
isInteger
public static boolean isInteger(double x)
Returns whether a number is an integer
-
setProperties
public void setProperties(String properties)
-
getProperties
public String getProperties()
-
getPropertyCount
public int getPropertyCount()
-
temporarilyHide
public void temporarilyHide()
Deprecated
-
mouseDragged
public void mouseDragged(MouseEvent e)
-
mouseMoved
public void mouseMoved(MouseEvent e)
-
mouseReleased
public void mouseReleased(MouseEvent e)
-
getXBase
public double getXBase()
-
getYBase
public double getYBase()
-
getFloatWidth
public double getFloatWidth()
-
getFloatHeight
public double getFloatHeight()
-
getAngle
public double getAngle()
Overridden by PolygonRoi (angle between first two points), TextRoi (text angle) and Line (line angle).
-
enableSubPixelResolution
public void enableSubPixelResolution()
-
setIsCursor
public void setIsCursor(boolean isCursor)
-
isCursor
public boolean isCursor()
-
getDebugInfo
public String getDebugInfo()
-
getStatistics
public ImageStatistics getStatistics()
-
getRotationCenter
public FloatPolygon getRotationCenter()
-
setRotationCenter
public void setRotationCenter(double x, double y)
-
size
public int size()
Returns the number of points in this selection; equivalent to getFloatPolygon().npoints.
-
setPreviousRoi
public static void setPreviousRoi(Roi roi)
Saves 'roi' so it can be restored later using Edit/Selection/Restore Selection.
-
getPreviousRoi
public static Roi getPreviousRoi()
Returns the Roi saved by setPreviousRoi().
-
getContourCentroid
public double[] getContourCentroid()
-
convertToPolygon
public Roi convertToPolygon()
Deprecated.Obsolete, replaced by Roi.convertLineToArea()
-
convertLineToArea
public static Roi convertLineToArea(Roi line)
Converts a line selection into an area (polygon or composite) selection.
Author: Michael Schmid
-
getHashCode
public int getHashCode()
Returns a hashcode for this Roi that typically changes if it is moved, even though it is still the same object.
-
setFlattenScale
public void setFlattenScale(double scale)
-
notifyListeners
public void notifyListeners(int id)
-
addRoiListener
public static void addRoiListener(RoiListener listener)
-
removeRoiListener
public static void removeRoiListener(RoiListener listener)
-
getListeners
public static Vector getListeners()
-
iterator
public Iterator<Point> iterator()
Required by theIterableinterface. Use to iterate over the contained coordinates. Usage example:for (Point p : roi) { // process p }Author: Wilhelm Burger- Specified by:
iteratorin interfaceIterable<Point>- See Also:
getContainedPoints(),getContainedFloatPoints()
-
-