예제 #1
0
        /// <summary>
        /// Calcula parâmetros da transformação.
        /// </summary>
        private void btnProximo_Click(object sender, EventArgs e)
        {
            PointF[] targetPoints = new PointF[this.pointsList.Count];
            PointF[] sourcePoints = new PointF[this.pointsList.Count];

            Cursor.Current = Cursors.WaitCursor;

            // pontos do sistema de origem
            for (int i = 0; i < this.pointsList.Count; ++i)
            {
                sourcePoints[i] = new PointF((float)this.pointsList[i].X, (float)this.pointsList[i].Y);
            }

            // pontos do sistema de destino
            try
            {
                if (this.pointsList.Count == 6)
                {
                    string[] refPoint = ConfigurationManager.AppSettings["6pt_RefPoint1"].Split(new char[] { ',' });
                    targetPoints[0] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["6pt_RefPoint2"].Split(new char[] { ',' });
                    targetPoints[1] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["6pt_RefPoint3"].Split(new char[] { ',' });
                    targetPoints[2] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["6pt_RefPoint4"].Split(new char[] { ',' });
                    targetPoints[3] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["6pt_RefPoint5"].Split(new char[] { ',' });
                    targetPoints[4] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["6pt_RefPoint6"].Split(new char[] { ',' });
                    targetPoints[5] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));
                }
                else
                {
                    string[] refPoint = ConfigurationManager.AppSettings["12pt_RefPoint1"].Split(new char[] { ',' });
                    targetPoints[0] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint2"].Split(new char[] { ',' });
                    targetPoints[1] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint3"].Split(new char[] { ',' });
                    targetPoints[2] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint4"].Split(new char[] { ',' });
                    targetPoints[3] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint5"].Split(new char[] { ',' });
                    targetPoints[4] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint6"].Split(new char[] { ',' });
                    targetPoints[5] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint7"].Split(new char[] { ',' });
                    targetPoints[6] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint8"].Split(new char[] { ',' });
                    targetPoints[7] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint9"].Split(new char[] { ',' });
                    targetPoints[8] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint        = ConfigurationManager.AppSettings["12pt_RefPoint10"].Split(new char[] { ',' });
                    targetPoints[9] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint         = ConfigurationManager.AppSettings["12pt_RefPoint11"].Split(new char[] { ',' });
                    targetPoints[10] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));

                    refPoint         = ConfigurationManager.AppSettings["12pt_RefPoint12"].Split(new char[] { ',' });
                    targetPoints[11] = new PointF(float.Parse(refPoint[0]), float.Parse(refPoint[1]));
                }
            }
            catch
            {
                MessageBox.Show(this, this.resourceMgr.GetString("MSG0014"), this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
                return;
            }

            // calcula parâmetros da transformação
            try
            {
                if (this.pointsList.Count == 6)
                {
                    MathLib.CalcProjectiveTransfCoeffs6pt(out this.coeffTransf, ref sourcePoints, ref targetPoints);
                }
                else
                {
                    MathLib.CalcProjectiveTransfCoeffs12pt(out this.coeffTransf, ref sourcePoints, ref targetPoints);
                }
            }
            catch
            {
                MessageBox.Show(this, this.resourceMgr.GetString("MSG0015"), this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
                return;
            }

            // modifica cursor
            Cursor.Current = Cursors.Default;

            // retorno
            this.DialogResult = DialogResult.OK;

            // fecha o formulário
            Close();
        }