/// <summary> /// Takes an input volume and extracts the contours for all voxels that have the given /// foreground value. /// Contour extraction will take account of holes and inserts, up to the default nesting level. /// </summary> /// <param name="volume">The input volume.</param> /// <param name="foregroundId">The ID we are looking for when extracting contours.</param> /// <param name="smoothingType">The type of smoothing that should be applied when going from a /// point polygon to a contour.</param> /// <param name="maxNestingLevel">The maximum nesting level up to which polygons should be extracted. If set to /// 0, only the outermost polygons will be returned. If 1, the outermost polygons and the holes therein. /// If 2, the outermost polygon, the holes, and the foreground inside the holes.</param> /// <returns>The collection of contours.</returns> public static IReadOnlyList <ContourPolygon> ContoursWithHoles(Volume2D <byte> volume, byte foregroundId = ModelConstants.MaskForegroundIntensity, ContourSmoothingType smoothingType = ContourSmoothingType.Small, int maxNestingLevel = DefaultMaxPolygonNestingLevel) { var polygonPoints = PolygonsWithHoles(volume, foregroundId, maxNestingLevel); return(polygonPoints .Select(x => new ContourPolygon(SmoothPolygon.Smooth(x, smoothingType), x.TotalPixels)) .ToList()); }
/// <summary> /// Takes an input volume and extracts the contours for all voxels that have the given /// foreground value. /// Contour extraction will not take account of holes, and hence only return the outermost /// contour around a region of interest. /// </summary> /// <param name="volume">The input volume.</param> /// <param name="foregroundId">The ID we are looking for when extracting contours.</param> /// <param name="smoothingType">The type of smoothing that should be applied when going from a /// point polygon to a contour.</param> /// <returns>The collection of contours.</returns> public static IReadOnlyList <ContourPolygon> ContoursFilled(Volume2D <byte> volume, byte foregroundId = ModelConstants.MaskForegroundIntensity, ContourSmoothingType smoothingType = ContourSmoothingType.Small) { var polygonPoints = PolygonsFilled(volume, foregroundId); return(polygonPoints .Select(x => { var isCounterClockwise = false; var smoothedPoints = SmoothPolygon.SmoothPoints(x.Points, isCounterClockwise, smoothingType); return new ContourPolygon(smoothedPoints, x.VoxelCounts.Total); }) .ToList()); }