Ejemplo n.º 1
0
        public GraphRenderer(GraphManager <T> manager)
        {
            _manager = manager;

            // typeface for step costs
            _typeface = _manager.Dialog.FontFamily.GetTypefaces().ElementAt(0);

            // create darkening shades for increasing costs
            _brushes = new Brush[_manager.MaxCost];
            for (byte i = 0; i < _manager.MaxCost; i++)
            {
                byte  channel = (byte)(255 - (255 * i) / _manager.MaxCost);
                Color color   = Color.FromRgb(channel, channel, channel);
                _brushes[i] = new SolidColorBrush(color);
                _brushes[i].Freeze();
            }

            _blackPen = new Pen(Brushes.Black, 1); _blackPen.Freeze();
            _bluePen  = new Pen(Brushes.Blue, 1); _bluePen.Freeze();
            _redPen   = new Pen(Brushes.Red, 1); _redPen.Freeze();

            // pen for Delaunay subdivision edges
            _edgePen           = new Pen(Brushes.Gold, 1);
            _edgePen.DashStyle = DashStyles.Dot;
            _edgePen.Freeze();
        }
Ejemplo n.º 2
0
        public static GraphManager <PointI> CreatePolygonGridManager(
            GraphDialog dialog, RegularPolygon polygon)
        {
            int         width = 20, height = 20;
            PolygonGrid grid = new PolygonGrid(polygon);

            grid.Size = new SizeI(width, height);

            // shrink grid until it fits in output box
            double outputWidth  = dialog.OutputBox.Width - 16;
            double outputHeight = dialog.OutputBox.Height - 16;

            while (grid.DisplayBounds.Width > outputWidth)
            {
                grid.Size = new SizeI(--width, height);
            }
            while (grid.DisplayBounds.Height > outputHeight)
            {
                grid.Size = new SizeI(width, --height);
            }

            var manager = new GraphManager <PointI>(dialog, 4);

            manager.Graph    = grid;
            manager.Renderer = new GraphRenderer <PointI>(manager);
            return(manager);
        }
Ejemplo n.º 3
0
        private void ShowGraph()
        {
            if (!_isInitialized)
            {
                return;
            }

            object         item            = GraphCombo.SelectedItem;
            bool           vertexNeighbors = (bool)VertexNeighbors.IsChecked;
            RegularPolygon polygon         = null;

            if (item == SquareEdgeGraph)
            {
                polygon = new RegularPolygon(24, 4, PolygonOrientation.OnEdge, vertexNeighbors);
            }
            else if (item == SquareVertexGraph)
            {
                polygon = new RegularPolygon(24, 4, PolygonOrientation.OnVertex, vertexNeighbors);
            }
            else if (item == HexagonEdgeGraph)
            {
                polygon = new RegularPolygon(16, 6, PolygonOrientation.OnEdge);
            }
            else if (item == HexagonVertexGraph)
            {
                polygon = new RegularPolygon(16, 6, PolygonOrientation.OnVertex);
            }

            if (polygon == null)
            {
                _manager = GraphManager <PointD> .CreateSubdivisionManager(this);

                VertexNeighbors.IsEnabled = false;
            }
            else
            {
                _manager = GraphManager <PointI> .CreatePolygonGridManager(this, polygon);

                VertexNeighbors.IsEnabled = (polygon.Sides == 4);
            }

            OutputBox.Children.Clear();
            OutputBox.Children.Add(_manager.Renderer);
            ShowAlgorithm(true);
        }
Ejemplo n.º 4
0
        public static GraphManager <PointD> CreateSubdivisionManager(GraphDialog dialog)
        {
            RectD output = new RectD(0, 0, dialog.OutputBox.Width, dialog.OutputBox.Height);
            RectD bounds = new RectD(8, 8, output.Width - 16, output.Height - 16);

            PointD[] points = GeoAlgorithms.RandomPoints(40, bounds, new PointDComparerX(), 20);

            VoronoiResults results  = Voronoi.FindAll(points, output);
            Subdivision    division = results.ToDelaunySubdivision(output, true);

            var manager = new GraphManager <PointD>(dialog, 8);

            manager.Graph    = division;
            manager.Renderer = new GraphRenderer <PointD>(manager);

            // scaling factor to keep step costs above node distance
            manager._scaleCost = output.Width + output.Height;
            return(manager);
        }