internal static double CompatibleTriangleQuality(GhostTriangle2D ghostTriangle, Polygon2D firstPolygon, Polygon2D secondPolygon)
        {
            double d1 = TriangleQuality(ghostTriangle.ToTriangle(firstPolygon));
            double d2 = TriangleQuality(ghostTriangle.ToTriangle(secondPolygon));

            return Math.Min(d1, d2);
        }
 public Polygon2DDiviser(Polygon2D parent)
 {
     Parent = parent;
     SubDivision = new Polygon2DCollection();
     Divisers = new LineSegment2DCollection();
     InnerPoints = new Point2DCollection();
     SubDivision.Add(Parent);
 }
Example #3
0
        public Polygon2D(Polygon2D polygon)
        {
            Vertices = new Point2DCollection();

            Vertices.Clone(polygon.Vertices);

            SetStatus();
        }
 public Polygon2DAdorner(Polygon2D p)
 {
     polygon = p;
     triangles = new Triangle2DCollection(1);
     lineSegments = new LineSegment2DCollection(1);
     internalSegments = new Vector2DCollection(1);
     ghostTriangles = new GhostTriangle2DCollection(1);
 }
Example #5
0
        public GhostWeb(Polygon2D poly, GhostTriangle2DCollection ghostTriangles)
        {
            Polygon = poly;

            webNodes = new WebNode[poly.PointCount];

            this.BuildGhostWeb(ghostTriangles);
        }
Example #6
0
        public Fliper(Polygon2D firstPolygon, Polygon2D secondPolygon)
        {
            if (firstPolygon.VertexCount != secondPolygon.VertexCount)
            {
                throw (new ArgumentException());
            }

            this.FirstPolygon = firstPolygon;
            this.SecondPolygon = secondPolygon;
        }
        public CompatibleDiviser(Polygon2D a, Polygon2D b)
        {
            this.firstPolygon = a;
            this.secondPolygon = b;

            this.firstPolygonCollection = new Polygon2DCollection();
            this.secondPolygonCollection = new Polygon2DCollection();

            targetDiviser = new TargetDiviser(b);
        }
        internal SurfaceFitter(Polygon2D a, Polygon2D b, GhostTriangle2DCollection ghost)
        {
            if (a.VertexCount != b.VertexCount)
            {
                throw (new ArgumentException());
            }

            sourcePolygon = a;
            targetPolygon = b;
            ghostTriangles = ghost;
        }
        public Polygon2DCollection(Polygon2D[] polygons, int capacity)
        {
            Capacity = capacity;
            CurrentCount = polygons.Length;
            if (Capacity < CurrentCount)
            {
                throw (new CollectionCapacityException());
            }

            Polygons = polygons;
        }
        public Polygon2DLinkMaker(Polygon2D polygon, int a, int b)
            : base(polygon)
        {
            if (!polygon.isRegular)
            {
                throw (new ArgumentException());
            }

            FirstPoint = polygon.GetPoint(a);
            LastPoint = polygon.GetPoint(b);
            LinkDivisers = new Point2DCollection();
            //Partitions = new Polygon2DCollection();
            //Partitions.Add(polygon);
        }
        public HighQualityTriangulator(Polygon2D a, Polygon2D b)
        {
            if (!a.isRegular && !b.isRegular)
            {
                throw (new ArgumentException());
            }
            if (a.VertexCount != b.VertexCount)
            {
                throw (new ArgumentException());
            }

            FirstPolygons = new Polygon2DDiviser(a);
            SecondPolygons = new Polygon2DDiviser(b);
        }
