Beispiel #1
0
 public Calculations()
 {
     _matrix = new Matrix<Cell>(matrixSize, matrixSize);
     for (var i = 0; i < matrixSize; i++)
     {
         for (var j = 0; j < matrixSize; j++)
         {
             _matrix[i, j] = new Cell();
         }
     }
 }
Beispiel #2
0
        public void Dispose()
        {
            if (_log.IsEmpty())
            {
                return;
            }
            else
            {
                var sample = _log.First();
                var mins = new Matrix<Cell>(sample.Height, sample.Width);
                var maxes = new Matrix<Cell>(sample.Height, sample.Width);

                var gmin = new Cell();
                var gmax = new Cell();
                for (var i = 0; i < sample.Height; ++i)
                {
                    for (var j = 0; j < sample.Width; ++j)
                    {
                        var min_tau = _log.Select(m => Math.Abs(m[i, j].Tau)).Where(val => val > 0).MinOrDefault();
                        var min_ux = _log.Select(m => Math.Abs(m[i, j].Ux)).Where(val => val > 0).MinOrDefault();
                        var min_uz = _log.Select(m => Math.Abs(m[i, j].Uz)).Where(val => val > 0).MinOrDefault();
                        var min = new Cell { Tau = min_tau, Ux = min_ux, Uz = min_uz };
                        mins[i, j] = min;

                        Func<float, float, float> minof = (v1, v2) => v1 == 0 ? v2 : v2 == 0 ? v1 : Math.Min(v1, v2);
                        gmin.Tau = minof(min_tau, gmin.Tau);
                        gmin.Ux = minof(min_ux, gmin.Ux);
                        gmin.Uz = minof(min_uz, gmin.Uz);

                        var max_tau = _log.Select(m => Math.Abs(m[i, j].Tau)).Where(val => val > 0).MaxOrDefault();
                        var max_ux = _log.Select(m => Math.Abs(m[i, j].Ux)).Where(val => val > 0).MaxOrDefault();
                        var max_uz = _log.Select(m => Math.Abs(m[i, j].Uz)).Where(val => val > 0).MaxOrDefault();
                        var max = new Cell { Tau = max_tau, Ux = max_ux, Uz = max_uz };
                        maxes[i, j] = max;

                        Func<float, float, float> maxof = (v1, v2) => v1 == 0 ? v2 : v2 == 0 ? v1 : Math.Max(v1, v2);
                        gmax.Tau = maxof(max_tau, gmax.Tau);
                        gmax.Ux = maxof(max_ux, gmax.Ux);
                        gmax.Uz = maxof(max_uz, gmax.Uz);
                    }
                }

                if (Directory.Exists(PathToTau)) Directory.Delete(PathToTau, true);
                if (Directory.Exists(PathToUx)) Directory.Delete(PathToUx, true);
                if (Directory.Exists(PathToUz)) Directory.Delete(PathToUz, true);
                Directory.CreateDirectory(PathToTau);
                Directory.CreateDirectory(PathToUx);
                Directory.CreateDirectory(PathToUz);

                var index = 0;
                foreach (var entry in _log)
                {
                    var tauBmp = new Bitmap(entry.Width, entry.Height);
                    var uxBmp = new Bitmap(entry.Width, entry.Height);
                    var uzBmp = new Bitmap(entry.Width, entry.Height);

                    for (var i = 0; i < entry.Height; ++i)
                    {
                        for (var j = 0; j < entry.Height; ++j)
                        {
                            var tauci = Rank(entry[i, j].Tau, gmax.Tau, Palette.Count);
                            var uxci = Rank(entry[i, j].Ux, gmax.Ux, Palette.Count);
                            var uzci = Rank(entry[i, j].Uz, gmax.Uz, Palette.Count);

                            tauBmp.SetPixel(j, i, Palette.ElementAt(tauci));
                            uxBmp.SetPixel(j, i, Palette.ElementAt(uxci));
                            uzBmp.SetPixel(j, i, Palette.ElementAt(uzci));
                        }
                    }

                    tauBmp.Save(PathToTau + index.ToString("0000") + ".bmp");
                    uxBmp.Save(PathToUx + index.ToString("0000") + ".bmp");
                    uzBmp.Save(PathToUz + index.ToString("0000") + ".bmp");

                    index++;
                }
            }
        }