Class FastPolygonUnion

java.lang.Object
qupath.lib.roi.FastPolygonUnion

public class FastPolygonUnion extends Object
Compute a faster union of large numbers of polygons.

This is a sufficiently common requirement, especially with pixel classification, to require its own method.

The algorithm is:

  1. Extract all polygons from the input.
  2. Identify intersecting and non-intersecting polygons
  3. Group all polygons that should potentially be merged, because they intersect (directly or indirectly) with other polygons in the group; each polygon should be represented in only one group
  4. Union all the polygon groups
  5. Combine all resulting polygons into a single polygon or multipolygon
This partitioning of the problem makes it possible to parallelize checking for intersections and computing the union of groups.
  • Constructor Details

    • FastPolygonUnion

      public FastPolygonUnion()
  • Method Details

    • union

      public static Geometry union(Geometry... geoms)
      Compute a union of all polygons contained in an array of geometries. Non-polygon geometries will be ignored.
      Parameters:
      geoms -
      Returns:
      the union of polygons, or an empty polygon if no geometries are provided
    • union

      public static Geometry union(Collection<? extends Geometry> geoms)
      Compute a union of all polygons contained in a collection of geometries. Non-polygon geometries will be ignored.
      Parameters:
      geoms -
      Returns:
      the union of polygons, or an empty polygon if no geometries are provided