Beispiel #1
0
        private void recalculateFieldsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string dir = FolderBrowser("Select folder with metadata txt for recalculation");

            if (dir == null)
            {
                return;
            }

            //find all .txt files in the directory
            List <string> dirs = FileDecoder.TakeFileNames(dir);

            //System.Windows.Forms.MessageBox.Show(string.Join("\n", dirs));
            data.fileNames = dirs.ToArray();

            //find all strings with "Move XY"
            string[] cornerInfo = FileDecoder.readFields(dirs);
            //System.Windows.Forms.MessageBox.Show(string.Join("\n", cornerInfo));

            //calculate points
            data.dataPoint = CornerReader.CalculatePoints(cornerInfo);

            if (data.dataPoint == null || data.afterPoint == null ||
                data.beforePoint == null)
            {
                return;
            }

            //Load data

            FieldCalculation.RecalculateFields(data);
            //save data
            dataForm.Hide();
            dataForm.Show();
        }
Beispiel #2
0
        private void loadCornersAfterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string dir = FolderBrowser("Select folder with metadata txt - after");

            if (dir == null)
            {
                return;
            }

            //find all .txt files in the directory
            List <string> dirs = FileDecoder.TakeFileNames(dir);

            //System.Windows.Forms.MessageBox.Show(string.Join("\n", dirs));

            //find all strings with "Move XY"
            string[] cornerInfo = FileDecoder.readCorners(dirs);
            //System.Windows.Forms.MessageBox.Show(string.Join("\n", cornerInfo));

            //calculate points
            data.afterPoint = CornerReader.ReorderPoints(CornerReader.CalculatePoints(cornerInfo));

            if (data.afterPoint == null)
            {
                return;
            }
            //Load data
            nX1.Text = "X: " + data.afterPoint[0].X.ToString();
            nX2.Text = "X: " + data.afterPoint[1].X.ToString();
            nX3.Text = "X: " + data.afterPoint[2].X.ToString();
            nX4.Text = "X: " + data.afterPoint[3].X.ToString();

            nY1.Text = "Y: " + data.afterPoint[0].Y.ToString();
            nY2.Text = "Y: " + data.afterPoint[1].Y.ToString();
            nY3.Text = "Y: " + data.afterPoint[2].Y.ToString();
            nY4.Text = "Y: " + data.afterPoint[3].Y.ToString();

            FieldCalculation.FindCompensations(data);

            translationX.Text = "X: " + data.dX.ToString();
            translationY.Text = "Y: " + data.dY.ToString();
            rotAngle.Text     = (-data.angle * (180 / Math.PI)).ToString() + "°";
        }
        public static void RecalculateFields(DataStorage data)
        {
            PointF befMid = CornerReader.CenterOfMass(data.beforePoint);
            PointF aftMid = CornerReader.CenterOfMass(data.afterPoint);

            double angle = -data.angle; // (Math.PI / 180);
            double sin   = Math.Sin(angle);
            double cos   = Math.Cos(angle);

            string[][] store = new string[data.dataPoint.Length + 1][];
            store[0]    = new string[5];
            store[0][0] = "Field name";
            store[0][1] = "Old X";
            store[0][2] = "Old Y";
            store[0][3] = "New X";
            store[0][4] = "New Y";

            PointF p = Point.Empty;

            for (int i = 0, row = 1; i < data.dataPoint.Length; i++, row++)
            {
                store[row] = new string[5];
                p          = data.dataPoint[i];

                string name = data.fileNames[i];
                store[row][0] = name.Substring(name.LastIndexOf("\\") + 1, name.Length - name.LastIndexOf("\\") - 5).Replace("Cerry", "").Replace("GFP", "");
                store[row][1] = p.X.ToString();
                store[row][2] = p.Y.ToString();

                p             = RecalculatePoint(p, sin, cos, befMid, aftMid);
                store[row][3] = p.X.ToString();
                store[row][4] = p.Y.ToString();
            }

            data.store = store;
        }
        public static void FindCompensations(DataStorage data)
        {
            data.dX    = 0f;
            data.dY    = 0f;
            data.angle = 0f;

            if (data.afterPoint == null || data.beforePoint == null)
            {
                return;
            }

            //calculate center of mass for the two times
            PointF befMid = CornerReader.CenterOfMass(data.beforePoint);
            PointF aftMid = CornerReader.CenterOfMass(data.afterPoint);

            //apply info to the data storage
            data.dX = befMid.X - aftMid.X;
            data.dY = befMid.Y - aftMid.Y;
            // move the center of mass to Cxy(0,0)
            PointF befP = new PointF(data.beforePoint[3].X, data.beforePoint[3].Y);

            befP.X -= befMid.X;
            befP.Y -= befMid.Y;

            PointF aftP = new PointF(data.afterPoint[3].X, data.afterPoint[3].Y);

            aftP.X -= aftMid.X;
            aftP.Y -= aftMid.Y;

            double befAngl = Math.Atan(befP.Y / befP.X);
            double aftAngl = Math.Atan(aftP.Y / aftP.X);

            //System.Windows.Forms.MessageBox.Show(befP.X + "\n" + befP.Y + "\n" + befAngl);
            //System.Windows.Forms.MessageBox.Show(aftP.X + "\n" + aftP.Y + "\n" + aftAngl);
            data.angle = befAngl - aftAngl;
        }