public Polygon2DTriangulator(Polygon2DAdorner a,Polygon2DAdorner b)
        {
            Polygon2DEditor polygonEditor = null;

            if (!a.polygon.isSimple || !b.polygon.isSimple)
            {
                throw (new ArgumentException());
            }
            if (a.polygon.PointDirection != b.polygon.PointDirection)
            {
                polygonEditor = new Polygon2DEditor(a.polygon);
                polygonEditor.Invert();
            }

            Debug.Assert(a.polygon.PointDirection == b.polygon.PointDirection);
            FirstPolygon = a;
            SecondPolygon = b;
            Diviser = new Polygon2DDiviser(a.Count);
            ghostPoint = new GhostPoint2DCollection();
            ghostTriangle = new GhostTriangle2DCollection();

            polygonEditor = new Polygon2DEditor(this.FirstPolygon.polygon);
            polygonEditor.Clear();
            polygonEditor = new Polygon2DEditor(this.SecondPolygon.polygon);
            polygonEditor.Clear();
        }
        public void Clear()
        {
            this.ghostTriangle = new GhostTriangle2DCollection();

            Polygon2DEditor polygonEditor = new Polygon2DEditor(this.FirstPolygon.polygon);
            polygonEditor.Clear();
            polygonEditor = new Polygon2DEditor(this.SecondPolygon.polygon);
            polygonEditor.Clear();

            this.FirstPolygon.ApplyGhostTriangles(this.ghostTriangle);
            this.SecondPolygon.ApplyGhostTriangles(this.ghostTriangle);
        }
        public void Clear()
        {
            Polygon2DEditor polygonEditor = new Polygon2DEditor(this.polygon);

            polygonEditor.Clear();
            this.ghostTriangles.Clear();
            this.lineSegments.Clear();
            this.triangles.Clear();

            if (this.child != null)
            {
                this.child.Clear();
            }
        }
        public void FromString(string polygonString)
        {
            string[] str = polygonString.Split('|');

            string[] s = str[0].Split('#');

            for (int j = 0; j < s.Length; j++)
            {
                Polygon2DEditor polygonEditor = new Polygon2DEditor(this.FirstPolygon);

                polygonEditor.AddPoint(ConvertPoint2DFromString(s[j]));
            }

            s = str[1].Split('#');

            for (int j = 0; j < s.Length; j++)
            {
                Polygon2DEditor polygonEditor = new Polygon2DEditor(this.LastPolygon);

                polygonEditor.AddPoint(ConvertPoint2DFromString(s[j]));
            }
        }
        private void Divide(GhostTriangle2D ghostTriangle)
        {
            Triangle2D triangle = ghostTriangle.ToTriangle(firstPolygon);

            Point2D point = (triangle.A + triangle.B.ToVector() + triangle.C.ToVector()) / 3;

            Polygon2DEditor polygonEditor = new Polygon2DEditor(firstPolygon);

            polygonEditor.AddInnerPoint(point);

            triangle = ghostTriangle.ToTriangle(secondPolygon);

            point = (triangle.A + triangle.B.ToVector() + triangle.C.ToVector()) / 3;

            polygonEditor = new Polygon2DEditor(secondPolygon);

            polygonEditor.AddInnerPoint(point);
        }
        private GhostTriangle2D Split(Polygon2D first, Polygon2D second, GhostTriangle2D ghostTriangle)
        {
            Triangle2D triangle = ghostTriangle.ToTriangle(first);
            LineSegment2D splitLine = Max(triangle.AB, triangle.BC, triangle.AC);
            int a = first.GetPointIndex(splitLine.FirstPoint);
            int b = first.GetPointIndex(splitLine.LastPoint);
            Point2D p1 = splitLine.MidPoint;
            splitLine = new LineSegment2D(second.GetPoint(a), second.GetPoint(b));
            Point2D p2 = splitLine.MidPoint;

            Polygon2DEditor polygonEditor = new Polygon2DEditor(first);
            polygonEditor.AddInnerPoint(p1);
            polygonEditor = new Polygon2DEditor(second);
            polygonEditor.AddInnerPoint(p2);

            return new GhostTriangle2D(a, b, first.PointCount - 1);
        }
