Example #1
0
        /// <summary>
        /// registers a geo cell at (x,y) with the cell path, storing current pathDistance.
        /// </summary>
        /// <param name="cellPath"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="pathDistance"></param>
        /// <returns></returns>
        protected bool registerCell(CellPath cellPath, int x, int y, double pathDistance, out MapCell mc)
        {
            mc = _mapper.geoCellAt(x, y);

            if (mc == null || mc.val > 0)
            {
                return(true);  // ray hit an obstacle or the wall
            }

            //if (!cellPath.ContainsCell(mc))
            {
                cellPath.Add(new CellPathElement()
                {
                    mapCell = mc, distanceMeters = pathDistance, cellPath = cellPath
                });
            }

            return(false);   // not hit any obstacle or wall
        }
Example #2
0
        private void drawGeoCells(List <UIElement> geoList)
        {
            try
            {
                MapperVicinity mapperVicinity = CurrentMapper;

                double frameWidth  = canvasGeo.ActualWidth;
                double frameHeight = canvasGeo.ActualHeight;

                double geoCellWidth  = frameWidth / mapperVicinity.GeoMapWidth;
                double geoCellHeight = frameHeight / mapperVicinity.GeoMapHeight;

                metersPerPixelX = MapperSettings.elementSizeMeters * mapperVicinity.GeoMapWidth / frameWidth;
                metersPerPixelY = MapperSettings.elementSizeMeters * mapperVicinity.GeoMapHeight / frameHeight;

                // Create a couple of SolidColorBrush and use it to paint the rectangles:
                SolidColorBrush myBrush0 = new SolidColorBrush(Colors.White);
                SolidColorBrush myBrush1 = new SolidColorBrush(Colors.Black);

                for (int i = 0; i < mapperVicinity.GeoMapHeight; i++)
                {
                    for (int j = 0; j < mapperVicinity.GeoMapWidth; j++)
                    {
                        MapCell cell = mapperVicinity.geoCellAt(j, i);

                        SolidColorBrush myBrush = null;

                        bool isEmpty = cell.val < 1;

                        if (_currentRoutePlanner != null)
                        {
                            // see if the cell belongs to any path, and allow to see if  that was the best path:
                            var query = from cp in _currentRoutePlanner.cellPaths
                                        where cp.ContainsCell(cell)
                                        orderby cp.isBest descending
                                        select cp;

                            if (query.Count() > 0)
                            {
                                myBrush = query.First().isBest ? myBrushB : myBrushP;
                                isEmpty = false;    // belongs to a path
                            }
                            else
                            {
                                myBrush = cell.val < 1 ? myBrush0 : myBrush1;
                            }
                        }
                        else
                        {
                            myBrush = cell.val < 1 ? myBrush0 : myBrush1;
                        }

                        if (!isEmpty)
                        {
                            Rectangle rect = new Rectangle();
                            rect.Width   = geoCellWidth;
                            rect.Height  = geoCellHeight;
                            rect.RadiusX = 4;
                            rect.RadiusY = 4;
                            rect.Margin  = new Thickness(j * geoCellWidth, i * geoCellHeight, 0, 0);

                            bool isCenterCell = i == mapperVicinity.GeoMapHeight / 2 && j == mapperVicinity.GeoMapWidth / 2;

                            rect.Stroke          = isCenterCell ? Brushes.Magenta : Brushes.Red;
                            rect.StrokeThickness = isCenterCell ? 5 : 0.5d;
                            rect.Fill            = myBrush;
                            geoList.Add(rect);
                        }
                    }
                }
            }
            catch { }
        }
Example #3
0
        private void drawGeoCells(List <UIElement> geoList)
        {
            try
            {
                MapperVicinity mapperVicinity = CurrentMapper;

                double frameWidth  = canvasGeo.ActualWidth;
                double frameHeight = canvasGeo.ActualHeight;

                double geoCellWidth  = frameWidth / mapperVicinity.GeoMapWidth;
                double geoCellHeight = frameHeight / mapperVicinity.GeoMapHeight;

                metersPerPixelX = MapperSettings.elementSizeMeters * mapperVicinity.GeoMapWidth / frameWidth;
                metersPerPixelY = MapperSettings.elementSizeMeters * mapperVicinity.GeoMapHeight / frameHeight;

                for (int i = 0; i < mapperVicinity.GeoMapHeight; i++)
                {
                    for (int j = 0; j < mapperVicinity.GeoMapWidth; j++)
                    {
                        MapCell cell = mapperVicinity.geoCellAt(j, i);

                        SolidColorBrush myBrush = null;

                        bool isEmpty = cell.val < 1;

                        if (_currentRoutePlanner != null)
                        {
                            // see if the cell belongs to any path, and allow to see if  that was the best path:
                            var query = from cp in _currentRoutePlanner.cellPaths
                                        where cp.ContainsCell(cell)
                                        orderby cp.isBest descending
                                        select cp;

                            if (query.Any())
                            {
                                myBrush = query.First().isBest ? myBrushB : myBrushP;
                                isEmpty = false;    // belongs to a path
                            }
                        }

                        if (!isEmpty)
                        {
                            if (myBrush == null)
                            {
                                myBrush = cell.HasHuman ? myBrushH : (cell.val < 1 ? myBrush0 : new SolidColorBrush(cell.DisplayColor));
                            }
                            Rectangle rect = new Rectangle();
                            rect.Width   = geoCellWidth;
                            rect.Height  = geoCellHeight;
                            rect.RadiusX = 4;
                            rect.RadiusY = 4;
                            rect.Margin  = new Thickness(j * geoCellWidth, i * geoCellHeight, 0, 0);

                            bool isCenterCell = i == mapperVicinity.GeoMapHeight / 2 && j == mapperVicinity.GeoMapWidth / 2;

                            rect.Stroke          = isCenterCell ? Brushes.Magenta : Brushes.Red;
                            rect.StrokeThickness = isCenterCell ? 5 : 0.5d;
                            rect.Fill            = myBrush;
                            geoList.Add(rect);

                            if (cell.val > 0)
                            {
                                double fontSize = 10.0d;

                                Label cellValueLabel = new Label()
                                {
                                    FontSize = fontSize, Foreground = Brushes.Black, Background = myBrush
                                };
                                cellValueLabel.Content = cell.val;
                                cellValueLabel.Margin  = rect.Margin;
                                geoList.Add(cellValueLabel);
                            }
                        }
                    }
                }
            }
            catch { }
        }