Module ij
Package ij.gui

Class PolygonRoi

java.lang.Object
ij.gui.Roi
ij.gui.PolygonRoi
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.awt.Point>
Direct Known Subclasses:
EllipseRoi, FreehandRoi, PointRoi, RotatedRectRoi

public class PolygonRoi
extends Roi
This class represents a polygon region of interest or polyline of interest.
See Also:
Serialized Form
  • Field Details

    • maxPoints

      protected int maxPoints
    • xp

      protected int[] xp
    • yp

      protected int[] yp
    • xpf

      protected float[] xpf
    • ypf

      protected float[] ypf
    • xp2

      protected int[] xp2
    • yp2

      protected int[] yp2
    • nPoints

      protected int nPoints
    • xSpline

      protected float[] xSpline
    • ySpline

      protected float[] ySpline
    • splinePoints

      protected int splinePoints
  • Constructor Details

    • PolygonRoi

      public PolygonRoi​(int[] xPoints, int[] yPoints, int nPoints, int type)
      Creates a new polygon or polyline ROI from x and y coordinate arrays. Type must be Roi.POLYGON, Roi.FREEROI, Roi.TRACED_ROI, Roi.POLYLINE, Roi.FREELINE or Roi.ANGLE.
    • PolygonRoi

      public PolygonRoi​(float[] xPoints, float[] yPoints, int nPoints, int type)
      Creates a new polygon or polyline ROI from float x and y arrays. Type must be Roi.POLYGON, Roi.FREEROI, Roi.POLYLINE, Roi.FREELINE or Roi.ANGLE.
    • PolygonRoi

      public PolygonRoi​(float[] xPoints, float[] yPoints, int type)
      Creates a new polygon or polyline ROI from float x and y arrays. Type must be Roi.POLYGON, Roi.FREEROI, Roi.POLYLINE, Roi.FREELINE or Roi.ANGLE.
    • PolygonRoi

      public PolygonRoi​(java.awt.Polygon p, int type)
      Creates a new polygon or polyline ROI from a Polygon. Type must be Roi.POLYGON, Roi.FREEROI, Roi.TRACED_ROI, Roi.POLYLINE, Roi.FREELINE or Roi.ANGLE.
    • PolygonRoi

      public PolygonRoi​(FloatPolygon p, int type)
      Creates a new polygon or polyline ROI from a FloatPolygon. Type must be Roi.POLYGON, Roi.FREEROI, Roi.TRACED_ROI, Roi.POLYLINE, Roi.FREELINE or Roi.ANGLE.
    • PolygonRoi

      public PolygonRoi​(int[] xPoints, int[] yPoints, int nPoints, ImagePlus imp, int type)
      Deprecated.
    • PolygonRoi

      public PolygonRoi​(int sx, int sy, ImagePlus imp)
      Starts the process of creating a new user-generated polygon or polyline ROI.
  • Method Details

    • draw

      public void draw​(java.awt.Graphics g)
      Overrides:
      draw in class Roi
    • drawPixels

      public void drawPixels​(ImageProcessor ip)
      Description copied from class: Roi
      Draws the selection outline on the specified ImageProcessor.
      Overrides:
      drawPixels in class Roi
      See Also:
      ImageProcessor.setColor(java.awt.Color), ImageProcessor.setLineWidth(int)
    • grow

      protected void grow​(int sx, int sy)
      Overrides:
      grow in class Roi
    • updatePolygon

      protected void updatePolygon()
    • mouseMoved

      public void mouseMoved​(java.awt.event.MouseEvent e)
      Overrides:
      mouseMoved in class Roi
    • wipeBack

      protected void wipeBack()
    • exitConstructingMode

      public void exitConstructingMode()
    • moveHandle

      protected void moveHandle​(int sx, int sy)
      Overrides:
      moveHandle in class Roi
    • resetBoundingRect

      protected void resetBoundingRect()
    • mouseDownInHandle

      protected void mouseDownInHandle​(int handle, int sx, int sy)
      Overrides:
      mouseDownInHandle in class Roi
    • deleteHandle

      public void deleteHandle​(double ox, double oy)
    • deletePoint

      protected void deletePoint​(int index)
    • getClosestPoint

      protected int getClosestPoint​(double x, double y, FloatPolygon points)
    • fitSpline

      public void fitSpline​(int evaluationPoints)
      Fits a spline, which becomes the new shape of this Roi
    • fitSpline

      public void fitSpline()
      Fits a spline, which becomes the new shape of this Roi
    • removeSplineFit

      public void removeSplineFit()
    • isSplineFit

      public boolean isSplineFit()
      Returns 'true' if this selection has been fitted with a spline.
    • fitSplineForStraightening

      public void fitSplineForStraightening()
      Creates a spline fitted polygon with (roughly) one pixel segment lengths and sets it as the Roi shape. It can be retrieved using the getFloatPolygon() method.
    • handleMouseUp

      protected void handleMouseUp​(int sx, int sy)
      With segmented selections, ignore first mouse up and finalize when user double-clicks, control-clicks or clicks in start box.
      Overrides:
      handleMouseUp in class Roi
    • addOffset

      protected void addOffset()
    • contains

      public boolean contains​(int x, int y)
      Returns whether the center of pixel (x,y) is contained in the Roi. The position of a pixel center determines whether a pixel is selected. Note the ImageJ convention of 0.5 pixel shift between outline and pixel centers, i.e., pixel (0,0) is enclosed by the rectangle spanned between (0,0) and (1,1). Points exactly at the left (right) border are considered outside (inside); points exactly on horizontal borders, are considered outside (inside) at the border with the lower (higher) y. This convention is opposite to that of the java.awt.Shape class. In x, the offset is chosen slightly below 0.5 to reduce the impact of numerical errors.
      Overrides:
      contains in class Roi
    • containsPoint

      public boolean containsPoint​(double x, double y)
      Returns whether coordinate (x,y) is contained in the Roi. Note that the coordinate (0,0) is the top-left corner of pixel (0,0). Use contains(int, int) to determine whether a given pixel is contained in the Roi.
      Overrides:
      containsPoint in class Roi
    • isHandle

      public int isHandle​(int sx, int sy)
      Returns a handle number if the specified screen coordinates are inside or near a handle, otherwise returns -1.
      Overrides:
      isHandle in class Roi
    • getMask

      public ImageProcessor getMask()
      Description copied from class: Roi
      Always returns null for rectangular Roi's
      Overrides:
      getMask in class Roi
    • getLength

      public double getLength()
      Returns the perimeter (for ROIs) or length (for lines).
      Overrides:
      getLength in class Roi
    • getUncalibratedLength

      public double getUncalibratedLength()
    • getAngle

      public double getAngle()
      Returns the angle in degrees between the first two segments of this polyline.
      Overrides:
      getAngle in class Roi
    • getNCoordinates

      public int getNCoordinates()
      Returns the number of points that define this PolygonRoi.
      See Also:
      getNonSplineCoordinates()
    • getXCoordinates

      public int[] getXCoordinates()
      Obsolete; replaced by either getPolygon() or getFloatPolygon().
    • getYCoordinates

      public int[] getYCoordinates()
      Obsolete; replaced by either getPolygon() or getFloatPolygon().
    • getNonSplineCoordinates

      public java.awt.Polygon getNonSplineCoordinates()
    • getNonSplineFloatPolygon

      public FloatPolygon getNonSplineFloatPolygon()
    • getPolygon

      public java.awt.Polygon getPolygon()
      Returns this PolygonRoi as a Polygon.
      Overrides:
      getPolygon in class Roi
      See Also:
      ImageProcessor.setRoi(java.awt.Rectangle), ImageProcessor.drawPolygon(java.awt.Polygon), ImageProcessor.fillPolygon(java.awt.Polygon)
    • getFloatPolygon

      public FloatPolygon getFloatPolygon()
      Returns this polygon or polyline as float arrays in image pixel coordinates.
      Overrides:
      getFloatPolygon in class Roi
    • size

      public int size()
      Returns the number of points in this selection; equivalent to getPolygon().npoints.
      Overrides:
      size in class Roi
    • getInterpolatedPolygon

      public FloatPolygon getInterpolatedPolygon​(double interval, boolean smooth)
      Description copied from class: Roi
      Returns, as a FloatPolygon, an interpolated version of this selection with points spaced 'interval' pixels apart. If 'smooth' is true, traced and freehand selections are first smoothed using a 3 point running average.
      Overrides:
      getInterpolatedPolygon in class Roi
    • clipRectMargin

      protected int clipRectMargin()
      Overrides:
      clipRectMargin in class Roi
    • clone

      public java.lang.Object clone()
      Returns a copy of this PolygonRoi.
      Overrides:
      clone in class Roi
    • setLocation

      public void setLocation​(double x, double y)
      Description copied from class: Roi
      Set the location of the ROI in image coordinates.
      Overrides:
      setLocation in class Roi
    • enableSubPixelResolution

      public void enableSubPixelResolution()
      Overrides:
      enableSubPixelResolution in class Roi
    • getDebugInfo

      public java.lang.String getDebugInfo()
      Overrides:
      getDebugInfo in class Roi