コード例 #1
0
        public static string GetLogDisplayString(LogDisplayModel logDisplay)
        {
            var array = logDisplay.GetArrayCopy();

            return(JsonConvert.SerializeObject(array, Formatting.Indented, JsonSerializerSettings));
        }
コード例 #2
0
        public static void Estimation(LogDisplayModel display, double minKernelRadius, double maxKernelRadius,
                                      double alpha,
                                      out LogDisplayModel newDisplay)
        {
            Debug.WriteLine($"Estimation START");
            var maxShots = display.Max;
            var avgShots = display.GetAvgShots();
            var array    = display.GetArrayCopy();
            var newArray = new uint[array.GetLength(0), array.GetLength(1), display.ColorCount];
            var width    = display.Width;
            var height   = display.Height;

            Algebra.DividePlane(width, height, Environment.ProcessorCount, out var dic);
            var length = dic.Count;

            const double gamma = 1.0 / 1.1;

            Parallel.For(0, length, i =>
            {
                var d = dic[i];
                for (var y = d[1]; y < d[1] + d[3]; y++)
                {
                    for (var x = d[0]; x < d[0] + d[2]; x++)
                    {
                        var countShots = CountShots(array, x, y);
                        // var kernelWidth = (int) maxKernelRadius;
                        var kernelWidth = 0;

                        if (countShots > 0)
                        {
                            // var density = 1.0 - Math.Pow(Math.Log(countShots + 1.0, maxShots), gamma);
                            //var kernelWidth = GetKernelWidth(density, maxKernelRadius, minKernelRadius, alpha);
                            //var density = maxShots / countShots;
                            //kernelWidth = (int) (maxKernelRadius / Math.Pow(countShots, alpha));


                            var density = 1.0 - Math.Pow(Math.Log(countShots + 1.0, avgShots), gamma);
                            kernelWidth = (int)Math.Round(density * maxKernelRadius);
                            kernelWidth = Math.Max(0, kernelWidth);
                        }

                        if (kernelWidth > 0)
                        {
                            const double weight = 1.2;
                            var kernel          = GetKernel(kernelWidth, weight);
                            var k = K(kernel, array, x, y);
                            Copy(x, y, k, newArray);
                        }
                        else
                        {
                            Copy(x, y, array, newArray);
                        }
                    }
                }
            });

            newDisplay = new LogDisplayModel(newArray, display.BackColor)
            {
                RenderColorMode = display.RenderColorMode
            };
            Debug.WriteLine($"Estimation END");
        }