Class AreaROI
- All Implemented Interfaces:
Serializable
,ROI
It may be decomposed into one or more polygons (vertices), in which case the sign of the area is important in indicating whether the region should be considered 'positive' or a hole.
The underlying idea is based on java.awt.Area, but implemented so as to avoid a dependency on AWT.
However, because this implementation is relatively simple, it doesn't do the complicated checking and computations of AWT Areas - and so ought not be used directly. Rather, AWTAreaROI is strongly to be preferred.
The real usefulness of this class is in enabling Serialization of all ROIs to avoid a dependency on AWT, since potentially a deserialized version of this could then be used to create different kinds of Area (e.g. java.awt.Area or some JavaFX alternative.)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface qupath.lib.roi.interfaces.ROI
ROI.RoiType
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(double x, double y) Deprecated.Test is the ROI contains specified x, y coordinates.protected Shape
Deprecated.Create aShape
object to represent the ROI.Deprecated.boolean
Deprecated.Deprecated.Beware this method! This will return all polygon points (useful e.g.double
getArea()
Deprecated.Get the area of this ROI.double
Deprecated.Returns the height of the ROI bounding box.double
Deprecated.Returns the width of the ROI bounding box.double
Deprecated.Returns the x coordinate for the top left of the ROI bounding box.double
Deprecated.Returns the y coordinate for the top left of the ROI bounding box.int
getC()
Get channel index, or -1 if the ROI relates to all available channels.double
Deprecated.Get the x coordinate of the ROI centroid;double
Deprecated.Get the y coordinate of the ROI centroid;Default implementation using JTS.Deprecated.Returns a org.locationtech.jts.geom.Geometry object.Get the ImagePlane, which contains the values for c, z and t in a single object.double
Deprecated.Get ROI length.int
Default implementation, callsROI.getAllPoints()
and then caches the result.Deprecated.Get a String representation of the kind of ROI we have, e.g.Deprecated.Get the RoiType, used to distinguish between points, lines and areas.double
getScaledArea
(double pixelWidth, double pixelHeight) Deprecated.Get scaled area of the ROI, for use with calibrated pixel sizes.double
getScaledLength
(double pixelWidth, double pixelHeight) Deprecated.Get the scaled length, for use with calibrated pixel sizes.getShape()
Deprecated.Returns a java.awt.Shape representing this ROI, if possible.protected Shape
Get a (possibly cached) shape representation of the ROI.double
Calculate the solidity, defined as ROI area / convex hull area.int
getT()
Get time point index.int
getZ()
Get z-stack slice index.int
hashCode()
Deprecated.boolean
intersects
(double x, double y, double width, double height) Deprecated.Test if the ROI intersects a specified region.protected boolean
intersectsBounds
(double x, double y, double width, double height) Quick check whether the specified rectangle intersects with the bounds of this ROI.boolean
isArea()
Returns true if this ROI encloses an area.boolean
isEmpty()
True if the bounding box has zero areaboolean
isLine()
Returns true if this ROI consists of line segments and does not enclose an area.boolean
isPoint()
Returns true if this ROI represents distinct (unconnected) points.int
Deprecated.Get the number of vertices used to represent this area.scale
(double scaleX, double scaleY, double originX, double originY) Deprecated.Create a scaled version of this ROI.toString()
translate
(double dx, double dy) Deprecated.Create a translated version of this ROI.updatePlane
(ImagePlane plane) Deprecated.Create a new ROI defining the same region on a differentImagePlane
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface qupath.lib.roi.interfaces.ROI
getScaledArea, getScaledLength, intersects, scale
-
Method Details
-
nVertices
public int nVertices()Deprecated.Get the number of vertices used to represent this area. There is some 'fuzziness' to the meaning of this, since curved regions will be flattened and the same complex areas may be represented in different ways - nevertheless it provides some measure of the 'complexity' of the area.- Returns:
-
getArea
public double getArea()Deprecated.Description copied from interface:ROI
Get the area of this ROI. For lines and points this returns 0. -
getLength
public double getLength()Deprecated.Description copied from interface:ROI
Get ROI length. This is defined as- perimeter in the case of area ROIs
- total length of line segments in the case of line or polyline ROIs
- 0 in the case of point ROIs
-
getRoiName
Deprecated.Description copied from interface:ROI
Get a String representation of the kind of ROI we have, e.g. "Rectangle", "Ellipse", "Polygon"- Specified by:
getRoiName
in interfaceROI
- Returns:
-
getCentroidX
public double getCentroidX()Deprecated.Get the x coordinate of the ROI centroid;Warning: If the centroid computation was too difficult (i.e. the area is particularly elaborate), then the center of the bounding box will be used instead! (However this should not be relied upon as it is liable to change in later versions)
- Specified by:
getCentroidX
in interfaceROI
- Returns:
-
getCentroidY
public double getCentroidY()Deprecated.Get the y coordinate of the ROI centroid;Warning: If the centroid computation was too difficult (i.e. the area is particularly elaborate), then the center of the bounding box will be used instead! (However this should not be relied upon as it is liable to change in later versions)
- Specified by:
getCentroidY
in interfaceROI
- Returns:
-
contains
public boolean contains(double x, double y) Deprecated.Description copied from interface:ROI
Test is the ROI contains specified x, y coordinates. Only Area ROIs can return true, i.e. whereROI.isArea()
returns true. All other ROIs (points, lines) return false. -
intersects
public boolean intersects(double x, double y, double width, double height) Deprecated.Description copied from interface:ROI
Test if the ROI intersects a specified region.Note that this test is intended as a fast initial filter; a more detailed test using
ROI.getGeometry()
is recommended when exact results are needed.- Specified by:
intersects
in interfaceROI
- Parameters:
x
- the x coordinate of the region bounding boxy
- the y coordinate of the region bounding boxwidth
- the width of the region bounding boxheight
- the height of the region bounding box- Returns:
- true if the ROI intersects the region, false otherwise
-
duplicate
Deprecated.Description copied from interface:ROI
Create a duplicate of the ROI.This method is deprecated, since ROIs are (or are moving towards being) immutable... making it pointless to duplicate them.
-
translate
Deprecated.Description copied from interface:ROI
Create a translated version of this ROI. The original ROI is unchanged. -
scale
Deprecated.Description copied from interface:ROI
Create a scaled version of this ROI. Coordinates are multiplied by the given scaling factors, while the original ROI is unchanged.- Specified by:
scale
in interfaceROI
- Parameters:
scaleX
- horizontal scale valuescaleY
- vertical scale valueoriginX
- value subtracted from each x-ordinate prior to scaling, and added back afterwardsoriginY
- value subtracted from each y-ordinate prior to scaling, and added back afterwards- Returns:
- See Also:
-
getScaledArea
public double getScaledArea(double pixelWidth, double pixelHeight) Deprecated.Description copied from interface:ROI
Get scaled area of the ROI, for use with calibrated pixel sizes.- Specified by:
getScaledArea
in interfaceROI
- Parameters:
pixelWidth
-pixelHeight
-- Returns:
- See Also:
-
getScaledLength
public double getScaledLength(double pixelWidth, double pixelHeight) Deprecated.Description copied from interface:ROI
Get the scaled length, for use with calibrated pixel sizes.- Specified by:
getScaledLength
in interfaceROI
- Parameters:
pixelWidth
-pixelHeight
-- Returns:
- See Also:
-
getBoundsX
public double getBoundsX()Deprecated.Description copied from interface:ROI
Returns the x coordinate for the top left of the ROI bounding box.- Specified by:
getBoundsX
in interfaceROI
- Returns:
-
getBoundsY
public double getBoundsY()Deprecated.Description copied from interface:ROI
Returns the y coordinate for the top left of the ROI bounding box.- Specified by:
getBoundsY
in interfaceROI
- Returns:
-
getBoundsWidth
public double getBoundsWidth()Deprecated.Description copied from interface:ROI
Returns the width of the ROI bounding box.- Specified by:
getBoundsWidth
in interfaceROI
- Returns:
-
getBoundsHeight
public double getBoundsHeight()Deprecated.Description copied from interface:ROI
Returns the height of the ROI bounding box.- Specified by:
getBoundsHeight
in interfaceROI
- Returns:
-
getAllPoints
Deprecated.Beware this method! This will return all polygon points (useful e.g. for convex hull calculations), but since the area itself isn't necessarily polygonal then tracing through the points does *not* necessarily result in the same shape as that which the area represents.- Specified by:
getAllPoints
in interfaceROI
- Returns:
-
updatePlane
Deprecated.Description copied from interface:ROI
Create a new ROI defining the same region on a differentImagePlane
. The original ROI is unchanged.- Specified by:
updatePlane
in interfaceROI
- Parameters:
plane
- the new plane to use- Returns:
- Throws:
UnsupportedOperationException
- because AreaROI is a legacy class that is no longer supported
-
equals
Deprecated. -
hashCode
public int hashCode()Deprecated. -
getGeometry
Deprecated.Description copied from interface:ROI
Returns a org.locationtech.jts.geom.Geometry object.- Specified by:
getGeometry
in interfaceROI
- Returns:
-
getShape
Deprecated.Description copied from interface:ROI
Returns a java.awt.Shape representing this ROI, if possible.Note that PointROI throws an UnsupportedOperationException as it cannot adequately be represented by a Shape object.
-
createShape
Deprecated.Create aShape
object to represent the ROI.- Returns:
- a new Shape object
-
getRoiType
Deprecated.Description copied from interface:ROI
Get the RoiType, used to distinguish between points, lines and areas.- Specified by:
getRoiType
in interfaceROI
- Returns:
-
getImagePlane
Description copied from interface:ROI
Get the ImagePlane, which contains the values for c, z and t in a single object.- Specified by:
getImagePlane
in interfaceROI
- Returns:
-
getZ
public int getZ()Description copied from interface:ROI
Get z-stack slice index.Default is 0 if the image it relates to is not a z-stack.
-
getT
public int getT()Description copied from interface:ROI
Get time point index.Default is 0 if the image it relates to is not a time series.
-
getC
public int getC()Description copied from interface:ROI
Get channel index, or -1 if the ROI relates to all available channels.(This is not currently used, but may be in the future)
-
getShapeInternal
Get a (possibly cached) shape representation of the ROI. This may be mutable, and so should not be passed outside the class.- Returns:
-
isEmpty
public boolean isEmpty()True if the bounding box has zero area -
intersectsBounds
protected boolean intersectsBounds(double x, double y, double width, double height) Quick check whether the specified rectangle intersects with the bounds of this ROI. This can be used to avoid a more expensive intersection check.- Parameters:
x
- x coordinate of the rectangle to testy
- y coordinate of the rectangle to testwidth
- width of the rectangle to testheight
- height of the rectangle to test- Returns:
- true if the bounds intersect, false otherwise
-
toString
-
getNumPoints
public int getNumPoints()Default implementation, callsROI.getAllPoints()
and then caches the result. Subclasses may override for efficiency.- Specified by:
getNumPoints
in interfaceROI
- Returns:
- Implementation Note
- the default implementation assumes that ROIs are immutable.
-
isLine
public boolean isLine()Description copied from interface:ROI
Returns true if this ROI consists of line segments and does not enclose an area. -
isArea
public boolean isArea()Description copied from interface:ROI
Returns true if this ROI encloses an area. -
isPoint
public boolean isPoint()Description copied from interface:ROI
Returns true if this ROI represents distinct (unconnected) points. -
getConvexHull
Default implementation using JTS. Subclasses may replace this with a more efficient implementation.- Specified by:
getConvexHull
in interfaceROI
- Returns:
-
getSolidity
public double getSolidity()Description copied from interface:ROI
Calculate the solidity, defined as ROI area / convex hull area. Returns Double.NaN if the ROI does not represent an area.- Specified by:
getSolidity
in interfaceROI
- Returns:
-