ij.gui
Class ShapeRoi

java.lang.Object
  extended by ij.gui.AbstractRoi
      extended by ij.gui.AttributeRoi
          extended by ij.gui.Roi
              extended by ij.gui.ShapeRoi
All Implemented Interfaces:
RoiBeans, RoiConstance, java.io.Serializable, java.lang.Cloneable

public class ShapeRoi
extends Roi

A subclass of ij.gui.Roi (2D Regions Of Interest) implemented in terms of java.awt.Shape. A ShapeRoi is constructed from a ij.gui.Roi object, or as a result of logical operators (i.e., union, intersection, exclusive or, and subtraction) provided by this class. These operators use the package java.awt.geom as a backend.
This code is in the public domain.

See Also:
Serialized Form

Field Summary
 java.awt.geom.Path2D p2dD
           
 
Fields inherited from class ij.gui.Roi
asp_bk, aspect, cachedMask, center, clipboard, clipHeight, clipHeightd, clipWidth, clipWidthd, clipX, clipXd, clipY, clipYd, constrain, defaultFillColor, handleColor, ic, imageID, instanceColor, lineWidth, mag, nonScalable, oldHeight, oldHeightd, oldWidth, oldWidthd, oldX, oldXd, oldY, oldYd, onePixelWide, overlay, pasteMode, previousRoi, roundRect, updateFullWindow
 
Fields inherited from class ij.gui.AttributeRoi
drawDoubleClick, fillColor, fillDoubleClick, imp, ROIColor, stroke, strokeColor, type, wideLine, xMax, yMax
 
Fields inherited from interface ij.gui.RoiConstance
ADD_TO_ROI, ANGLE, COMPOSITE, CONSTRUCTING, DRAW_HANDLE, EVT_HANDLE_SIZE, FILL_HANDLE, FREELINE, FREEROI, HANDLE_SIZE, LINE, MOVING, MOVING_HANDLE, MOVING_ROUNDRECT_HANDLE, NO_MODS, NORMAL, NOT_PASTING, OVAL, POINT, POLYGON, POLYLINE, RECTANGLE, RESIZING, SUBTRACT_FROM_ROI, TRACED_ROI
 
Constructor Summary
ShapeRoi(float[] shapeArray)
          Constructs a ShapeRoi from an array of variable length path segments.
ShapeRoi(int x, int y, java.awt.Shape s)
          Constructs a ShapeRoi from a Shape.
ShapeRoi(Roi r)
          Constructs a ShapeRoi from an Roi.
ShapeRoi(java.awt.Shape s)
          Constructs a ShapeRoi from a Shape.
 
Method Summary
 ShapeRoi and(ShapeRoi sr)
          Unary intersection operator.
 java.lang.Object clone()
          Returns a deep copy of this.
 boolean contains(int x, int y)
          Checks whether the specified coordinates are inside a on this ROI's shape boundaries.
 void draw(java.awt.Graphics g)
          Non-destructively draws the shape of this object on the associated ImagePlus.
 void drawPixels(ImageProcessor ip)
          Draws the shape of this object onto the specified ImageProcessor.
 void drawPixels(ImageProcessor ip, java.awt.geom.GeneralPath path)
          Draws the shape of this object onto the specified ImageProcessor.
 void drawRoiBrush(java.awt.Graphics g)
           
 java.awt.Polygon getConvexHull()
          Always returns null.
 double[] getFeretValues()
          Caculates "Feret" (maximum caliper width) and "MinFeret" (minimum caliper width).
 double getLength()
          Returns the perimeter if this ShapeRoi can be decomposed into simple ROIs, otherwise returns zero.
 ImageProcessor getMask()
          Returns this ROI's mask pixels as a ByteProcessor with pixels "in" the mask set to white (255) and pixels "outside" the mask set to black (0).
 Roi[] getRois()
          Converts a Shape into Roi object(s).
 java.awt.Shape getShape()
          Returns a reference to the Shape object encapsulated by this ShapeRoi.
 float[] getShapeAsArray()
          Retrieves the end points and control points of the path as a float array.
 int isHandle(int sx, int sy)
          Always returns -1 since ShapeRois do not have handles.
 ShapeRoi not(ShapeRoi sr)
          Unary subtraction operator.
 ShapeRoi or(ShapeRoi sr)
          Unary union operator.
 Roi shapeToRoi()
          Attempts to convert this ShapeRoi into a non-composite Roi.
 ShapeRoi xor(ShapeRoi sr)
          Unary exclusive or operator.
 
Methods inherited from class ij.gui.Roi
abortPaste, clipRectMargin, drawfillOverlay, drawHandle, drawOverlay, drawPixels, drawRoiHandle, drawStroke, endPaste, equals, fillRoiHandle, getBoundingRect, getBounds, getCornerDiameter, getCurrentPasteMode, getDrawOffset, getFloatBounds, getFloatPolygon, getHandleSize, getMagnification, getPasteMode, getPolygon, getPrototypeOverlay, getRoundRectArcSize, getScaledStroke, getState, getTypeAsString, grow, handleMouseDown, handleMouseDrag, handleMouseUp, isArea, isDrawingTool, isLine, isVisible, mouseDownInHandle, moveHandle, nudge, nudgeCorner, screenX, screenXD, screenY, screenYD, setCornerDiameter, setDrawOffset, setImage, setInstanceColor, setLineWidth, setLocation, setNonScalable, setPasteMode, setPrototypeOverlay, setRoundRectArcSize, showStatus, startPaste, subPixelResolution, temporarilyHide, toFloat, toInt, toInt, toIntR, toString, update, updateClipRect, updateWideLine
 
Methods inherited from class ij.gui.AttributeRoi
copyAttributes, getAngle, getColor, getCPosition, getDefaultFillColor, getFeretsDiameter, 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

