예제 #1
0
 public static void FindEdgeSpans(
     string pointGridFilePath,
     string outputFilePath)
 {
     using var pointGrid = PointGrid.Load(pointGridFilePath);
     using var timer     = TimedOperation.Start("points", totalWork: pointGrid.ViewPort.Resolution.Height);
     EdgeSpanStream.Write(
         outputFilePath,
         pointGrid.ViewPort,
         pointGrid.ComputationType,
         GetEdgeSpans(pointGrid, timer));
 }
예제 #2
0
    public void ShouldRountTrip()
    {
        using (var tempFile = new TempFile())
        {
            var pointsInSet = new[]
            {
                true,
                true,
                true,
                true,

                false,
                true,
                true,
                false,

                false,
                false,
                true,
                false,

                false,
                false,
                false,
                false,
            };

            PointGrid.Write(
                tempFile.Path,
                new ViewPort(
                    new ComplexArea(new DoubleRange(-1, 1), new DoubleRange(-1, 1)),
                    new Size(4, 4)),
                ComputationType.ScalarFloat,
                pointsInSet);

            using (var pointGrid = PointGrid.Load(tempFile.Path))
            {
                var rows = pointGrid.ToArray();

                for (int rowIndex = 0; rowIndex < 4; rowIndex++)
                {
                    Assert.That(rows[rowIndex].Y, Is.EqualTo(rowIndex), "Wrong row Y position.");
                    Assert.That(
                        rows[rowIndex].ToArray(),
                        Is.EqualTo(pointsInSet.Skip(rowIndex * 4).Take(4).ToArray()),
                        "Did not return correct values for points in set.");
                }
            }
        }
    }
    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);
    }