Class Contour

java.lang.Object
imagingbook.common.regions.Contour
All Implemented Interfaces:
Comparable<Contour>, Iterable<Pnt2d>
Direct Known Subclasses:
Contour.Inner, Contour.Outer

public class Contour extends Object implements Comparable<Contour>, Iterable<Pnt2d>

This class represents a closed contour as a sequence of pixel coordinates. It implements the Comparable interface for sorting contours by length. It supports iteration over the points along the contour, e.g., by

 Contour C = ...;
 for (Point p : C) {
    // process p ...
 }
 
Version:
2020/12/21
  • Constructor Details

    • Contour

      public Contour(int label)
      Creates a new (empty) contour with the given region label.
      Parameters:
      label - the region label for this contour.
  • Method Details

    • addPoint

      public void addPoint(Pnt2d p)
    • getPointList

      public List<Pnt2d> getPointList()
      Get the list of contour points.
      Returns:
      a reference to the internal list of contour points.
    • getPointArray

      public Pnt2d[] getPointArray()
      Get the contour points as an array.
      Returns:
      a new array of contour points.
    • getLength

      public int getLength()
      Get the length of the contour.
      Returns:
      the number of points on the contour.
    • getLabel

      public int getLabel()
      Get the region label associated with this contour.
      Returns:
      the region label of the contour.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPolygonPath

      Get the polygon for this contour (for subsequent drawing).
      Returns:
      the polygon.
    • getPolygonPath

      public Path2D getPolygonPath(double xOffset, double yOffset)
      Get the polygon for this contour (for subsequent drawing). An offset can be specified for shifting the contour positions to pixel centers (by passing 0.5, 0.5).
      Parameters:
      xOffset - the horizontal offset.
      yOffset - the vertical offset.
      Returns:
      a polygon.
    • countDuplicatePoints

      public int countDuplicatePoints()
      Returns the number of successive duplicates in this contour. The result should be zero.
      Returns:
      as described.
    • isClosed

      public boolean isClosed(NeighborhoodType2D nht)
      Checks if this contour is closed w.r.t. the specified NeighborhoodType2D, i.e., if the last and the first contour point are "connected".
      Parameters:
      nht - the (@link NeighborhoodType}.
      Returns:
      true if the contour is closed.
    • compareTo

      public int compareTo(Contour other)
      Specified by:
      compareTo in interface Comparable<Contour>
    • iterator

      public Iterator<Pnt2d> iterator()
      Specified by:
      iterator in interface Iterable<Pnt2d>