コード例 #1
0
ファイル: WholeMerger.cs プロジェクト: mur-mur-moon/Clipper
        private void MergeInnerWithInner(Polygon WindowHole, Polygon PolygonHole)
        {
            PolygonMerger PM = new PolygonMerger(WindowHole, PolygonHole, MergedContoursType.INNER_WITH_INNER/* 3*/);

            List<Polygon> contoursToAdd = PM.MakeUnion();
            if (PM.NoIntersect)
            {
                if (Utility.PointInPolygon(WindowHole, PolygonHole.GetVertex(0)) == Utility.Inside)
                {
                    RESULT.AddSubPolygon(PolygonHole);
                }
                else if (Utility.PointInPolygon(PolygonHole, WindowHole.GetVertex(0)) == Utility.Inside)
                {
                    RESULT.AddSubPolygon(WindowHole);
                }
            }
            else
            {
                for (int i = 0; i < contoursToAdd.Count; i++)
                {
                    RESULT.AddSubPolygon(contoursToAdd[i]);
                }

            }
        }
コード例 #2
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
 public void AddPoint(EventArgs e)
 {
     EditorState edState = new AddingPoints();
     State = edState;
     CurPoints.Clear();
     CurContour = null;
 }
コード例 #3
0
ファイル: DBConnector.cs プロジェクト: mur-mur-moon/Clipper
        public Polygon GetPolygonByName(string s)
        {
            DBase db = new DBase(DataContextConnection);

            Polygon poly = new Polygon();

            // construct polygon
            Polygons DBpoly = (from c in db.Polygons
                                         where c.NAME==s && c.PARENT_ID==null
                                         select c).SingleOrDefault<Polygons>();

            foreach (Points pnt in DBpoly.Points)
            {
                Point p = new Point(pnt.X,pnt.Y);
                poly.AddVertex(p);
            }
            // construct subPolygons
            IQueryable <Polygons> DBsubpolys = from c in db.Polygons
                              where c.PARENT_ID == DBpoly.ID
                              select c;

            foreach (Polygons DBsubpoly in DBsubpolys)
            {
                Polygon subpoly = new Polygon();

                foreach (Points pnt in DBsubpoly.Points)
                {
                    Point p = new Point(pnt.X, pnt.Y);
                    subpoly.AddVertex(p);
                }
                poly.AddSubPolygon(subpoly);
            }

            return poly;
        }
コード例 #4
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
        public void AddOuterContour()
        {
            Polygon polyg = new Polygon();
            Polygs.Add(polyg);
            CurPolygon = polyg;

            EditorState edState = new NewPolygon();
            State = edState;
        }
コード例 #5
0
ファイル: Utility.cs プロジェクト: mur-mur-moon/Clipper
 public static double PolygonSquare(Polygon Polyg)
 {
     double sum = 0;
     for (int i = 0; i < Polyg.VertexCount; i++)
     {
         int j = i + 1;
         if (i == Polyg.VertexCount - 1) j = 0;
         sum += Polyg.GetVertex(i).X * Polyg.GetVertex(j).Y - Polyg.GetVertex(j).X * Polyg.GetVertex(i).Y;
     }
     return sum/2;
 }
コード例 #6
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
        public void AddInnerContour()
        {
            if (CurPolygon == null)
            {
                MessageBox.Show("Внешний контур не задан!");
                return;
            }
            Polygon polyg = new Polygon();
            CurContour = polyg;
               // Polygs.Add(polyg);
            CurPolygon.AddSubPolygon(polyg);

            EditorState edState = new NewContour();
            State = edState;
        }
コード例 #7
0
ファイル: EditorState.cs プロジェクト: mur-mur-moon/Clipper
        private void AddNewPoint(ImageEditor imgEd, MouseEventArgs e, Polygon polyg)
        {
            int pos = Math.Max(imgEd.CurPoints[0], imgEd.CurPoints[1]);
            if (pos == polyg.VertexCount-1) pos++;

            Point E = imgEd.ShiftPointIfNotEmpty(new Point(e.X, e.Y));
            Graphics g = imgEd.GetGraphics();
            polyg.Paint(g, new Pen(Brushes.White, 2));
            polyg.AddVertexAt(pos, E);
            imgEd.ReDraw();
            g = imgEd.GetGraphics();
            polyg.Paint(g);
            imgEd.ReDraw();

            imgEd.CurPoints.Clear();
        }
