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();
        }
Example #2
0
        internal void Flipping(GhostTriangle2DCollection ghostTriangles)
        {
            for (int i = 0; i < ghostTriangles.Count; i++)
            {
                for (int j = i; j < ghostTriangles.Count; j++)
                {
                    GhostTriangle2D t1 = ghostTriangles[i];
                    GhostTriangle2D t2 = ghostTriangles[j];

                    if (isNeighbor(t1, t2))
                    {
                        Polygon2D p1 = FlipArea(t1, t2, this.FirstPolygon);
                        Polygon2D p2 = FlipArea(t1, t2, this.SecondPolygon);

                        if (p1.isConvex && p2.isConvex)
                        {
                            double d1 = QualityDeterminer.CompatibleTriangleQuality(t1, this.FirstPolygon, this.SecondPolygon);
                            double d2 = QualityDeterminer.CompatibleTriangleQuality(t2, this.FirstPolygon, this.SecondPolygon);

                            double d = Math.Min(d1, d2);

                            FlipGhostTriangle(t1, t2);

                            d1 = QualityDeterminer.CompatibleTriangleQuality(t1, this.FirstPolygon, this.SecondPolygon);
                            d2 = QualityDeterminer.CompatibleTriangleQuality(t2, this.FirstPolygon, this.SecondPolygon);

                            if (d > Math.Min(d1, d2))
                            {
                                FlipGhostTriangle(t1, t2);
                            }
                        }
                    }
                }
            }
        }
        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();
        }
Example #4
0
        internal void Flipping(GhostTriangle2DCollection ghostTriangles)
        {
            for (int i = 0; i < ghostTriangles.Count; i++)
            {
                for (int j = i; j < ghostTriangles.Count; j++)
                {
                    GhostTriangle2D t1 = ghostTriangles[i];
                    GhostTriangle2D t2 = ghostTriangles[j];

                    if (isNeighbor(t1, t2))
                    {
                        Polygon2D p1 = FlipArea(t1, t2, this.FirstPolygon);
                        Polygon2D p2 = FlipArea(t1, t2, this.SecondPolygon);

                        if (p1.isConvex && p2.isConvex)
                        {
                            double d1 = QualityDeterminer.CompatibleTriangleQuality(t1, this.FirstPolygon, this.SecondPolygon);
                            double d2 = QualityDeterminer.CompatibleTriangleQuality(t2, this.FirstPolygon, this.SecondPolygon);

                            double d = Math.Min(d1, d2);

                            FlipGhostTriangle(t1, t2);

                            d1 = QualityDeterminer.CompatibleTriangleQuality(t1, this.FirstPolygon, this.SecondPolygon);
                            d2 = QualityDeterminer.CompatibleTriangleQuality(t2, this.FirstPolygon, this.SecondPolygon);

                            if (d > Math.Min(d1, d2))
                            {
                                FlipGhostTriangle(t1, t2);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public void Triangulation()
        {
            if (!this.polygon.isRegular || !this.polygon.isSimple)
            {
                throw (new ApplicationException("Can not triangulate this polygon!"));
            }

            //this.triangles.Clear();
            //this.lineSegments.Clear();
            this.internalSegments.Clear();
            this.ghostTriangles = new GhostTriangle2DCollection();
            this.Clear();

            int Count = this.polygon.VertexCount;

            int[] flag = new int[Count];

            for (int i = 0; i < Count; i++)
            {
                flag[i] = i;
            }

            int a = 0;
            int b = 1;
            int c = 2;

            while (Count > 3)
            {
                LineSegment2D lineSegment = new LineSegment2D(this.polygon.GetPoint(flag[a]), this.polygon.GetPoint(flag[c]));

                if (this.polygon.Contains(lineSegment))
                {
                    Count--;
                    this.Triangulation(flag[a], flag[b], flag[c]);

                    for (int i = b; i < Count; i++)
                    {
                        flag[i] = flag[i + 1];
                    }

                    a = a % Count;
                    b = (a + 1) % Count;
                    c = (b + 1) % Count;
                    continue;
                }
                else
                {
                    a = (a + 1) % Count;
                    b = (b + 1) % Count;
                    c = (c + 1) % Count;
                }
            }
            this.Triangulation(flag[a], flag[b], flag[c]);

            if (this.child != null)
            {
                this.child.Triangulation();
            }
        }
Example #6
0
        public GhostWeb(Polygon2D poly, GhostTriangle2DCollection ghostTriangles)
        {
            Polygon = poly;

            webNodes = new WebNode[poly.PointCount];

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

            webNodes = new WebNode[poly.PointCount];

            this.BuildGhostWeb(ghostTriangles);
        }
        public void Union(GhostTriangle2DCollection ghostTriangle2DCollection)
        {
            Capacity += ghostTriangle2DCollection.Capacity;

            GhostTriangle2D[] ghostTriangles = new GhostTriangle2D[Capacity];

            this.GhostTriangles.CopyTo(ghostTriangles, 0);
            ghostTriangle2DCollection.GhostTriangles.CopyTo(ghostTriangles, this.Count);
            this.GhostTriangles = ghostTriangles;
            CurrentCount       += ghostTriangle2DCollection.Count;
        }
Example #11
0
        internal SurfaceFitter(Polygon2D a, Polygon2D b, GhostTriangle2DCollection ghost)
        {
            if (a.VertexCount != b.VertexCount)
            {
                throw (new ArgumentException());
            }

            sourcePolygon  = a;
            targetPolygon  = b;
            ghostTriangles = ghost;
        }
Example #12
0
        internal SurfaceFitter(Polygon2D a, Polygon2D b, GhostTriangle2DCollection ghost)
        {
            if (a.VertexCount != b.VertexCount)
            {
                throw (new ArgumentException());
            }

            sourcePolygon = a;
            targetPolygon = b;
            ghostTriangles = ghost;
        }
        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()
        {
            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);
        }
Example #15
0
        private void BuildGhostTriangle()
        {
            this.ghostTriangle = new GhostTriangle2DCollection();

            for (int i = 0; i < this.FirstResult.Count; i++)
            {
                Polygon2D polygon = this.FirstResult[i];

                int a = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(0));
                int b = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(1));
                int c = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(2));

                this.ghostTriangle.Add(new GhostTriangle2D(a, b, c));
            }
        }
        private void SplitGhostTriangle(GhostTriangle2DCollection ghostTriangles, GhostTriangle2D ghostTriangle)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                if (isNeighbor(ghostTriangles[i], ghostTriangle))
                {
                    Map(ghostTriangles[i], ghostTriangle);

                    GhostTriangle2D triangle = new GhostTriangle2D(ghostTriangles[i].A, ghostTriangles[i].C, ghostTriangle.C);

                    ghostTriangles.Add(triangle);

                    ghostTriangles[i].A = ghostTriangle.C;
                }
            }
        }
        internal void Split(GhostTriangle2DCollection ghostTriangles)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                Triangle2D t1 = ghostTriangles[i].ToTriangle(firstPolygon);
                Triangle2D t2 = ghostTriangles[i].ToTriangle(secondPolygon);

                double d1 = QualityDeterminer.ShapeQuality(t1);
                double d2 = QualityDeterminer.ShapeQuality(t2);

                if (d1 < TriangleDiviser.ShapeTolerance || d2 < TriangleDiviser.ShapeTolerance)
                {
                    GhostTriangle2D ghostTriangle = Split(ghostTriangles[i]);
                    SplitGhostTriangle(ghostTriangles, ghostTriangle);
                }
            }
        }
        internal void Split(GhostTriangle2DCollection ghostTriangles)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                Triangle2D t1 = ghostTriangles[i].ToTriangle(firstPolygon);
                Triangle2D t2 = ghostTriangles[i].ToTriangle(secondPolygon);

                double d1 = QualityDeterminer.ShapeQuality(t1);
                double d2 = QualityDeterminer.ShapeQuality(t2);

                if (d1 < TriangleDiviser.ShapeTolerance || d2 < TriangleDiviser.ShapeTolerance)
                {
                    GhostTriangle2D ghostTriangle = Split(ghostTriangles[i]);
                    SplitGhostTriangle(ghostTriangles, ghostTriangle);
                }
            }
        }