p2dD

public java.awt.geom.Path2D p2dD
Constructor Detail

ShapeRoi

public ShapeRoi(Roi r)
Constructs a ShapeRoi from an Roi.


ShapeRoi

public ShapeRoi(java.awt.Shape s)
Constructs a ShapeRoi from a Shape.


ShapeRoi

public ShapeRoi(int x,
                int y,
                java.awt.Shape s)
Constructs a ShapeRoi from a Shape.


ShapeRoi

public ShapeRoi(float[] shapeArray)
Constructs a ShapeRoi from an array of variable length path segments. Each segment consists of the segment type followed by 0-3 end points and control points. Depending on the type, a segment uses from 1 to 7 elements of the array.

Method Detail

clone

public java.lang.Object clone()
Returns a deep copy of this.

Overrides:
clone in class Roi

or

public ShapeRoi or(ShapeRoi sr)
Unary union operator. The caller is set to its union with the argument.

Returns:
the union of this and sr

and

public ShapeRoi and(ShapeRoi sr)
Unary intersection operator. The caller is set to its intersection with the argument (i.e., the overlapping regions between the operands).

Returns:
the overlapping regions between this and sr

xor

public ShapeRoi xor(ShapeRoi sr)
Unary exclusive or operator. The caller is set to the non-overlapping regions between the operands.

Returns:
the union of the non-overlapping regions of this and sr

not

public ShapeRoi not(ShapeRoi sr)
Unary subtraction operator. The caller is set to the result of the operation between the operands.

Returns:
this subtracted from sr

getRois

public Roi[] getRois()
Converts a Shape into Roi object(s).
This method parses the shape into (possibly more than one) Roi objects and returns them in an array.
A simple, "regular" path results in a single Roi following these simple rules:
Shape type Roi class Roi type
java.awt.geom.Rectangle2D.Double ij.gui.Roi Roi.RECTANGLE
java.awt.geom.Ellipse2D.Double ij.gui.OvalRoi Roi.OVAL
java.awt.geom.Line2D.Double ij.gui.Line Roi.LINE
java.awt.Polygon ij.gui.PolygonRoi Roi.POLYGON


Each subpath of a java.awt.geom.GeneralPath is converted following these rules:
Segment
types
Number of
segments
Closed
path
Value of
forceAngle
Value of
forceTrace
Roi type
lines only: 0 ShapeRoi.NO_TYPE
1 ShapeRoi.NO_TYPE
2 Y ShapeRoi.NO_TYPE
N Roi.LINE
3 Y N Roi.POLYGON
N Y Roi.ANGLE
N N Roi.POLYLINE
4 Y Roi.RECTANGLE
N Roi.POLYLINE
<= MAXPOLY Y Roi.POLYGON
N Roi.POLYLINE
> MAXPOLY Y Y Roi.TRACED_ROI
N Roi.FREEROI
N Roi.FREELINE
anything
else:
<= 2 ShapeRoi.NO_TYPE
> 2 ShapeRoi.SHAPE_ROI

Returns:
an array of ij.gui.Roi objects.

shapeToRoi

public Roi shapeToRoi()
Attempts to convert this ShapeRoi into a non-composite Roi.

Returns:
an ij.gui.Roi object or null

contains

public boolean contains(int x,
                        int y)
Checks whether the specified coordinates are inside a on this ROI's shape boundaries.

Specified by:
contains in interface RoiBeans
Overrides:
contains in class Roi

getFeretValues

public double[] getFeretValues()
Caculates "Feret" (maximum caliper width) and "MinFeret" (minimum caliper width).

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

getLength

public double getLength()
Returns the perimeter if this ShapeRoi can be decomposed into simple ROIs, otherwise returns zero.

Specified by:
getLength in interface RoiBeans
Overrides:
getLength in class Roi

getShapeAsArray

public float[] getShapeAsArray()
Retrieves the end points and control points of the path as a float array. The array contains a sequence of variable length segments that use from from one to seven elements. The first element of a segment is the type as defined in the PathIterator interface. SEG_MOVETO and SEG_LINETO segments also include two coordinates, SEG_QUADTO segments include four coordinates and SEG_CUBICTO segments include six coordinates.


draw

public void draw(java.awt.Graphics g)
Non-destructively draws the shape of this object on the associated ImagePlus.

Specified by:
draw in interface RoiBeans
Overrides:
draw in class Roi

drawRoiBrush

public void drawRoiBrush(java.awt.Graphics g)

drawPixels

public void drawPixels(ImageProcessor ip)
Draws the shape of this object onto the specified ImageProcessor.
This method will always draw a flattened version of the actual shape (i.e., all curve segments will be approximated by line segments).

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

drawPixels

public void drawPixels(ImageProcessor ip,
                       java.awt.geom.GeneralPath path)
Draws the shape of this object onto the specified ImageProcessor.
This method will always draw a flattened version of the actual shape (i.e., all curve segments will be approximated by line segments).

Overrides:
drawPixels in class Roi
See Also:
ImageProcessor.setColor(java.awt.Color), ImageProcessor.setLineWidth(int)

getMask

public ImageProcessor getMask()
Returns this ROI's mask pixels as a ByteProcessor with pixels "in" the mask set to white (255) and pixels "outside" the mask set to black (0).

Specified by:
getMask in interface RoiBeans
Overrides:
getMask in class Roi

getShape

public java.awt.Shape getShape()
Returns a reference to the Shape object encapsulated by this ShapeRoi.


isHandle

public int isHandle(int sx,
                    int sy)
Always returns -1 since ShapeRois do not have handles.

Specified by:
isHandle in interface RoiBeans
Overrides:
isHandle in class Roi

getConvexHull

public java.awt.Polygon getConvexHull()
Always returns null.

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