Ejemplo n.º 1
0
        public void Plot()
        {
            _log.InfoFormat("Plotting image ({0:N0}x{1:N0})", _resolution.Width, _resolution.Height);
            _log.DebugFormat("Iterating {0:N0} times per point", _bailout);

            var viewPort = AreaFactory.RenderingArea;

            viewPort.LogViewport();

            var rotatedResolution = new Size(_resolution.Height, _resolution.Width);

            _log.Info("Calculating trajectories");

            var processedCount = 0;

            Parallel.ForEach(GetNumbers(), new ParallelOptions {
                MaxDegreeOfParallelism = GlobalArguments.DegreesOfParallelism
            }, number =>
            {
                foreach (var c in GetTrajectory(number))
                {
                    var point = viewPort.GetPointFromNumber(rotatedResolution, c).Rotate();

                    if (!_resolution.IsInside(point))
                    {
                        continue;
                    }

                    _hitPlot.IncrementPoint(point);
                }

                Interlocked.Increment(ref processedCount);
                if (processedCount % 1000 == 0)
                {
                    _log.DebugFormat("Plotted {0:N0} points' trajectories", processedCount);
                }
            });
            _log.DebugFormat("Plotted {0:N0} points' trajectories", processedCount);

            _log.Info("Done plotting trajectories");
            _log.DebugFormat("Maximum point hit count: {0:N0}", _hitPlot.Max());

            _hitPlot.SaveTrajectories(Path.Combine(_outputDirectory, _outputFilename));

            _log.DebugFormat("Saved plot as: {0}", _outputFilename);
        }
Ejemplo n.º 2
0
        public void Render(string outputDirectory, string outputFilename)
        {
            _log.Info("Loading trajectories...");

            _hitPlotRed.LoadTrajectories(Path.Combine(_inputInputDirectory, _inputFilenameRed));
            _hitPlotGreen.LoadTrajectories(Path.Combine(_inputInputDirectory, _inputFilenameGreen));
            _hitPlotBlue.LoadTrajectories(Path.Combine(_inputInputDirectory, _inputFilenameBlue));

            _log.Info("Done loading; finding maximums...");

            var maxRed   = _hitPlotRed.Max();
            var maxGreen = _hitPlotGreen.Max();
            var maxBlue  = _hitPlotBlue.Max();

            _log.DebugFormat("Found maximum red: {0:N0}", maxRed);
            _log.DebugFormat("Found maximum green: {0:N0}", maxGreen);
            _log.DebugFormat("Found maximum blue: {0:N0}", maxBlue);

            _log.Info("Starting to render");

            var outputImg = new Bitmap(_resolution.Width, _resolution.Height);

            var processedPixels =
                _resolution
                .GetAllPoints()
                .AsParallel()
                .WithDegreeOfParallelism(GlobalArguments.DegreesOfParallelism)
                .Select(p => ComputeColor(p, maxRed, maxGreen, maxBlue))
                .AsEnumerable();

            foreach (var result in processedPixels)
            {
                outputImg.SetPixel(result.Item1.X, result.Item1.Y, result.Item2);
            }

            _log.Info("Finished rendering");

            _log.Debug("Saving image");
            outputImg.Save(Path.Combine(outputDirectory, String.Format("{0}.png", outputFilename)));
            _log.Debug("Done saving image");
        }
Ejemplo n.º 3
0
        public void Render(string outputDirectory, string outputFilename, ColorRamp colorRamp)
        {
            _log.InfoFormat("Creating image ({0:N0}x{1:N0})", _resolution.Width, _resolution.Height);

            _log.Info("Loading trajectory...");

            _hitPlot.LoadTrajectories(Path.Combine(_inputInputDirectory, _inputFilename));

            _log.Info("Done loading; finding maximum...");

            var max = _hitPlot.Max();

            _log.DebugFormat("Found maximum: {0:N0}", max);

            _log.Info("Starting to render");

            var outputImg = new Bitmap(_resolution.Width, _resolution.Height);

            var processedPixels =
                _resolution
                .GetAllPoints()
                .AsParallel()
                .WithDegreeOfParallelism(GlobalArguments.DegreesOfParallelism)
                .Select(p => ComputeColor(p, max, colorRamp))
                .AsEnumerable();

            foreach (var result in processedPixels)
            {
                outputImg.SetPixel(result.Item1.X, result.Item1.Y, result.Item2);
            }

            _log.Info("Finished rendering");

            _log.Debug("Saving image");
            outputImg.Save(Path.Combine(outputDirectory, String.Format("{0}.png", outputFilename)));
            _log.Debug("Done saving image");
        }