示例#1
0
        private void ResultFunc(
            IPixelBuffer pixelBuffer,
            RendererData rendererData,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            var incompleteRows = new HashSet <int>();

            for (var y = 0; y < pixelBuffer.Height; y++)
            {
                incompleteRows.Add(y);
            }

            while (incompleteRows.Count > 0)
            {
                queueDataAvailableEvent.WaitOne(TimeSpan.FromMilliseconds(1000));

                while (resultQueue.TryDequeue(out var renderLineResult))
                {
                    foreach (var data in renderLineResult.RowPixels)
                    {
                        rendererData.SetPixelData(data);
                    }
                    // assert pixelArray.Width == renderLineResult.Count
                    pixelBuffer.SetPixelRowColors(renderLineResult.Y, renderLineResult.RowPixels.Select(x => x.Color));
                    incompleteRows.Remove(renderLineResult.Y);

                    var totalRows       = Convert.ToSingle(pixelBuffer.Height);
                    var completeRows    = Convert.ToSingle(pixelBuffer.Height - incompleteRows.Count);
                    var percentComplete = completeRows / totalRows * 100.0f;
                    Console.WriteLine($"Percent Complete: {percentComplete:F}%");
                    Progress?.Invoke(this, new RenderProgressEventArgs(percentComplete));
                }
            }
        }
示例#2
0
        private void ResultFunc(
            IPixelBuffer pixelBuffer,
            RendererData rendererData,
            ConcurrentQueue <RenderResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            try
            {
                var incompletePixels = new HashSet <Tuple <int, int> >();
                for (var y = 0; y < pixelBuffer.Height; y++)
                {
                    for (int x = 0; x < pixelBuffer.Width; x++)
                    {
                        incompletePixels.Add(Tuple.Create(x, y));
                    }
                }

                var totalPixels = Convert.ToSingle(pixelBuffer.Height * pixelBuffer.Width);

                int previousPercent = 0;

                while (incompletePixels.Count > 0)
                {
                    queueDataAvailableEvent.WaitOne(TimeSpan.FromMilliseconds(1000));

                    while (resultQueue.TryDequeue(out var renderResult))
                    {
                        rendererData.SetPixelData(renderResult.PixelData);

                        // assert pixelArray.Width == renderLineResult.Count
                        pixelBuffer.SetPixelColor(renderResult.X, renderResult.Y, renderResult.PixelData.Color);
                        incompletePixels.Remove(Tuple.Create(renderResult.X, renderResult.Y));

                        var completePixels  = Convert.ToSingle(totalPixels - incompletePixels.Count);
                        var percentComplete = completePixels / totalPixels * 100.0f;
                        int intPercent      = Convert.ToInt32(percentComplete);
                        if (intPercent > previousPercent)
                        {
                            previousPercent = intPercent;
                            Console.WriteLine($"Percent Complete: {percentComplete:F}%");
                            Progress?.Invoke(this, new RenderProgressEventArgs(percentComplete));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }