Package com.xinapse.multisliceimage.roi
Class IrregularROI
java.lang.Object
com.xinapse.multisliceimage.roi.ROI
com.xinapse.multisliceimage.roi.IrregularROI
- All Implemented Interfaces:
EditableOutlineROI,RotatableROI,StretchableROI,Cloneable
- Direct Known Subclasses:
ContourROI,CurvedLineROI,IrregularROIInProgress
public class IrregularROI
extends ROI
implements Cloneable, StretchableROI, RotatableROI, EditableOutlineROI
A Class representing an irregularly-shaped closed region on an image.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe number of points forming the outline.static final StringThe token written to ROI output files to indicate that a list of points is to follow.protected double[]The x-coordinates of points forming the outline of this Irregular ROI in real-space (mm) coordinates.protected double[]The y-coordinates of points forming the outline of this Irregular ROI in real-space (mm) coordinates.Fields inherited from class com.xinapse.multisliceimage.roi.ROI
BUTTON_ICON_SIZE, handles, PREFERENCES_NODE_NAME, XTOKEN, YTOKEN -
Constructor Summary
ConstructorsConstructorDescriptionIrregularROI(double[] x, double[] y, int n, ROIState state) Creates a newIrregularROIwith the specified shape in mm coordinates.IrregularROI(List<? extends Point2D> pointsList, ROIState state) Creates a newIrregularROIwith the specified shape in mm coordinates. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a clone of thisROI.Returns the line that represents the line that joins the two points that are closest together (in space) between thisIrregularROIand anotherIrregularROI.booleanIndicates whether thisIrregularROIcontains anotherROIentirely within its borders.booleancontainsVertex(Point2D vertex) Tests whether the supplied vertex location is one of the vertex locations for this ROI.booleandeleteVertex(Handle handle) Delete a point on the outline of this EditableOutlineROI that is under a handle.booleandraw(Graphics g, Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation) Draws thisROIif it needs to be be drawn on screen.voiddrawInOrthoView(Image orthoView, org.jogamp.vecmath.Point3f orthoViewPosition, org.jogamp.java3d.Transform3D imageToViewTx, int nCols, int nRows, int nSlices, float pixelXSize, float pixelYSize, boolean filled) Draws this ROI on top of an orthogonal view of an image.booleanerasePoints(List<Point2D> erasePoints, float size, int nCols, int nRows, float pixelXSize, float pixelYSize) Erase points from this IrregularROI.voidflipHorizontal(Point2D flipPoint) Flip thisROIhorizontally about a given location.voidflipVertical(Point2D flipPoint) Flip thisROIvertically about a given location.static IconReturns an Icon that can be used for a button to create this type of ROI.Gets the centre (about which rotation will occur) of this RotatableROI in mm.org.jogamp.vecmath.Point2dReturns the centroid (centre of area) of thisROI.getCopy()Returns a copy of thisROI.static InteractionTypeReturns the type of interaction needed to create anIrregularROI.Return a description of this type ofROI.getFeret()Returns the minimum and maximum Feret's diameter for thisROI, in mm.getFollowingVisibleHandle(Handle handle) Returns the visible Handle that is immediately after the specified handle, in the order in which they were placed around the ROI.static StringgetName()Returns a descriptive name for this type of ROI.org.jogamp.vecmath.Vector2dgetNormal(int index) Returns the outward normal vector at a vertex.intReturns the number of vertices that define the outline.doubleReturns the perimeter length of thisROI.getPrecedingVisibleHandle(Handle handle) Returns the visible Handle that is immediately before the specified handle, in the order in which they were placed around the ROI.doubleReturns the angle between the major principal axis of thisROIand the x-axis.doublegetTheta()Returns the current rotation angle for this RotatableROI.getVertex(int index) Returns a vertex location for thisIrregularROI.Handle[]Returns an array of VertexHandles.Point2D[]Returns the vertex locations for thisIrregularROI.inthashCode()Returns a hash code value for thisIrregularROI.booleaninsertTwoVertices(Handle handle) Insert two points into the outline of this EditableOutlineROI: one just before the one that is under a handle, and one just after.intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an intersection operation on the shape of this ROI with another ROI.join(IrregularROI roi) Joins this ROI to another IrregularROI with a waisted join - a join at the nearest point.static voidRun the self-test on this class.voidmakeConvex(float pixelXSize, float pixelYSize, float minConcaveRadius) Make this IrregularROI convex, or at least less concave.voidmakeConvex(CanAddROIToFrame canAddROIToFrame, float pixelXSize, float pixelYSize, float minConcaveRadius) Make this IrregularROI convex, or at least less concave.voidmove(double dx, double dy) Move thisROIby specified distances (in mm) in the x and y directions.voidmove(double dx, double dy, double stretchX, double stretchY) Moves and stretches an ROI.voidmoveVertex(Point2D newPos, Handle handle, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean pixelSnap) Move a point on the outline of this EditableOutlineROI to a new position.voidorderPoints(IrregularROI toROI) Sets the order of the outline points of this ROI so that they are in the closest possible correspondence (spatially) with the outline points of the supplied IrregularROI.voidModifies this IrregularROI, converting any self-intersecting segments so that after this method call, the ROI does not self-intersect.booleanReturns true if this ROI has line segments that cross.voidvoidsetTheta(double theta) Sets the rotation angle for this RotatableROI.voidSets one vertex position for this ROI.voidsetVertices(double[] x, double[] y) Sets the vertex positions for this ROI.voidsetVertices(double[] x, double[] y, int n) Sets the vertex positions for this ROI.voidsetVertices(Point2D[] vertices) Sets the vertex positions for this ROI.voidsetVertices(List<? extends Point2D> vertices) Sets the vertex positions for this ROI.voidsimplify(double minDistanceBetweenPoints) Simplifies the outline shape of this IrregularROI such that none of the vertex points is less than the specified minimum distance apart.toSpline()Converts this IrregularROI to a SplineROI.toSpline(int nKnotPoints) Converts this IrregularROI to a SplineROI with the specified number of knot points.toString()Methods inherited from class com.xinapse.multisliceimage.roi.ROI
andNot, andNot, andNot, clearDeletionHistory, dilate, exclusiveOr, exclusiveOr, getAnnotation, getBoundingRectangle, getBoundingRectangle, getCentroid, getClasses, getColor, getDesignTextFontSize, getDisplayedBounds2D, getDisplayedBounds2D, getDisplayedRoiArea, getFeret, getGroupUid, getGroupUid, getHandles, getHandleUnderPoint, getImageSource, getPixelValue, getROIs, getROIs, getROIs, getROIs, getROIs, getSlice, getState, getStats, getStats, getStats, getTextColor, getUserColour, group, intersect, intersect, intersects, isDeleted, isEditable, isGroup, isReloaded, isSameAnnotation, isSameColour, isSelected, join, logicalUnion, markDeleted, mmPosToPix, moveROIs, pixPosToMm, printStats, selectDeselect, setAnnotation, setCreationHistory, setGroupUid, setSlice, setState, setTextColor, setTextSize, setUserColour, ungroup, ungroup, union, union, write, writeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.xinapse.multisliceimage.roi.StretchableROI
getDisplayedBounds2D
-
Field Details
-
POINTSTOKEN
The token written to ROI output files to indicate that a list of points is to follow.- See Also:
-
xpts
protected double[] xptsThe x-coordinates of points forming the outline of this Irregular ROI in real-space (mm) coordinates. -
ypts
protected double[] yptsThe y-coordinates of points forming the outline of this Irregular ROI in real-space (mm) coordinates. -
nPoints
protected int nPointsThe number of points forming the outline.
-
-
Constructor Details
-
IrregularROI
Creates a newIrregularROIwith the specified shape in mm coordinates.- Parameters:
x- an array of x-coordinates for the points forming the outline.y- an array of y-coordinates for the points forming the outline.n- the number points to be taken from the x and y arrays - must be less than or equal to then length of the smallest array.state- theROIStateof the newly-createdROI.- Throws:
ROIException- if theROIcannot be created as specified.
-
IrregularROI
Creates a newIrregularROIwith the specified shape in mm coordinates.- Parameters:
pointsList- a List ofPoint2D, in real-space (mm) coordinates, forming the outline.state- theROIStateof the newly-created ROI.- Throws:
ROIException- if the ROI cannot be created as specified.
-
-
Method Details
-
getVertices
Returns the vertex locations for thisIrregularROI.- Returns:
- the vertex locations as an array of
Point2D.
-
getVertex
Returns a vertex location for thisIrregularROI.- Parameters:
index- the index of the vertex to return.- Returns:
- the vertex location as a
Point2D.
-
getNormal
Returns the outward normal vector at a vertex.- Parameters:
index- the index to the vertex.- Returns:
- the outward unit normal vector.
- Throws:
ROIException- if the vertex index is invalid.
-
containsVertex
Tests whether the supplied vertex location is one of the vertex locations for this ROI.- Parameters:
vertex- the vertex location to test.- Returns:
- true if the supplied vertex location is one of the vertex locations for this ROI; false otherwise.
-
getCreateInteractionType
Returns the type of interaction needed to create anIrregularROI.- Returns:
- type of interaction needed to create an
IrregularROI-InteractionType.CLICK_OUTLINE.
-
move
public void move(double dx, double dy) Description copied from class:ROIMove thisROIby specified distances (in mm) in the x and y directions. -
move
public void move(double dx, double dy, double stretchX, double stretchY) Description copied from interface:StretchableROIMoves and stretches an ROI. A stretch value is a scaling factor for dimensions in either the horizontal or vertical directions. A stretch of 1.0 means no stretch.- Specified by:
movein interfaceStretchableROI- Parameters:
dx- the distance (in mm) to move the centre of theStretchableROIin the horizontal direction.dy- the distance (in mm) to move the centre of theStretchableROIin the vertical direction.stretchX- the stretch in the horizontal direction.stretchY- the stretch in the vertical direction.
-
flipVertical
Description copied from class:ROIFlip thisROIvertically about a given location.- Specified by:
flipVerticalin classROI- Parameters:
flipPoint- the point about which the ROI will be flipped.
-
flipHorizontal
Description copied from class:ROIFlip thisROIhorizontally about a given location.- Specified by:
flipHorizontalin classROI- Parameters:
flipPoint- the point about which the ROI will be flipped.
-
moveVertex
public void moveVertex(Point2D newPos, Handle handle, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean pixelSnap) throws ROIException Description copied from interface:EditableOutlineROIMove a point on the outline of this EditableOutlineROI to a new position.- Specified by:
moveVertexin interfaceEditableOutlineROI- Parameters:
newPos- the new location of the vertex in real-space coordinates.handle- the Handle that the user has grabbed, used to identify the vertex to be moved.nCols- the number of image columns.nRows- the number of image rows.pixelXSize- the pixel width in mm.pixelYSize- the pixel height in mm.pixelSnap- whether pixel snap is turned on.- Throws:
ROIException- if the vertex cannot be moved to the requested position.
-
deleteVertex
Description copied from interface:EditableOutlineROIDelete a point on the outline of this EditableOutlineROI that is under a handle.- Specified by:
deleteVertexin interfaceEditableOutlineROI- Parameters:
handle- the Handle that the user has grabbed, used to identify the vertex to be deleted.- Returns:
- true if a point is successfully deleted.
- Throws:
ROIException- if the point cannot be deleted from this ROI.
-
insertTwoVertices
Description copied from interface:EditableOutlineROIInsert two points into the outline of this EditableOutlineROI: one just before the one that is under a handle, and one just after.- Specified by:
insertTwoVerticesin interfaceEditableOutlineROI- Parameters:
handle- the Handle that the user has grabbed, used to identify the vertex around which the new vertices are to be placed.- Returns:
- true if a point is successfully inserted.
-
setVertex
Sets one vertex position for this ROI.- Parameters:
pos- the coordinates of the new position.idx- an index to the corordinate position.- Throws:
ArrayIndexOutOfBoundsException- if the index is invalid.ROIException- if the moving the vertex would result in an invalid IrregularROI.
-
setVertices
Sets the vertex positions for this ROI.- Parameters:
vertices- an array of new vertex positions.- Throws:
ROIException- if the setting the vertex positions would result in an invalid IrregularROI.
-
setVertices
Sets the vertex positions for this ROI.- Parameters:
vertices- ajava.util.List<? extends Point2D>of new vertex positions.- Throws:
ROIException- if the setting the vertex positions would result in an invalid IrregularROI.
-
setVertices
Sets the vertex positions for this ROI.- Parameters:
x- an array of x-coordinates for the new vertex positions.y- an array of y-coordinates for the new vertex positions.- Throws:
ROIException- if the vertices cannot be set as specified.
-
setVertices
Sets the vertex positions for this ROI.- Parameters:
x- an array of x-coordinates for the new vertex positions.y- an array of y-coordinates for the new vertex positions.n- the number of points to copy from the arrays, starting at index 0.- Throws:
ROIException- if the vertices cannot be set as specified.ROIException- if the setting the vertex positions would result in an invalid IrregularROI.
-
getCentre
Description copied from interface:RotatableROIGets the centre (about which rotation will occur) of this RotatableROI in mm.- Specified by:
getCentrein interfaceRotatableROI- Returns:
- the centre of this ROI, about which rotation will occur.
-
setTheta
public void setTheta(double theta) Description copied from interface:RotatableROISets the rotation angle for this RotatableROI.- Specified by:
setThetain interfaceRotatableROI- Parameters:
theta- the rotation angle.
-
getTheta
public double getTheta()Description copied from interface:RotatableROIReturns the current rotation angle for this RotatableROI.- Specified by:
getThetain interfaceRotatableROI- Returns:
- theta the current rotation angle.
-
getNPoints
public int getNPoints()Returns the number of vertices that define the outline.- Returns:
- the number of vertices that define the outline.
-
erasePoints
public List<IrregularROI> erasePoints(List<Point2D> erasePoints, float size, int nCols, int nRows, float pixelXSize, float pixelYSize) Erase points from this IrregularROI. erasePoints may edit this IrregularROI by deleting points, or it may split this IrregularROI into two or more new IrregularROIs. If more than one IrregularROI is returned, then the (edited) original IrregularROI will be in the list of returned IrregularROIs, and will be the remaining IrregularROI which is biggest (has the most points).- Parameters:
erasePoints- a List of points through which the erasing pen has passed.size- the size of the erasing pen in mm.nCols- the number of image columns.nRows- the number of image rows.pixelXSize- the pixel width in mm.pixelYSize- the pixel height in mm.- Returns:
- a List of IrregularROIs resulting from the points erasure.
-
simplify
Simplifies the outline shape of this IrregularROI such that none of the vertex points is less than the specified minimum distance apart.- Parameters:
minDistanceBetweenPoints- the minimum distance betwen vertex points.- Throws:
ROIException- if the outline simplification results in an invalid ROI.
-
join
Joins this ROI to another IrregularROI with a waisted join - a join at the nearest point. If the two ROIs overlap, then the resulting ROI is just the union of the two ROIs.- Parameters:
roi- the roi to which this is to be joined.- Returns:
- the original ROI joined to the ROI supplied as an argument.
- Throws:
ROIException- if the two ROIs cannot be joined.
-
closestPoints
Returns the line that represents the line that joins the two points that are closest together (in space) between thisIrregularROIand anotherIrregularROI.- Parameters:
roi- theIrregularROIagainst which thisIrregularROIwill be tested.- Returns:
- a
Line2Drepresenting the line that joins the two closest points. The first end of the line will be on thisIrregularROI, and the second will be on the supplied argumentIrregularROI.
-
orderPoints
Sets the order of the outline points of this ROI so that they are in the closest possible correspondence (spatially) with the outline points of the supplied IrregularROI.- Parameters:
toROI- the IrregularROI to which the order of the outline points is to me matched.- Throws:
ROIException- if the number of outline points is different between this IrregularROI and the supplied IrregularROI.
-
toSpline
Converts this IrregularROI to a SplineROI. The number of knot points will be set automatically so that the SplineROI is a good approximation to this IrregularROI. The knot points will be evenly spaced around the outline of the SplineROI.- Returns:
- a SplineROI that is an approximation to this IrregularROI.
-
toSpline
Converts this IrregularROI to a SplineROI with the specified number of knot points. The knot points will be evenly spaced around the outline of this IrregularROI.- Parameters:
nKnotPoints- the number of knot points in the SplineROI.- Returns:
- a SplineROI that is an approximation to this IrregularROI.
- Throws:
ROIException- if the specified number of knot points is less than 3.
-
makeConvex
public void makeConvex(float pixelXSize, float pixelYSize, float minConcaveRadius) throws CancelledException Make this IrregularROI convex, or at least less concave. The supplied pixel sizes are used to decide on the separation between data points around the IrregularROI. A minimum radius of curvature for concave radii of curvature is given.- Parameters:
pixelXSize- the width of an image pixel in mm.pixelYSize- the height of an image pixel in mm.minConcaveRadius- the minimum radius of curvature for concave parts of thisROI.- Throws:
CancelledException- if the operation is cancelled by the user.
-
makeConvex
public void makeConvex(CanAddROIToFrame canAddROIToFrame, float pixelXSize, float pixelYSize, float minConcaveRadius) Make this IrregularROI convex, or at least less concave. The supplied pixel sizes are used to decide on the separation between data points around the IrregularROI. A minimum radius of curvature for concave radii of curvature is given. The action of making the ROI convex will be executed asynchronously using aSwingWorkerthat will update theImageDisplayerwhen finished.- Parameters:
canAddROIToFrame- theCanAddROIToFrameto be updated when the operation is complete.pixelXSize- the width of an image pixel in mm.pixelYSize- the height of an image pixel in mm.minConcaveRadius- the minimum radius of curvature for concave parts of thisROI.
-
draw
public boolean draw(Graphics g, Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation) Description copied from class:ROIDraws thisROIif it needs to be be drawn on screen.- Overrides:
drawin classROI- Parameters:
g- the graphics context for the drawing operation.visibleRectangle- the part of the image that can be seen on-screen.imageDrawCols- width of the area in which this portion of the image is to be drawn.imageDrawRows- height of the area in which this portion of the image is to be drawn.xOffset- a horizontal offset for drawing operations.yOffset- a vertical offset for drawing operations.nCols- the number of columns in the image on which thisROIis defined.nRows- the number of rows in the image on which thisROIis defined.pixelXSize- pixel width for the image on which thisROIis defined.pixelYSize- pixel height for the image on which thisROIis defined.drawAnnotation- a flag to indicate whether annotation should be drawn.- Returns:
trueif theROIis visible and been drawn on screen;falseotherwise.
-
drawInOrthoView
public void drawInOrthoView(Image orthoView, org.jogamp.vecmath.Point3f orthoViewPosition, org.jogamp.java3d.Transform3D imageToViewTx, int nCols, int nRows, int nSlices, float pixelXSize, float pixelYSize, boolean filled) Description copied from class:ROIDraws this ROI on top of an orthogonal view of an image.- Specified by:
drawInOrthoViewin classROI- Parameters:
orthoView- theImageinto which the ROI is to be drawn.orthoViewPosition- the coordinates (col, row, slice position) of the orthogonal view in the original image.imageToViewTx- theTransform3Dthat maps original image pixel coordinates to pixel coordinates in the orthogonal view.nCols- the number of columns in the original image.nRows- the number of rows in the original image.nSlices- the number of slices in the original image.pixelXSize- the pixel width in the original image.pixelYSize- the pixel height in the original image.filled- whether the ROI should be drawn filled (effective only for ROIs that enclose an area).
-
getFeret
Description copied from class:ROIReturns the minimum and maximum Feret's diameter for thisROI, in mm. -
getPerimeter
public double getPerimeter()Description copied from class:ROIReturns the perimeter length of thisROI.- Specified by:
getPerimeterin classROI- Returns:
- the perimeter length of this
ROI.
-
getCentroid
public org.jogamp.vecmath.Point2d getCentroid()Description copied from class:ROIReturns the centroid (centre of area) of thisROI.- Specified by:
getCentroidin classROI- Returns:
- the centroid of this
ROI.
-
getPrincipalAxisAngle
public double getPrincipalAxisAngle()Returns the angle between the major principal axis of thisROIand the x-axis.- Returns:
- the main principal axis angle of this
ROI.
-
getVertexHandles
Description copied from interface:EditableOutlineROIReturns an array of VertexHandles.- Specified by:
getVertexHandlesin interfaceEditableOutlineROI- Returns:
- an array of VertexHandles, or null if this ROI is not having its outline edited.
-
getPrecedingVisibleHandle
Description copied from interface:EditableOutlineROIReturns the visible Handle that is immediately before the specified handle, in the order in which they were placed around the ROI.- Specified by:
getPrecedingVisibleHandlein interfaceEditableOutlineROI- Parameters:
handle- the handle for which to get the preceding handle.- Returns:
- the preceding visible Handle, or null if there is no preceding visible handle.
-
getFollowingVisibleHandle
Description copied from interface:EditableOutlineROIReturns the visible Handle that is immediately after the specified handle, in the order in which they were placed around the ROI.- Specified by:
getFollowingVisibleHandlein interfaceEditableOutlineROI- Parameters:
handle- the handle for which to get the following handle.- Returns:
- the following visible Handle, or null if there is no following visible handle.
-
selfIntersects
public boolean selfIntersects()Returns true if this ROI has line segments that cross.- Returns:
- true if this ROI has line segments that cross; false otherwise.
-
removeSelfIntersections
Modifies this IrregularROI, converting any self-intersecting segments so that after this method call, the ROI does not self-intersect. Any "internal" hollows that result from self-intersections are removed.- Throws:
ROIException- if the operation cannot be completed.
-
contains
Indicates whether thisIrregularROIcontains anotherROIentirely within its borders. -
intersect
public List<ROI> intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Description copied from class:ROIPerforms an intersection operation on the shape of this ROI with another ROI.- Overrides:
intersectin classROI- Parameters:
roi- the ROI with which to perform the intersection operation.progressMonitor- if non-null, the IndeterminateProgressMonitor that can be used to cancel the operation.- Returns:
- a List<ROI> of ROIs that result from the operation.
- Throws:
ROIException- if the operation cannot be performed.CancelledException- if the operation is cancelled by the user.
-
equals
Description copied from class:ROI -
hashCode
public int hashCode()Returns a hash code value for thisIrregularROI.- Overrides:
hashCodein classROI- Returns:
- a hash code value for this
IrregularROI.
-
set
Description copied from class:ROI- Specified by:
setin classROI- Parameters:
roi- the ROI from which the shape is set.- Throws:
ClassCastException- if the sub-class of the argumentROIis not the same as thisROI.
-
getCopy
Description copied from class:ROIReturns a copy of thisROI. The copy will be identical in shape and annotation as the original ROI, but with a history of that of a newly-created ROI. -
clone
Description copied from class:ROI -
toString
Description copied from class:ROI -
getDescription
Description copied from class:ROIReturn a description of this type ofROI.- Specified by:
getDescriptionin classROI- Returns:
- a String describing the type of this
ROI.
-
getName
Returns a descriptive name for this type of ROI.- Returns:
- a String describing this type of ROI.
-
getButtonIcon
Returns an Icon that can be used for a button to create this type of ROI.- Returns:
- an Icon that can be used to represent this type of ROI.
-
main
Run the self-test on this class.- Parameters:
args- ignored.
-