Example #12
0
        private Polygon2D FlipArea(GhostTriangle2D a, GhostTriangle2D b, Polygon2D poly)
        {
            if (!isNeighbor(a, b))
            {
                throw (new ArgumentException());
            }

            Map(a, b);

            Point2DCollection points = new Point2DCollection(4);

            points.Add(poly.GetPoint(a.C));
            points.Add(poly.GetPoint(a.A));
            points.Add(poly.GetPoint(b.C));
            points.Add(poly.GetPoint(b.B));

            Polygon2D polygon = new Polygon2D(points);
            return polygon;
        }
 public Polygon2DEditor(Polygon2D polygon)
 {
     Polygon = polygon;
 }
 internal static double TriangleQuality(GhostTriangle2D ghostTriangle, Polygon2D polygon)
 {
     return TriangleQuality(ghostTriangle.ToTriangle(polygon));
 }
        internal static double ShapeQuality(GhostTriangle2D ghostTriangle, Polygon2D polygon)
        {
            Triangle2D triangle = ghostTriangle.ToTriangle(polygon);

            return ShapeQuality(triangle);
        }
 private bool isEdge(int a, int b,Polygon2D polygon)
 {
     if (Math.Abs(a - b) == 1 || Math.Abs(a - b) == polygon.VertexCount - 1)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
        /// <summary>
        /// Divide a sub polygon by a line segment.
        /// </summary>
        /// <param name="lineSegment">the line segment.</param>
        /// <param name="poly">the polygon to divide.</param>
        /// <returns>one of the sub polygon divided from the polygon.</returns>
        internal Polygon2D DividedBy(LineSegment2D lineSegment, Polygon2D poly)
        {
            if (poly.isDiagonal(lineSegment))
            {
                int a = poly.HasVertex(lineSegment.FirstPoint);
                int b = poly.HasVertex(lineSegment.LastPoint);

                if (a > b)
                {
                    int tmp = a;
                    a = b;
                    b = tmp;
                }

                Point2DCollection p2 = new Point2DCollection(b - a + 1);
                Point2DCollection p1 = new Point2DCollection(poly.VertexCount - p2.Size + 2);

                for (int i = 0; i < poly.VertexCount; i++)
                {
                    if (i <= a || i >= b)
                    {
                        p1.Add(poly.GetPoint(i));
                    }
                    if (i >= a && i <= b)
                    {
                        p2.Add(poly.GetPoint(i));
                    }
                }

                if (p1.Count > p2.Count)
                {
                    SubDivision.Add(new Polygon2D(p1));
                    return new Polygon2D(p2);
                }
                else
                {
                    SubDivision.Add(new Polygon2D(p2));
                    return new Polygon2D(p1);
                }
            }
            else if (lineSegment.Intersects(poly))
            {
                Point2DCollection Points = new Point2DCollection(2);

                for (int i = 0; i < poly.VertexCount; i++)
                {
                    LineSegment2D border = poly.GetEdge(i);

                    Point2D p = lineSegment.GetIntersectPoint(border);

                    if (p.isRegular)
                    {
                        Points.DistinctAdd(p);
                    }
                }

                Debug.Assert(Points.Count == 2);

                if (poly.HasVertex(Points[0]) == Polygon2D.NoSuchPoint)
                {
                    poly.Add(Points[0], poly.OnEdge(Points[0]));
                    Parent.AddInner(Points[0]);
                    this.InnerPoints.DistinctAdd(Points[0]);
                }

                if (poly.HasVertex(Points[1]) == Polygon2D.NoSuchPoint)
                {
                    poly.Add(Points[1], poly.OnEdge(Points[1]));
                    Parent.AddInner(Points[1]);
                    this.InnerPoints.DistinctAdd(Points[1]);
                }

                LineSegment2D line = new LineSegment2D(Points[0], Points[1]);

                return DividedBy(line, poly);
            }
            else
            {
                return poly;
            }
        }
 public TriangleDiviser(Polygon2D a, Polygon2D b)
 {
     firstPolygon = a;
     secondPolygon = b;
 }
Example #19
0
        private void PolygonScroll(Polygon2D polygon)
        {
            Polygon2DEditor pe = new Polygon2DEditor(polygon);

            pe.Scroll();
        }
Example #20
0
        private void Initialize()
        {
            this.MoveTimer.Stop();
            this.splitingMenuItem1.Checked = true;
            this.subDivisionMenuItem.Checked = true;
            this.flippingMenuItem1.Checked = true;
            this.areaBasedRemeshingMenuItem.Checked = true;

            this.competibleTriangulationMenuItem.Checked = true;
            StatusController.Triangulator = TriangulationTech.Simple;

            Polygon2D firstPolygon = new Polygon2D(new Point2DCollection());
            LeftPolygon = new Polygon2DAdorner(firstPolygon);
            Polygon2D secondPolygon = new Polygon2D(new Point2DCollection());
            RightPolygon = new Polygon2DAdorner(secondPolygon);

            this.triangulationMenuItem.Enabled = false;
            StatusController.canAddPoint = true;
            this.toolBarButton4.Enabled = true;
            this.toolBarButton4.Pushed = true;
            this.toolBar1.Buttons[5].Enabled = false;
            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.statusBarPanel1.Text = this.GetPolygonStatus(new Point2D(1, 1));
            this.statusBarPanel2.Text = "Hint Index : -1 ";
            this.Invalidate();
        }
Example #21
0
        public Triangle2D ToTriangle(Polygon2D polygon)
        {
            Point2D a = polygon.GetPoint(this.A);
            Point2D b = polygon.GetPoint(this.B);
            Point2D c = polygon.GetPoint(this.C);

            return new Triangle2D(a, b, c);
        }
Example #22
0
 private void SetReverse(Polygon2D polygon)
 {
     for (int i = 0; i < polygon.VertexCount; i++)
     {
         Point2D point = polygon.GetPoint(i);
         if (this.Reverse < point.Y)
         {
             this.Reverse = point.Y;
         }
     }
 }
Example #23
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;
        }
