Class Boundary2DSimpleMeasurer


public class Boundary2DSimpleMeasurer extends Boundary2DWrapper

Wrapper of a boundary scanner, that measures some simple parameters of every scanned boundary.

This class overrides only next() and resetCounters() methods of the abstract Boundary2DWrapper class. Namely, next() method, after calling parent.next(), corrects several internal fields, describing some parameters of the current measured object (more precisely, parameters of its completions). These fields are reset to initial values by resetCounters() method. After finishing scanning some boundary, for example, after scanBoundary call, you may use the following access methods to get measured parameters:

More precisely, this class measures the figure, bounded by some contour line, following along the scanned boundary. The precise type of this line is specified by an argument of ContourLineType class, passed to the instantiation method:

getInstance(Boundary2DScanner, ContourLineType, java.util.EnumSet)

In the simplest case (ContourLineType.STRICT_BOUNDARY), the contour line is just the scanned boundary.

Please also note that not all parameters, available via area(), perimeter() and other methods, are measured by this class. The set of parameters that should be really measured is specified via EnumSet while creating the instance in the instantiation method. You should not specify extra parameters, that are not needful: extra calculations can slow down the scanning.

Author:
Daniel Alievsky
  • Method Details

    • getInstance

      public static Boundary2DSimpleMeasurer getInstance(Boundary2DScanner parent, ContourLineType contourLineType, EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters)
      Creates an instance of this class, that is based on the specified parent scanner and, while scanning any boundary by the parent scanner, measures the specified set of object parameters.
      Parameters:
      parent - the parent scanner.
      contourLineType - the style of the contour line: the created object will measure the object, lying inside this line.
      measuredParameters - the set of parameters that should be measured: all parameters, which are not inside this set, are not modified by next() method and stay to be equal to their initial value.
      Returns:
      new instance of this class.
      Throws:
      NullPointerException - if one of the arguments is null.
      See Also:
    • contourLineType

      public ContourLineType contourLineType()
      Returns the contour line style, used for measuring: this class measures the object, lying inside this line.

      The returned reference is identical to the corresponding argument of getInstance(Boundary2DScanner, ContourLineType, EnumSet) method, used for creating this instance.

      Returns:
      the contour line style, used for measuring by this instance.
    • measuredParameters

      public final EnumSet<Boundary2DSimpleMeasurer.ObjectParameter> measuredParameters()
      Returns the set of parameters, measured by this instance. All parameters, which are not inside this set, are not modified by next() method and stay to be equal to their initial value.

      The returned set is a clone of the corresponding argument of getInstance(Boundary2DScanner, ContourLineType, EnumSet) method, used for creating this instance.

      Returns:
      the set of parameters, measured by this instance.
    • resetCounters

      public void resetCounters()
      Description copied from class: Boundary2DScanner
      Resets the counters, returned by Boundary2DScanner.stepCount() and Boundary2DScanner.orientedArea() method, and all other counters, that are possibly increased by inheritors of this class. This method is automatically called at the end of Boundary2DScanner.nextBoundary() and Boundary2DScanner.goTo(long, long, net.algart.matrices.scanning.Boundary2DScanner.Side) methods.
      Overrides:
      resetCounters in class Boundary2DWrapper
    • next

      public void next()
      Description copied from class: Boundary2DScanner
      Move the current position to the next segment of the currently scanned object boundary. External boundaries are scanned in clockwise order, internal boundaries in anticlockwise order (if we suppose that the x axis is directed rightwards and the y axis is directed downwards).

      If the current position does not correspond to an object boundary, the position will be changed to some unknown position near the current one (precise behavior is not specified).

      In addition to switching to the next position, this method can do something else: see comments to methods getSingleBoundaryScanner, getAllBoundariesScanner, getMainBoundariesScanner, and comments to classes Boundary2DSimpleMeasurer, Boundary2DProjectionMeasurer.

      Overrides:
      next in class Boundary2DWrapper
    • area

      public double area()
      Returns the oriented area inside the contour, following along the scanned boundary. "Oriented" means that the result is equal to the area of the figure inside this contour, Equivalent to area(thisObject.contourLineType()).
      Returns:
      the oriented area inside the scanned contour.
    • perimeter

      public double perimeter()
      Returns the total length of the contour, following along the scanned boundary: an estimated perimeter of the measured object, "drawn" at the bit matrix. Equivalent to perimeter(thisObject.contourLineType()).
      Returns:
      the length of the contour line, following along the scanned boundary.
    • minX

      public double minX()
      Returns the minimal x-coordinate of all points at the contour, following along the scanned boundary.

      If contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE, the result is equal to the minimal value of the result of x() method since the last resetCounters() call. If contourLineType()==ContourLineType.STRICT_BOUNDARY or contourLineType()==ContourLineType.SEGMENT_CENTERS_POLYLINE, the result is less by 0.5.

      Returns:
      the minimal x-coordinate of all points at the contour, following along the scanned boundary.
    • maxX

      public double maxX()
      Returns the maximal x-coordinate of all points at the contour, following along the scanned boundary.

      If contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE, the result is equal to the maximal value of the result of x() method since the last resetCounters() call. If contourLineType()==ContourLineType.STRICT_BOUNDARY or contourLineType()==ContourLineType.SEGMENT_CENTERS_POLYLINE, the result is greater by 0.5.

      Returns:
      the maximal x-coordinate of all points at the contour, following along the scanned boundary.
    • minY

      public double minY()
      Returns the minimal y-coordinate of all points at the contour, following along the scanned boundary.

      If contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE, the result is equal to the minimal value of the result of y() method since the last resetCounters() call. If contourLineType()==ContourLineType.STRICT_BOUNDARY or contourLineType()==ContourLineType.SEGMENT_CENTERS_POLYLINE, the result is less by 0.5.

      Returns:
      the minimal x-coordinate of all points at the contour, following along the scanned boundary.
    • maxY

      public double maxY()
      Returns the maximal y-coordinate of all points at the contour, following along the scanned boundary.

      If contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE, the result is equal to the maximal value of the result of y() method since the lastresetCounters() call. If contourLineType()==ContourLineType.STRICT_BOUNDARY or contourLineType()==ContourLineType.SEGMENT_CENTERS_POLYLINE, the result is greater by 0.5.

      Returns:
      the maximal y-coordinate of all points at the contour, following along the scanned boundary.
    • minXPlusY

      public double minXPlusY()
      Returns the minimal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
      Returns:
      the minimal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
    • maxXPlusY

      public double maxXPlusY()
      Returns the maximal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
      Returns:
      the maximal value of the sum x+y of coordinates of all points at the contour, following along the scanned boundary.
    • minXMinusY

      public double minXMinusY()
      Returns the minimal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
      Returns:
      the minimal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
    • maxXMinusY

      public double maxXMinusY()
      Returns the maximal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
      Returns:
      the maximal value of the difference x−y of coordinates of all points at the contour, following along the scanned boundary.
    • centroidX

      public double centroidX()
      Returns the x-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.

      Note that the centroid may be undefined for some styles of contours, if the area of the figure inside the contour, returned by area() method, is zero. For example, it is possible for "thin" 1-pixel "lines" in the case contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE. In this case, this method returns Double.NaN.

      Also note: if it is an internal boundary, it is the centroid of a "hole".

      Returns:
      the x-coordinate of the centroid of the figure the contour, following along the scanned boundary.
    • centroidY

      public double centroidY()
      Returns the y-coordinate of the centroid (center of mass) of the figure, lying inside the contour, following along the scanned boundary.

      Note that the centroid may be undefined for some styles of contours, if the area of the figure inside the contour, returned by area() method, is zero. For example, it is possible for "thin" 1-pixel "lines" in the case contourLineType()==ContourLineType.PIXEL_CENTERS_POLYLINE. In this case, this method returns Double.NaN.

      Also note: if it is an internal boundary, it is the centroid of a "hole".

      Returns:
      the y-coordinate of the centroid of the figure the contour, following along the scanned boundary.
    • toString

      public String toString()
      Returns a brief string description of this object.

      The result of this method may depend on implementation.

      Overrides:
      toString in class Boundary2DScanner
      Returns:
      a brief string description of this object.