Example #1
0
        /// <summary>
        /// Takes a circle in image space and returns a cooresponding ellipse in image space.
        /// This is an ill posed problem. The center is respected but the radius could be taken
        /// anywhere around the circle in image space, and that yields different radii in world space.
        /// We use the point along the X axis as the radius.
        /// </summary>
        public Ellipse GetEllipseFromCircle(PointF center, float radius, out PointF radiusLeftInImage, out PointF radiusRightInImage)
        {
            radiusLeftInImage  = new PointF(center.X - radius, center.Y);
            radiusRightInImage = new PointF(center.X + radius, center.Y);

            if (calibratorType == CalibratorType.Line)
            {
                return(new Ellipse(center, radius, radius, 0));
            }

            // Rebuild the world-space circle based on center and radius alone.
            PointF centerInWorld = GetPoint(center);

            // Estimate the radius in world space.
            // Get scalar will assumes reference direction to be X-axis in image space.
            float radiusInWorld = GetScalar(radius);

            // Get the intersection points of a horizontal diameter.
            // This is used to draw a line from the center to the outline of the ellipse in perspective.
            radiusLeftInImage  = GetImagePoint(centerInWorld.Translate(-radiusInWorld, 0));
            radiusRightInImage = GetImagePoint(centerInWorld.Translate(radiusInWorld, 0));

            // Get the square enclosing the circle for mapping.
            PointF         a         = GetImagePoint(centerInWorld.Translate(-radiusInWorld, -radiusInWorld));
            PointF         b         = GetImagePoint(centerInWorld.Translate(radiusInWorld, -radiusInWorld));
            PointF         c         = GetImagePoint(centerInWorld.Translate(radiusInWorld, radiusInWorld));
            PointF         d         = GetImagePoint(centerInWorld.Translate(-radiusInWorld, radiusInWorld));
            QuadrilateralF quadImage = new QuadrilateralF(a, b, c, d);

            ProjectiveMapping mapping = new ProjectiveMapping();

            mapping.Update(QuadrilateralF.CenteredUnitSquare, quadImage);
            return(mapping.Ellipse());
        }
Example #2
0
        /// <summary>
        /// Takes a circle in real world coordinates and returns a cooresponding ellipse in image coordinates.
        /// </summary>
        public Ellipse GetEllipseFromCircle(PointF center, float radius)
        {
            if (calibratorType == CalibratorType.Line)
            {
                return(new Ellipse(GetImagePoint(center), GetImageScalar(radius), GetImageScalar(radius), 0));
            }

            // Get the square enclosing the circle for mapping.
            PointF         a         = GetImagePoint(center.Translate(-radius, -radius));
            PointF         b         = GetImagePoint(center.Translate(radius, -radius));
            PointF         c         = GetImagePoint(center.Translate(radius, radius));
            PointF         d         = GetImagePoint(center.Translate(-radius, radius));
            QuadrilateralF quadImage = new QuadrilateralF(a, b, c, d);

            ProjectiveMapping mapping = new ProjectiveMapping();

            mapping.Update(QuadrilateralF.CenteredUnitSquare, quadImage);
            return(mapping.Ellipse());
        }
Example #3
0
        private void DrawDistortedLine(Graphics canvas, Pen pen, PointF a, PointF b, ProjectiveMapping projectiveMapping, DistortionHelper distorter, IImageToViewportTransformer transformer)
        {
            a = projectiveMapping.Forward(a);
            b = projectiveMapping.Forward(b);

            if (distorter != null && distorter.Initialized)
            {
                a = distorter.Distort(a);
                b = distorter.Distort(b);

                List <PointF> curve       = distorter.DistortLine(a, b);
                List <Point>  transformed = transformer.Transform(curve);
                canvas.DrawCurve(penEdges, transformed.ToArray());
            }
            else
            {
                canvas.DrawLine(pen, transformer.Transform(a), transformer.Transform(b));
            }
        }
Example #4
0
        private void DrawGrid(Graphics canvas, Pen pen, ProjectiveMapping projectiveMapping, DistortionHelper distorter, IImageToViewportTransformer transformer)
        {
            int start = 0;
            int end   = styleHelper.GridDivisions;
            int total = styleHelper.GridDivisions;

            // Horizontals
            for (int i = start; i <= end; i++)
            {
                float v = i * ((float)planeHeight / total);
                DrawDistortedLine(canvas, pen, new PointF(0, v), new PointF(planeWidth, v), projectiveMapping, distorter, transformer);
            }

            // Verticals
            for (int i = start; i <= end; i++)
            {
                float h = i * (planeWidth / total);
                DrawDistortedLine(canvas, pen, new PointF(h, 0), new PointF(h, planeHeight), projectiveMapping, distorter, transformer);
            }
        }
Example #5
0
        private void DrawDiagonals(Graphics canvas, Pen pen, QuadrilateralF quadPlane, ProjectiveMapping projectiveMapping, DistortionHelper distorter, IImageToViewportTransformer transformer)
        {
            DrawDistortedLine(canvas, penEdges, quadPlane.A, quadPlane.B, projectiveMapping, distorter, transformer);
            DrawDistortedLine(canvas, penEdges, quadPlane.B, quadPlane.C, projectiveMapping, distorter, transformer);
            DrawDistortedLine(canvas, penEdges, quadPlane.C, quadPlane.D, projectiveMapping, distorter, transformer);
            DrawDistortedLine(canvas, penEdges, quadPlane.D, quadPlane.A, projectiveMapping, distorter, transformer);

            DrawDistortedLine(canvas, penEdges, quadPlane.A, quadPlane.C, projectiveMapping, distorter, transformer);
            DrawDistortedLine(canvas, penEdges, quadPlane.B, quadPlane.D, projectiveMapping, distorter, transformer);
        }