コード例 #1
0
        /// <summary>
        /// Returns the heat at the given index.
        /// </summary>
        /// <param name="datapointMap">The datapoint sets per grid element.</param>
        /// <param name="xIndex">The x-index to calculate the heat for.</param>
        /// <param name="yIndex">The y-index to calculate the heat for.</param>
        /// <returns>The heat at the given cell.</returns>
        private double GetHeatValue(HashSet <HeatDatapoint>[,] datapointMap, int xIndex, int yIndex)
        {
            // Transform the heatmap indexes into map coordinates
            double xValue = (xIndex + 0.5) / (double)_heatmap.GetLength(0) * _tier.GetInfoLength(); // Shift the value of the index by 0.5 to get the center of it
            double yValue = (yIndex + 0.5) / (double)_heatmap.GetLength(1) * _tier.GetInfoWidth();  // Shift the value of the index by 0.5 to get the center of it
            // Transform the radius into grid length
            double radiusX = Radius / _tier.GetInfoLength() * _heatmap.GetLength(0);
            double radiusY = Radius / _tier.GetInfoWidth() * _heatmap.GetLength(1);
            // Count the datapoints within radius
            double aggregatedValue = 0;

            for (int x = (int)(xIndex - radiusX); x < xIndex + radiusX; x++)
            {
                for (int y = (int)(yIndex - radiusY); y < yIndex + radiusY; y++)
                {
                    if (x >= 0 && y >= 0 && x < datapointMap.GetLength(0) && y < datapointMap.GetLength(1) && datapointMap[x, y] != null)
                    {
                        aggregatedValue += datapointMap[x, y]
                                           .Where(d => GetDistance(d, xValue, yValue) < Radius) // Only look at datapoints within the radius
                                           .Sum(d => GetWeightedValue(xValue, yValue, d));      // Get the value of this datapoint (distance to the heat tile center is reflected if desired)
                    }
                }
            }
            // Return the result
            return(aggregatedValue);
        }
コード例 #2
0
        public SimulationVisualTier3D(ITierInfo tier, DetailLevel detailLevel)
            : base(tier)
        {
            _tier = tier;
            var visual = new BoxVisual3D
            {
                Fill   = VisualizationConstants.BrushTierVisual,
                Center = new Point3D(
                    (_tier.GetInfoTLX() + _tier.GetInfoLength()) / 2.0,
                    (_tier.GetInfoTLY() + _tier.GetInfoWidth()) / 2.0,
                    _tier.GetInfoZ() - TIER_HEIGHT / 2.0),
                Length = _tier.GetInfoLength(),
                Width  = _tier.GetInfoWidth(),
                Height = TIER_HEIGHT
            };

            Children.Add(visual);
        }
