/// <summary> /// We current have the following approaches: /// - None: Takes the mask representation of the polygon and return the outer edge /// - Small: Uses a simplistic 'code-book' approach to smoothing the outer edge of the polygon /// </summary> /// <param name="polygon">The input mask representation of the extracted polygon.</param> /// <param name="smoothingType">The smoothing type to use.</param> /// <returns>The smoothed polygon.</returns> public static PointF[] Smooth(InnerOuterPolygon polygon, ContourSmoothingType smoothingType = ContourSmoothingType.Small) { var result = SmoothAndMerge( polygon, (points, isCounterClockwise) => SmoothPoints(points, isCounterClockwise, smoothingType)); return(ContourSimplifier.RemoveRedundantPoints(result)); }
/// <summary> /// Smoothes a PointF polygon that contains an inner and an outer rim. Inner and outer rim are /// smoothed separately, and then connected via a zero width "channel": The smoothed /// contour will first follow the outer polygon, then go to the inner contour, follow /// the inner contour, and then go back to the outer contour. /// </summary> /// <param name="polygon"></param> /// <param name="smoothingFunction"></param> /// <returns></returns> private static PointF[] SmoothAndMerge(InnerOuterPolygon polygon, Func <IReadOnlyList <PointInt>, bool, PointF[]> smoothingFunction) { var result = smoothingFunction(polygon.Outer.Points, false); foreach (var inner in polygon.Inner) { result = ConnectViaVerticalLine(result, smoothingFunction(inner.Points, true), inner.StartPointMinimumY); } return(result); }