예제 #1
0
        /// <summary>
        /// Calculates the overall color at a specific location.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="x">The location x.</param>
        /// <param name="radius">The analyzation radius.</param>
        /// <param name="quality">The quality (higher is better).</param>
        /// <returns>The overall color at a specific location.</returns>
        private static RgbColor CalculateColorAt(MultislitConfiguration configuration, double x, double radius, int quality)
        {
            RgbColor result = new RgbColor(0, 0, 0);

            foreach (WavelengthColorPair light in configuration.LightSources)
            {
                result = result + (light.Color * MultiSlitIntensityCalculator.CalculateIntensity(light.Wavelength, configuration.Slits, x, radius, quality));
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Calculates the vertical brightness distribution.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="height">The screen height.</param>
        /// <returns>The vertical brightness distribution.</returns>
        private static double[] CalculateYBrightnessDistribution(MultislitConfiguration configuration, int height)
        {
            double[] brightnessFactors = new double[height];
            for (int iy = 0; iy < height; iy++)
            {
                double y = (iy - height * 0.5) / configuration.Scale;

                //This formula actually has no scientific base but it is damn close to the reality
                double brightness = (10 / Math.Pow(1.25, Math.Abs(y / 2.5)));

                brightnessFactors[iy] = brightness;
            }

            return(brightnessFactors);
        }
예제 #3
0
        public static Bitmap RenderHighRes(MultislitConfiguration configuration, Size size, ProgressProvider progress)
        {
            double[] yBrightnessFactors = MultislitRenderer.CalculateYBrightnessDistribution(configuration, size.Height);

            using (FastBitmap target = new FastBitmap(size, Color.FromArgb(10, 10, 10)))
            {
                int    chunkSize      = 10;
                int    finishedChunks = 0;
                double chunkFactor    = ((double)chunkSize / size.Width);
                if (configuration.LightSources.Any())
                {
                    Parallel.For(0, (int)Math.Ceiling(size.Width / (double)chunkSize), i =>
                    {
                        for (int ix = i * chunkSize; ix < Math.Min(i * chunkSize + chunkSize, size.Width); ix++)
                        {
                            double x        = (ix - size.Width * 0.5) / configuration.Scale;
                            RgbColor xColor = configuration.Brightness * MultislitRenderer.CalculateColorAt(configuration, x, 1, 250);

                            for (int iy = 0; iy < size.Height; iy++)
                            {
                                if (target == null || target.IsDisposed)
                                {
                                    return;
                                }

                                if (configuration.DisplayDistribution)
                                {
                                    target[ix, iy] = xColor;
                                }
                                else
                                {
                                    target[ix, iy] = yBrightnessFactors[iy] * xColor;
                                }
                            }
                        }

                        finishedChunks++;
                        progress.Progress = chunkFactor * finishedChunks;
                    });
                }

                return((Bitmap)target.InternalBitmap.Clone());
            }
        }
예제 #4
0
 /// <summary>
 /// Renders an image of the specified multislit configuration.
 /// </summary>
 /// <param name="configuration">The multislit configuration.</param>
 /// <param name="size">The image size.</param>
 /// <returns>A rendering of the specified multislit configuration</returns>
 public static Bitmap Render(MultislitConfiguration configuration, Size size)
 {
     return(MultislitRenderer.Render(configuration, size, 1));
 }