コード例 #3
0
        public override void Init()
        {
            // Canvas size and transformation
            _contentHost.Width  = _currentTier.GetInfoLength() * DEFAULT_TRANSFORMATION_FACTOR;
            _contentHost.Height = _currentTier.GetInfoWidth() * DEFAULT_TRANSFORMATION_FACTOR;
            _transformer        = new Transformation2D(_currentTier.GetInfoLength(), _currentTier.GetInfoWidth(), _contentHost.Width, _contentHost.Height);
            // Remove old visuals (if any)
            foreach (var visual in _contentControl.Children.OfType <SimulationVisual2D>().Cast <UIElement>().ToArray())
            {
                Remove(visual);
            }
            foreach (var visual in _contentControl.Children.OfType <Image>().Cast <UIElement>().ToArray())
            {
                Remove(visual);
            }
            // --> Init visuals
            double waypointRadius  = _instance.GetInfoTiers().First().GetInfoWaypoints().First().GetInfoLength() / 2.0;
            double strokeThickness = 0.2 * Math.Min(_transformer.ProjectXLength(waypointRadius), _transformer.ProjectYLength(waypointRadius));

            // Add bots
            _botVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
            {
                SimulationVisualBot2D botVisual = new SimulationVisualBot2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, botVisual);
                return(botVisual);
            });
            // Add non-visual bots
            _shadowBotVisuals = _instance.GetInfoBots().Except(_botVisuals.Keys).ToDictionary(k => k, v =>
            {
                SimulationVisualBot2D botVisual = new SimulationVisualBot2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, botVisual);
                return(botVisual);
            });
            // Add pods
            _podVisuals = _currentTier.GetInfoPods().ToDictionary(k => k, v =>
            {
                SimulationVisualPod2D podVisual = new SimulationVisualPod2D(v, _config.DetailLevel, _transformer, strokeThickness, _heatModeEnabled, _elementClickAction, this);
                _infoControl.Register(v, podVisual);
                return(podVisual);
            });
            // Add non-visual bots
            _shadowPodVisuals = _instance.GetInfoPods().Except(_podVisuals.Keys).ToDictionary(k => k, v =>
            {
                SimulationVisualPod2D podVisual = new SimulationVisualPod2D(v, _config.DetailLevel, _transformer, strokeThickness, _heatModeEnabled, _elementClickAction, this);
                _infoControl.Register(v, podVisual);
                return(podVisual);
            });
            // Add input-stations
            _iStationVisuals = _currentTier.GetInfoInputStations().ToDictionary(k => k, v =>
            {
                SimulationVisualInputStation2D iStationVisual = new SimulationVisualInputStation2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, iStationVisual);
                return(iStationVisual);
            });
            // Add output-stations
            _oStationVisuals = _currentTier.GetInfoOutputStations().ToDictionary(k => k, v =>
            {
                SimulationVisualOutputStation2D oStationVisual = new SimulationVisualOutputStation2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                _infoControl.Register(v, oStationVisual);
                return(oStationVisual);
            });
            // Add elevator entrances
            _elevatorEntranceVisuals = _instance.GetInfoElevators().SelectMany(e => e.GetInfoWaypoints()).Where(wp => wp.GetInfoCurrentTier() == _currentTier).ToDictionary(k => k, v =>
            {
                SimulationVisualElevatorEntrance2D elevatorEntranceVisual = new SimulationVisualElevatorEntrance2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                //_infoControl.Register(v, elevatorEntranceVisual); // TODO enable again
                return(elevatorEntranceVisual);
            });
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                // Refine level of detail
                if (_config.DetailLevel >= DetailLevel.Full)
                {
                    // Add each waypoint
                    _waypointVisuals = _currentTier.GetInfoWaypoints().ToDictionary(k => k, v =>
                    {
                        SimulationVisualWaypoint2D waypointVisual = new SimulationVisualWaypoint2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                        _infoControl.Register(v, waypointVisual);
                        return(waypointVisual);
                    });
                }
                else
                {
                    // Only add the complete waypoint graph without explicit information about each waypoint
                    _waypointGraphVisual = SimulationVisualWaypointGraph2D.GenerateWaypointGraphImage(_currentTier, _transformer, strokeThickness);
                }
                // Add guards
                _guardVisuals = _currentTier.GetInfoGuards().ToDictionary(k => k, v =>
                {
                    SimulationVisualGuard2D guardVisual = new SimulationVisualGuard2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this);
                    _infoControl.Register(v, guardVisual);
                    return(guardVisual);
                });
            }
            // Add if desired
            if (_config.DrawGoal)
            {
                // Add goal markers
                _botGoalMarkerVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualGoalMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual goal markers
                _shadowBotGoalMarkerVisuals = _instance.GetInfoBots().Except(_botGoalMarkerVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualGoalMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // Add if desired
            if (_config.DrawDestination)
            {
                // Add destination markers
                _botDestinationMarkerVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualDestinationMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual destination markers
                _shadowBotDestinationMarkerVisuals = _instance.GetInfoBots().Except(_botDestinationMarkerVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualDestinationMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // Add if desired
            if (_config.DrawPath)
            {
                // Add path markers
                _botPathVisuals = _currentTier.GetInfoBots().ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualPathMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
                // Add non-visual path markers
                _shadowBotPathVisuals = _instance.GetInfoBots().Except(_botPathVisuals.Keys).ToDictionary(k => k, v =>
                {
                    return(new SimulationVisualPathMarker2D(v, _config.DetailLevel, _transformer, strokeThickness, _elementClickAction, this));
                });
            }
            // --> Add the generated elements to the GUI
            // Add new waypoint visuals to the view
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                if (_config.DetailLevel >= DetailLevel.Full)
                {
                    foreach (var waypoint in _currentTier.GetInfoWaypoints())
                    {
                        Add(_waypointVisuals[waypoint]);
                    }
                }
                else
                {
                    Add(_waypointGraphVisual);
                }
            }
            // Add new iStation visuals to the view
            foreach (var iStation in _currentTier.GetInfoInputStations())
            {
                Add(_iStationVisuals[iStation]);
            }
            // Add new oStation visuals to the view
            foreach (var oStation in _currentTier.GetInfoOutputStations())
            {
                Add(_oStationVisuals[oStation]);
            }
            foreach (var elevatorEntrance in _elevatorEntranceVisuals.Keys)
            {
                Add(_elevatorEntranceVisuals[elevatorEntrance]);
            }
            // Add new path marker visuals to the view
            if (_config.DrawPath)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botPathVisuals[bot]);
                }
            }
            // Add new destination marker visuals to the view
            if (_config.DrawDestination)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botDestinationMarkerVisuals[bot]);
                }
            }
            // Add new pod visuals to the view
            foreach (var pod in _currentTier.GetInfoPods())
            {
                Add(_podVisuals[pod]);
            }
            // Add new bot visuals to the view
            foreach (var bot in _currentTier.GetInfoBots())
            {
                Add(_botVisuals[bot]);
            }
            // Add new goal marker visuals to the view
            if (_config.DrawGoal)
            {
                foreach (var bot in _currentTier.GetInfoBots())
                {
                    Add(_botGoalMarkerVisuals[bot]);
                }
            }
            // Add new guard visuals to the view
            if (_config.DetailLevel >= DetailLevel.Debug)
            {
                foreach (var guard in _currentTier.GetInfoGuards())
                {
                    Add(_guardVisuals[guard]);
                }
            }
            // Update the view
            Update(true);
        }