예제 #1
0
파일: BezierUtils.cs 프로젝트: rAum/mmgk
        public static void DrawPoints(PaintEventArgs e, Bezier b, Brush p, Brush c, int size = 4)
        {
            int n = b.points.Count - 1;

            for (int i = 1; i < n; ++i)
                e.Graphics.FillEllipse(p, ComplexToRect(b.points[i], size));

            e.Graphics.FillEllipse(c, ComplexToRect(b.points[0], size + 1));
            e.Graphics.FillEllipse(c, ComplexToRect(b.points[n], size + 1));
        }
예제 #2
0
파일: BezierUtils.cs 프로젝트: rAum/mmgk
        public static void DrawBezier(PaintEventArgs e, Bezier b, float stepSize = 0.005f)
        {
            PointF prev = b.castelijou(0.0).ToPointF();
            PointF curr;
            Pen p = new Pen(Brushes.Black, 5);
            for (double t = stepSize; t <= 1.0f; t += stepSize)
            {
                curr = b.castelijou(t).ToPointF();
                e.Graphics.DrawLine(p, prev, curr);

                prev = curr;
            }
            e.Graphics.DrawLine(p, prev, b.castelijou(1.0).ToPointF());
        }
예제 #3
0
파일: BezierUtils.cs 프로젝트: rAum/mmgk
        public static void DrawConvexHull(PaintEventArgs e, Bezier b, Pen p)
        {
            List<Complex> hull = GrahamHull.GetGrahamHull(b.points);

            if (hull.Count < 2)
                return; // no need to draw..

            PointF prev = hull[0].ToPointF();
            PointF curr;
            foreach (var ch in hull)
            {
                curr = ch.ToPointF();
                e.Graphics.DrawLine(p, prev, curr);
                prev = curr;
            }
            e.Graphics.DrawLine(p, prev, hull[0].ToPointF());
        }
예제 #4
0
파일: BezierUtils.cs 프로젝트: rAum/mmgk
 public static void DrawConnections(PaintEventArgs e, Bezier b, Pen p)
 {
     var pt = b.points.Select(x => {return x.ToPointF(); } ).ToArray();
     e.Graphics.DrawLines(p, pt);
 }
예제 #5
0
파일: MainWindow.cs 프로젝트: rAum/mmgk
        private void drawingPanel_Click(object sender, EventArgs e)
        {
            MouseEventArgs mos = e as MouseEventArgs;
            switch (mode)
            {
                case Mode.ConstructCurve:
                case Mode.PathCreate:
                    if (mos.Button == MouseButtons.Left)
                    {
                        construct.Add(mos.Location);
                        (sender as Panel).Invalidate();
                        construct.exit = false;
                    }
                    else if (mos.Button == MouseButtons.Right)
                    {
                        if (mode == Mode.PathCreate)
                        {
                            if (construct.exit)
                            {
                                WorkingMode = Mode.Normal;
                                Cursor = Cursors.Default;
                            }
                            else if (construct.CanBeDrawed() && construct.currentSet == null) // first curve
                            {
                                Complex last = new Complex(construct.bezier.points[construct.bezier.points.Count - 1]);
                                construct.currentSet = new BezierSet(construct.bezier);
                                beziers.Add(construct.currentSet);
                                construct.bezier = new Bezier();

                                construct.pt = new List<Complex>();
                                construct.Add(new Point((int)last.Re, (int)last.Im));
                            }
                            else if (construct != null && construct.currentSet != null && construct.bezier != null)
                            {
                                var last = construct.currentSet.set.Last();
                                construct.currentSet.set.Add(construct.bezier);
                                last.ConnectRight(construct.bezier, false); // polacz z pierwszym
                                Complex l = construct.bezier.points[construct.bezier.Degree - 1];

                                construct.pt = new List<Complex>();
                                construct.Add(new Point((int)l.Re, (int)l.Im));
                            }
                            construct.exit = true;
                        }
                        else
                        {
                            if (construct != null && construct.bezier != null && construct.bezier.points.Count > 1)
                            {
                                beziers.Add(new BezierSet(construct.bezier));
                            }
                            WorkingMode = Mode.Normal;
                            Cursor = Cursors.Default;
                        }
                        (sender as Panel).Invalidate();
                    }
                    break;

                case Mode.AddingNewCurve:
                    if (mos.Button == MouseButtons.Left)
                    {
                        addnew.Add(mos.Location);
                        (sender as Panel).Invalidate();
                        if (addnew.Ready())
                        {
                            Cursor = Cursors.Arrow;
                            FormAddCurve ask = new FormAddCurve();

                            ask.ShowDialog(this);

                            // construct curve with enough control points
                            Bezier b = new Bezier(addnew.pt, ask.Degree - 2);

                            beziers.Add(new BezierSet(b));

                            // exit adding curve
                            WorkingMode = Mode.Normal;
                            drawingPanel.Invalidate();
                        }
                    }
                    break;
                case Mode.Merging:
                    if (mos.Button == MouseButtons.Right)
                        WorkingMode = Mode.Normal;
                    else if (mos.Button == MouseButtons.Left)
                    {
                        var p = FindNearestPoint(mos);
                        if (p != null)
                        {
                            if (normalMode.ptr.i == 0) // jesli zaznaczony byl po lewej
                            {
                                if (normalMode.ptr.bez.ConnectLeft(p.bez, p.i != 0)) // to dopnij z prawej strony z odpowiednim koncem
                                {
                                    if (p.bset != normalMode.ptr.bset)
                                    {
                                        normalMode.ptr.bset.Add(p.bset);
                                        beziers.Remove(p.bset);
                                    }
                                    drawingPanel.Invalidate();
                                    WorkingMode = Mode.Normal;
                                }

                            }
                            else if (normalMode.ptr.i == normalMode.ptr.bez.Degree - 1)
                            {
                                if (normalMode.ptr.bez.ConnectRight(p.bez, p.i != 0))
                                {
                                    if (p.bset != normalMode.ptr.bset)
                                    {
                                        normalMode.ptr.bset.Add(p.bset);
                                        beziers.Remove(p.bset);
                                    }
                                    drawingPanel.Invalidate();
                                    WorkingMode = Mode.Normal;
                                }

                            }
                        }
                    }
                    break;
            }
        }