Example #7
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            Point2D point = new Point2D(e.X, e.Y - 30);
            Polygon2DAdorner polygonAdorner = null;
            Partition part = OnPart(point);

            this.statusBarPanel1.Text = this.GetPolygonStatus(point);
            if (part == Partition.Left)
            {
                polygonAdorner = this.LeftPolygon;
            }
            else
            {
                point.X -= this.ClientSize.Width / 2;
                polygonAdorner = this.RightPolygon;
            }

            int i = StatusController.CatchPoint;

            if (i != -1)
            {
                this.Cursor = System.Windows.Forms.Cursors.Default;

                if (StatusController.availablePartition == part)
                {
                    Polygon2DEditor pe = new Polygon2DEditor(polygonAdorner.polygon);

                    pe.SetPoint(point, i);

                    StatusController.canRestart = false;

                }

                this.Invalidate();
            }
            else
            {
                i = polygonAdorner.HitTest(point);
                if (i == -1)
                {
                    this.Cursor = System.Windows.Forms.Cursors.Default;
                }
                else
                {
                    this.Cursor = System.Windows.Forms.Cursors.Cross;
                }
                this.statusBarPanel2.Text =point.ToString() + "    " + "Hint Index : " + i.ToString() + " ";
            }

            if (StatusController.isZoomView)
            {
                PointF midPoint;
                if (part == Partition.Left)
                {
                    midPoint = new PointF(this.ClientSize.Width / 4, this.ClientSize.Height / 2);

                }
                else
                {
                    midPoint = new PointF(3 * this.ClientSize.Width / 4, this.ClientSize.Height / 2);
                }

                if (e.X < midPoint.X && e.Y  < midPoint.Y)
                {
                    this.Cursor = System.Windows.Forms.Cursors.PanNW;
                }
                else if (e.X > midPoint.X && e.Y  < midPoint.Y)
                {
                    this.Cursor = System.Windows.Forms.Cursors.PanNE;
                }
                else if (e.X < midPoint.X && e.Y > midPoint.Y)
                {
                    this.Cursor = System.Windows.Forms.Cursors.PanSW;
                }
                else
                {
                    this.Cursor = System.Windows.Forms.Cursors.PanSE;
                }
            }
        }
