Class SplitMergeLineFit

Direct Known Subclasses:
SplitMergeLineFitLoop, SplitMergeLineFitSegment

public abstract class SplitMergeLineFit
extends Object
Base class for algorithm which employ a split and merge strategy to fitting a set of line segments onto an ordered set of points. The lines are an approximation of the original shape described by the point list. This list can either be connected at the end (looped) or not, depending on the implementation. The points in the list are assumed to be ordered with each consecutive point connected to its neighbors. The output is a set of indexes which correspond to points in the original list that compose the line segments. A minimum of two indexes will be returned. The returned set of line segments is guaranteed to match the original set of points to within a user specified tolerance. That is, no point in the list will be more than 'tol' distance away from a line segment. A line is split when a point between two end points is greater than the split distance. A corner is removed (two lines merged) if the corner is less than the split distance away from two of its adjacent neighbors. The split threshold is specified as a fraction of line distance to maximize scale invariance. The minimum split threshold is specified in units of pixels because a simple ratio doesn't work well for small objects. Split and merge is repeated until there is no more change or the maximum number of iterations has been reached.
  • Field Details

    • maxIterations

      protected int maxIterations
    • toleranceFractionSq

      protected double toleranceFractionSq
    • minimumSideLength

      protected ConfigLength minimumSideLength
    • minimumSideLengthPixel

      protected int minimumSideLengthPixel
    • contour

      @Nullable protected @Nullable List<Point2D_I32> contour
    • line

      protected LineParametric2D_F64 line
    • point2D

      protected Point2D_F64 point2D
    • splits

      protected DogArray_I32 splits
    • changed

      protected DogArray_B changed
    • abortSplits

      protected int abortSplits
  • Constructor Details

    • SplitMergeLineFit

      protected SplitMergeLineFit​(double splitFraction, ConfigLength minimumSideLength, int maxIterations)
      Configures algorithm
      splitFraction - A line will be split if a point is more than this fraction of its length away from the line. Try 0.05
      minimumSideLength - The minimum length of a side as a function of contour length
      maxIterations - Maximum number of split and merge refinements. Set to zero to disable refinement. Try 20
  • Method Details

    • process

      public boolean process​(List<Point2D_I32> list, DogArray_I32 vertexes)
      Approximates the input list with a set of line segments
      list - (Input) Ordered list of connected points.
      vertexes - (Output) Indexes in the input list which are corners in the polyline
      true if it could fit a polygon to the points or false if not
    • _process

      protected abstract boolean _process​(List<Point2D_I32> list)
    • splitThresholdSq

      protected double splitThresholdSq​(Point2D_I32 a, Point2D_I32 b)
      Computes the split threshold from the end point of two lines
    • setMaxIterations

      public void setMaxIterations​(int maxIterations)
    • setSplitFraction

      public void setSplitFraction​(double toleranceSplit)
    • getAbortSplits

      public int getAbortSplits()
    • setAbortSplits

      public void setAbortSplits​(int abortSplits)