static DetectorPoint MaxPoint(int[,] array)
        {
            GetWidthAndHeight(array, out var width, out var height);
            var point = new DetectorPoint(0, 0);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (array[x, y] > array[point.X, point.Y])
                    {
                        point = new DetectorPoint(x, y);
                    }
                }
            }
            return(point);
        }
        static DetectorPoint GetBiggestNeighbor(int[,] array, int x, int y)
        {
            var           points  = GetNeighbors(array, x, y);
            var           current = int.MinValue;
            DetectorPoint output  = new DetectorPoint(-1, -1);

            foreach (var p in points)
            {
                if (array[p.X, p.Y] > current)
                {
                    output = new DetectorPoint(p.X, p.Y);
                }
            }

            if (output.X == -1 || output.Y == -1)
            {
                throw new ArgumentException("Well that was unexpected. Egregious internal error.");
            }
            return(output);
        }
Exemple #3
0
        public void ReadDetectorPlane(string fileName)
        {
            var lines = File.ReadLines(fileName);

            m_Points = new List <DetectorPoint>();

            try
            {
                var    ScAngle = lines.ElementAt(1).Split('\t')[2];
                double phi     = Double.Parse(ScAngle);

                var    CoordLine = lines.ElementAt(2).Replace(";", "").Replace("\t", "").Replace(" ", "").Replace("]", "").Replace("[", "").Split('=')[1].Split(',');
                double cx        = Double.Parse(CoordLine[0]);
                double cy        = Double.Parse(CoordLine[1]);
                double cz        = Double.Parse(CoordLine[2]);

                var    NormalLine = lines.ElementAt(3).Replace(";", "").Replace("\t", "").Replace(" ", "").Replace("]", "").Replace("[", "").Split('=')[1].Split(',');
                double ncx        = Double.Parse(NormalLine[0]);
                double ncy        = Double.Parse(NormalLine[1]);
                double ncz        = Double.Parse(NormalLine[2]);

                phi *= Math.PI / 180.0;
                phi  = (Math.PI / 2.0 - phi);

                if (cx > 0.0)
                {
                    phi = -phi;
                }

                Func <DetectorPoint, double, DetectorPoint> Rotate = (p, angle) => {
                    var wx  = p.x;
                    var wy  = p.y;
                    var dwx = wx * Math.Cos(angle) - wy * Math.Sin(angle);
                    var dwy = wx * Math.Sin(angle) + wy * Math.Cos(angle);
                    p.x = -dwx;
                    p.y = dwy;
                    return(p);
                };

                m_Points = new List <DetectorPoint>();
                foreach (var line in lines.Skip(6))
                {
                    var           coords = line.Split('\t');
                    DetectorPoint cp     = new DetectorPoint()
                    {
                        x      = double.Parse(coords[0]) - cx,
                        y      = double.Parse(coords[1]) - cy,
                        z      = double.Parse(coords[2]) - cz,
                        lambda = double.Parse(coords[3]),
                    };

                    m_Points.Add(Rotate(cp, phi));
                }

                MaxDetectorPositionMer = 30;  // Math.Round(m_Points.Max(x => x.x) * 1.2, 3);
                MinDetectorPositionMer = -30; // Math.Round(m_Points.Min(x => x.x) * 1.2, 3);

                MeredionalMax = MaxDetectorPositionMer;
                MeredionalMin = MinDetectorPositionMer;

                MaxDetectorPositionSag = 5;  // Math.Round(m_Points.Max(x => x.z) * 1.2, 3);
                MinDetectorPositionSag = -5; // Math.Round(m_Points.Min(x => x.z) * 1.2, 3);

                SaggitalMax = MaxDetectorPositionSag;
                SaggitalMin = MinDetectorPositionSag;

                isReady = true;
            }
            catch (Exception e)
            {
                Logger.Error(e.ToString());
                return;
            }
        }