Example #19
0
        public void BuildGhostWeb(GhostTriangle2DCollection ghostTriangles)
        {
            this.available = true;

            for (int i = 0; i < ghostTriangles.Count; i++)
            {
                int a = ghostTriangles[i].A;
                int b = ghostTriangles[i].B;
                int c = ghostTriangles[i].C;

                this.BuildWebNode(a, b, c);
                this.BuildWebNode(b, c, a);
                this.BuildWebNode(c, a, b);

                if (!this.available)
                {
                    return;
                }
            }
        }
        internal void Divide(GhostTriangle2DCollection ghostTriangles)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                if(QualityDeterminer.AreaQuality(ghostTriangles[i], firstPolygon) < AreaTolerance|| QualityDeterminer.AreaQuality(ghostTriangles[i], secondPolygon) < AreaTolerance)
                {
                    Divide(ghostTriangles[i]);

                    GhostTriangle2D ghostTriangle = new GhostTriangle2D(ghostTriangles[i].A, ghostTriangles[i].B, this.firstPolygon.PointCount - 1);

                    ghostTriangles.Add(ghostTriangle);

                    ghostTriangle = new GhostTriangle2D(ghostTriangles[i].A, this.firstPolygon.PointCount - 1, ghostTriangles[i].C);

                    ghostTriangles.Add(ghostTriangle);

                    ghostTriangles[i].A = this.firstPolygon.PointCount - 1;
                }
            }
        }
        internal void Divide(GhostTriangle2DCollection ghostTriangles)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                if (QualityDeterminer.AreaQuality(ghostTriangles[i], firstPolygon) < AreaTolerance || QualityDeterminer.AreaQuality(ghostTriangles[i], secondPolygon) < AreaTolerance)
                {
                    Divide(ghostTriangles[i]);

                    GhostTriangle2D ghostTriangle = new GhostTriangle2D(ghostTriangles[i].A, ghostTriangles[i].B, this.firstPolygon.PointCount - 1);

                    ghostTriangles.Add(ghostTriangle);

                    ghostTriangle = new GhostTriangle2D(ghostTriangles[i].A, this.firstPolygon.PointCount - 1, ghostTriangles[i].C);

                    ghostTriangles.Add(ghostTriangle);

                    ghostTriangles[i].A = this.firstPolygon.PointCount - 1;
                }
            }
        }
        private void SplitGhostTriangle(GhostTriangle2DCollection ghostTriangles, GhostTriangle2D ghostTriangle)
        {
            int Count = ghostTriangles.Count;

            for (int i = 0; i < Count; i++)
            {
                if (isNeighbor(ghostTriangles[i], ghostTriangle))
                {
                    Map(ghostTriangles[i], ghostTriangle);

                    GhostTriangle2D triangle = new GhostTriangle2D(ghostTriangles[i].A, ghostTriangles[i].C, ghostTriangle.C);

                    ghostTriangles.Add(triangle);

                    ghostTriangles[i].A = ghostTriangle.C;
                }
            }
        }
        private void BuildGhostTriangle()
        {
            this.ghostTriangle = new GhostTriangle2DCollection();

            for (int i = 0; i < this.FirstResult.Count; i++)
            {
                Polygon2D polygon = this.FirstResult[i];

                int a = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(0));
                int b = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(1));
                int c = this.FirstPolygons.Parent.GetPointIndex(polygon.GetPoint(2));

                this.ghostTriangle.Add(new GhostTriangle2D(a, b, c));
            }
        }
