ij.gui
Class Roi

java.lang.Object
  extended by ij.gui.AbstractRoi
      extended by ij.gui.AttributeRoi
          extended by ij.gui.Roi
All Implemented Interfaces:
RoiBeans, RoiConstance, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ImageRoi, Line, OvalRoi, PolygonRoi, RectangleRoi, RoundRectangleRoi, ShapeRoi, TextRoi

public class Roi
extends AttributeRoi
implements java.lang.Cloneable, java.io.Serializable

A rectangular region of interest and superclass for the other ROI classes.

See Also:
Serialized Form

Field Summary
static java.awt.BasicStroke onePixelWide
           
static Roi previousRoi
           
 java.awt.Shape roundRect
           
 
Fields inherited from interface ij.gui.RoiConstance
ADD_TO_ROI, ANGLE, COMPOSITE, CONSTRUCTING, DRAW_HANDLE, DUPLICATE_HANDLE, EVT_HANDLE_SIZE, FILL_HANDLE, FREELINE, FREEROI, HANDLE_SIZE, LINE, MAG_HANDLE, MOVING, MOVING_HANDLE, MOVING_ROUNDRECT_HANDLE, NO_MODS, NORMAL, NOT_PASTING, OVAL, POINT, POLYGON, POLYLINE, RECTANGLE, RESIZING, SUBTRACT_FROM_ROI, TRACED_ROI, UNDO_HANDLE
 
Constructor Summary
Roi(double x, double y, double width, double height)
          Creates a rounded rectangular ROI using double arguments.
Roi(double x, double y, double width, double height, double cornerDiameter)
          Creates a new rounded rectangular ROI.
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(int x, int y, int width, int height)
          Creates a rectangular ROI.
Roi(int x, int y, int width, int height, ImagePlus imp)
          Deprecated.  
Roi(int x, int y, int width, int height, int cornerDiameter)
          Creates a new rounded rectangular ROI.
Roi(java.awt.Rectangle r)
          Creates a new rectangular Roi.
Roi(java.awt.geom.Rectangle2D.Double r)
          Creates a new rectangular Roi.
 
Method Summary
 void abortPaste()
           
 void appRoiHandle(java.awt.Graphics g, double x, double y, java.awt.Color color)
           
 java.lang.Object clone()
          Returns a copy of this roi.
 boolean contains(int x, int y)
           
 void draw(java.awt.Graphics g)
           
 void drawfillOverlay(java.awt.Graphics g, boolean fillcolor)
           
 void drawHandle(java.awt.Graphics g, int x, int y)
           
 void drawOverlay(java.awt.Graphics g)
           
 void drawPixels()
          Deprecated. replaced by drawPixels(ImageProcessor)
 void drawPixels(ImageProcessor ip)
          Draws the selection outline on the specified ImageProcessor.
 void drawPixels(ImageProcessor ip, java.awt.geom.GeneralPath path)
          Draws the selection outline on the specified ImageProcessor.
 void drawRoiHandle(java.awt.Graphics g, double x, double y)
           
 void drawStroke(java.awt.Graphics2D g)
           
 void endPaste()
           
 boolean equals(java.lang.Object obj)
          Checks whether two rectangles are equal.
 void fillRoiHandle(java.awt.Graphics g, double x, double y)
           
 java.awt.Rectangle getBoundingRect()
          Deprecated. replaced by getBounds()
 java.awt.Rectangle getBounds()
          Return this selection's bounding rectangle.
 int getCornerDiameter()
          Returns the rounded rectangle corner diameter (pixels).
static int getCurrentPasteMode()
          Returns the current paste transfer mode.
 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..
 java.awt.geom.Rectangle2D.Double getFloatBounds()
          Return this selection's bounding rectangle.
 FloatPolygon getFloatPolygon()
           
 int getHandleSize()
           
 double getLength()
          Returns the perimeter length.
 ImageProcessor getMask()
          Always returns null for rectangular Roi's
 int getPasteMode()
          Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.
 java.awt.Polygon getPolygon()
          Returns the outline of this selection as a Polygon, or null if this is a straight line selection.
 Overlay getPrototypeOverlay()
           
 int getRoundRectArcSize()
          Obsolete; replaced by getCornerDiameter().
 int getState()
           
 java.lang.String getTypeAsString()
          Convenience method that converts Roi type to a human-readable form.
 boolean isArea()
          Returns 'true' if this is an area selection.
 boolean isDrawingTool()
          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 isVisible()
          Returns true if this ROI is currently displayed on an image.
 void magRoiHandle(java.awt.Graphics g, double x, double y)
           
 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.
 void setCornerDiameter(int cornerDiameter)
          Sets the rounded rectangle corner diameter (pixels).
 void setDrawOffset(boolean drawOffset)
           
 void setImage(ImagePlus imp)
           
 void setInstanceColor(java.awt.Color c)
          Deprecated. replaced by setStrokeColor()
 void setLineWidth(int width)
          Deprecated. replaced by setStrokeWidth(int)
 void setLocation(int x, int y)
          Set the location of the ROI in image coordinates.
 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 setPrototypeOverlay(Overlay overlay)
           
 void setRoundRectArcSize(int cornerDiameter)
          Obsolete; replaced by setCornerDiameter().
 void startPaste(ImagePlus clipboard)
           
 boolean subPixelResolution()
          Returns true if this is a PolygonRoi that supports sub-pixel resolution.
 void temporarilyHide()
          Deprecated.  
