예제 #1
0
        private async void Wavefront(object sender, RoutedEventArgs e)
        {
            if (!CheckMapAndStopDrawing())
                return;
            DisableMenu();

            var mapTask = (IsFourNeighborhood) ? Task.Factory.StartNew(() => Potential.Wavefront4(_Map)) : Task.Factory.StartNew(() => Potential.Wavefront8(_Map));



            _Map = await mapTask;

            _Path = SteepestDescent.SteepestDescentPlanner.Plan(_Map);

            ShowMap();


            EnableMenu();
        }
예제 #2
0
        void LoadMap(Stream fileStream)
        {

            var img = new BitmapImage();
            img.SetSource(fileStream);


            var writeable = new WriteableBitmap(img);

            var width = img.PixelWidth;

            var map = new Cell[img.PixelWidth, img.PixelHeight];

            for (int row = 0; row < img.PixelHeight; ++row)
                for (int col = 0; col < img.PixelWidth; ++col)
                {
                    var cell = Cell.Free;
                    var pixel = writeable.GetPixeli(col, row);
                    switch (pixel)
                    {
                        case WHITE:
                            cell = Cell.Free;
                            break;
                        case BLACK:
                            cell = Cell.Obstacle;
                            break;
                        case RED:
                            cell = Cell.Goal;
                            break;
                        case GREEN:
                            cell = Cell.Start;
                            break;
                        default:
                            System.Diagnostics.Debugger.Break();
                            StatusText.Text = "Invalid Color encountered";
                            break;

                    }
                    map[col, row] = cell;
                }
            _Map = new RobotMap(map);
            _Path = null;
            ShowMap();
        }
예제 #3
0
        private async void Brushfire(object sender, RoutedEventArgs e)
        {
            if (!CheckMapAndStopDrawing())
                return;
            DisableMenu();


            Task<RobotMap> mapTask = (IsFourNeighborhood) ? Task.Factory.StartNew(() => Potential.Brushfire4(ObstacleValue, BrushfireDecrement, _Map)) : Task.Factory.StartNew(() => Potential.Brushfire8(ObstacleValue, BrushfireDecrement, _Map));

            mapTask = mapTask.ContinueWith(t =>
            {
                if (IsStraightLine)
                    return Potential.AddLinearAttraction(t.Result);
                if (IsManhattan)
                    return Potential.AddManhattanAttraction(t.Result);
                if (IsWaveFront)
                    return Potential.AddWavefrontAttraction(t.Result);

                throw new InvalidOperationException();
            });

            _Map = await mapTask;


            _Path = SteepestDescent.SteepestDescentPlanner.Plan(_Map);


            ShowMap();
            EnableMenu();
        }
예제 #4
0
        private WriteableBitmap MapToBitmap(RobotMap map)
        {
            var img = new WriteableBitmap(map.Cells.GetLength(0), map.Cells.GetLength(1));
            var cells = map.Cells;
            var min = map.MinMaxPotential.Item1;
            var max = map.MinMaxPotential.Item2;

            MapCanvas.Children.Clear();
            MapCanvas.Children.Add(MapImage);

            using (var ctx = img.GetBitmapContext(ReadWriteMode.ReadWrite))
            {
                var width = img.PixelWidth;
                for (int x = 0; x < img.PixelWidth; x++)
                {
                    for (int y = 0; y < img.PixelHeight; y++)
                    {
                        var cell = cells[x, y];
                        int color = BLACK;
                        if (cell.IsPotential)
                        {
                            var pot = ((Cell.Potential)cell).Item;
                            color = GiveRainbowColor(min, max, pot);
                            //var text = new TextBlock() { Text = pot.ToString() };
                            //MapCanvas.Children.Add(text);
                            //Canvas.SetLeft(text, x * SCALE_FACTOR);
                            //Canvas.SetTop(text, y * SCALE_FACTOR);
                        }
                        else if (cell.IsFree)
                            color = GREY;
                        else if (cell.IsGoal)
                            color = RED;
                        else if (cell.IsStart)
                            color = GREEN;
                        else if (cell.IsObstacle)
                            color = BLACK;

                        ctx.Pixels[x + y * width] = color;
                    }
                }
            }
            return img;
        }