Example #24
0
        public void Write(Polygon2D Polygon)
        {
            this.SetReverse(Polygon);

            XmlTextWriter xmlWriter = new XmlTextWriter(Path, Encoding.UTF8);

            xmlWriter.WriteStartDocument(true);
                xmlWriter.WriteStartElement("pn", "Polygon", "urn:Microsoft.VS.Akira.Triangulations");
                    xmlWriter.WriteStartElement("pn:Coordinate");
                        xmlWriter.WriteStartAttribute("", "type", "");
                            xmlWriter.WriteString("Reversed");
                        xmlWriter.WriteEndAttribute();
                        xmlWriter.WriteStartAttribute("", "top", "");
                            xmlWriter.WriteString(this.Reverse.ToString());
                        xmlWriter.WriteEndAttribute();
                        xmlWriter.WriteStartAttribute("", "margin", "");
                            xmlWriter.WriteString(XWFParser.Margin.ToString());
                        xmlWriter.WriteEndAttribute();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("pn:Vertices");
                        xmlWriter.WriteStartAttribute("","count","");
                        xmlWriter.WriteString(Polygon.VertexCount.ToString());
                        xmlWriter.WriteEndAttribute();

            for(int i = 0; i < Polygon.VertexCount; i++)
            {
                Point2D point = new Point2D(Polygon.GetPoint(i));
                point.Y = this.Reverse + XWFParser.Margin - point.Y;

                xmlWriter.WriteStartElement("pn:Vertex");
                xmlWriter.WriteStartAttribute("","index","");
                xmlWriter.WriteString(i.ToString());
                xmlWriter.WriteEndAttribute();
                xmlWriter.WriteStartAttribute("","x","");
                xmlWriter.WriteString(point.X.ToString());
                xmlWriter.WriteEndAttribute();
                xmlWriter.WriteStartAttribute("","y","");
                xmlWriter.WriteString(point.Y.ToString());
                xmlWriter.WriteEndAttribute();
                xmlWriter.WriteStartAttribute("","z","");
                xmlWriter.WriteString("0");
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteEndElement();
            }

                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("pn:Edges");

            for (int i = 0; i < Polygon.VertexCount; i++)
            {
                xmlWriter.WriteStartElement("pn:Edge");
                xmlWriter.WriteStartAttribute("","from","");
                xmlWriter.WriteString(i.ToString());
                xmlWriter.WriteEndAttribute();
                xmlWriter.WriteStartAttribute("","to","");
                xmlWriter.WriteString(((i+1) % Polygon.VertexCount).ToString());
                xmlWriter.WriteEndAttribute();
                xmlWriter.WriteEndElement();
            }

                    xmlWriter.WriteEndElement();
                xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();

            xmlWriter.Close();
        }
