Exemplo n.º 1
0
        public void drawVector(DelaunayTriangulator.Triangle tr)
        {
            Pen pen = new Pen(Color.Green);

            pen.Width    = 2;
            pen.StartCap = LineCap.RoundAnchor;
            pen.EndCap   = LineCap.ArrowAnchor;
            gr.DrawLine(pen, tr.M1.x, tr.M1.y, tr.M1.x + tr.M1.Vector.x, tr.M1.y + tr.M1.Vector.y);
            gr.DrawLine(pen, tr.M2.x, tr.M2.y, tr.M2.x + tr.M2.Vector.x, tr.M2.y + tr.M2.Vector.y);
            gr.DrawLine(pen, tr.M3.x, tr.M3.y, tr.M3.x + tr.M3.Vector.x, tr.M3.y + tr.M3.Vector.y);
        }
Exemplo n.º 2
0
        public void BrushTriangle(DelaunayTriangulator.Triangle triangle)
        {
            PointF[] myPoints1 = { new PointF(triangle.M1.x, triangle.M1.y), new PointF(triangle.M2.x, triangle.M2.y), new PointF(triangle.M3.x, triangle.M3.y) };
            //PathGradientBrush pgradBrush = new PathGradientBrush(myPoints1);
            int          i         = (int)Math.Truncate((1 - triangle.DensityOfTriangle) * 255);
            SolidBrush   redBrush  = new SolidBrush(Color.FromArgb(i, i, i));
            GraphicsPath graphPath = new GraphicsPath();

            graphPath.AddPolygon(myPoints1);
            gr.FillPath(redBrush, graphPath);
        }
Exemplo n.º 3
0
            internal void Process()
            {
                // Process all sorted points

                float circumCirclecenterX;
                float circumCirclecenterY;
                float circumCircleRadius;
                float dx, dy;
                float pointX = 0, pointY = 0;
                float pointYplusTolerance;

                PointF point = this.points[this.pointsIndices[this.pointsIndices.Length - 1]];

                for (int sortedIndex = 0; sortedIndex < this.pointsIndices.Length; ++sortedIndex)
                {
                    int pointIndex = this.pointsIndices[sortedIndex];

                    point = this.points[pointIndex];

                    if (sortedIndex != 0 && Math.Abs(point.X - pointX) < tolerance && Math.Abs(point.Y - pointY) < tolerance)
                    {
                        continue; // Ignore current point if equals to previous point. We check equality using tolerance.
                    }
                    pointX = point.X;
                    pointY = point.Y;
                    pointYplusTolerance = pointY + tolerance;

                    // Check if triangle contains current point in its circumcenter.
                    // If yes, add triangle edges to edges table and remove triangle.
                    for (int nextNonCompleted, triangleIndex = this.firstNonCompletedTriangle; triangleIndex >= 0; triangleIndex = nextNonCompleted)
                    {
                        // Calculate distance between triancle circumcircle center and current point
                        // Compare that distance with radius of triangle circumcircle
                        // If is less, it means that the point is inside of circumcircle, else, it means it is outside.

                        circumCirclecenterX = this.Triangles[triangleIndex].circumCirclecenterX;
                        circumCirclecenterY = this.Triangles[triangleIndex].circumCirclecenterY;
                        circumCircleRadius  = this.Triangles[triangleIndex].circumCircleRadius;
                        nextNonCompleted    = this.Triangles[triangleIndex].nextNonCompleted;

                        dx = pointX - circumCirclecenterX;
                        dy = pointY - circumCirclecenterY;

                        if ((dx * dx + dy * dy) <= circumCircleRadius)
                        {
                            // Point is inside triangle circumcircle.
                            // Add triangle edges to edge table and remove the triangle

                            this.ReplaceTriangleWithEdges(triangleIndex, ref this.Triangles[triangleIndex]);
                        }
                        else if ((circumCirclecenterY < pointYplusTolerance) && (dy > circumCircleRadius + tolerance))
                        {
                            // Triangle not need to be checked anymore.
                            // Remove it from linked list of non completed triangles.

                            this.MarkAsComplete(ref this.Triangles[triangleIndex]);
                        }
                    }

                    // Form new triangles for the current point
                    // Edges used more than once will be skipped
                    // Triangle vertices are arranged in clockwise order

                    for (int j = 0; j < this.edgesCount; ++j)
                    {
                        DelaunayTriangulator.EdgeEntry edge = this.edgesEntries[j];
                        if (this.edgesEntries[j].count == 1)
                        {
                            // If edge was used only one time, add a new triangle built from current edge.

                            this.AddTriangle(edge.A, edge.B, pointIndex);
                        }
                    }

                    // Clear edges table

                    ++this.edgesGeneration;
                    this.edgesCount = 0;
                }

                this.firstNonCompletedTriangle = -1;

                // Count valid triangles (triangles that don't share vertices with supertriangle) and find the last triangle.

                this.TrianglesLast  = this.TrianglesFirst;
                this.TrianglesCount = 0;
                if (this.TrianglesLast != -1)
                {
                    for (; ;)
                    {
                        DelaunayTriangulator.Triangle triangle = this.Triangles[this.TrianglesLast];

                        if (triangle.A < this.pointsCount && triangle.B < this.pointsCount && triangle.C < this.pointsCount)
                        {
                            // Valid triangle found. Increment count.
                            ++this.TrianglesCount;
                        }
                        else
                        {
                            // Current triangle is invalid. Mark it as invalid
                            this.Triangles[this.TrianglesLast].A = -1;
                        }

                        int next = this.Triangles[this.TrianglesLast].Next;
                        if (next == -1)
                        {
                            break;
                        }

                        this.TrianglesLast = next;
                    }
                }
            }
Exemplo n.º 4
0
 public void drawTriangle(DelaunayTriangulator.Triangle tr)
 {
     gr.DrawLine(darkGoldPen, tr.M1.x, tr.M1.y, tr.M2.x, tr.M2.y);
     gr.DrawLine(darkGoldPen, tr.M2.x, tr.M2.y, tr.M3.x, tr.M3.y);
     gr.DrawLine(darkGoldPen, tr.M3.x, tr.M3.y, tr.M1.x, tr.M1.y);
 }