Class ROIShape

Object
ROI
ROIShape
All Implemented Interfaces:
Serializable

public class ROIShape extends ROI
A class representing a region of interest within an image as a Shape. Such regions are binary by definition. Using a Shape representation allows boolean operations to be performed quickly and with compact storage. If a PropertyGenerator responsible for generating the ROI property of a particular OperationDescriptor (e.g., a warp) cannot reasonably produce an ROIShape representing the region, it should call getAsImage() on its sources and produce its output ROI in image form.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an ROIShape from an Area.
    Constructs an ROIShape from a Shape.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(ROI roi)
    Adds another mask to this one.
    boolean
    contains(double x, double y)
    Returns true if the mask contains the point (x, y).
    boolean
    contains(double x, double y, double w, double h)
    Returns true if a given rectangle (x, y, w, h) is entirely included within the mask.
    boolean
    contains(int x, int y)
    Returns true if the mask contains the point (x, y).
    boolean
    contains(int x, int y, int w, int h)
    Returns true if a given rectangle (x, y, w, h) is entirely included within the mask.
    boolean
    Returns true if the mask contains a given Point2D.
    boolean
    Returns true if a given Rectangle2D is entirely included within the mask.
    boolean
    Returns true if the mask contains a given Point.
    boolean
    Returns true if a given Rectangle is entirely included within the mask.
    Sets the mask to its exclusive-or with another mask.
    int[][]
    getAsBitmask(int x, int y, int width, int height, int[][] mask)
    Returns a bitmask for a given rectangular region of the ROI indicating whether the pixel is included in the region of interest.
    Returns the shape as a PlanarImage.
    getAsRectangleList(int x, int y, int width, int height)
    Returns a LinkedList of Rectangles for a given rectangular region of the ROI.
    Returns the internal Shape representation or null if a shape representation is not possible.
    Returns the bounds of the mask as a Rectangle.
    Returns the bounds of the mask as a Rectangle2D.
    Sets the mask to its intersection with another mask.
    boolean
    intersects(double x, double y, double w, double h)
    Returns true if a given rectangle (x, y, w, h) intersects the mask.
    boolean
    intersects(int x, int y, int w, int h)
    Returns true if a given rectangle (x, y, w, h) intersects the mask.
    boolean
    Returns true if a given Rectangle2D intersects the mask.
    boolean
    Returns true if a given Rectangle intersects the mask.
    Subtracts another mask from this one.
    Transforms the current contents of the ROI by a given AffineTransform.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ROIShape

      public ROIShape(Shape s)
      Constructs an ROIShape from a Shape.
      Parameters:
      s - A Shape.
      Throws:
      IllegalArgumentException - if s is null.
    • ROIShape

      public ROIShape(Area a)
      Constructs an ROIShape from an Area.
      Parameters:
      a - An Area.
  • Method Details

    • getBounds

      public Rectangle getBounds()
      Returns the bounds of the mask as a Rectangle.
      Overrides:
      getBounds in class ROI
    • getBounds2D

      public Rectangle2D getBounds2D()
      Returns the bounds of the mask as a Rectangle2D.
      Overrides:
      getBounds2D in class ROI
    • contains

      public boolean contains(Point p)
      Returns true if the mask contains a given Point.
      Overrides:
      contains in class ROI
      Parameters:
      p - a Point specifying the coordinates of the pixel to be queried.
      Returns:
      true if the pixel lies within the mask.
      Throws:
      IllegalArgumentException - is p is null.
    • contains

      public boolean contains(Point2D p)
      Returns true if the mask contains a given Point2D.
      Overrides:
      contains in class ROI
      Parameters:
      p - A Point2D specifying the coordinates of the pixel to be queried.
      Returns:
      true if the pixel lies within the mask.
      Throws:
      IllegalArgumentException - is p is null.
    • contains

      public boolean contains(int x, int y)
      Returns true if the mask contains the point (x, y).
      Overrides:
      contains in class ROI
      Parameters:
      x - An int specifying the X coordinate of the pixel to be queried.
      y - An int specifying the Y coordinate of the pixel to be queried.
      Returns:
      true if the pixel lies within the mask.
    • contains

      public boolean contains(double x, double y)
      Returns true if the mask contains the point (x, y).
      Overrides:
      contains in class ROI
      Parameters:
      x - A double specifying the X coordinate of the pixel to be queried.
      y - A double specifying the Y coordinate of the pixel to be queried.
      Returns:
      true if the pixel lies within the mask.
    • contains

      public boolean contains(Rectangle rect)
      Returns true if a given Rectangle is entirely included within the mask.
      Overrides:
      contains in class ROI
      Parameters:
      rect - A Rectangle specifying the region to be tested for inclusion.
      Returns:
      true if the rectangle is entirely contained within the mask.
      Throws:
      IllegalArgumentException - is rect is null.
    • contains

      public boolean contains(Rectangle2D rect)
      Returns true if a given Rectangle2D is entirely included within the mask.
      Overrides:
      contains in class ROI
      Parameters:
      rect - A Rectangle2D specifying the region to be tested for inclusion.
      Returns:
      true if the rectangle is entirely contained within the mask.
      Throws:
      IllegalArgumentException - is rect is null.
    • contains

      public boolean contains(int x, int y, int w, int h)
      Returns true if a given rectangle (x, y, w, h) is entirely included within the mask.
      Overrides:
      contains in class ROI
      Parameters:
      x - The int X coordinate of the upper left corner of the region.
      y - The int Y coordinate of the upper left corner of the region.
      w - The int width of the region.
      h - The int height of the region.
      Returns:
      true if the rectangle is entirely contained within the mask.
    • contains

      public boolean contains(double x, double y, double w, double h)
      Returns true if a given rectangle (x, y, w, h) is entirely included within the mask.
      Overrides:
      contains in class ROI
      Parameters:
      x - The double X coordinate of the upper left corner of the region.
      y - The double Y coordinate of the upper left corner of the region.
      w - The double width of the region.
      h - The double height of the region.
      Returns:
      true if the rectangle is entirely contained within the mask.
    • intersects

      public boolean intersects(Rectangle r)
      Returns true if a given Rectangle intersects the mask.
      Overrides:
      intersects in class ROI
      Parameters:
      r - A Rectangle specifying the region to be tested for inclusion.
      Returns:
      true if the rectangle intersects the mask.
      Throws:
      IllegalArgumentException - is r is null.
    • intersects

      public boolean intersects(Rectangle2D r)
      Returns true if a given Rectangle2D intersects the mask.
      Overrides:
      intersects in class ROI
      Parameters:
      r - A Rectangle2D specifying the region to be tested for inclusion.
      Returns:
      true if the rectangle intersects the mask.
      Throws:
      IllegalArgumentException - is r is null.
    • intersects

      public boolean intersects(int x, int y, int w, int h)
      Returns true if a given rectangle (x, y, w, h) intersects the mask.
      Overrides:
      intersects in class ROI
      Parameters:
      x - The int X coordinate of the upper left corner of the region.
      y - The int Y coordinate of the upper left corner of the region.
      w - The int width of the region.
      h - The int height of the region.
      Returns:
      true if the rectangle intersects the mask.
    • intersects

      public boolean intersects(double x, double y, double w, double h)
      Returns true if a given rectangle (x, y, w, h) intersects the mask.
      Overrides:
      intersects in class ROI
      Parameters:
      x - The double X coordinate of the upper left corner of the region.
      y - The double Y coordinate of the upper left corner of the region.
      w - The double width of the region.
      h - The double height of the region.
      Returns:
      true if the rectangle intersects the mask.
    • add

      public ROI add(ROI roi)
      Adds another mask to this one. This operation may force this mask to be rendered.
      Overrides:
      add in class ROI
      Parameters:
      roi - A ROI.
      Returns:
      A new ROI containing the new ROI data.
      Throws:
      IllegalArgumentException - is roi is null.
    • subtract

      public ROI subtract(ROI roi)
      Subtracts another mask from this one. This operation may force this mask to be rendered.
      Overrides:
      subtract in class ROI
      Parameters:
      roi - A ROI.
      Returns:
      A new ROI containing the new ROI data.
      Throws:
      IllegalArgumentException - is roi is null.
    • intersect

      public ROI intersect(ROI roi)
      Sets the mask to its intersection with another mask. This operation may force this mask to be rendered.
      Overrides:
      intersect in class ROI
      Parameters:
      roi - A ROI.
      Returns:
      A new ROI containing the new ROI data.
      Throws:
      IllegalArgumentException - is roi is null.
    • exclusiveOr

      public ROI exclusiveOr(ROI roi)
      Sets the mask to its exclusive-or with another mask. This operation may force this mask to be rendered.
      Overrides:
      exclusiveOr in class ROI
      Parameters:
      roi - A ROI.
      Returns:
      A new ROI containing the new ROI data.
      Throws:
      IllegalArgumentException - is roi is null.
    • getAsShape

      public Shape getAsShape()
      Returns the internal Shape representation or null if a shape representation is not possible.
      Overrides:
      getAsShape in class ROI
      Returns:
      The ROI as a Shape.
    • getAsImage

      public PlanarImage getAsImage()
      Returns the shape as a PlanarImage. This requires performing an antialiased rendering of the internal Shape.
      Overrides:
      getAsImage in class ROI
      Returns:
      If the upper-left corner of the bounds of this ROIShape is (0, 0), the returned image is a BufferedImage of type TYPE_BYTE_BINARY wrapped as a PlanarImage. Otherwise, the returned image is a (bilevel) TiledImage whose SampleModel is an instance of MultiPixelPackedSampleModel.
    • transform

      public ROI transform(AffineTransform at)
      Transforms the current contents of the ROI by a given AffineTransform.
      Overrides:
      transform in class ROI
      Parameters:
      at - An AffineTransform object.
      Returns:
      a new ROI containing the transformed ROI data.
      Throws:
      IllegalArgumentException - if at is null.
    • getAsBitmask

      public int[][] getAsBitmask(int x, int y, int width, int height, int[][] mask)
      Returns a bitmask for a given rectangular region of the ROI indicating whether the pixel is included in the region of interest. The results are packed into 32-bit integers, with the MSB considered to lie on the left. The last entry in each row of the result may have bits that lie outside of the requested rectangle. These bits are guaranteed to be zeroed.

      The mask array, if supplied, must be of length equal to or greater than height and each of its subarrays must have length equal to or greater than (width + 31)/32. If null is passed in, a suitable array will be constructed. If the mask is non-null but has insufficient size, an exception will be thrown.

      Overrides:
      getAsBitmask in class ROI
      Parameters:
      x - The X coordinate of the upper left corner of the rectangle.
      y - The Y coordinate of the upper left corner of the rectangle.
      width - The width of the rectangle.
      height - The height of the rectangle.
      mask - A two-dimensional array of ints at least (width + 31)/32 entries wide and (height) entries tall, or null.
      Returns:
      A reference to the mask parameter, or to a newly constructed array if mask is null.
    • getAsRectangleList

      public LinkedList getAsRectangleList(int x, int y, int width, int height)
      Returns a LinkedList of Rectangles for a given rectangular region of the ROI. The Rectangles in the list are merged into a minimal set.
      Overrides:
      getAsRectangleList in class ROI
      Parameters:
      x - The X coordinate of the upper left corner of the rectangle.
      y - The Y coordinate of the upper left corner of the rectangle.
      width - The width of the rectangle.
      height - The height of the rectangle.
      Returns:
      A LinkedList of Rectangles.