Class SplineROI
java.lang.Object
com.xinapse.multisliceimage.roi.ROI
com.xinapse.multisliceimage.roi.SplineROI
- All Implemented Interfaces:
EditableOutlineROI, RotatableROI
- Direct Known Subclasses:
OpenSplineROI
A Class representing a curved line on an image, either open or closed, represented by
a set of knots, with spline interpolators between the knots to define the shape of the curve.
-
Field Summary
Fields inherited from class ROI
BUTTON_ICON_SCALE, PREFERENCES_NODE_NAME, XTOKEN, YTOKEN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidalignKnots(SplineROI s1, SplineROI s2, int nKnots) Aligns the knot points in a pair of SplineROIs, so that there is spatial correspondence as far as possible across the knots.static voidalignKnots(List<SplineROI> rois, int minNKnots) Aligns the knot points in a set of SplineROIs, so that there is spatial correspondence as far as possible across the knots.approximate(int nKnots) Creates a new SplineROI which approximates this SplineROI, but which has the specified number of knot points and where the knot points are evenly distributed in the s-parameter.voidclose()Closes this SplineROI so that the outline is a closed path.booleanbooleandeleteVertex(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 offsetX, int offsetY, int nCols, int nRows, int nSlices, float pixelXSize, float pixelYSize, boolean filled) Draws this ROI on top of an orthogonal view of an image.booleanvoidflipHorizontal(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.org.jogamp.vecmath.Point2dGets the centre (about which rotation will occur) of thisRotatableROI, in mm coordinates.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 aSplineROI.doublegetCurvature(double s) Returns the signed curvature of the outline shape at a particular value of the s-parameter.doublegetCurvature(int index) Returns the signed curvature of the outline shape at a knot point.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.getKnotPoint(int index) Returns a knot point location for thisSplineROI.Point2D[]Returns the knot point locations for thisSplineROI.org.jogamp.vecmath.Point2dgetLocation(double s) Returns the position of the SplineROI outline at a particular value of the s-parameter.static StringgetName()Returns a descriptive name for this type of ROI.org.jogamp.vecmath.Vector2dgetNormal(double s) Returns the outward normal vector at a particular value of the s-parameter.org.jogamp.vecmath.Vector2dgetNormal(int index) Returns the outward normal vector at a knot point.intReturns the number of knot points that define the shape.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.doublegetSMax()Returns that maximum s-parameter value for thisSplineROI.doublegetTheta()Returns the current rotation angle for this RotatableROI.Handle[]Returns an array of VertexHandles.inthashCode()Returns a hash code value for thisSplineROI.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.static SplineROIinterpolate(SplineROI s1, SplineROI s2, double alpha) Creates a new SplineROI by interpolating between two SplineROIs.intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an intersection operation on the shape of this ROI with another ROI.booleanisClosed()Returns whether this SplineROI forms a closed path.voidmove(double dx, double dy) Move thisROIby specified distances (in mm) in the x and y directions.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.reduce(float fractionalError) Creates a new SplineROI which approximates this SplineROI, but which has the miniumum number of knot points to appoximate this SplineROI with the specified fractional error.voidRemoves the first knot point of this SplineROI.voidRemoves the last knot point of this SplineROI.booleanReturns true if this ROI has outline segments that cross.voidvoidsetKnotPoint(Point2D pos, int idx) Sets one knot point position for this ROI.voidsetKnotPoints(double[] x, double[] y) Sets the knot point positions for this ROI.voidsetKnotPoints(double[] x, double[] y, int n) Sets the knot point positions for this ROI.voidsetKnotPoints(float[] x, float[] y) Sets the knot point positions for this ROI.voidsetKnotPoints(Point2D[] knotPoints) Sets the knot point positions for this ROI.voidsetKnotPoints(List<? extends Point2D> knotPoints) Sets the knotPoint positions for this ROI.voidsetTheta(double theta, org.jogamp.vecmath.Point2d centre) Sets the rotation angle for this RotatableROI.voidstretch(double dx, double dy, double stretchX, double stretchY) Moves and stretches an ROI.Creates a new IrregularROI that is close to the shape of this SplineROI.toString()Methods inherited from class ROI
andNot, andNot, andNot, clearDeletionHistory, createXMLElement, dilate, exclusiveOr, exclusiveOr, getAnnotation, getBoundingRectangle, getBoundingRectangle, getCentroid, getClasses, getColor, getDesignTextFontSize, getDisplayedBounds2D, getDisplayedBounds2D, getFeret, getGroupUid, getGroupUid, getHandles, getHandleUnderPoint, getImageSource, getPixelValue, getROIs, getROIs, getROIs, getROIs, getROIs, getROIs, getSlice, getState, getStats, getStats, getStats, getTextColor, getUserColour, getXMLDeclaration, group, intersect, intersect, intersects, isDeleted, isEditable, isGroup, isReloaded, isSameAnnotation, isSameColour, isSelected, join, logicalUnion, main, markDeleted, mmPosToPix, moveROIs, pixPosToMm, printStats, selectDeselect, setAnnotation, setGroupUid, setSlice, setState, setTextColor, setTextSize, setUserColour, ungroup, ungroup, union, union, write, write, writeCoordinatesMethods inherited from interface RotatableROI
setTheta
-
Constructor Details
-
SplineROI
Creates a newSplineROIwith the specified shape in mm coordinates.- Parameters:
x- an array of x-coordinates of the knot points.y- an array of y-coordinates of the knot points.closed- whether the SplineROI is closed.state- theROIStateof the newly-createdROI.- Throws:
ROIException- if the SplineROI cannot be created as specified.
-
SplineROI
public SplineROI(double[] x, double[] y, boolean closed, byte userColour, ROIState state, boolean checkIntegrity) throws ROIException Creates a newSplineROIwith the specified shape in mm coordinates.- Parameters:
x- an array of x-coordinates of the knot points.y- an array of y-coordinates of the knot points.closed- whether the SplineROI is closed.userColour- the colour of this ROI. A value of 0 indicates that the ROI will be drawn with the default colour for normal ROIs if unselected.state- theROIStateof the newly-createdROI.checkIntegrity- whether to check the integrity of the ROI.- Throws:
ROIException- if the SplineROI cannot be created as specified.
-
-
Method Details
-
isClosed
public boolean isClosed()Returns whether this SplineROI forms a closed path.- Returns:
- true if closed; false if an open path.
-
close
Closes this SplineROI so that the outline is a closed path.- Throws:
ROIException- if closing would not create a valid SplineROI.
-
getKnotPoints
-
getSMax
public double getSMax()Returns that maximum s-parameter value for thisSplineROI.- Returns:
- the maximum value of the s-parameter.
-
removeLastKnotPoint
Removes the last knot point of this SplineROI.- Throws:
ROIException- if removal would result in an invalid ROI.
-
removeFirstKnotPoint
Removes the first knot point of this SplineROI.- Throws:
ROIException- if removal would result in an invalid ROI.
-
getKnotPoint
-
getCreateInteractionType
Returns the type of interaction needed to create aSplineROI.- Returns:
- type of interaction needed to create a
SplineROI-InteractionType.CLICK_POINTS.
-
move
-
stretch
public void stretch(double dx, double dy, double stretchX, double stretchY) Description copied from class:ROIMoves 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:
stretchin classROI- Parameters:
dx- the distance (in mm) to move the centre of theROIin the horizontal direction.dy- the distance (in mm) to move the centre of theROIin 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.
-
setKnotPoint
Sets one knot point position for this ROI.- Parameters:
pos- the coordinates of the new position.idx- an index to the knot point.- Throws:
ArrayIndexOutOfBoundsException- if the index is invalid.ROIException- if the moving the knot point would result in an invalid SplineROI.
-
setKnotPoints
Sets the knot point positions for this ROI.- Parameters:
knotPoints- an array of new knot point positions.- Throws:
ROIException- if the knot points cannot be set as specified.
-
setKnotPoints
Sets the knotPoint positions for this ROI.- Parameters:
knotPoints- aList<? extends Point2D>of new knot point positions.- Throws:
ROIException- if the setting the knot point positions would result in an invalid SplineROI.
-
setKnotPoints
Sets the knot point positions for this ROI.- Parameters:
x- a list of x-coordinates for the new knot point positions.y- a list of y-coordinates for the new knot point positions.- Throws:
ROIException- if the knot points cannot be set as specified.
-
setKnotPoints
Sets the knot point positions for this ROI.- Parameters:
x- a list of x-coordinates for the new knot point positions.y- a list of y-coordinates for the new knot point positions.- Throws:
ROIException- if the knot points cannot be set as specified.
-
setKnotPoints
Sets the knot point positions for this ROI.- Parameters:
x- an array of x-coordinates for the new knot point positions.y- an array of y-coordinates for the new knot point positions.n- the number of points to copy from the arrays, starting at index 0.- Throws:
ROIException- if the knot points cannot be set as specified.
-
getCentre
public org.jogamp.vecmath.Point2d getCentre()Description copied from interface:RotatableROIGets the centre (about which rotation will occur) of thisRotatableROI, in mm coordinates.- Specified by:
getCentrein interfaceRotatableROI- Returns:
- the point about which rotation will occur.
-
setTheta
public void setTheta(double theta, org.jogamp.vecmath.Point2d centre) Description copied from interface:RotatableROISets the rotation angle for this RotatableROI.- Specified by:
setThetain interfaceRotatableROI- Parameters:
theta- the rotation angle, in radians.centre- the centre of rotation, in image coordinates.
-
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 knot points that define the shape.- Returns:
- the number of knot points that define the shape.
-
getLocation
public org.jogamp.vecmath.Point2d getLocation(double s) Returns the position of the SplineROI outline at a particular value of the s-parameter.- Parameters:
s- the s-parameter value.- Returns:
- the location of the outline at the position defined by the s-parameter value.
-
getNormal
public org.jogamp.vecmath.Vector2d getNormal(int index) Returns the outward normal vector at a knot point.- Parameters:
index- the index to the knot point.- Returns:
- the outward unit normal vector.
-
getNormal
public org.jogamp.vecmath.Vector2d getNormal(double s) Returns the outward normal vector at a particular value of the s-parameter.- Parameters:
s- the s-parameter value.- Returns:
- the outward unit normal vector at a location of the outline defined by the s-parameter value.
-
getCurvature
public double getCurvature(int index) Returns the signed curvature of the outline shape at a knot point.- Parameters:
index- the index to the knot point.- Returns:
- the signed curvature at a knot point.
-
getCurvature
public double getCurvature(double s) Returns the signed curvature of the outline shape at a particular value of the s-parameter.- Parameters:
s- the s-parameter value.- Returns:
- the signed curvature at a location of the outline defined by the s-parameter value.
-
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 offsetX, int offsetY, 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.offsetX- the offset in the horizontal direction of the orthoView image, relative to the JPanel into which it will be drawn.offsetY- the offset in the vertical direction of the orthoView image, relative to the JPanel into which it will be drawn.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
-
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
-
toIrregular
Creates a new IrregularROI that is close to the shape of this SplineROI.- Returns:
- a new IrregularROI that is close to the shape of this SplineROI.
-
approximate
Creates a new SplineROI which approximates this SplineROI, but which has the specified number of knot points and where the knot points are evenly distributed in the s-parameter.- Parameters:
nKnots- the number of knot points in the new SplineROI.- Returns:
- a new SplineROI which will approximate this SplineROI but which will have the given number of knot points, with the knot points evenly distributed in s.
- Throws:
ROIException- if the specified number of knot points is invalid.
-
reduce
Creates a new SplineROI which approximates this SplineROI, but which has the miniumum number of knot points to appoximate this SplineROI with the specified fractional error.- Parameters:
fractionalError- the maximum fractional error in outline position that can be tolerated.- Returns:
- a new SplineROI which will approximate this SplineROI but which will have the minimum number of knot points, with the knot points evenly distributed in s.
-
interpolate
Creates a new SplineROI by interpolating between two SplineROIs. The new SplineROI is equal to (1-alpha)*s1 + alpha*s2.The number of knot points in the interpolated ROI will be equal to the greater of the number of knot points in s1 and s2.
- Parameters:
s1- the first SplineROI.s2- the second SplineROI.alpha- the alpha interpolation parameter.- Returns:
- a new SplineROI by interpolating between two SplineROIs.
- Throws:
ROIException- if the interpolation can't be performed.
-
alignKnots
Aligns the knot points in a set of SplineROIs, so that there is spatial correspondence as far as possible across the knots. On return, the number of knot points in the SplineROIs will be a power of two, and the knot points will be evenly spaced in the s-parameter.The number of knot points in each of the ROIs may be increased to the next-highest power of two that is greater than or equal to the largest number of knot points found in any of the ROIs.
- Parameters:
rois- the List of ROIs to align.minNKnots- the minimum number of knot points in the aligned ROIs.- Throws:
ROIException- if the ROIs cannot be aligned.
-
alignKnots
Aligns the knot points in a pair of SplineROIs, so that there is spatial correspondence as far as possible across the knots.The number of knot points in each of the ROIs will be set to the specified number of knot points, and the knots will be evenly spaced in the s-parameter.
- Parameters:
s1- the first SplineROI to align.s2- the second SplineROI to align.nKnots- the number of knot points in the aligned ROIs.- Throws:
ROIException- if the ROIs cannot be aligned.
-
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 outline segments that cross.- Returns:
- true if this ROI has outline segments that cross; false otherwise.
-
contains
-
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
-
hashCode
-
set
-
getCopy
-
toString
-
getDescription
-
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.
-