Example #25
0
        private void Restart()
        {
            this.FileName = null;

            this.Clear();

            StatusController.canRestart = true;
            polygonLinkAdorner = null;

            if (StatusController.availablePartition == Partition.Left)
            {
                Polygon2D firstPolygon = new Polygon2D(new Point2DCollection());
                LeftPolygon = new Polygon2DAdorner(firstPolygon);
            }
            else
            {
                Polygon2D secondPolygon = new Polygon2D(new Point2DCollection());
                RightPolygon = new Polygon2DAdorner(secondPolygon);
            }
            this.triangulationMenuItem.Enabled = false;
            StatusController.canAddPoint = true;
            this.toolBarButton4.Enabled = true;
            this.toolBarButton4.Pushed = true;
            this.toolBar1.Buttons[5].Enabled = false;

            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.statusBarPanel1.Text = this.GetPolygonStatus(new Point2D(1,1));
            this.statusBarPanel2.Text = "Hint Index : -1 ";

            this.Invalidate();
        }
        /// <summary>
        /// Divide a polygon by a path.(point2DCollection)
        /// </summary>
        /// <param name="path">the path.</param>
        /// <param name="polygon">the polygon to divide.</param>
        public void DividedBy(Point2DCollection path, Polygon2D polygon)
        {
            int a = polygon.HasVertex(path.FirstPoint);
            int b = polygon.HasVertex(path.LastPoint);

            if (a == Polygon2D.NoSuchPoint || b == Polygon2D.NoSuchPoint)
            {
                throw (new ArgumentException());
            }

            if (a > b)
            {
                int tmp = a;

                a = b;
                b = tmp;
            }

            Point2DCollection p2 = new Point2DCollection();
            Point2DCollection p1 = new Point2DCollection();

            for (int i = 0; i < polygon.VertexCount; i++)
            {
                if (i <= a || i >= b)
                {
                    p1.Add(polygon.GetPoint(i));
                }

                if (i >= a && i <= b)
                {
                    p2.Add(polygon.GetPoint(i));
                }
            }

            for (int i = 1; i < path.Count - 1; i++)
            {
                p1.Add(path[i], a + i);
                p2.Add(path[i], 0);
                Parent.AddInner(path[i]);
            }

            if (p1.Count > p2.Count)
            {
                SubDivision.Add(new Polygon2D(p1));
                SubDivision.Add(new Polygon2D(p2));
            }
            else
            {
                SubDivision.Add(new Polygon2D(p2));
                SubDivision.Add(new Polygon2D(p1));
            }
        }
        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 #28
0
        private GhostWeb(Polygon2D poly)
        {
            Polygon = poly;

            webNodes = new WebNode[poly.PointCount];
        }
Example #29
0
        /// <summary>
        /// Whether ths line segment intersects a polygon.
        /// </summary>
        /// <param name="polygon">the polygon.</param>
        /// <returns>true if intersects.</returns>
        public bool Intersects(Polygon2D polygon)
        {
            bool bResult = false;

            for (int i = 0; i < polygon.VertexCount; i++)
            {
                LineSegment2D lineSegment = polygon.GetEdge(i);

                //bResult |= this.TrulyIntersects(polygon.GetEdge(i));
                bResult |= (this.TrulyLineIntersects(lineSegment) && lineSegment.Intersects(this));
                if (bResult)
                {
                    return true;
                }
            }

            return bResult;
        }
Example #30
0
 internal Rebuild(Polygon2D poly)
 {
     polygon = new Polygon2D(poly);
     ghostTriangles = new GhostTriangle2DCollection();
 }