Ejemplo n.º 1
0
        private void DrawVoronoiDiagram()
        {
            var pointColor    = Color.FromRgb(25, 25, 25);
            var triangleColor = Color.FromRgb(50, 50, 50);
            var lineColor     = Color.FromRgb(22, 22, 22);

            if (_voronoiDiagram != null)
            {
                //Show Bounds
                if (ShowBounds == true)
                {
                    _drawService.DrawRectangle(_voronoiDiagram.Bounds, Colors.Red);
                }

                //Draw Triangulation
                if (_voronoiDiagram.Triangulation != null)
                {
                    foreach (var t in _voronoiDiagram.Triangulation)
                    {
                        //Fill triangles in a random color

                        if (ColorTriangles)
                        {
                            _drawService.DrawPolygon(t, Extensions.Extensions.RandomColor());
                        }

                        if (DrawTriangles == true)
                        {
                            _drawService.DrawTriangle(t, triangleColor);
                        }
                    }
                }


                //Voronoi Colors
                if (_voronoiDiagram.VoronoiCells != null && ColorVoronoi.Value == true || DrawVoronoi.Value == true)
                {
                    foreach (var cell in _voronoiDiagram.GetCellsInBounds())
                    {
                        var c = (ColorVoronoi == true) ? _baseColor.GetRandomColorOffset(0.2) : lineColor;
                        _drawService.DrawCell(cell, c, ColorVoronoi.Value);
                    }
                }
            }

            //Draw Points
            if (DrawPoints == true)
            {
                foreach (var p in _points)
                {
                    _drawService.DrawPoint(p, PointSize, pointColor);
                    if (ShowPointInfo == true)
                    {
                        _drawService.DrawText(p.ToString(), pointColor, p);
                    }
                }
            }
        }