Package ij.gui
Class ShapeRoi
- java.lang.Object
-
- ij.gui.Roi
-
- ij.gui.ShapeRoi
-
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Point>
public class ShapeRoi extends Roi
A subclass ofij.gui.Roi(2D Regions Of Interest) implemented in terms of java.awt.Shape. A ShapeRoi is constructed from aij.gui.Roiobject, or as a result of logical operators (i.e., union, intersection, exclusive or, and subtraction) provided by this class. These operators use the packagejava.awt.geomas a backend.
This code is in the public domain.- Author:
- Cezar M.Tigaret
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class ij.gui.Roi
ANGLE, asp_bk, aspect, cachedMask, center, clipboard, clipHeight, clipWidth, clipX, clipY, COMPOSITE, constrain, CONSTRUCTING, defaultFillColor, fillColor, flattenScale, FREELINE, FREEROI, HANDLE_SIZE, handleColor, ic, ignoreClipRect, imp, instanceColor, LINE, lineWidth, mag, MOVING, MOVING_HANDLE, nonScalable, NORMAL, NOT_PASTING, oldHeight, oldWidth, oldX, oldY, onePixelWide, OVAL, overlay, pasteMode, POINT, POLYGON, POLYLINE, previousRoi, RECTANGLE, RESIZING, ROIColor, stroke, strokeColor, TRACED_ROI, type, updateFullWindow, wideLine, xMax, yMax
-
-
Constructor Summary
Constructors Constructor Description ShapeRoi(float[] shapeArray)Constructs a ShapeRoi from an array of variable length path segments.ShapeRoi(int x, int y, Shape s)Constructs a ShapeRoi from a Shape.ShapeRoi(Roi r)Constructs a ShapeRoi from an Roi.ShapeRoi(Shape s)Constructs a ShapeRoi from a Shape.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ShapeRoiand(ShapeRoi sr)Unary intersection operator.Objectclone()Returns a deep copy of this.booleancontains(int x, int y)Checks whether the specified coordinates are inside a on this ROI's shape boundaries.voiddraw(Graphics g)Non-destructively draws the shape of this object on the associated ImagePlus.voiddrawPixels(ImageProcessor ip)Draws the shape of this object onto the specified ImageProcessor.voiddrawRoiBrush(Graphics g)PolygongetConvexHull()double[]getFeretValues()Caculates "Feret" (maximum caliper width) and "MinFeret" (minimum caliper width).FloatPolygongetFloatPolygon()doublegetLength()Returns the perimeter if this ShapeRoi can be decomposed into simple ROIs, otherwise returns zero.ImageProcessorgetMask()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).PolygongetPolygon()Returns the outline of this selection as a Polygon, or null if this is a straight line selection.Roi[]getRois()Converts a Shape into Roi object(s).ShapegetShape()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.intisHandle(int sx, int sy)Always returns -1 since ShapeRois do not have handles.ShapeRoinot(ShapeRoi sr)Unary subtraction operator.ShapeRoior(ShapeRoi sr)Unary union operator.RoishapeToRoi()Attempts to convert this ShapeRoi into a non-composite Roi.intsize()If this ROI consists of a single polygon, retuns the number of vertices, otherwise returns 4.ShapeRoixor(ShapeRoi sr)Unary exclusive or operator.-
Methods inherited from class ij.gui.Roi
abortPaste, addRoiListener, clipRectMargin, copyAttributes, drawOverlay, drawPixels, enableSubPixelResolution, endPaste, equals, getAngle, getAngle, getBoundingRect, getBounds, getColor, getContainedFloatPoints, getContainedPoints, getContourCentroid, getCornerDiameter, getCPosition, getCurrentPasteMode, getDebugInfo, getDefaultFillColor, getDrawOffset, getFeretsDiameter, getFillColor, getFloatAngle, getFloatBounds, getFloatHeight, getFloatWidth, getHashCode, getImage, getImageID, getInterpolatedPolygon, getInterpolatedPolygon, getInterpolatedPolygon, getMagnification, getName, getPasteMode, getPosition, getProperties, getProperty, getPropertyCount, getPrototypeOverlay, getRotationCenter, getRoundRectArcSize, getScaledStroke, getState, getStatistics, getStroke, getStrokeColor, getStrokeWidth, getTPosition, getType, getTypeAsString, getXBase, getYBase, getZPosition, grow, handleMouseDown, handleMouseDrag, handleMouseUp, hasHyperStackPosition, isActiveOverlayRoi, isArea, isCursor, isDrawingTool, isLine, isVisible, iterator, lineCircleIntersection, mouseDownInHandle, mouseDragged, mouseMoved, mouseReleased, moveHandle, notifyListeners, nudge, nudgeCorner, removeRoiListener, screenX, screenXD, screenY, screenYD, setColor, setCornerDiameter, setDefaultFillColor, setDrawOffset, setFillColor, setFlattenScale, setIgnoreClipRect, setImage, setInstanceColor, setIsCursor, setLineWidth, setLocation, setLocation, setName, setNonScalable, setPasteMode, setPosition, setPosition, setPosition, setProperties, setProperty, setPrototypeOverlay, setRotationCenter, setRoundRectArcSize, setStroke, setStrokeColor, setStrokeWidth, setStrokeWidth, showStatus, startPaste, subPixelResolution, temporarilyHide, toFloat, toInt, toInt, toIntR, toString, update, updateClipRect, updateWideLine
-
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ShapeRoi
public ShapeRoi(Roi r)
Constructs a ShapeRoi from an Roi.
-
ShapeRoi
public ShapeRoi(Shape s)
Constructs a ShapeRoi from a Shape.
-
ShapeRoi
public ShapeRoi(int x, int y, 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
-
or
public ShapeRoi or(ShapeRoi sr)
Unary union operator. The caller is set to its union with the argument.- Returns:
- the union of
thisandsr
-
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
thisandsr
-
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
thisandsr
-
not
public ShapeRoi not(ShapeRoi sr)
Unary subtraction operator. The caller is set to the result of the operation between the operands.- Returns:
thissubtracted fromsr
-
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 ajava.awt.geom.GeneralPathis converted following these rules:Segment
typesNumber of
segmentsClosed
pathValue of
forceAngleValue of
forceTraceRoi 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.
-
getFeretValues
public double[] getFeretValues()
Caculates "Feret" (maximum caliper width) and "MinFeret" (minimum caliper width).- Overrides:
getFeretValuesin classRoi
-
getLength
public double getLength()
Returns the perimeter if this ShapeRoi can be decomposed into simple ROIs, otherwise returns zero.
-
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(Graphics g)
Non-destructively draws the shape of this object on the associated ImagePlus.
-
drawRoiBrush
public void drawRoiBrush(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).- Overrides:
drawPixelsin classRoi- 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).
-
getShape
public 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.
-
getConvexHull
public Polygon getConvexHull()
- Overrides:
getConvexHullin classRoi
-
getPolygon
public Polygon getPolygon()
Description copied from class:RoiReturns the outline of this selection as a Polygon, or null if this is a straight line selection.- Overrides:
getPolygonin classRoi- See Also:
ImageProcessor.setRoi(java.awt.Rectangle),ImageProcessor.drawPolygon(java.awt.Polygon),ImageProcessor.fillPolygon(java.awt.Polygon)
-
getFloatPolygon
public FloatPolygon getFloatPolygon()
- Overrides:
getFloatPolygonin classRoi
-
-