Esempio n. 1
0
        public Point?Transform(Point point)
        {
            Polygon2D container  = null;
            int       polygonRow = -1;
            int       polygonCol = -1;

            for (int i = 0; i < m_rows - 1; i++)
            {
                bool done = false;
                for (int j = 0; j < m_cols - 1; j++)
                {
                    if (m_polygons[i, j].IsInside(point))
                    {
                        container = m_polygons[i, j];

                        polygonRow = i;
                        polygonCol = j;

                        done = true;
                        break;
                    }
                }

                if (done)
                {
                    break;
                }
            }

            if (container != null)
            {
                MatrixH homography = m_homographies[container];
                if (homography != null)
                {
                    System.Drawing.PointF originalPt = new System.Drawing.PointF((float)point.X, (float)point.Y);
                    System.Drawing.PointF tempPt     = homography.TransformPoints(originalPt)[0];

                    Point transformedPt = new Point(tempPt.X, tempPt.Y);

                    if (Constants.DebugPrint)
                    {
                        Debug.WriteLine(point + " -> " + transformedPt);
                    }

                    if (m_direction == ModelDirection.Portrait)
                    {
                        transformedPt = new Point(transformedPt.Y, 1.0 - transformedPt.X);
                    }

                    return(transformedPt);
                }
            }

            if (Constants.DebugPrint)
            {
                Debug.WriteLine(point + ": (" + polygonRow + ", " + polygonCol + ")");
            }

            return(null);
        }
Esempio n. 2
0
        public void MultiplyTest()
        {
            MatrixH matrix = new MatrixH(Matrix.Identity(3));

            PointH[] points = new PointH[]
            {
                new PointH(1, 2),
                new PointH(5, 2),
                new PointH(12, 2),
                new PointH(1, 2),
                new PointH(10, 2),
            };


            PointH[] expected = new PointH[]
            {
                new PointH(1, 2),
                new PointH(5, 2),
                new PointH(12, 2),
                new PointH(1, 2),
                new PointH(10, 2),
            };

            PointH[] actual = (PointH[])points.Clone();
            matrix.TransformPoints(actual);

            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
            Assert.AreEqual(expected[3], actual[3]);
            Assert.AreEqual(expected[4], actual[4]);
        }
Esempio n. 3
0
        // Compute inliers using the Symmetric Transfer Error,
        private int[] distance(MatrixH H, double t)
        {
            int n = pointSet1.Length;

            // Compute the projections (both directions)
            PointF[] p1 = H.TransformPoints(pointSet1);
            PointF[] p2 = H.Inverse().TransformPoints(pointSet2);

            // Compute the distances
            double[] d2 = new double[n];
            for (int i = 0; i < n; i++)
            {
                // Compute the distance as
                float ax = pointSet1[i].X - p2[i].X;
                float ay = pointSet1[i].Y - p2[i].Y;
                float bx = pointSet2[i].X - p1[i].X;
                float by = pointSet2[i].Y - p1[i].Y;
                d2[i] = (ax * ax) + (ay * ay) + (bx * bx) + (by * by);
            }

            // Find and return the inliers
            return(Matrix.Find(d2, z => z < t));
        }