Example #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            Point2D point = new Point2D(e.X, e.Y - 30);

            if (StatusController.availablePartition != OnPart(point))
            {
                StatusController.availablePartition = OnPart(point);
                this.Invalidate();
                return;
            }

            if (StatusController.isZoomView)
            {
                if (e.Button == MouseButtons.Left)
                {
                    this.MoveTimer.Start();
                    if (OnPart(point) == Partition.Left)
                    {

                        PointF midPoint = new PointF(this.ClientSize.Width / 4, this.ClientSize.Height / 2);

                        if (e.X < midPoint.X)
                        {
                            StatusController.LeftZoom.Offset.X += (float)StatusController.LeftZoom.ratio;
                        }
                        else
                        {
                            StatusController.LeftZoom.Offset.X -= (float)StatusController.LeftZoom.ratio;
                        }
                        if (e.Y < midPoint.Y)
                        {
                            StatusController.LeftZoom.Offset.Y += (float)StatusController.LeftZoom.ratio;
                        }
                        else
                        {
                            StatusController.LeftZoom.Offset.Y -= (float)StatusController.LeftZoom.ratio;
                        }

                    }
                    else
                    {
                        PointF midPoint = new PointF(3 * this.ClientSize.Width / 4, this.ClientSize.Height / 2);

                        if (e.X < midPoint.X)
                        {
                            StatusController.RightZoom.Offset.X += (float)StatusController.RightZoom.ratio;
                        }
                        else
                        {
                            StatusController.RightZoom.Offset.X -= (float)StatusController.RightZoom.ratio;
                        }

                        if (e.Y < midPoint.Y)
                        {
                            StatusController.RightZoom.Offset.Y += (float)StatusController.RightZoom.ratio;
                        }
                        else
                        {
                            StatusController.RightZoom.Offset.Y -= (float)StatusController.RightZoom.ratio;
                        }
                    }
                }
                else if (e.Button == MouseButtons.Right)
                {
                    this.MoveTimer.Stop();
                    StatusController.LeftZoom.ratio = 1.0;
                    StatusController.LeftZoom.Offset = new PointF(0.0F, -30.0F);

                    StatusController.RightZoom.ratio = 1.0;
                    StatusController.RightZoom.Offset = new PointF(0.0F, -30.0F);
                }
                this.Invalidate();
                return;
            }

            Polygon2DAdorner polygonAdorner = null;

            if (OnPart(point) == Partition.Left)
            {
                polygonAdorner = this.LeftPolygon;
            }
            else
            {
                point.X -= this.ClientSize.Width / 2;
                polygonAdorner = this.RightPolygon;
            }

            if (e.Button == MouseButtons.Left)
            {

                int i = polygonAdorner.HitTest(point);

                if (i == -1 && StatusController.canAddPoint)
                {
                    if (StatusController.availablePartition == Partition.Left)
                    {
                        Polygon2DEditor pe = new Polygon2DEditor(FirstPolygon);

                        pe.AddPoint(point);

                        StatusController.canRestart = false;
                    }
                    else
                    {
                        Polygon2DEditor pe = new Polygon2DEditor(this.SecondPolygon);

                        pe.AddPoint(new Point2D(point));

                        StatusController.canRestart = false;
                    }
                }

                else
                {
                    StatusController.CatchPoint = i;
                }
            }
            else
            {
                int i = polygonAdorner.HitTest(point);

                if (i != -1)
                {
                    if (StatusController.availablePartition == Partition.Left)
                    {
                        Polygon2DEditor pe = new Polygon2DEditor(this.FirstPolygon);

                        pe.RemovePoint(i);

                        StatusController.canRestart = false;
                    }
                    else
                    {
                        Polygon2DEditor pe = new Polygon2DEditor(this.SecondPolygon);

                        pe.RemovePoint(i);

                        StatusController.canRestart = false;
                    }
                }
            }
            this.Invalidate();
        }
Example #9
0
        private void PolygonScroll(Polygon2D polygon)
        {
            Polygon2DEditor pe = new Polygon2DEditor(polygon);

            pe.Scroll();
        }
        private void AddInnerPoints(Polygon2DAdorner polygon)
        {
            for (int j = 0; j < this.ghostPoint.Count; j++)
            {
                for (int i = 0; i < polygon.internalSegments.Count; i++)
                {
                    int a = (int)(polygon.internalSegments[i].X);
                    int b = (int)(polygon.internalSegments[i].Y);

                    if (a == this.ghostPoint[j].FirstIndex && b == this.ghostPoint[j].LastIndex || a == this.ghostPoint[j].LastIndex && b == this.ghostPoint[j].FirstIndex)
                    {
                        Point2D point = null;
                        LineSegment2D lineSegment = null;

                        lineSegment = new LineSegment2D(polygon.polygon.GetPoint(a), polygon.polygon.GetPoint(b));

                        point = lineSegment.GetPoint(this.ghostPoint[j].LocalPosition);

                        Polygon2DEditor polygonEditor = new Polygon2DEditor(polygon.polygon);

                        polygonEditor.AddInnerPoint(point);

                        break;
                    }
                }
            }
        }