static 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.
 java.lang.String toString()
           
 void undoRoiHandle(java.awt.Graphics g, double x, double y)
           
 void update(boolean add, boolean subtract)
          If 'add' is true, adds this selection to the previous one.
 void updateWideLine(float width)
           
 
Methods inherited from class ij.gui.AttributeRoi
copyAttributes, getAngle, getColor, getConvexHull, getCPosition, getDefaultFillColor, getFeretsDiameter, getFeretValues, getFillColor, getImage, getImageID, getName, getPosition, getStroke, getStrokeColor, getStrokeWidth, getTPosition, getType, getZPosition, setColor, setDefaultFillColor, setFillColor, setName, setPosition, setPosition, setStroke, setStrokeColor, setStrokeWidth, setStrokeWidth
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

roundRect

public java.awt.Shape roundRect

previousRoi

public static Roi previousRoi

onePixelWide

public static final java.awt.BasicStroke onePixelWide
Constructor Detail

Roi

public Roi(int x,
           int y,
           int width,
           int height)
Creates a rectangular ROI.


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,
           double cornerDiameter)
Creates a new rounded rectangular ROI.


Roi

public Roi(double x,
           double y,
           double width,
           double height)
Creates a rounded rectangular ROI using double arguments.


Roi

public Roi(java.awt.Rectangle r)
Creates a new rectangular Roi.


Roi

