/// <summary> /// Plots and draws the sealing slabs. /// </summary> /// <param name="plotter">The plotter.</param> /// <param name="drawer">The drawer.</param> /// <param name="calculation">The calculation.</param> /// <param name="iteration">The iteration.</param> /// <param name="freeToTotalPixelRatioPercent">The free to total pixel ratio percent.</param> /// <param name="sealingSlabs">The sealing slabs.</param> private void PlotAndDraw(IPlotter plotter, BitBresenhamDrawer drawer, Calculation calculation, int iteration, out double freeToTotalPixelRatioPercent, out List <SealingSlab> sealingSlabs) { // Instantiate for each loop instead of initially, otherwise the memory will be exhausted. var grid = new BitGrid(calculation.WidthPixels, calculation.HeightPixels); sealingSlabs = plotter.PlotSealingSlabs <SealingSlab>().ToList(); // Only save sealing slabs that were drawn. sealingSlabs = calculationService.DrawSealingSlabs(drawer, grid, sealingSlabs); foreach (var sealingSlab in sealingSlabs) { sealingSlab.CalculationId = calculation.Id; sealingSlab.Iteration = iteration + 1; } // Save in percent. freeToTotalPixelRatioPercent = grid.FreeToTotalPixelRatioPercent; }
/// <summary> /// Gets the estimated seconds. /// </summary> /// <param name="plotter">The plotter.</param> /// <param name="calculation">The calculation.</param> /// <param name="circleChunkSize">Size of the circle chunk.</param> /// <returns></returns> private double GetEstimatedSeconds(IPlotter plotter, Calculation calculation, int circleChunkSize) { // Plot one iteration to have an estimation of sealing slab count double freeToTotalPixelRatioPercent; List <SealingSlab> sealingSlabs; var drawer = new BitBresenhamDrawer(); PlotAndDraw(plotter, drawer, calculation, 1, out freeToTotalPixelRatioPercent, out sealingSlabs); int sealingSlabCount = sealingSlabs.Count(); int averageSealingSlabCount = sealingSlabCount * calculation.Iterations; // Not all iterations sealing slabs have to be saved and some may have already been saved. int maxIteration = sealingSlabDepot.GetMaxIteration(calculation.Id); int saveSealingSlabCount = sealingSlabCount * (App.Config.SaveIterationsCount - maxIteration); return(estimationService.CalculateEstimatedTimeInSeconds(calculation.SealingSlabRadiusPixels, averageSealingSlabCount, saveSealingSlabCount, circleChunkSize)); }
/// <summary> /// Calculates the unset area. /// </summary> /// <param name="calculation">The calculation.</param> /// <param name="plotter">The plotter.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private UnsetAreaResult CalculateUnsetArea(Calculation calculation, IPlotter plotter, CancellationToken cancellationToken) { var drawer = new BitBresenhamDrawer(); double[] freeToTotalPixelRatios = new double[calculation.Iterations]; var iterationSealingSlabs = new List <SealingSlab> [calculation.Iterations]; Parallel.For(0, calculation.Iterations, (i) => { cancellationToken.ThrowIfCancellationRequested(); double freeToTotalPixelRatioPercent; List <SealingSlab> sealingSlabs; PlotAndDraw(plotter, drawer, calculation, i, out freeToTotalPixelRatioPercent, out sealingSlabs); freeToTotalPixelRatios[i] = freeToTotalPixelRatioPercent; iterationSealingSlabs[i] = sealingSlabs; }); return(new UnsetAreaResult(iterationSealingSlabs, freeToTotalPixelRatios)); }