Exemplo n.º 1
0
        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (newPolygon == null)
            {
                return;
            }

            Point point    = new Point(e.X, e.Y);
            int   distance = (e.X - lastX) * (e.X - lastX) + (e.Y - lastY) * (e.Y - lastY);

            if (distance < minDistance)
            {
                newPolygon.MoveHandleTo(point, newPolygon.HandleCount);
            }
            else
            {
                newPolygon.AddPoint(point);
                lastX = e.X;
                lastY = e.Y;
            }

            drawArea.Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Mouse move - resize new polygon
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (newPolygon == null)
            {
                return;                 // precaution
            }
            Point point    = new Point(e.X, e.Y);
            int   distance = (e.X - lastX) * (e.X - lastX) + (e.Y - lastY) * (e.Y - lastY);

            if (distance < minDistance)
            {
                // Distance between last two points is less than minimum -
                // move last point
                newPolygon.MoveHandleTo(point, newPolygon.HandleCount);
            }
            else
            {
                // Add new point
                newPolygon.AddPoint(point);
                lastX = e.X;
                lastY = e.Y;
            }

            drawArea.Refresh();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reduce the number of points in a polygon.
        /// </summary>
        /// <param name="Points">The points.</param>
        /// <param name="Tolerance">The tolerance.</param>
        /// <returns></returns>
        public static DrawPolygon ReductionPolygon(List <PointF> Points, Double Tolerance)
        {
            Int32        firstPoint        = 0;
            Int32        lastPoint         = Points.Count - 1;
            List <Int32> pointIndexsToKeep = new List <Int32>();

            //Add the first and last index to the keepers
            pointIndexsToKeep.Add(firstPoint);
            pointIndexsToKeep.Add(lastPoint);

            //The first and the last PointF can not be the same
            while (Points[firstPoint].Equals(Points[lastPoint]))
            {
                lastPoint--;
            }

            Reduction(Points, firstPoint, lastPoint, Tolerance, ref pointIndexsToKeep);

            DrawPolygon returnPolygon = new DrawPolygon();
            Point       point;

            pointIndexsToKeep.Sort();
            foreach (Int32 index in pointIndexsToKeep)
            {
                point   = new Point();
                point.X = (int)Points[index].X;
                point.Y = (int)Points[index].Y;
                returnPolygon.AddPoint(point);
            }

            return(returnPolygon);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Change mokkan extraction parameters
        /// </summary>
        private void ChangeExtraction()
        {
            if (_init)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            List <Boundary> bounds = MokkanExtraction.BoundaryTracking(_binBmp, _bndRec);

            // get top regions
            List <int> tops = new List <int>();

            GetTopAreas(bounds, _mokkanNum, tops);

            // number of regions
            int n = Math.Min(_mokkanNum, tops.Count - 1);

            DrawPolygon reducePolygon;

            MkaMokkanInfo.LastRBangou -= _list.Count;
            _list.Clear();
            Bitmap   ret = (Bitmap)_oriBmp.Clone();
            Graphics g   = Graphics.FromImage(ret);

            g.DrawRectangle(Pens.Red, _bndRec);

            for (int i = 0; i < n; i++)
            {
                if (_tolerance == 0)
                {
                    reducePolygon = new DrawPolygon();
                    foreach (PointF p in bounds[tops[i]].Points)
                    {
                        reducePolygon.AddPoint(new Point((int)p.X, (int)p.Y));
                    }
                }
                else
                {
                    // get reduce polygon
                    reducePolygon = PolygonApproximation.ReductionPolygon(bounds[tops[i]].Points, _tolerance);
                }

                _list.Add(reducePolygon);
                MkaMokkanInfo.LastRBangou++;

                g.DrawPolygon(_pen, bounds[tops[i]].Points.ToArray());
                g.FillPolygon(_brush, bounds[tops[i]].Points.ToArray());
            }

            g.Dispose();
            bounds.Clear();
            tops.Clear();

            if (picImageView.Image != null)
            {
                picImageView.Image.Dispose();
            }
            picImageView.Image = ret;

            this.Cursor = Cursors.Default;
        }