Example #11
0
        public void AreaBasedRemeshing()
        {
            if (!this.available)
            {
                return;
            }

            for (int i = this.Polygon.VertexCount; i < this.Polygon.PointCount;  i++)
            {
                if (this.Polygon.isOnEdge(this.Polygon.GetPoint(i)) || this.Polygon.isVertex(this.Polygon.GetPoint(i)))
                {
                    continue;
                }

                double[] d = this.GetValue(i);

                Line2D line1 = null;
                Line2D line2 = null;
                Point2D point = null;

                try
                {
                    line1 = new Line2D(0.5 * d[3], 0.5 * d[4], 0.5 * d[5] - d[7] * d[1]);
                    line2 = new Line2D(0.5 * d[4], 0.5 * d[2], 0.5 * d[6] - d[7] * d[0]);
                }
                catch (ArgumentException)
                {
                    return;
                }

                point = line1.Intersects(line2);

                if (point.isRegular && this.isRegular(i, point) && this.Polygon.Contains(point))
                {
                    Polygon2DEditor polygonEditor = new Polygon2DEditor(this.Polygon);

                    polygonEditor.SetPoint(point.X, point.Y, i);
                }
            }
        }
Example #12
0
        private Polygon2D BuildPolygon()
        {
            Polygon2D polygon = new Polygon2D();
            Polygon2DEditor polygonEditor = new Polygon2DEditor(polygon);
            int j = 0;

            for (int i = 0; i < this.indices.Length; i++)
            {
                this.points[j].Y = this.Reverse - this.points[j].Y + XWFParser.Margin;
                polygonEditor.AddPoint(this.points[j]);
                j = this.indices[j];
            }

            return polygon;
        }
        public void FastTriangluation()
        {
            int from = 0;
            int to = 2;
            Polygon2DEditor polygonEditor = new Polygon2DEditor(this.FirstPolygons.Parent);

            polygonEditor.Clear();
            polygonEditor = new Polygon2DEditor(this.SecondPolygons.Parent);
            polygonEditor.Clear();

            this.InitLinkDistance();

            for (int i = 0; i < FirstPolygons.SubDivision.Count; i++)
            {
                int vertexCount = FirstPolygons.SubDivision[i].VertexCount;
                Polygon2D firstPolygon = FirstPolygons.SubDivision[i];
                Polygon2D secondPolygon = SecondPolygons.SubDivision[i];

                if (vertexCount <= 3)
                {
                    continue;
                }

                int dist = MAX_DIST;

                for (int j = 0; j < vertexCount; j++)
                {
                    for (int k = j + 2; k < vertexCount; k++)
                    {
                        if (j == k || Math.Abs(j - k) == 1 || Math.Abs(j - k) == vertexCount - 1)
                        {
                            continue;
                        }

                        LineSegment2D testLine = new LineSegment2D(firstPolygon.GetPoint(j), firstPolygon.GetPoint(k));

                        if (firstPolygon.InflectsEdge(testLine))
                        {
                            continue;
                        }

                        testLine = new LineSegment2D(secondPolygon.GetPoint(j), secondPolygon.GetPoint(k));
                        if (secondPolygon.InflectsEdge(testLine))
                        {
                            continue;
                        }

                        LinkDistance link = this.linkDistance.Contains(this.FirstPolygons.GetParentIndex(j, i), this.FirstPolygons.GetParentIndex(k, i), 0);

                        int d;

                        if (link != null)
                        {
                            d = link.linkDistance;
                        }

                        else
                        {
                            FirstTarget = new Polygon2DLinkMaker(firstPolygon, j, k);
                            SecondTarget = new Polygon2DLinkMaker(secondPolygon, j, k);
                            FirstTarget.Divide();
                            SecondTarget.Divide();

                            d = Math.Max(FirstTarget.LinkDistance, SecondTarget.LinkDistance);

                            link = new LinkDistance(this.FirstPolygons.GetParentIndex(j, i), this.FirstPolygons.GetParentIndex(k, i), 0, d);
                        }

                        if (dist > d)
                        {
                            dist = d;
                            from = j;
                            to = k;
                        }
                        else if (dist == d)
                        {
                            if (Math.Abs(vertexCount / 2 - Math.Abs(j - k)) > Math.Abs(vertexCount / 2 - Math.Abs(from - to)))
                            {
                                from = j;
                                to = k;
                            }
                        }
                    }
                }

                FirstTarget = new Polygon2DLinkMaker(firstPolygon, from, to);
                SecondTarget = new Polygon2DLinkMaker(secondPolygon, from, to);
                FirstTarget.Divide();
                FirstTarget.BuildPath();
                SecondTarget.Divide();
                SecondTarget.BuildPath();

                if (dist != Math.Max(FirstTarget.LinkDistance, SecondTarget.LinkDistance))
                {
                    dist = Math.Max(FirstTarget.LinkDistance, SecondTarget.LinkDistance);
                    this.linkDistance.Set(this.FirstPolygons.GetParentIndex(from, i), this.FirstPolygons.GetParentIndex(to, i), 0, dist);
                }

                int Extra = dist - FirstTarget.LinkDistance;

                if (Extra > 0)
                {
                    FirstTarget.LinkDivisers.Extend(Extra);
                }

                Extra = dist - SecondTarget.LinkDistance;
                if (Extra > 0)
                {
                    SecondTarget.LinkDivisers.Extend(Extra);
                }

                FirstPolygons.DividedBy(FirstTarget.LinkDivisers, firstPolygon);
                SecondPolygons.DividedBy(SecondTarget.LinkDivisers, secondPolygon);
            }

            GetResult();
            BuildGhostTriangle();
        }