コード例 #8
0
ファイル: Polygon.cs プロジェクト: mur-mur-moon/Clipper
        public Polygon(string[] lines)
        {
            VertexList = new List<Point>();
            SubPolygs = new List<Polygon>();
            if (lines.Length <= 3) return;

            int vertCount = 0, subCount = 0;
            Int32.TryParse(lines[1], out vertCount);
            Int32.TryParse(lines[2], out subCount);
            int shift = 3, i = 0;
            for (i = 0; i < vertCount; i++)
            {
                System.Windows.Point pw = System.Windows.Point.Parse(lines[i + shift]);
                Point p = new Point((int)pw.X,(int) pw.Y);
                VertexList.Add(p);
            }
            shift += i;
            for (int k = 0; k < subCount; k++)
            {
                Polygon sub = new Polygon();
                SubPolygs.Add(sub);
                shift ++;

                int vertSubCount = 0;
                Int32.TryParse(lines[shift], out vertSubCount);
                shift++;

                int j = 0;
                for (j = 0; j < vertSubCount; j++)
                {
                    System.Windows.Point pw = System.Windows.Point.Parse(lines[j + shift]);
                    Point p = new Point((int)pw.X, (int)pw.Y);
                    sub.VertexList.Add(p);
                }
                shift += j;
            }
        }
コード例 #9
0
ファイル: WholeMerger.cs プロジェクト: mur-mur-moon/Clipper
 public WholeMerger(Polygon _WINDOW, Polygon _POLYGON)
 {
     WINDOW = _WINDOW;
     POLYGON = _POLYGON;
     RESULT = new Polygon();
 }
コード例 #10
0
ファイル: Polygon.cs プロジェクト: mur-mur-moon/Clipper
 public void AddSubPolygon(Polygon subpolyg)
 {
     SubPolygs.Add(subpolyg);
 }
コード例 #11
0
ファイル: Polygon.cs プロジェクト: mur-mur-moon/Clipper
        public void PaintOne(Polygon p, Graphics g, Pen pen)
        {
            for (int i = 0; i < p.VertexCount; i++)
            {
                int prev = 0;
                if (i != 0) prev = i - 1;
                else prev = p.VertexCount - 1;

                g.DrawLine(pen, new Point(p.GetVertex(prev).X, p.GetVertex(prev).Y), new Point(p.GetVertex(i).X, p.GetVertex(i).Y));
            }
        }
コード例 #12
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
        public void ImageClean()
        {
            CurPolygon = null;
            Polygs.Clear();
            CurPoints.Clear();
            EditingOff();

            g = GetGraphics();
            g.Clear(System.Drawing.Color.White);
            ReDraw();

            NotValidated = false;
        }
コード例 #13
0
 public PolygonValidater(Polygon p)
 {
     polygon = p;
     segments = new List<Segment>();
 }
コード例 #14
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
        public void Merge()
        {
            if (Polygs.Count < PolygonMaxNumber)
            { MessageBox.Show("Для объединения необходимо создать " + PolygonMaxNumber.ToString() + " полигона"); return; }

            WholeMerger WholeMerg = new WholeMerger(Polygs[0], Polygs[1]);
            WholeMerg.Merge();
            if (WholeMerg.noSharedPoints) {ImageClean(); return; }
            Polygon United = WholeMerg.GetResult();
            CurPolygon = United;

            Polygs.Clear();
            Polygs.Add(United);

            g = GetGraphics();
            g.Clear(System.Drawing.Color.White);
            ReDraw();

            g = GetGraphics();
            United.Paint(g);
            ReDraw();
        }