Example #24
0
 internal Rebuild(Polygon2D poly)
 {
     polygon = new Polygon2D(poly);
     ghostTriangles = new GhostTriangle2DCollection();
 }
        public void Triangulation()
        {
            if (!this.polygon.isRegular || !this.polygon.isSimple)
            {
                throw (new ApplicationException("Can not triangulate this polygon!"));
            }

            //this.triangles.Clear();
            //this.lineSegments.Clear();
            this.internalSegments.Clear();
            this.ghostTriangles = new GhostTriangle2DCollection();
            this.Clear();

            int Count = this.polygon.VertexCount;
            int[] flag = new int[Count];

            for (int i = 0; i < Count; i++)
            {
                flag[i] = i;
            }

            int a = 0;
            int b = 1;
            int c = 2;

            while (Count > 3)
            {
                LineSegment2D lineSegment = new LineSegment2D(this.polygon.GetPoint(flag[a]), this.polygon.GetPoint(flag[c]));

                if (this.polygon.Contains(lineSegment))
                {
                    Count--;
                    this.Triangulation(flag[a], flag[b], flag[c]);

                    for (int i = b; i < Count; i++)
                    {
                        flag[i] = flag[i + 1];
                    }

                    a = a % Count;
                    b = (a + 1) % Count;
                    c = (b + 1) % Count;
                    continue;
                }
                else
                {
                    a = (a + 1) % Count;
                    b = (b + 1) % Count;
                    c = (c + 1) % Count;
                }
            }
            this.Triangulation(flag[a],flag[b],flag[c]);

            if (this.child != null)
            {
                this.child.Triangulation();
            }
        }
 internal void ApplyGhostTriangles(GhostTriangle2DCollection Triangles)
 {
     this.ghostTriangles = Triangles;
 }
Example #27
0
        public void BuildGhostWeb(GhostTriangle2DCollection ghostTriangles)
        {
            this.available = true;

            for (int i = 0; i < ghostTriangles.Count;  i++)
            {
                int a = ghostTriangles[i].A;
                int b = ghostTriangles[i].B;
                int c = ghostTriangles[i].C;

                this.BuildWebNode(a, b, c);
                this.BuildWebNode(b, c, a);
                this.BuildWebNode(c, a, b);

                if (!this.available)
                {
                    return;
                }
            }
        }
Example #28
0
 internal void ApplyGhostTriangles(GhostTriangle2DCollection Triangles)
 {
     this.ghostTriangles = Triangles;
 }
Example #29
0
        public void Union(GhostTriangle2DCollection ghostTriangle2DCollection)
        {
            Capacity += ghostTriangle2DCollection.Capacity;

            GhostTriangle2D[] ghostTriangles = new GhostTriangle2D[Capacity];

            this.GhostTriangles.CopyTo(ghostTriangles, 0);
            ghostTriangle2DCollection.GhostTriangles.CopyTo(ghostTriangles, this.Count);
            this.GhostTriangles = ghostTriangles;
            CurrentCount += ghostTriangle2DCollection.Count;
        }
Example #30
0
 internal Rebuild(Polygon2D poly)
 {
     polygon        = new Polygon2D(poly);
     ghostTriangles = new GhostTriangle2DCollection();
 }