Package com.xinapse.multisliceimage.roi
Class LineROI
java.lang.Object
com.xinapse.multisliceimage.roi.ROI
com.xinapse.multisliceimage.roi.LineROI
- All Implemented Interfaces:
LinearROI
,RegularROI
,RotatableROI
,Cloneable
A Class representing a straight line on an image.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The token written to ROI output files to represent the x-coordinate of the first end of the line.static final String
The token written to ROI output files to represent the x-coordinate of the second end of the line.static final String
The token written to ROI output files to represent the y-coordinate of the first end of the line.static final String
The token written to ROI output files to represent the y-coordinate of the second end of the line.Fields inherited from class com.xinapse.multisliceimage.roi.ROI
BUTTON_ICON_SIZE, handles, PREFERENCES_NODE_NAME, XTOKEN, YTOKEN
-
Constructor Summary
ConstructorDescriptionLineROI
(double x1, double y1, double x2, double y2) Creates a new LineROI with the coordinates of the points forming the line in mm coordinates.Creates a new LineROI with the coordinates of the points forming the line in mm coordinates.Creates a new LineROI with the coordinates of the points forming the line in mm coordinates. -
Method Summary
Modifier and TypeMethodDescriptionandNot
(ROI roi, IndeterminateProgressMonitor progressMonitor) Logically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>
of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI.clone()
Returns a clone of thisROI
.boolean
boolean
draw
(Graphics g, Rectangle visibleRectangle, int imageDrawCols, int imageDrawRows, int xOffset, int yOffset, int nCols, int nRows, float pixelXSize, float pixelYSize, boolean drawAnnotation) LineROIs are a special case, since we can't use the Bounding Rectangle to decide whether a Line is on screen, since the line may be vertical or horizontal, and therefore have an empty boundng rectangle.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) Draws this ROI on top of an orthogonal view of an image.boolean
exclusiveOr
(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an exclusive OR operation on the shape of this ROI with another ROI.void
flipHorizontal
(Point2D flipPoint) Flip thisROI
horizontally about a given location.void
flipVertical
(Point2D flipPoint) Flip thisROI
vertically about a given location.getBoundingRectangle
(int nCols, int nRows, float pixelXSize, float pixelYSize) Returns a high-precision rectangle (in pixel coordinates) that just bounds this ROI.static Icon
Returns 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.Point2d
Returns the centroid (centre of area) of thisROI
.getCopy()
Returns a copy of thisROI
.static ROICreateDialog
getCreateDialog
(CanAddROIToFrame listener) Returns a JDialog that can be used to create Line ROIs.static InteractionType
Returns the type of interaction needed to create a LineROI.Return a description of this type ofROI
.getFeret()
Returns the minimum and maximum Feret's diameter for thisROI
, in mm.static ROI
getInstance
(Point2D p1, Point2D p2, int nCols, int nRows, float pixelXSize, float pixelYSize, byte userColour, ROIState state) Creates a new LineROI.Point2D[]
getIntensityProfile
(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, ComplexMode complexMode) double
getIntersectionLength
(Rectangle2D rectangle, int nCols, int nRows, float pixelXSize, float pixelYSize) Calculates the length of the line segment where this LineROI intersects the given Rectangle argument.double
Returns the length of this ROI in mm.double
getLengthPix
(float pixelXSize, float pixelYSize) Returns the length of this ROI in image pixels.getLine()
Returns the line forming this LineROI in mm coordinates.static String
getName()
Returns a descriptive name for this type of ROI.getOppositeEnd
(EndHandle endHandle) Returns the location of the end that is at the other end to the specified handle.double
Returns the perimeter length of this ROI.double
Returns the angle between the major principal axis of thisROI
and the x-axis.double
Returns the area of this regular ROI in square mm.getStats
(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, MaskAction maskAction, MaskMode maskMode, double maskValue, PrintStream intensityOutputStream, boolean isUnitsMM, ComplexMode complexMode) Returns statistics about thisROI
, and (optionally) performs a masking operation.double
getTheta()
Returns the current rotation angle for this RotatableROI.double
getX1()
Returns the x-coordinate of the first end of the line.double
getX2()
Returns the x-coordinate of the second end of the line.double
getY1()
Returns the y-coordinate of the first end of the line.double
getY2()
Returns the y-coordinate of the second end of the line.int
hashCode()
Returns a hash code value for thisLineROI
.intersect
(ROI roi, IndeterminateProgressMonitor progressMonitor) Performs an intersection operation on the shape of this ROI with another ROI.void
move
(double dx, double dy) Move thisROI
by specified distances (in mm) in the x and y directions.void
Moves this LineROI so that the ends are at the new specified locations.boolean
selectDeselect
(Point point, boolean editMode, boolean showDeleted, int nAlreadySelected) Selects or deselects anROI
after a user click at the point.void
void
setTheta
(double theta) Sets the rotation angle for this RotatableROI.toString()
union
(ROI roi, IndeterminateProgressMonitor progressMonitor) Logically add (forms the union) an ROI to this ROI to create a newjava.util.List<ROI>
of ROIs that is the result of adding the shapes of the two ROIs.Methods inherited from class com.xinapse.multisliceimage.roi.ROI
andNot, andNot, clearDeletionHistory, dilate, exclusiveOr, getAnnotation, getBoundingRectangle, getCentroid, getClasses, getColor, getDesignTextFontSize, getDisplayedBounds2D, getDisplayedBounds2D, getDisplayedRoiArea, getFeret, getGroupUid, getGroupUid, getHandles, getHandleUnderPoint, getImageSource, getPixelValue, getROIs, getROIs, getROIs, getROIs, getROIs, getSlice, getState, getStats, getStats, getTextColor, getUserColour, group, intersect, intersect, intersects, isDeleted, isEditable, isGroup, isReloaded, isSameAnnotation, isSameColour, isSelected, join, logicalUnion, main, markDeleted, mmPosToPix, moveROIs, pixPosToMm, printStats, setAnnotation, setCreationHistory, setGroupUid, setSlice, setState, setTextColor, setTextSize, setUserColour, ungroup, ungroup, union, write, write
-
Field Details
-
X1TOKEN
The token written to ROI output files to represent the x-coordinate of the first end of the line.- See Also:
-
Y1TOKEN
The token written to ROI output files to represent the y-coordinate of the first end of the line.- See Also:
-
X2TOKEN
The token written to ROI output files to represent the x-coordinate of the second end of the line.- See Also:
-
Y2TOKEN
The token written to ROI output files to represent the y-coordinate of the second end of the line.- See Also:
-
-
Constructor Details
-
LineROI
Creates a new LineROI with the coordinates of the points forming the line in mm coordinates. The ROI state will beROIState.NORMAL
.- Parameters:
x1
- the x-location of the first end of the line.y1
- the y-location of the first end of the line.x2
- the x-location of the second end of the line.y2
- the y-location of the second end of the line.- Throws:
ROIException
- if the line length is zero.
-
LineROI
Creates a new LineROI with the coordinates of the points forming the line in mm coordinates.- Parameters:
x1
- the x-location of the first end of the line.y1
- the y-location of the first end of the line.x2
- the x-location of the second end of the line.y2
- the y-location of the second end of the line.state
- the selection state of the LineROI.- Throws:
ROIException
- if the line length is zero.
-
LineROI
public LineROI(double x1, double y1, double x2, double y2, byte userColour, ROIState state) throws ROIException Creates a new LineROI with the coordinates of the points forming the line in mm coordinates.- Parameters:
x1
- the x-location of the first end of the line.y1
- the y-location of the first end of the line.x2
- the x-location of the second end of the line.y2
- the y-location of the second end of the line.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
- the selection state of the LineROI.- Throws:
ROIException
- if the line length is zero.
-
-
Method Details
-
getLine
Returns the line forming this LineROI in mm coordinates.- Returns:
- the line forming this LineROI in mm coordinates.
-
getLength
public double getLength()Description copied from interface:LinearROI
Returns the length of this ROI in mm. -
getLengthPix
public double getLengthPix(float pixelXSize, float pixelYSize) Description copied from interface:LinearROI
Returns the length of this ROI in image pixels.- Specified by:
getLengthPix
in interfaceLinearROI
- Parameters:
pixelXSize
- the size of image pixels in the horizontal direction.pixelYSize
- the size of image pixels in the vertical direction.- Returns:
- the length of this ROI in image pixels.
-
getIntensityProfile
public Point2D[] getIntensityProfile(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, ComplexMode complexMode) Description copied from interface:LinearROI
Returns an array ofPoint2D
representing the pixel intensities along thisLinearROI
. The x-value of a point is a position along theLinearROI
, and the y-value is the intensity. The first and last points will be at the ends of theLinearROI
, but the location of the points in between is not prescribed by this interface.- Specified by:
getIntensityProfile
in interfaceLinearROI
- Parameters:
pix
- the array of pixel intensities for in which thisLinearROI
is positioned.dataType
- thePixelDataType
of the array of pixel intensities.nCols
- the number of columns in the slice.nRows
- the number of rows in the slice.offset
- an offset (in pixels) into the pixel value array for the starting pixel of the slice on which this ROI is defined.pixelXSize
- the size of image pixels in the horizontal direction.pixelYSize
- the size of image pixels in the vertical direction.complexMode
- the calculation mode for Complex images. The intensity profile returned will correspond to the mode: the real part, imaginary part, magnitude or phase.- Returns:
- an array of
Point2D
representing the pixel intensities along this LinearROI.
-
getX1
public double getX1()Returns the x-coordinate of the first end of the line.- Returns:
- the x-coordinate of the first end of the line.
-
getY1
public double getY1()Returns the y-coordinate of the first end of the line.- Returns:
- the y-coordinate of the first end of the line.
-
getX2
public double getX2()Returns the x-coordinate of the second end of the line.- Returns:
- the x-coordinate of the second end of the line.
-
getY2
public double getY2()Returns the y-coordinate of the second end of the line.- Returns:
- the y-coordinate of the second end of the line.
-
getOppositeEnd
Returns the location of the end that is at the other end to the specified handle.- Parameters:
endHandle
- the Handle for the first end.- Returns:
- the location of the end opposite to the supplied EndHandle.
-
getInstance
public static ROI getInstance(Point2D p1, Point2D p2, int nCols, int nRows, float pixelXSize, float pixelYSize, byte userColour, ROIState state) Creates a new LineROI.- Parameters:
p1
- the location of the first end of the line, in image pixels.p2
- the location of the second end of the line, in image pixels.nCols
- the number of columns of pixels in the image.nRows
- the number of rows of pixels in the image.pixelXSize
- the image pixel width.pixelYSize
- the image pixel height.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
- the selection state of the LineROI.- Returns:
- a new LineROI.
-
getTheta
public double getTheta()Description copied from interface:RotatableROI
Returns the current rotation angle for this RotatableROI.- Specified by:
getTheta
in interfaceRotatableROI
- Returns:
- theta the current rotation angle.
-
setTheta
public void setTheta(double theta) Description copied from interface:RotatableROI
Sets the rotation angle for this RotatableROI.- Specified by:
setTheta
in interfaceRotatableROI
- Parameters:
theta
- the rotation angle.
-
getCentre
Description copied from interface:RotatableROI
Gets the centre (about which rotation will occur) of this RotatableROI in mm.- Specified by:
getCentre
in interfaceRotatableROI
- Returns:
- the centre of this ROI, about which rotation will occur.
-
getCreateInteractionType
Returns the type of interaction needed to create a LineROI.- Returns:
- type of interaction needed to create a LineROI - InteractionType.CLICK_DRAG.
-
getSquareArea
public double getSquareArea()Description copied from interface:RegularROI
Returns the area of this regular ROI in square mm.- Specified by:
getSquareArea
in interfaceRegularROI
- Returns:
- zero.
-
move
Moves this LineROI so that the ends are at the new specified locations.- Parameters:
p1
- the new location of the first end of the line.p2
- the new location of the second end of the line.
-
move
public void move(double dx, double dy) Description copied from class:ROI
Move thisROI
by specified distances (in mm) in the x and y directions. -
flipVertical
Description copied from class:ROI
Flip thisROI
vertically about a given location.- Specified by:
flipVertical
in classROI
- Parameters:
flipPoint
- the point about which the ROI will be flipped.
-
flipHorizontal
Description copied from class:ROI
Flip thisROI
horizontally about a given location.- Specified by:
flipHorizontal
in classROI
- Parameters:
flipPoint
- the point about which the ROI will be flipped.
-
union
Description copied from class:ROI
Logically add (forms the union) an ROI to this ROI to create a newjava.util.List<ROI>
of ROIs that is the result of adding the shapes of the two ROIs. -
andNot
Description copied from class:ROI
Logically AND NOTs (subtracts) an ROI from this ROI to create a newjava.util.List<ROI>
of ROIs that is the result of subtracting the shape of the supplied ROI from this ROI. -
intersect
public List<ROI> intersect(ROI roi, IndeterminateProgressMonitor progressMonitor) throws ROIException, CancelledException Description copied from class:ROI
Performs an intersection operation on the shape of this ROI with another ROI.- Overrides:
intersect
in 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.
-
exclusiveOr
Description copied from class:ROI
Performs an exclusive OR operation on the shape of this ROI with another ROI.- Overrides:
exclusiveOr
in classROI
- Parameters:
roi
- the ROI with which to perform the XOR 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.
-
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) LineROIs are a special case, since we can't use the Bounding Rectangle to decide whether a Line is on screen, since the line may be vertical or horizontal, and therefore have an empty boundng rectangle.- Overrides:
draw
in 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 thisROI
is defined.nRows
- the number of rows in the image on which thisROI
is defined.pixelXSize
- pixel width for the image on which thisROI
is defined.pixelYSize
- pixel height for the image on which thisROI
is defined.drawAnnotation
- a flag to indicate whether annotation should be drawn.- Returns:
true
if theROI
is visible and been drawn on screen;false
otherwise.
-
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:ROI
Draws this ROI on top of an orthogonal view of an image.- Specified by:
drawInOrthoView
in classROI
- Parameters:
orthoView
- theImage
into which the ROI is to be drawn.orthoViewPosition
- the coordinates (col, row, slice position) of the orthogonal view in the original image.imageToViewTx
- theTransform3D
that 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).
-
selectDeselect
public boolean selectDeselect(Point point, boolean editMode, boolean showDeleted, int nAlreadySelected) Description copied from class:ROI
Selects or deselects anROI
after a user click at the point.- Overrides:
selectDeselect
in classROI
- Parameters:
point
- thePoint
at which the user has clicked.editMode
-true
if the tool working with ROIs is in edit mode;false
if it is in view mode.showDeleted
-true
if the tool working with ROIs is set to show deleted ROIs;false
if it is not.nAlreadySelected
- the number of ROIs already selected. This determines the exact selection/deselection behaviour.- Returns:
true
if the selection was changed.
-
getStats
public ROIStats getStats(Object pix, PixelDataType dataType, int nCols, int nRows, int offset, float pixelXSize, float pixelYSize, MaskAction maskAction, MaskMode maskMode, double maskValue, PrintStream intensityOutputStream, boolean isUnitsMM, ComplexMode complexMode) Description copied from class:ROI
Returns statistics about thisROI
, and (optionally) performs a masking operation.- Overrides:
getStats
in classROI
- Parameters:
pix
- the whole image pixel value array. If pix is null, then the intensity-related stats will all be set to zero.dataType
- the type of pixels.nCols
- the number of columns in the slice.nRows
- the number of rows in the slice.offset
- an offset (in pixels) into the pixel value array for the starting pixel of the slice on which thisROI
is defined.pixelXSize
- the size of image pixels in the horizontal direction.pixelYSize
- the size of image pixels in the vertical direction.maskAction
- one of:MaskAction.NONE
for no masking;MaskAction.MASK_INSIDE
to set pixel values to maskValue inside the shape; orMaskAction.MASK_OUTSIDE
to set the pixel values to maskValue outside the shape.MaskAction.MASK_INSIDE_SOFT
to perform soft masking inside the shape;MaskAction.MASK_OUTSIDE_SOFT
to perform soft masking outside the shape.
maskMode
- how much of a pixel must be inside ROIs for the pixel to be part of the mask.maskValue
- the pixel value to set outside/inside the shape when performing masking ops.intensityOutputStream
- if non-null
, pixel intensities within the ROI will be printed to thisPrintStream
.isUnitsMM
-true
if the (x,y) coordinates of the pixel intensities are to be written in mm,false
if the coordinates are to be writtn in pixel units.complexMode
- the calculation mode forPixelDataType.COMPLEX
images. The statistics returned will correspond to the mode: the real part, imaginary part, magnitude or phase.- Returns:
- statistics about the ROI.
-
getIntersectionLength
public double getIntersectionLength(Rectangle2D rectangle, int nCols, int nRows, float pixelXSize, float pixelYSize) Calculates the length of the line segment where this LineROI intersects the given Rectangle argument. The Rectangle is in image pixel coordinates.- Parameters:
rectangle
- the Rectangle2d for which to find the intersection line length.nCols
- the number of image columns.nRows
- the number of image rows.pixelXSize
- the image pixel width, in mm.pixelYSize
- the image pixel height, in mm.- Returns:
- the length of the intersection line.
-
getBoundingRectangle
Returns a high-precision rectangle (in pixel coordinates) that just bounds this ROI.- Overrides:
getBoundingRectangle
in classROI
- Parameters:
nCols
- the number of columns in the image on which this ROI is defined.nRows
- the number of rows in the image on which this ROI is defined.pixelXSize
- pixel width for the image on which this ROI is defined.pixelYSize
- pixel height for the image on which this ROI is defined.- Returns:
- a Rectangle2D that just bounds this ROI.
-
getFeret
Description copied from class:ROI
Returns the minimum and maximum Feret's diameter for thisROI
, in mm. -
getPerimeter
public double getPerimeter()Returns the perimeter length of this ROI. The perimeter of a LineROI is defined as twice its length.- Specified by:
getPerimeter
in classROI
- Returns:
- the perimeter length of this ROI.
-
getCentroid
public org.jogamp.vecmath.Point2d getCentroid()Description copied from class:ROI
Returns the centroid (centre of area) of thisROI
.- Specified by:
getCentroid
in classROI
- Returns:
- the centroid of this
ROI
.
-
getPrincipalAxisAngle
public double getPrincipalAxisAngle()Returns the angle between the major principal axis of thisROI
and the x-axis. The angle returned will be between the angle between the line and the x-axis.- Returns:
- the main principal axis angle of this
ROI
.
-
getCreateDialog
Returns a JDialog that can be used to create Line ROIs.- Parameters:
listener
- the CanAddROIToFrame to which the ROI will be added when the Add button of the Dialog is clicked.- Returns:
- a JDialog that can be used to create Line ROIs.
-
contains
-
equals
Description copied from class:ROI
-
hashCode
public int hashCode()Returns a hash code value for thisLineROI
. -
set
Description copied from class:ROI
- Specified by:
set
in classROI
- Parameters:
roi
- the ROI from which the shape is set.- Throws:
ClassCastException
- if the sub-class of the argumentROI
is not the same as thisROI
.
-
getCopy
Description copied from class:ROI
Returns 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. -
getDescription
Description copied from class:ROI
Return a description of this type ofROI
.- Specified by:
getDescription
in classROI
- Returns:
- a String describing the type of this
ROI
.
-
clone
Description copied from class: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.
-
toString
Description copied from class:ROI
-