Example #14
0
        public void Fitting()
        {
            GhostWeb ghostWeb = new GhostWeb(this.sourcePolygon, this.ghostTriangles);

            Vector[] vectors = new Vector[this.sourcePolygon.PointCount];

            for (int i = 0; i < vectors.Length; i++)
            {
                vectors[i] = new Vector(vectors.Length);
                vectors[i][i] = 1;

                if (i < this.sourcePolygon.VertexCount || this.sourcePolygon.isOnEdge(this.sourcePolygon.GetPoint(i)))
                {
                    continue;
                }

                else
                {
                    vectors[i][i] = 0;
                    WebNode webNode = ghostWeb.webNodes[i];

                    while (webNode!= null)
                    {
                        vectors[i][i] ++;
                        vectors[i][webNode.firstIndex] = -1;
                        vectors[i][webNode.secondIndex] = -1;

                        webNode = webNode.Next;
                    }
                }
            }

            Vector valx = new Vector(this.sourcePolygon.PointCount);
            Vector valy = new Vector(this.sourcePolygon.PointCount);

            for (int i = 0; i < this.targetPolygon.VertexCount; i++)
            {
                valx[i] = this.targetPolygon.GetPoint(i).X;
                valy[i] = this.targetPolygon.GetPoint(i).Y;
            }

            for (int i = this.sourcePolygon.VertexCount; i <this.sourcePolygon.PointCount; i++)
            {
                Point2D point = this.sourcePolygon.GetPoint(i);
                if(this.sourcePolygon.isOnEdge(point))
                {

                    int x = this.sourcePolygon.OnEdge(point);
                    LineSegment2D line = this.sourcePolygon.GetEdge(x);

                    double pos = line.GetPosition(point);
                    line = this.targetPolygon.GetEdge(x);

                    Point2D newPoint = line.GetPoint(pos);

                    valx[i] = newPoint.X;
                    valy[i] = newPoint.Y;
                }
            }

            Matrix m = new Matrix(vectors).Translate();

            UpdateStatus(this, "Constructing...");

            LinearSystem lsx = new LinearSystem(new Matrix(m), valx);

            UpdateStatus(this, "Done");

            lsx.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus);
            lsx.Gaussian(this.sourcePolygon.VertexCount);

            LinearSystem lsy = new LinearSystem(new Matrix(m), valy);
            lsy.UpdateStatus += new Microsoft.VS.Akira.Triangulations.LinearSystem.ShowStatus(UpdateStatus);
            lsy.Gaussian(this.sourcePolygon.VertexCount);

            Polygon2DEditor pe = new Polygon2DEditor(this.targetPolygon);

            UpdateStatus(this, "AddInner..");

            for (int i = this.sourcePolygon.VertexCount; i < this.sourcePolygon.PointCount; i++)
            {
                Point2D point = new Point2D(lsx.Value[i], lsy.Value[i]);
                pe.AddInnerPoint(point);
            }

            UpdateStatus(this, "Done");
        }