예제 #6
0
파일: Bezier.cs 프로젝트: rAum/mmgk
 public Bezier(Bezier b)
 {
     Id = IdCounter++;
     points = new List<Complex>(b.points.ToArray());
 }
예제 #7
0
파일: MainWindow.cs 프로젝트: rAum/mmgk
 public void Add(Point p)
 {
     pt.Add(new Complex(p.X, p.Y));
     if (pt.Count > 1)
         bezier = new Bezier(pt.ToArray());
 }
예제 #8
0
파일: Bezier.cs 프로젝트: rAum/mmgk
        public bool ConnectRight(Bezier s, bool last = true, bool force = false)
        {
            if (s == null || (right != null && force == false))
                return false;

            int nr = last ? s.Degree - 1 : 0;

            if (last) // tutejszy prawy z tamtym ostatnim [prawym]
            {
                if (s.right != null && force == false)
                    return false;

                right = s;
                rightNode = nr;
                s.right = this;
                s.rightNode = Degree - 1;
            }
            else // prawy z lewym
            {
                if (s.right != null && force == false)
                    return false;

                right = s;
                rightNode = nr;
                s.left = this;
                s.leftNode = Degree - 1;
            }

            return true;
        }
예제 #9
0
파일: Bezier.cs 프로젝트: rAum/mmgk
        public bool ConnectLeft(Bezier s, bool last = false, bool force = false)
        {
            if (s == null || (left != null && force == false))
                return false;

            int nr = last ? s.Degree - 1 : 0;

            if (last) // tutejszy lewy z tamtym ostatnim [prawym]
            {
                if (s.right != null && force == false)
                    return false;

                left = s;
                leftNode = nr;
                s.right = this;
                s.rightNode = 0;

                //Chaining(0);
                //Chaining(1);
                //Chaining(Degree - 1);
                //Chaining(Degree - 2);
            }
            else // lewy z lewym
            {
                if (s.left != null && force == false)
                    return false;

                left = s;
                leftNode = nr;
                s.left = this;
                s.leftNode = 0;

                //Chaining(0);
                //Chaining(1);
            }

            return true;
        }
예제 #10
0
파일: BezierSet.cs 프로젝트: rAum/mmgk
 public CurrentPtr(Bezier b, BezierSet s, int index)
 {
     bez = b;
     bset = s;
     i = index;
 }
예제 #11
0
파일: BezierSet.cs 프로젝트: rAum/mmgk
 public void Add(Bezier b)
 {
     set.Add(b);
 }
예제 #12
0
파일: BezierSet.cs 프로젝트: rAum/mmgk
 public BezierSet(Bezier b)
 {
     set = new List<Bezier>();
     set.Add(b);
 }