Do less progress reporting (#15)

This commit is contained in:
Patrick Stevens
2023-05-06 23:52:23 +01:00
committed by GitHub
parent a2d40daef2
commit b2df9db225
4 changed files with 12 additions and 24 deletions

View File

@@ -15,7 +15,6 @@ module Program =
let go (sample : SampleImages) (pngOutput : IFileInfo) (ctx : ProgressContext) =
let renderTask = ctx.AddTask "[green]Generating image[/]"
let writeUnorderedTask = ctx.AddTask "[green]Writing unordered pixels[/]"
let readTask = ctx.AddTask "[green]Reading in serialised pixels[/]"
let writeTask = ctx.AddTask "[green]Writing PPM file[/]"
let logFile =
@@ -35,7 +34,6 @@ module Program =
let maxProgress, image = SampleImages.get sample renderTask.Increment write
renderTask.MaxValue <- maxProgress / 1.0<progress>
writeUnorderedTask.MaxValue <- maxProgress / 1.0<progress>
readTask.MaxValue <- maxProgress / 1.0<progress>
writeTask.MaxValue <- maxProgress / 1.0<progress>
let tempOutput, await =
@@ -46,8 +44,7 @@ module Program =
async {
do! Async.AwaitTask await
let! pixelMap =
ImageOutput.readPixelMap readTask.Increment tempOutput (Image.rowCount image) (Image.colCount image)
let! pixelMap = ImageOutput.readPixelMap tempOutput (Image.rowCount image) (Image.colCount image)
let pixelMap = ImageOutput.assertComplete pixelMap
do! Png.write true writeTask.Increment pixelMap pngOutput

View File

@@ -36,7 +36,7 @@ module TestRayTracing =
async {
do! Async.AwaitTask await
let! pixelMap = ImageOutput.readPixelMap ignore tempOutput (Image.rowCount image) (Image.colCount image)
let! pixelMap = ImageOutput.readPixelMap tempOutput (Image.rowCount image) (Image.colCount image)
let arr = ImageOutput.assertComplete pixelMap
do! ImageOutput.writePpm false ignore arr outputFile
return ()

View File

@@ -1,11 +1,8 @@
namespace RayTracing
open System
open System.Collections.Generic
open System.Collections.Immutable
open System.IO
open System.IO.Abstractions
open System.Text
open System.Threading.Tasks
open SkiaSharp
@@ -68,13 +65,7 @@ module ImageOutput =
toRet
let readPixelMap
(incrementProgress : float<progress> -> unit)
(progress : IFileInfo)
(numRows : int)
(numCols : int)
: Async<Pixel ValueOption[][]>
=
let readPixelMap (progress : IFileInfo) (numRows : int) (numCols : int) : Async<Pixel ValueOption[][]> =
let rec go (dict : _[][]) (reader : Stream) =
let row = consumeAsciiInteger reader
@@ -104,8 +95,6 @@ module ImageOutput =
dict
else
incrementProgress 1.0<progress>
dict.[row].[col] <-
ValueSome
{
@@ -141,7 +130,6 @@ module ImageOutput =
let resume
(incrementProgress : float<progress> -> unit)
(soFar : IReadOnlyDictionary<int * int, Pixel>)
(image : Image)
(fs : IFileSystem)
: IFileInfo * Task<unit>
@@ -164,8 +152,9 @@ module ImageOutput =
outputStream.WriteByte pixel.Red
outputStream.WriteByte pixel.Green
outputStream.WriteByte pixel.Blue
incrementProgress 1.0<progress>
)
incrementProgress 1.0<progress>
)
}
@@ -219,7 +208,7 @@ module ImageOutput =
(fs : IFileSystem)
: IFileInfo * Task<unit>
=
resume progressIncrement ImmutableDictionary.Empty image fs
resume progressIncrement image fs
[<RequireQualifiedAccess>]
module Png =
@@ -246,10 +235,10 @@ module Png =
let colour = PixelOutput.toSkia gammaCorrect pixels.[row].[pixels.[row].Length - 1]
img.SetPixel (pixels.[row].Length - 1, row, colour)
incrementProgress 1.0<progress>
for row = 0 to pixels.Length - 2 do
writeRow row
incrementProgress 1.0<progress>
writeRow (pixels.Length - 1)

View File

@@ -208,7 +208,7 @@ module Scene =
let rowsIter = 2 * maxHeightCoord + 1
let colsIter = 2 * maxWidthCoord + 1
1.0<progress> * float (rowsIter * colsIter),
1.0<progress> * float rowsIter,
{
RowCount = rowsIter
ColCount = colsIter
@@ -219,16 +219,18 @@ module Scene =
let row = maxHeightCoord - row - 1
async {
return
let result =
Array.init
colsIter
(fun col ->
let col = col - maxWidthCoord
let ret = renderPixel print s rand camera maxWidthCoord maxHeightCoord row col
progressIncrement 1.0<progress>
ret
)
progressIncrement 1.0<progress>
return result
}
)
}