コード例 #15
0
ファイル: DBConnector.cs プロジェクト: mur-mur-moon/Clipper
        public void SavePolygon(Polygon polyg, string name)
        {
            DBase db = new DBase(DataContextConnection);
            // insert polygon
            Polygons DBpoly = new Polygons
            {
                NAME = name,
            };

            for (int i = 0; i < polyg.VertexCount; i++)
            {
                Points p = new Points
                {
                    X = polyg.GetVertex(i).X,

                    Y = polyg.GetVertex(i).Y,

                    POLYGON_ID = DBpoly.ID,
                };
                DBpoly.Points.Add(p);
            }
            db.Polygons.InsertOnSubmit(DBpoly);
            db.SubmitChanges();

            // insert subPolygons
            for (int i = 0; i < polyg.SubPolygs.Count; i++)
            {
                Polygons DBsubpoly = new Polygons
                {
                    NAME = name,
                    PARENT_ID = DBpoly.ID,
                };

                for (int j = 0; j < polyg.SubPolygs[i].VertexCount; j++)
                {
                    Points sp = new Points
                    {
                        X = polyg.SubPolygs[i].GetVertex(j).X,

                        Y = polyg.SubPolygs[i].GetVertex(j).Y,

                        POLYGON_ID = DBsubpoly.ID,
                    };
                    DBsubpoly.Points.Add(sp);
                }
                db.Polygons.InsertOnSubmit(DBsubpoly);
            }

            db.SubmitChanges();
        }
コード例 #16
0
ファイル: UtilityTest.cs プロジェクト: mur-mur-moon/Clipper
 // constructor
 public UtilityTest()
 {
     // create all polygons we need
     Polygon_ForGeneralCases = InitializePolygon_ForGeneralCases();
     Polygon_ForSpecialCases = InitializePolygon_ForSpecialCases();
 }
コード例 #17
0
ファイル: UtilityTest.cs プロジェクト: mur-mur-moon/Clipper
        private Polygon InitializePolygon_ForSpecialCases()
        {
            Polygon Polyg = new Polygon();

            Polyg.AddVertex(new Point(327, 233));
            Polyg.AddVertex(new Point(311, 280));
            Polyg.AddVertex(new Point(232, 252));
            Polyg.AddVertex(new Point(197, 185));
            Polyg.AddVertex(new Point(126, 147));
            Polyg.AddVertex(new Point(197, 128));
            Polyg.AddVertex(new Point(232, 145));
            Polyg.AddVertex(new Point(232, 125));
            Polyg.AddVertex(new Point(327, 125));

            return Polyg;
        }
コード例 #18
0
ファイル: UtilityTest.cs プロジェクト: mur-mur-moon/Clipper
        private Polygon InitializePolygon_ForGeneralCases()
        {
            Polygon Polyg = new Polygon();
            Polyg.AddVertex(new Point(235, 47));
            Polyg.AddVertex(new Point(408, 47));
            Polyg.AddVertex(new Point(370, 195));
            Polyg.AddVertex(new Point(238, 113));
            Polyg.AddVertex(new Point(112, 208));
            Polyg.AddVertex(new Point(112, 158));
            Polyg.AddVertex(new Point(152, 115));
            Polyg.AddVertex(new Point(112, 105));
            Polyg.AddVertex(new Point(112, 76));

            return Polyg;
        }
コード例 #19
0
ファイル: EditorState.cs プロジェクト: mur-mur-moon/Clipper
 protected bool WhereIsThePoint(MouseEventArgs e, ImageEditor imgEd, out Polygon p, out int index)
 {
     int mouseSensitivity = imgEd.mouseSensitivity;
     p = null;
     index = -1;
     for (int i = 0; i < imgEd.CurPolygon.VertexCount; i++)
     {
         if (Math.Abs(e.X - imgEd.CurPolygon.GetVertex(i).X) <= mouseSensitivity
             && Math.Abs(e.Y - imgEd.CurPolygon.GetVertex(i).Y) <= mouseSensitivity)
         {
             p = imgEd.CurPolygon;
             index = i;
             return true;
         }
     }
     for (int i = 0; i < imgEd.CurPolygon.SubPolygs.Count; i++)
     {
         for (int j = 0; j < imgEd.CurPolygon.SubPolygs[i].VertexCount; j++)
         {
             if (Math.Abs(e.X - imgEd.CurPolygon.SubPolygs[i].GetVertex(j).X) <= mouseSensitivity
                 && Math.Abs(e.Y - imgEd.CurPolygon.SubPolygs[i].GetVertex(j).Y) <= mouseSensitivity)
             {
                 p = imgEd.CurPolygon.SubPolygs[i];
                 index = j;
                 return true;
             }
         }
     }
     MessageBox.Show("Указанная точка не совпадает ни с одной из вершин редактируемого полигона! Можно снизить чувствительность курсора");
     return false;
 }
