Package ij.gui
Class Roi
java.lang.Object
ij.gui.Roi
- All Implemented Interfaces:
Serializable
,Cloneable
A rectangular region of interest and superclass for the other ROI classes.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected double
protected boolean
protected ImageProcessor
protected boolean
protected ImagePlus
protected int
protected int
protected int
protected int
static final int
protected boolean
static final int
protected static Color
protected Color
static final int
static final int
static final int
protected Color
protected ImageCanvas
protected boolean
protected ImagePlus
protected Color
static final int
protected static int
protected double
static final int
static final int
protected boolean
static final int
static final int
protected int
protected int
protected int
protected int
static final BasicStroke
static final int
protected boolean
protected static int
static final int
static final int
static final int
static Roi
static final int
static final int
protected static Color
protected BasicStroke
protected Color
static final int
protected int
protected boolean
protected boolean
protected int
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionRoi
(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.Deprecated.Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates.Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates.Creates a new rectangular Roi. -
Method Summary
Modifier and TypeMethodDescriptionvoid
static void
addRoiListener
(RoiListener listener) protected int
clone()
Returns a copy of this roi.boolean
contains
(int x, int y) void
copyAttributes
(Roi roi2) Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection.void
void
void
Deprecated.replaced by drawPixels(ImageProcessor)void
Draws the selection outline on the specified ImageProcessor.void
void
endPaste()
boolean
Checks whether two rectangles are equal.double
getAngle()
Overridden by PolygonRoi (angle between first two points), TextRoi (text angle) and Line (line angle).double
getAngle
(int x1, int y1, int x2, int y2) Returns the angle in degrees between the specified line and a horizontal line.Deprecated.replaced by getBounds()Return this selection's bounding rectangle.static Color
getColor()
Returns the default (global) color used for drawing ROI outlines.double[]
int
Returns the rounded rectangle corner diameter (pixels).final int
Returns the channel position of this ROI, or zero if this ROI is not associated with a particular channel.static int
Returns the current paste transfer mode.static Color
boolean
Returns true if this is a PolygonRoi that supports sub-pixel resolution and polygons are drawn on zoomed images offset down and to the right by 0.5 pixels..double
Returns Feret's diameter, the greatest distance between any two points along the ROI boundary.double[]
Caculates "Feret" (maximum caliper width), "FeretAngle" and "MinFeret" (minimum caliper width), "FeretX" and "FeretY".Returns the fill color used to display this ROI, or null if it is displayed transparently.double
getFloatAngle
(double x1, double y1, double x2, double y2) Returns the angle in degrees between the specified line and a horizontal line.Return this selection's bounding rectangle.double
double
int
Returns a hashcode for this Roi that typically changes if it is moved, even though it is still the same object.getImage()
Returns the ImagePlus associated with this ROI, or null.int
Returns the ID of the image associated with this ROI.Returns, as a FloatPolygon, an interpolated version of this selection that has points spaced 1.0 pixel apart.getInterpolatedPolygon
(double interval, boolean smooth) Returns, as a FloatPolygon, an interpolated version of this selection with points spaced 'interval' pixels apart.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.double
Returns the perimeter length.protected double
getMask()
Always returns null for rectangular Roi'sgetName()
Returns the name of this ROI, or null.int
Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.Returns the outline of this selection as a Polygon, or null if this is a straight line selection.int
Returns the stack position (image number) of this ROI, or zero if the ROI is not associated with a particular stack image.getProperty
(String property) int
int
Obsolete; replaced by getCornerDiameter().protected BasicStroke
int
getState()
Returns the Stroke used to draw this ROI, or null if no Stroke is used.Returns the the color used to draw the ROI outline or null if the default color is being used.float
Returns the lineWidth.final int
Returns the frame position of this ROI, or zero if this ROI is not associated with a particular frame.int
getType()
Convenience method that converts Roi type to a human-readable form.double
getXBase()
double
getYBase()
final int
Returns the slice position of this ROI, or zero if this ROI is not associated with a particular slice.protected void
grow
(int sx, int sy) protected void
handleMouseDown
(int sx, int sy) protected void
handleMouseDrag
(int sx, int sy, int flags) protected void
handleMouseUp
(int screenX, int screenY) final boolean
Returns 'true' if this ROI is displayed and is also in an overlay.boolean
isArea()
Returns 'true' if this is an area selection.boolean
isCursor()
boolean
Returns 'true' if this is an ROI primarily used from drawing (e.g., TextRoi or Arrow).int
isHandle
(int sx, int sy) Returns a handle number if the specified screen coordinates are inside or near a handle, otherwise returns -1.boolean
isLine()
Returns 'true' if this is a line selection.boolean
Returns true if this ROI is currently displayed on an image.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 void
mouseDownInHandle
(int handle, int sx, int sy) void
void
void
protected void
moveHandle
(int sx, int sy) void
notifyListeners
(int id) void
nudge
(int key) Nudge ROI one pixel on arrow key press.void
nudgeCorner
(int key) Nudge lower right corner of rectangular and oval ROIs by one pixel based on arrow key press.static void
removeRoiListener
(RoiListener listener) protected int
screenX
(int ox) protected int
screenXD
(double ox) protected int
screenY
(int oy) protected int
screenYD
(double oy) static void
Sets the default (global) color used for ROI outlines.void
setCornerDiameter
(int cornerDiameter) Sets the rounded rectangle corner diameter (pixels).static void
setDefaultFillColor
(Color color) void
setDrawOffset
(boolean drawOffset) void
setFillColor
(Color color) Sets the fill color used to display this ROI, or set to null to display it transparently.void
setIgnoreClipRect
(boolean ignoreClipRect) void
void
Deprecated.replaced by setStrokeColor()void
setIsCursor
(boolean isCursor) void
setLineWidth
(int width) Deprecated.replaced by setStrokeWidth(int)void
setLocation
(double x, double y) Set the location of the ROI in image coordinates.void
setLocation
(int x, int y) Set the location of the ROI in image coordinates.void
Sets the name of this ROI.void
setNonScalable
(boolean nonScalable) Set 'nonScalable' true to have TextRois in a display list drawn at a fixed location and size.static void
setPasteMode
(int transferMode) Sets the Paste transfer mode.void
setPosition
(int n) Sets the stack position (image number) of this ROI.void
setPosition
(int channel, int slice, int frame) Sets the hyperstack position of this ROI.void
setProperties
(String properties) void
setProperty
(String key, String value) void
setPrototypeOverlay
(Overlay overlay) void
setRotationCenter
(double x, double y) void
setRoundRectArcSize
(int cornerDiameter) Obsolete; replaced by setCornerDiameter().void
setStroke
(BasicStroke stroke) Sets the Stroke used to draw this ROI.void
Sets the color used by this ROI to draw its outline.void
setStrokeWidth
(double width) This is a version of setStrokeWidth() that accepts a double argument.void
setStrokeWidth
(float width) Sets the width of the line used to draw this ROI.protected void
void
startPaste
(ImagePlus clipboard) boolean
Returns true if this is a slection that supports sub-pixel resolution.void
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.toString()
void
update
(boolean add, boolean subtract) If 'add' is true, adds this selection to the previous one.protected void
void
updateWideLine
(float width)
-
Field Details
-
CONSTRUCTING
public static final int CONSTRUCTING- See Also:
-
MOVING
public static final int MOVING- See Also:
-
RESIZING
public static final int RESIZING- See Also:
-
NORMAL
public static final int NORMAL- See Also:
-
MOVING_HANDLE
public static final int MOVING_HANDLE- See Also:
-
RECTANGLE
public static final int RECTANGLE- See Also:
-
OVAL
public static final int OVAL- See Also:
-
POLYGON
public static final int POLYGON- See Also:
-
FREEROI
public static final int FREEROI- See Also:
-
TRACED_ROI
public static final int TRACED_ROI- See Also:
-
LINE
public static final int LINE- See Also:
-
POLYLINE
public static final int POLYLINE- See Also:
-
FREELINE
public static final int FREELINE- See Also:
-
ANGLE
public static final int ANGLE- See Also:
-
COMPOSITE
public static final int COMPOSITE- See Also:
-
POINT
public static final int POINT- See Also:
-
HANDLE_SIZE
public static final int HANDLE_SIZE- See Also:
-
NOT_PASTING
public static final int NOT_PASTING- See Also:
-
previousRoi
-
onePixelWide
-
ROIColor
-
pasteMode
protected static int pasteMode -
lineWidth
protected static int lineWidth -
defaultFillColor
-
type
protected int type -
xMax
protected int xMax -
yMax
protected int yMax -
imp
-
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
-
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
-
handleColor
-
strokeColor
-
instanceColor
-
fillColor
-
stroke
-
nonScalable
protected boolean nonScalable -
overlay
protected boolean overlay -
wideLine
protected boolean wideLine -
ignoreClipRect
protected boolean ignoreClipRect
-
-
Constructor Details
-
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
Creates a new rectangular Roi. -
Roi
Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates. -
Roi
Starts the process of creating a user-defined rectangular Roi, where sx and sy are the starting screen coordinates. -
Roi
Deprecated.
-
-
Method Details
-
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. -
setImage
-
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()Caculates "Feret" (maximum caliper width), "FeretAngle" and "MinFeret" (minimum caliper width), "FeretX" and "FeretY". -
getConvexHull
-
getBounds
Return this selection's bounding rectangle. -
getFloatBounds
Return this selection's bounding rectangle. -
getBoundingRect
Deprecated.replaced by getBounds() -
getPolygon
Returns the outline of this selection as a Polygon, or null if this is a straight line selection. -
getFloatPolygon
-
getInterpolatedPolygon
Returns, as a FloatPolygon, an interpolated version of this selection that has points spaced 1.0 pixel apart. -
getInterpolatedPolygon
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
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 -
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
-
clone
Returns a copy of this roi. See Thinking is Java by Bruce Eckel (www.eckelobjects.com) for a good description of object cloning. -
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
-
drawOverlay
-
drawPixels
public void drawPixels()Deprecated.replaced by drawPixels(ImageProcessor) -
drawPixels
Draws the selection outline on the specified ImageProcessor. -
contains
public boolean contains(int x, int y) -
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
protected void showStatus() -
getMask
Always returns null for rectangular Roi's -
startPaste
-
endPaste
public void endPaste() -
abortPaste
public void abortPaste() -
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
Sets the default (global) color used for ROI outlines.- See Also:
-
getColor
Returns the default (global) color used for drawing ROI outlines.- See Also:
-
setStrokeColor
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. -
getStrokeColor
Returns the the color used to draw the ROI outline or null if the default color is being used.- See Also:
-
setFillColor
Sets the fill color used to display this ROI, or set to null to display it transparently.- See Also:
-
getFillColor
Returns the fill color used to display this ROI, or null if it is displayed transparently.- See Also:
-
setDefaultFillColor
-
getDefaultFillColor
-
copyAttributes
Copy the attributes (outline color, fill color, outline width) of 'roi2' to the this selection. -
setInstanceColor
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 width) 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 width) This is a version of setStrokeWidth() that accepts a double argument. -
getStrokeWidth
public float getStrokeWidth()Returns the lineWidth. -
setStroke
Sets the Stroke used to draw this ROI. -
getStroke
Returns the Stroke used to draw this ROI, or null if no Stroke is used. -
getScaledStroke
-
getName
Returns the name of this ROI, or null. -
setName
Sets the name of this ROI. -
setPasteMode
public static void setPasteMode(int transferMode) Sets the Paste transfer mode.- See Also:
-
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.- See Also:
-
getPosition
public int getPosition()Returns the stack position (image number) of this ROI, or zero if the ROI is not associated with a particular stack image.- See Also:
-
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:
-
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
-
getPrototypeOverlay
-
getPasteMode
public int getPasteMode()Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.- See Also:
-
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. -
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
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
public boolean getDrawOffset()Returns true if this is a PolygonRoi that supports sub-pixel resolution and polygons are drawn on zoomed images offset down and to the right by 0.5 pixels.. -
setDrawOffset
public void setDrawOffset(boolean drawOffset) -
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
Checks whether two rectangles are equal. -
screenX
protected int screenX(int ox) -
screenY
protected int screenY(int oy) -
screenXD
protected int screenXD(double ox) -
screenYD
protected int screenYD(double 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. -
setProperty
-
getProperty
-
setProperties
-
getProperties
-
getPropertyCount
public int getPropertyCount() -
toString
-
temporarilyHide
public void temporarilyHide()Deprecated -
mouseDragged
-
mouseMoved
-
mouseReleased
-
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
-
getStatistics
-
getRotationCenter
-
setRotationCenter
public void setRotationCenter(double x, double y) -
getContourCentroid
public double[] getContourCentroid() -
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. -
notifyListeners
public void notifyListeners(int id) -
addRoiListener
-
removeRoiListener
-