private bool UpdateTriangles(Triangle tRight, Triangle tLeft, Section commonSection, List <Triangle> tmpResult, Graphics g = null, Pen linePen = null, Pen pointPen = null, Pen newLinePen = null, int formHeight = 0, int delay = 0)
        {
            //меняем общее ребро у двух треугольников
            Point leftExcessPoint  = TriangulationBuilder.GetExcessPoint(tLeft, commonSection);
            Point rightExcessPoint = TriangulationBuilder.GetExcessPoint(tRight, commonSection);

            if (commonSection.CountAnglesSum(leftExcessPoint) + commonSection.CountAnglesSum(rightExcessPoint) < 180)
            {
                Point up   = commonSection.A;
                Point down = commonSection.B;
                if (new Vector(down, rightExcessPoint).GetVectorMultiplication(new Vector(down, leftExcessPoint)) < 0)
                {
                    up   = commonSection.B;
                    down = commonSection.A;
                }

                tmpResult.Remove(tLeft);
                tmpResult.Remove(tRight);
                Triangle toAddFirst  = new Triangle(leftExcessPoint, down, rightExcessPoint);
                Triangle toAddSecond = new Triangle(rightExcessPoint, up, leftExcessPoint);
                tmpResult.Add(toAddFirst);
                tmpResult.Add(toAddSecond);

                if (g != null && linePen != null && newLinePen != null && formHeight != -1 && delay != -1)
                {
                    g.DrawLine(new Pen(Color.White, 2), (int)commonSection.A.X, formHeight - (int)commonSection.A.Y,
                               (int)commonSection.B.X, formHeight - (int)commonSection.B.Y);
                    g.DrawLine(newLinePen, (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y);

                    Thread.Sleep(delay);

                    g.DrawLine(new Pen(Color.White, 2), (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y);
                    g.DrawLine(linePen, (int)leftExcessPoint.X, formHeight - (int)leftExcessPoint.Y, (int)rightExcessPoint.X, formHeight - (int)rightExcessPoint.Y);

                    toAddFirst.Paint(g, linePen, pointPen, formHeight);
                    toAddSecond.Paint(g, linePen, pointPen, formHeight);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void MatchButtonClick(object sender, EventArgs e)
        {
            List <Minutia> minutiasFrom = GetMinutiasFrom(ImageFrom);

            MessageBox.Show("Found " + minutiasFrom.Count + " minutias in left picture.");

            List <Classes.Point> pointsFrom        = new List <Classes.Point>();
            Graphics             ImageFromGraphics = ImageFrom.CreateGraphics();

            foreach (Minutia m in minutiasFrom)
            {
                Classes.Point p = new Classes.Point(m.X, ImageFrom.Height - m.Y + 1);
                p.Paint(ImageFromGraphics, defPointPen, ImageFrom.Height);
                pointsFrom.Add(p);
            }

            if (minutiasFrom.Count > 500)
            {
                string            messageBoxText = "Do you really want to continue?\n You'll just waste your time...";
                string            caption        = "Too many minutuias";
                MessageBoxButtons mb             = MessageBoxButtons.OKCancel;
                if (MessageBox.Show(messageBoxText, caption, mb) == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
            }

            Classes.TriangulationBuilder tb = new Classes.TriangulationBuilder(pointsFrom);
            MessageBox.Show("Triangulation built! It has: " + tb.triangles.Count + " triangles.");

            List <Classes.Triangle> triangulationFrom = tb.triangles;

            foreach (Classes.Triangle t in tb.triangles)
            {
                t.Paint(ImageFromGraphics, defLinePen, defPointPen, ImageFrom.Height);
            }

            List <Minutia> minutiasTo = GetMinutiasFrom(ImageTo);

            MessageBox.Show("Found " + minutiasTo.Count + " minutias in right picture");

            List <Classes.Point> pointsTo = new List <Classes.Point>();


            Graphics ImageToGraphics = ImageTo.CreateGraphics();

            foreach (Minutia m in minutiasTo)
            {
                Classes.Point p = new Classes.Point(m.X, ImageTo.Height - m.Y + 1);
                p.Paint(ImageToGraphics, defPointPen, ImageTo.Height);
                pointsTo.Add(p);
            }

            if (minutiasTo.Count > 500)
            {
                string            messageBoxText = "Do you really want to continue?\n You'll just waste your time...";
                string            caption        = "Too many minutuias";
                MessageBoxButtons mb             = MessageBoxButtons.OKCancel;
                if (MessageBox.Show(messageBoxText, caption, mb) == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
            }

            Classes.TriangulationBuilder tbTo;
            if (minutiasTo.Count < 500)
            {
                tbTo = new Classes.TriangulationBuilder(pointsTo);
            }
            else
            {
                tbTo = new Classes.TriangulationBuilder(pointsTo, ImageToGraphics, defLinePen, defPointPen, new Pen(Color.Gold, 1), ImageTo.Height, 0);
            }

            MessageBox.Show("Triangulation built! It has: " + tbTo.triangles.Count + " triangles.");

            List <Classes.Triangle> triangulationTo = tbTo.triangles;

            foreach (Classes.Triangle t in tbTo.triangles)
            {
                t.Paint(ImageToGraphics, defLinePen, defPointPen, ImageFrom.Height);
            }

            Classes.TriangulationsMatcher tm = new Classes.TriangulationsMatcher(triangulationFrom, triangulationTo);
            double[] result = tm.Match(0.001, 90);
            MessageBox.Show("Equals: " + result[0] + ", very close:" + result[1]);
        }
Ejemplo n.º 3
0
        private void MatchButtonClick(object sender, EventArgs e)
        {
            List<Minutia> minutiasFrom = GetMinutiasFrom(ImageFrom);

            MessageBox.Show("Found " + minutiasFrom.Count + " minutias in left picture.");

            List<Classes.Point> pointsFrom = new List<Classes.Point>();
            Graphics ImageFromGraphics = ImageFrom.CreateGraphics();
            foreach (Minutia m in minutiasFrom)
            {
                Classes.Point p = new Classes.Point(m.X, ImageFrom.Height - m.Y+1);
                p.Paint(ImageFromGraphics, defPointPen, ImageFrom.Height);
                pointsFrom.Add(p);
            }

            if (minutiasFrom.Count > 500)
            {
                string messageBoxText = "Do you really want to continue?\n You'll just waste your time...";
                string caption = "Too many minutuias";
                MessageBoxButtons mb = MessageBoxButtons.OKCancel;
                if (MessageBox.Show(messageBoxText, caption, mb) == System.Windows.Forms.DialogResult.Cancel)
                    return;
            }

            Classes.TriangulationBuilder tb = new Classes.TriangulationBuilder(pointsFrom);
            MessageBox.Show("Triangulation built! It has: "+tb.triangles.Count+" triangles.");

            List<Classes.Triangle> triangulationFrom = tb.triangles;
            foreach (Classes.Triangle t in tb.triangles) {
                t.Paint(ImageFromGraphics, defLinePen, defPointPen, ImageFrom.Height);
            }

            List<Minutia> minutiasTo = GetMinutiasFrom(ImageTo);

            MessageBox.Show("Found " + minutiasTo.Count + " minutias in right picture");

            List<Classes.Point> pointsTo = new List<Classes.Point>();

            Graphics ImageToGraphics = ImageTo.CreateGraphics();
            foreach (Minutia m in minutiasTo)
            {
                Classes.Point p = new Classes.Point(m.X, ImageTo.Height - m.Y+1);
                p.Paint(ImageToGraphics, defPointPen, ImageTo.Height);
                pointsTo.Add(p);
            }

            if (minutiasTo.Count > 500)
            {
                string messageBoxText = "Do you really want to continue?\n You'll just waste your time...";
                string caption = "Too many minutuias";
                MessageBoxButtons mb = MessageBoxButtons.OKCancel;
                if (MessageBox.Show(messageBoxText, caption, mb) == System.Windows.Forms.DialogResult.Cancel)
                    return;
            }

            Classes.TriangulationBuilder tbTo;
            if (minutiasTo.Count < 500)
                tbTo = new Classes.TriangulationBuilder(pointsTo);
            else
                tbTo = new Classes.TriangulationBuilder(pointsTo, ImageToGraphics, defLinePen, defPointPen, new Pen(Color.Gold, 1), ImageTo.Height, 0);

            MessageBox.Show("Triangulation built! It has: " + tbTo.triangles.Count + " triangles.");

            List<Classes.Triangle> triangulationTo = tbTo.triangles;
            foreach (Classes.Triangle t in tbTo.triangles)
            {
                t.Paint(ImageToGraphics, defLinePen, defPointPen, ImageFrom.Height);
            }

            Classes.TriangulationsMatcher tm = new Classes.TriangulationsMatcher(triangulationFrom, triangulationTo);
            double[] result = tm.Match(0.001,90);
            MessageBox.Show("Equals: " + result[0] + ", very close:" + result[1]);
        }