コード例 #20
0
ファイル: ImageEditor.cs プロジェクト: mur-mur-moon/Clipper
 public void DeletePoint(EventArgs e)
 {
     EditorState edState = new DeletingPoints();
     State = edState;
     CurContour = null;
 }
コード例 #21
0
ファイル: Main.cs プロジェクト: mur-mur-moon/Clipper
        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ImgEditor.Polygs.Count == 2) { MessageBox.Show("Вначале объедините существующие полигоны"); return; }

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "Выберите файл";
            openFileDialog.Filter = "Текстовые файлы|*.txt";

            if (openFileDialog.ShowDialog() != DialogResult.OK) return;
            string[] lines = ToFileFromFile.ReadFromFile(openFileDialog.FileName);

            Polygon poly = new Polygon(lines);
            Graphics g = ImgEditor.GetGraphics();
            poly.Paint(g);
            ImgEditor.ReDraw();

            ImgEditor.Polygs.Add(poly);
            ImgEditor.CurPolygon = poly;
        }
コード例 #22
0
ファイル: Utility.cs プロジェクト: mur-mur-moon/Clipper
        public static int PointInPolygon(Polygon Polyg, Point a)
        {
            // из точки проводим луч вертикально вниз и считаем пересечения со сторонами полигона
            int intersectNum = 0;
            bool EndIntersect = false, SecondLoop = false;
            int SegStartX = 0;

            for (int i = 0; i < Polyg.VertexCount; i++)
            {
                int j = i + 1;
                if (i == Polyg.VertexCount - 1) j = 0;
                // точка совпала с одним из концов отрезка
                if (a == Polyg.GetVertex(i) || a == Polyg.GetVertex(j)) return OnBorder;
                // начало и конец отрезка лежат по одну сторону от луча
                int Min_X = Math.Min(Polyg.GetVertex(i).X, Polyg.GetVertex(j).X);
                int Max_X = Math.Max(Polyg.GetVertex(i).X, Polyg.GetVertex(j).X);
                if (a.X < Min_X || a.X > Max_X) continue;

                if (a.Y == Polyg.GetVertex(i).Y && a.Y == Polyg.GetVertex(j).Y) return OnBorder;

                double X_dif = (double)(Polyg.GetVertex(j).X - Polyg.GetVertex(i).X);
                if (X_dif !=0 )
                {
                    double _y = Polyg.GetVertex(i).Y +
                        (a.X - Polyg.GetVertex(i).X) * (Polyg.GetVertex(j).Y - Polyg.GetVertex(i).Y) / X_dif;

                    if (a.Y <= _y)
                    {
                        // точки начала и конца лежат на луче
                        if (Polyg.GetVertex(i).X == a.X && Polyg.GetVertex(j).X == a.X) continue;
                        // конец отрезка лежит на луче
                        if (Polyg.GetVertex(j).X == a.X)
                        {
                            SegStartX = Polyg.GetVertex(i).X;
                            EndIntersect = true;
                        }
                        else
                        {
                            if (EndIntersect)
                            {
                                if (a.X > Math.Min(SegStartX, Polyg.GetVertex(j).X)
                                    && a.X < Math.Max(SegStartX, Polyg.GetVertex(j).X))
                                {
                                    intersectNum++;
                                    if (SecondLoop) { intersectNum--; break; }
                                }
                                else if (SecondLoop) {  intersectNum--; break;}
                                EndIntersect = false;
                            }
                            else intersectNum++;
                        }
                    }
                }

                if (j == Polyg.VertexCount - 1 && EndIntersect)
                {
                    i = -1;
                    SecondLoop = true;
                }
            }

            if (intersectNum % 2 == 1) return Inside;
            else return Outside;
        }