public static void Render(string pointFilePath, Size?resolution) { using var points = PointStream.Load(pointFilePath); var viewPort = points.ViewPort; var actualResolution = resolution ?? points.ViewPort.Resolution; if (actualResolution != points.ViewPort.Resolution) { viewPort = new ViewPort(viewPort.Area, actualResolution); } var imageFilePath = pointFilePath + $".{actualResolution.Width}x{actualResolution.Height}.png"; using var timer = TimedOperation.Start("points", totalWork: actualResolution.Area()); var image = new FastImage(actualResolution); image.Fill(Color.White); Parallel.ForEach(points, point => { image.SetPixel(viewPort.GetPosition(point), Color.Black); timer.AddWorkDone(1); }); image.Save(imageFilePath); }
public static void RenderAllSpans(string edgeSpansPath, string imageFilePath, bool showDirections) { Log.Info($"Output image: {imageFilePath}"); if (showDirections) { Log.Info("Displaying span directions as well."); } using var spans = EdgeSpanStream.Load(edgeSpansPath); using var timer = TimedOperation.Start("edge spans", totalWork: showDirections?spans.Count * 2 : spans.Count); var scale = showDirections ? 3 : 1; var resolution = spans.ViewPort.Resolution.Scale(scale); var image = new FastImage(resolution); image.Fill(Color.White); Parallel.ForEach(spans, logicalSpan => { if (showDirections) { var scaledLocation = logicalSpan.Location.Scale(scale); for (int yDelta = 0; yDelta < 3; yDelta++) { for (int xDelta = 0; xDelta < 3; xDelta++) { image.SetPixel( scaledLocation.OffsetBy(xDelta, yDelta), (logicalSpan.Location.X + logicalSpan.Location.Y) % 2 == 1 ? Color.Black : Color.Gray); } } } else { image.SetPixel( logicalSpan.Location, Color.Black); } timer.AddWorkDone(1); }); if (showDirections) { Parallel.ForEach(spans, locatedSpan => { var scaledLocation = locatedSpan.Location.Scale(scale); var pointingTo = scaledLocation.OffsetBy(1, 1).OffsetIn(locatedSpan.ToOutside); image.SetPixel( pointingTo, Color.Red); timer.AddWorkDone(1); }); } image.Save(imageFilePath); }
public static void Render(string gridFilePath, string imageFilePath) { Log.Info($"Output image: {imageFilePath}"); using var grid = PointGrid.Load(gridFilePath); using var timer = TimedOperation.Start("points", totalWork: grid.ViewPort.Resolution.Area()); var image = new FastImage(grid.ViewPort.Resolution); image.Fill(Color.White); Parallel.ForEach(grid, row => { foreach (var setSegment in row.GetSegmentsInSet()) { foreach (var x in Enumerable.Range(setSegment.StartCol, setSegment.Length)) { image.SetPixel(x, row.Y, Color.Black); } } timer.AddWorkDone(grid.ViewPort.Resolution.Width); }); image.Save(imageFilePath); }