Class Downsampling

java.lang.Object
com.ggalmazor.downsampling.Downsampling

public final class Downsampling extends Object
Entry point for all downsampling algorithms provided by this library.

All methods accept a sorted List<T extends Point> and return a List<T>, preserving the concrete point type throughout. The input list must be sorted by Point.getX() in monotonically non-decreasing order. No method mutates the input list or its elements.

Algorithms:

  • lttb(java.util.List<T>, int) — Largest-Triangle Three-Buckets. Bucket-based; output size is buckets + 2. The buckets parameter controls how many middle points are selected.
  • rdp(java.util.List<T>, double) — Ramer-Douglas-Peucker. Distance-based; output size is data-driven. The epsilon parameter is the minimum perpendicular distance for a point to be retained — larger values produce smaller outputs.
  • pip(java.util.List<T>, int) — Perceptually Important Points. Iterative; output size is always exactly targetSize. The targetSize parameter is the desired total number of output points including first and last.
  • Method Details

    • lttb

      public static <T extends Point> List<T> lttb(List<T> input, int buckets)
      Downsamples input using the Largest-Triangle Three-Buckets algorithm with the BucketizationStrategy.DYNAMIC strategy.

      The output contains buckets + 2 points: one selected from each middle bucket, plus the first and last points of the input.

      Type Parameters:
      T - the type of the Point elements
      Parameters:
      input - the sorted input list of points
      buckets - the number of middle buckets (and therefore middle output points)
      Returns:
      the downsampled list
    • lttb

      public static <T extends Point> List<T> lttb(List<T> input, int buckets, BucketizationStrategy strategy)
      Downsamples input using the Largest-Triangle Three-Buckets algorithm with the specified BucketizationStrategy.

      With BucketizationStrategy.DYNAMIC the output contains exactly buckets + 2 points. With BucketizationStrategy.FIXED, empty x-span intervals are skipped so the output may contain fewer than buckets + 2 points.

      Type Parameters:
      T - the type of the Point elements
      Parameters:
      input - the sorted input list of points
      buckets - the number of middle buckets
      strategy - the bucketization strategy to use
      Returns:
      the downsampled list
    • rdp

      public static <T extends Point> List<T> rdp(List<T> input, double epsilon)
      Downsamples input using the Ramer-Douglas-Peucker algorithm.

      The output size is determined by the data shape and epsilon: every retained interior point has a perpendicular distance greater than epsilon from the line connecting its enclosing retained neighbours. A larger epsilon retains fewer points; epsilon = 0 retains all points.

      Type Parameters:
      T - the type of the Point elements
      Parameters:
      input - the sorted input list of points
      epsilon - the minimum perpendicular distance for a point to be retained
      Returns:
      the downsampled list; always includes the first and last input points
    • pip

      public static <T extends Point> List<T> pip(List<T> input, int targetSize)
      Downsamples input using the Perceptually Important Points algorithm.

      The output contains exactly targetSize points (or all input points if targetSize >= input.size()). Points are selected greedily in order of decreasing perpendicular distance to their currently-selected neighbours.

      Type Parameters:
      T - the type of the Point elements
      Parameters:
      input - the sorted input list of points
      targetSize - the desired total number of output points, including first and last
      Returns:
      the downsampled list