public Roi(java.awt.geom.Rectangle2D.Double 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.


Roi

public Roi(int x,
           int y,
           int width,
           int height,
           ImagePlus imp)
Deprecated. 

Method Detail

setLocation

public void setLocation(int x,
                        int y)
Set the location of the ROI in image coordinates.

Specified by:
setLocation in interface RoiBeans

setImage

public void setImage(ImagePlus imp)
Specified by:
setImage in interface RoiBeans

getState

public int getState()
Specified by:
getState in interface RoiBeans

getLength

public double getLength()
Returns the perimeter length.

Specified by:
getLength in interface RoiBeans

getBounds

public java.awt.Rectangle getBounds()
Return this selection's bounding rectangle.

Specified by:
getBounds in interface RoiBeans

getFloatBounds

public java.awt.geom.Rectangle2D.Double getFloatBounds()
Return this selection's bounding rectangle.

Specified by:
getFloatBounds in interface RoiBeans

getBoundingRect

public java.awt.Rectangle getBoundingRect()
Deprecated. replaced by getBounds()

Specified by:
getBoundingRect in interface RoiBeans

getPolygon

public java.awt.Polygon getPolygon()
Returns the outline of this selection as a Polygon, or null if this is a straight line selection.

Specified by:
getPolygon in interface RoiBeans
See Also:
ImageProcessor.setRoi(java.awt.Rectangle), ImageProcessor.drawPolygon(java.awt.Polygon), ImageProcessor.fillPolygon(java.awt.Polygon)

getFloatPolygon

public FloatPolygon getFloatPolygon()
Specified by:
getFloatPolygon in interface RoiBeans

nudge

public void nudge(int key)
Nudge ROI one pixel on arrow key press.

Specified by:
nudge in interface RoiBeans

nudgeCorner

public void nudgeCorner(int key)
Nudge lower right corner of rectangular and oval ROIs by one pixel based on arrow key press.

Specified by:
nudgeCorner in interface RoiBeans

getHandleSize

public int getHandleSize()
Specified by:
getHandleSize in interface RoiBeans

draw

public void draw(java.awt.Graphics g)
Specified by:
draw in interface RoiBeans

drawOverlay

public void drawOverlay(java.awt.Graphics g)
Specified by:
drawOverlay in interface RoiBeans

drawfillOverlay

public void drawfillOverlay(java.awt.Graphics g,
                            boolean fillcolor)

drawRoiHandle

public void drawRoiHandle(java.awt.Graphics g,
                          double x,
                          double y)

appRoiHandle

public void appRoiHandle(java.awt.Graphics g,
                         double x,
                         double y,
                         java.awt.Color color)

fillRoiHandle

public void fillRoiHandle(java.awt.Graphics g,
                          double x,
                          double y)

magRoiHandle

public void magRoiHandle(java.awt.Graphics g,
                         double x,
                         double y)

undoRoiHandle

public void undoRoiHandle(java.awt.Graphics g,
                          double x,
                          double y)

drawHandle

public void drawHandle(java.awt.Graphics g,
                       int x,
                       int y)
Specified by:
drawHandle in interface RoiBeans

drawPixels

public void drawPixels()
Deprecated. replaced by drawPixels(ImageProcessor)

Specified by:
drawPixels in interface RoiBeans

drawPixels

public void drawPixels(ImageProcessor ip)
Draws the selection outline on the specified ImageProcessor.

Specified by:
drawPixels in interface RoiBeans
See Also:
ImageProcessor.setColor(java.awt.Color), ImageProcessor.setLineWidth(int)

drawPixels

public void drawPixels(ImageProcessor ip,
                       java.awt.geom.GeneralPath path)
Draws the selection outline on the specified ImageProcessor.

See Also:
ImageProcessor.setColor(java.awt.Color), ImageProcessor.setLineWidth(int)

drawStroke

public void drawStroke(java.awt.Graphics2D g)

contains

public boolean contains(int x,
                        int y)
Specified by:
contains in interface RoiBeans

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.

Specified by:
isHandle in interface RoiBeans

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.

Specified by:
update in interface RoiBeans

getMask

public ImageProcessor getMask()
Always returns null for rectangular Roi's

Specified by:
getMask in interface RoiBeans

setInstanceColor

public void setInstanceColor(java.awt.Color c)
Deprecated. replaced by setStrokeColor()

Specified by:
setInstanceColor in interface RoiBeans

setLineWidth

public void setLineWidth(int width)
Deprecated. replaced by setStrokeWidth(int)

Specified by:
setLineWidth in interface RoiBeans

updateWideLine

public void updateWideLine(float width)
Specified by:
updateWideLine in interface RoiBeans

setNonScalable

public void setNonScalable(boolean nonScalable)
Set 'nonScalable' true to have TextRois in a display list drawn at a fixed location and size.

Specified by:
setNonScalable in interface RoiBeans

setCornerDiameter

public void setCornerDiameter(int cornerDiameter)
Sets the rounded rectangle corner diameter (pixels).

Specified by:
setCornerDiameter in interface RoiBeans
Overrides:
setCornerDiameter in class AttributeRoi

getCornerDiameter

public int getCornerDiameter()
Returns the rounded rectangle corner diameter (pixels).

Specified by:
getCornerDiameter in interface RoiBeans
Overrides:
getCornerDiameter in class AttributeRoi

setRoundRectArcSize

public void setRoundRectArcSize(int cornerDiameter)
Obsolete; replaced by setCornerDiameter().

Specified by:
setRoundRectArcSize in interface RoiBeans
Overrides:
setRoundRectArcSize in class AttributeRoi

getRoundRectArcSize

public int getRoundRectArcSize()
Obsolete; replaced by getCornerDiameter().

Specified by:
getRoundRectArcSize in interface RoiBeans
Overrides:
getRoundRectArcSize in class AttributeRoi

setPrototypeOverlay

public void setPrototypeOverlay(Overlay overlay)
Specified by:
setPrototypeOverlay in interface RoiBeans

getPrototypeOverlay

public Overlay getPrototypeOverlay()
Specified by:
getPrototypeOverlay in interface RoiBeans

startPaste

public void startPaste(ImagePlus clipboard)
Specified by:
startPaste in interface RoiBeans

endPaste

public void endPaste()
Specified by:
endPaste in interface RoiBeans

abortPaste

public void abortPaste()
Specified by:
abortPaste in interface RoiBeans

setPasteMode

public static void setPasteMode(int transferMode)
Sets the Paste transfer mode.

See Also:
Blitter

getPasteMode

public int getPasteMode()
Returns the current paste transfer mode, or NOT_PASTING (-1) if no paste operation is in progress.

Specified by:
getPasteMode in interface RoiBeans
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.

Specified by:
isArea in interface RoiBeans

isLine

public boolean isLine()
Returns 'true' if this is a line selection.

Specified by:
isLine in interface RoiBeans

isDrawingTool

public boolean isDrawingTool()
Returns 'true' if this is an ROI primarily used from drawing (e.g., TextRoi or Arrow).

Specified by:
isDrawingTool in interface RoiBeans

getTypeAsString

public java.lang.String getTypeAsString()
Convenience method that converts Roi type to a human-readable form.

Specified by:
getTypeAsString in interface RoiBeans

isVisible

public boolean isVisible()
Returns true if this ROI is currently displayed on an image.

Specified by:
isVisible in interface RoiBeans

subPixelResolution

public boolean subPixelResolution()
Returns true if this is a PolygonRoi that supports sub-pixel resolution.

Specified by:
subPixelResolution in interface RoiBeans

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..

Specified by:
getDrawOffset in interface RoiBeans

setDrawOffset

public void setDrawOffset(boolean drawOffset)
Specified by:
setDrawOffset in interface RoiBeans

clone

public java.lang.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.

Overrides:
clone in class AbstractRoi

equals

public boolean equals(java.lang.Object obj)
Checks whether two rectangles are equal.

Specified by:
equals in interface RoiBeans
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Specified by:
toString in interface RoiBeans
Overrides:
toString in class java.lang.Object

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.


temporarilyHide

public void temporarilyHide()
Deprecated.