void _runBtm_Click(object sender, RoutedEventArgs e)
        {
            //input validation
            #region Events validation
            #region data event
            if (this._includedataEvents.IsChecked.Value)
            {
                bool dataEventAssigned = false;
                foreach (var item in this._host.cellularFloor.AllSpatialDataFields.Values)
                {
                    SpatialDataField spatialDataField = item as SpatialDataField;
                    if (spatialDataField != null)
                    {
                        if (spatialDataField.UseToCaptureEvent)
                        {
                            dataEventAssigned = true;
                            break;
                        }
                    }
                }
                if (!dataEventAssigned)
                {
                    var result = MessageBox.Show("Do you want to ignore spatial data events?",
                                                 "Spatial data events are not defined", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result == MessageBoxResult.Yes)
                    {
                        this._includedataEvents.IsChecked = false;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            #endregion
            #region activity engagement events
            if (this._includeActivityEngagementEvents.IsChecked.Value)
            {
                bool activityEventAssigned = false;
                foreach (var item in this._host.AllActivities.Values)
                {
                    if (item.UseToCaptureEvent)
                    {
                        activityEventAssigned = true;
                        break;
                    }
                }
                if (!activityEventAssigned)
                {
                    var result = MessageBox.Show("Do you want to ignore activity engagement events?",
                                                 "Activity engagement events are not defined", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result == MessageBoxResult.Yes)
                    {
                        this._includeActivityEngagementEvents.IsChecked = false;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            #endregion
            #region visual events
            if (this._includeVisualEvents.IsChecked.Value)
            {
                if (this._host.VisualEventSettings == null)
                {
                    var result = MessageBox.Show("Do you want to ignore visual events?",
                                                 "Visual events are not defined", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (result == MessageBoxResult.Yes)
                    {
                        this._includeVisualEvents.IsChecked = false;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            #endregion

            if (!this._includeVisualEvents.IsChecked.Value && !this._includedataEvents.IsChecked.Value && !this._includeActivityEngagementEvents.IsChecked.Value)
            {
                MessageBox.Show("Cannot proceed without defining events in relation to spatial data, visibility or activity engagement!");
                return;
            }
            #endregion
            #region numeric data validation
            double timeStep, duration;
            int    timeSamplingRate;
            if (!double.TryParse(_timeStep.Text, out timeStep))
            {
                MessageBox.Show("Invalid value for 'Time Step'");
                return;
            }
            else if (timeStep <= 0)
            {
                MessageBox.Show("'Time Step' must be larger than zero");
                return;
            }
            if (!double.TryParse(_timeDuration.Text, out duration))
            {
                MessageBox.Show("Invalid value for 'Total Simulation Duration'");
                return;
            }
            else if (duration <= 0)
            {
                MessageBox.Show("'Total Simulation Duration' must be larger than zero");
                return;
            }
            if (!int.TryParse(_timeSamplingRate.Text, out timeSamplingRate))
            {
                MessageBox.Show("Invalid value for 'Time Sampling Rate'");
                return;
            }
            else if (timeSamplingRate <= 0)
            {
                MessageBox.Show("'Time Sampling Rate' must be larger than zero");
                return;
            }
            #endregion
            #region Event Name Validation

            if (string.IsNullOrEmpty(_dataFieldName.Text) || string.IsNullOrWhiteSpace(_dataFieldName.Text))
            {
                MessageBox.Show("A name is needed to save the captured event Data!",
                                "Invalid Name");
                return;
            }
            if (this._host.AllOccupancyEvent.ContainsKey(_dataFieldName.Text))
            {
                MessageBox.Show(string.Format("'{0}' is already assigned to an exiting event Data!", _dataFieldName.Text),
                                "Invalid Name");
                return;
            }
            #endregion
            #region trail Data File Address
            if (string.IsNullOrEmpty(this._trailDataFileAddress) || string.IsNullOrWhiteSpace(this._trailDataFileAddress))
            {
                var result = MessageBox.Show("Do you want to ignore saving the trail data of events?",
                                             "Invalid input", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            #endregion

            this._runBtm.Click -= _runBtm_Click;
            Dispatcher.Invoke(new Action(() =>
            {
                this._closeBtm.SetValue(Button.IsEnabledProperty, false);
                this._runBtm.SetValue(Button.IsEnabledProperty, false);
                this._interface.SetValue(StackPanel.IsEnabledProperty, false);
                this._progress.SetValue(Grid.VisibilityProperty, System.Windows.Visibility.Visible);
            }), DispatcherPriority.ContextIdle);
            EvaluationEvent capturedOccupancyEvent = null;
            switch (this._eventType)
            {
            case EvaluationEventType.Optional:
                var simulator_OP = new OptionalScenarioSimulation(this._host, timeStep, duration);
                //register report progress event
                simulator_OP.ReportProgress += this.updateProgressBar;

                capturedOccupancyEvent = simulator_OP.CaptureEvent(this._includedataEvents.IsChecked.Value,
                                                                   this._includeVisualEvents.IsChecked.Value, (int)double.Parse(this._pointPerSeconds.Text),
                                                                   _dataFieldName.Text, this._trailDataFileAddress, this._host.VisualEventSettings, this._visibilityExists.IsChecked.Value, this._analyzeFrequency.IsChecked.Value);
                this._host.AllOccupancyEvent.Add(capturedOccupancyEvent.Name, capturedOccupancyEvent);
                simulator_OP.ReportProgress -= this.updateProgressBar;
                break;

            case EvaluationEventType.Mandatory:
                if (!this._host.AgentMandatoryScenario.IsReadyForPerformance())
                {
                    MessageBox.Show(this._host.AgentMandatoryScenario.Message, "Incomplete Scenario", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                this._host.AgentMandatoryScenario.LoadQueues(this._host.AllActivities, 0.0);
                var simulator_MAN = new SpatialAnalysis.Agents.MandatoryScenario.MandatoryScenarioSimulation(this._host, timeStep, duration);
                //register report progress event
                simulator_MAN.ReportProgress += this.updateProgressBar;

                capturedOccupancyEvent = simulator_MAN.CaptureEvent(this._includedataEvents.IsChecked.Value, this._includeVisualEvents.IsChecked.Value,
                                                                    this._includeActivityEngagementEvents.IsChecked.Value, (int)double.Parse(this._pointPerSeconds.Text),
                                                                    _dataFieldName.Text, this._trailDataFileAddress, this._host.VisualEventSettings,
                                                                    this._visibilityExists.IsChecked.Value, this._analyzeFrequency.IsChecked.Value);
                this._host.AllOccupancyEvent.Add(capturedOccupancyEvent.Name, capturedOccupancyEvent);
                simulator_MAN.ReportProgress -= this.updateProgressBar;
                break;
            }
            this._closeBtm.IsEnabled = true;
        }
Beispiel #2
0
        /// <summary>
        /// Applies filter on the specified spatial data.
        /// </summary>
        /// <param name="spatialData">The spatial data.</param>
        /// <param name="name">The name of the filtered data.</param>
        /// <param name="filter">The weighting factors of the filter.</param>
        /// <param name="rayIndices">The ray indices.</param>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <returns>ISpatialData.</returns>
        public static ISpatialData Apply(ISpatialData spatialData, string name, double[,] filter,
                                         Dictionary <Index, Index[]> rayIndices, CellularFloor cellularFloor)
        {
            int neighborhood_range             = filter.GetLength(0);
            Dictionary <Cell, double> filtered = new Dictionary <Cell, double>();

            foreach (Cell cell in spatialData.Data.Keys)
            {
                double value = IsovistClippedGaussian.Apply(spatialData, cell, filter, neighborhood_range, rayIndices, cellularFloor);
                filtered.Add(cell, value);
            }
            ISpatialData newData = null;

            switch (spatialData.Type)
            {
            case DataType.SpatialData:
                if (spatialData.GetType() == typeof(SpatialDataField))
                {
                    newData = new SpatialDataField(name, filtered);
                }
                else if (spatialData.GetType() == typeof(SimulationResult))
                {
                    SimulationResult simulationResult = (SimulationResult)spatialData;
                    newData = new SimulationResult(name, filtered, simulationResult.TimeStep, simulationResult.SimulationDuration);
                }
                else if (spatialData.GetType() == typeof(MandatorySimulationResult))
                {
                    MandatorySimulationResult mandatorySimulationResult = (MandatorySimulationResult)spatialData;
                    newData = new MandatorySimulationResult(name, filtered, mandatorySimulationResult.TimeStep, mandatorySimulationResult.SimulationDuration, mandatorySimulationResult.WalkedDistancePerHour,
                                                            mandatorySimulationResult.TimeInMainStations, mandatorySimulationResult.WalkingTime, mandatorySimulationResult.ActivityEngagementTime,
                                                            mandatorySimulationResult.SequencesWhichNeededVisualDetection, mandatorySimulationResult.AverageDelayChanceForVisualDetection,
                                                            mandatorySimulationResult.MinimumDelayChanceForVisualDetection,
                                                            mandatorySimulationResult.MaximumDelayChanceForVisualDetection);
                }
                break;

            case DataType.ActivityPotentialField:
                newData = new FieldUtility.Activity(filtered, ((Activity)spatialData).Origins, ((Activity)spatialData).DestinationArea, ((Activity)spatialData).DefaultState, name, cellularFloor);
                ((Activity)newData).TrySetEngagementTime(((Activity)spatialData).MinimumEngagementTime, ((Activity)spatialData).MaximumEngagementTime);
                break;

            case DataType.OccupancyEvent:
                if (spatialData.GetType() == typeof(MandatoryEvaluationEvent))
                {
                    MandatoryEvaluationEvent event_ = (MandatoryEvaluationEvent)spatialData;
                    newData = new SpatialAnalysis.Events.MandatoryEvaluationEvent(name, filtered, event_.Likelihood, event_.TimeSamplingRate, event_.TimeStep, event_.Duration,
                                                                                  event_.MaximumVelocityMagnitude, event_.VisibilityAngle, event_.HasCapturedVisualEvents, event_.HasCapturedDataEvents, event_.EventType, event_.CapturedEventTrails)
                    {
                        HasActivityEngagementEvent = event_.HasActivityEngagementEvent
                    };
                }
                else
                {
                    EvaluationEvent event_ = (EvaluationEvent)spatialData;
                    newData = new SpatialAnalysis.Events.EvaluationEvent(name, filtered, event_.Likelihood, event_.TimeSamplingRate, event_.TimeStep, event_.Duration,
                                                                         event_.MaximumVelocityMagnitude, event_.VisibilityAngle, event_.HasCapturedVisualEvents, event_.HasCapturedDataEvents, event_.EventType, event_.CapturedEventTrails);
                }
                break;
            }
            return(newData);
        }