Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            T = ICPTransformation.ComputeTransformation(Shape1, Shape2);
            List <Point> Shape2T = ApplyTransformation(T, Shape2);
            Pen          pBlue   = new Pen(Brushes.Blue, 1);
            Pen          pRed    = new Pen(Brushes.Red, 1);
            Graphics     g       = panel2.CreateGraphics();

            DisplayShape(Shape1, pBlue, g);
            DisplayShape(Shape2T, pRed, g);
            MessageBox.Show("Cost = " + ICPTransformation.ComputeCost(Shape1, Shape2, T).ToString());
        }
Example #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            double[] cost = new double[Shape1.Count];

            for (int i = 0; i < Shape1.Count; i++)
            {
                double xprime = T.A * Shape2[i].X + T.B * Shape2[i].Y + T.T1;
                double yprime = -1 * T.B * Shape2[i].X + T.A * Shape2[i].Y + T.T2;
                cost[i] = (Shape1[i].X - xprime) * (Shape1[i].X - xprime) + (Shape1[i].Y - yprime) * (Shape1[i].Y - yprime);
            }


            int count = (int)(Shape1.Count * 0.8) + 1;

            int[] index = new int[count];

            for (int j = 0; j < count; j++)//remove 20% of the points with the largest errors
            {
                double min = cost.Min();
                index[j]       = cost.ToList().IndexOf(min);
                cost[index[j]] = cost.Max();
            }

            //Sort the indexes in order to NOT show a random shape
            Array.Sort(index);
            for (int i = 0; i < index.Length; i++)
            {
                Shape1Transformed.Add(Shape1[index[i]]);
                Shape2Transformed.Add(Shape2[index[i]]);
            }
            Transformation T2      = ICPTransformation.ComputeTransformation(Shape1Transformed, Shape2Transformed);
            List <Point>   Shape2T = this.ApplyTransformation(T2, Shape2Transformed);
            Pen            pBlue   = new Pen(Brushes.Blue, 1);
            Pen            pRed    = new Pen(Brushes.Red, 1);
            Graphics       g       = panel3.CreateGraphics();

            DisplayShape(Shape1Transformed, pBlue, g);
            DisplayShape(Shape2T, pRed, g);
            MessageBox.Show("Cost = " + ICPTransformation.ComputeCost(Shape1Transformed, Shape2Transformed, T2).ToString());
        }