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
protected  double asp_bk
           
protected  boolean aspect
           
protected  ImageProcessor cachedMask
           
protected  boolean center
           
protected  ImagePlus clipboard
           
protected  int clipHeight
           
protected  int clipWidth
           
protected  int clipX
           
protected  int clipY
           
protected  boolean constrain
           
protected static java.awt.Color defaultFillColor
           
protected  java.awt.Color handleColor
           
protected  ImageCanvas ic
           
protected  int imageID
           
protected  java.awt.Color instanceColor
           
protected static int lineWidth
           
protected  double mag
           
protected  boolean nonScalable
           
protected  int oldHeight
           
protected  int oldWidth
           
protected  int oldX
           
protected  int oldY
           
static java.awt.BasicStroke onePixelWide
           
protected  boolean overlay
           
protected static int pasteMode
           
static Roi previousRoi
           
protected  boolean updateFullWindow
           
 
Fields inherited from class ij.gui.AttributeRoi
fillColor, imp, ROIColor, stroke, strokeColor, type, wideLine, xMax, yMax
 
Fields inherited from interface ij.gui.RoiConstance
ADD_TO_ROI, ANGLE, COMPOSITE, CONSTRUCTING, FREELINE, FREEROI, HANDLE_SIZE, LINE, MOVING, MOVING_HANDLE, NO_MODS, NORMAL, NOT_PASTING, OVAL, POINT, POLYGON, POLYLINE, RECTANGLE, RESIZING, SUBTRACT_FROM_ROI, TRACED_ROI
 
Constructor Summary
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 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()
           
protected  int clipRectMargin()
           
 java.lang.Object clone()
          Returns a copy of this roi.
 boolean contains(int x, int y)
           
 void draw(java.awt.Graphics g)
           
 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 endPaste()
           
 boolean equals(java.lang.Object obj)
          Checks whether two rectangles are equal.
 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.
protected  double getMagnification()
           
 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().
protected  java.awt.BasicStroke getScaledStroke()
          Returns the Stroke used to draw this ROI, or null if no Stroke is used.
 int getState()
          Returns the ID of the image associated with this ROI.
 java.lang.String getTypeAsString()
          Convenience method that converts Roi type to a human-readable form.
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)
           
 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.
protected  void mouseDownInHandle(int handle, int sx, int sy)
           
protected  void moveHandle(int sx, int sy)
           
 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.
protected  int screenX(int ox)
           
protected  int screenXD(double ox)
           
protected  int screenY(int oy)
           
protected  int screenYD(double oy)
           
 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)
          Returns the frame position of this ROI, or zero if this ROI is not associated with a particular frame.
 void setRoundRectArcSize(int cornerDiameter)
          Obsolete; replaced by setCornerDiameter().
protected  void showStatus()
           
 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 update(boolean add, boolean subtract)
          If 'add' is true, adds this selection to the previous one.
protected  void updateClipRect()
           
 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
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

previousRoi

public static Roi previousRoi

onePixelWide

public static final java.awt.BasicStroke onePixelWide

pasteMode

protected static int pasteMode

lineWidth

protected static int lineWidth

defaultFillColor

protected static java.awt.Color defaultFillColor

imageID

protected int imageID

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 java.awt.Color handleColor

instanceColor

protected java.awt.Color instanceColor

nonScalable

protected boolean nonScalable

overlay

protected boolean overlay
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(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()
Returns the ID of the image associated with this ROI.

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

grow

protected void grow(int sx,
                    int sy)
Specified by:
grow in class AbstractRoi

moveHandle

protected void moveHandle(int sx,
                          int sy)
Specified by:
moveHandle in class AbstractRoi

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

updateClipRect

protected void updateClipRect()
Specified by:
updateClipRect in class AbstractRoi

clipRectMargin

protected int clipRectMargin()
Specified by:
clipRectMargin in class AbstractRoi

handleMouseDrag

protected void handleMouseDrag(int sx,
                               int sy,
                               int flags)
Specified by:
handleMouseDrag in class AbstractRoi

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

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)

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

mouseDownInHandle

protected void mouseDownInHandle(int handle,
                                 int sx,
                                 int sy)
Specified by:
mouseDownInHandle in class AbstractRoi

handleMouseDown

protected void handleMouseDown(int sx,
                               int sy)
Specified by:
handleMouseDown in class AbstractRoi

handleMouseUp

protected void handleMouseUp(int screenX,
                             int screenY)
Specified by:
handleMouseUp in class AbstractRoi

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

showStatus

protected void showStatus()
Specified by:
showStatus in class AbstractRoi

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

getScaledStroke

protected java.awt.BasicStroke getScaledStroke()
Returns the Stroke used to draw this ROI, or null if no Stroke is used.

Specified by:
getScaledStroke in class AbstractRoi

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)
Returns the frame position of this ROI, or zero if this ROI is not associated with a particular frame.

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

getMagnification

protected double getMagnification()
Specified by:
getMagnification in class AbstractRoi

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

screenX

protected int screenX(int ox)
Specified by:
screenX in class AbstractRoi

screenY

protected int screenY(int oy)
Specified by:
screenY in class AbstractRoi

screenXD

protected int screenXD(double ox)
Specified by:
screenXD in class AbstractRoi

screenYD

protected int screenYD(double oy)
Specified by:
screenYD in class AbstractRoi

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.