Exemplo n.º 1
0
 public static void DrawContour(Contour contour, PaintEventArgs e)
 {
     (contour as Ellipse).DrawEllipse(e.Graphics);
 }
Exemplo n.º 2
0
 public static void DrawContour(Contour contour, PaintEventArgs e)
 {
     (contour as Tetragon).DrawLines(e.Graphics);
 }
Exemplo n.º 3
0
        public void DrawEllipse(int[,] contourMask, Contour contour, int _contourIndex)
        {
            _dequeueNorth.Clear();
            _dequeueWest.Clear();
            _points.Clear();


            float  x, y;
            double angle;
            int    xc, yc;

            int a, b;  //ellipse parameters

            double p1, p2;

            _center = contour.Markers[0].CenterPosition;
            xc      = _center.X;
            yc      = _center.Y;

            a     = (int)Math.Round(Geometry.EuclidianDistance(contour.Markers[1].CenterPosition, contour.Markers[2].CenterPosition)) / 2;
            b     = (int)Math.Round(Geometry.EuclidianDistance(contour.Markers[3].CenterPosition, contour.Markers[4].CenterPosition)) / 2;
            angle = Geometry.ComputeEllipseAngle(contour.Markers[1].CenterPosition, contour.Markers[2].CenterPosition);
            angle = -angle;
            x     = 0; y = b;

            _dequeueNorth.Add(Geometry.RotatePointAroundOrigin(angle, x, y));

            p1 = (b * b) - (a * a * b) + (a * a) / 4;

            while ((2.0 * b * b * x) <= (2.0 * a * a * y))
            {
                x++;
                if (p1 <= 0)
                {
                    p1 = p1 + (2.0 * b * b * x) + (b * b);
                }
                else
                {
                    y--;
                    p1 = p1 + (2.0 * b * b * x) + (b * b) - (2.0 * a * a * y);
                }

                _dequeueNorth.Add(Geometry.RotatePointAroundOrigin(angle, x, y));
                x = -x;

                _dequeueNorth.Insert(0, Geometry.RotatePointAroundOrigin(angle, x, y));
                x = -x;
            }

            x = a;
            y = 0;

            _dequeueWest.Add(Geometry.RotatePointAroundOrigin(angle, x, y));

            p2 = (a * a) + 2.0 * (b * b * a) + (b * b) / 4;
            while ((2.0 * b * b * x) > (2.0 * a * a * y))
            {
                y++;
                if (p2 > 0)
                {
                    p2 = p2 + (a * a) - (2.0 * a * a * y);
                }
                else
                {
                    x--;
                    p2 = p2 + (2.0 * b * b * x) - (2.0 * a * a * y) + (a * a);
                }

                _dequeueWest.Insert(0, Geometry.RotatePointAroundOrigin(angle, x, y));
                y = -y;

                _dequeueWest.Add(Geometry.RotatePointAroundOrigin(angle, x, y));
                y = -y;
            }

            _points.InsertRange(0, _dequeueNorth);
            _points.InsertRange(_points.Count, _dequeueWest);

            int n = _points.Count;

            for (int i = 0; i < n; i++)
            {
                _points.Add(new Point(xc + _points[i].X, yc - _points[i].Y));
                _points[i] = new Point(xc - _points[i].X, yc + _points[i].Y);
            }

            DrawPixels(contourMask, _contourIndex);
            contourMask[_center.X, _center.Y] = _contourIndex;
        }