Example #1
0
        /// <summary>
        /// Applies the filter on the specified spatial data.
        /// </summary>
        /// <param name="spatialData">The spatial data.</param>
        /// <param name="name">The name of the filtered data .</param>
        /// <returns>ISpatialData.</returns>
        public ISpatialData Apply(ISpatialData spatialData, string name)
        {
            //Gaussian.failedRays = 0;
            ISpatialData data = IsovistClippedGaussian.Apply(spatialData, name, this.Filter, this.RayIndices, this._cellularFloor);

            //MessageBox.Show("Failed Rays: " + Gaussian.failedRays.ToString());
            return(data);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IsovistClippedGaussian"/> class.
        /// </summary>
        /// <param name="cellularFloor">The cellular floor.</param>
        /// <param name="range">The range of interpolation.</param>
        /// <param name="tolerance">The tolerance.</param>
        public IsovistClippedGaussian(CellularFloor cellularFloor, int range, double tolerance = OSMDocument.AbsoluteTolerance)
        {
            this.Range          = range;
            this._cellularFloor = cellularFloor;
            this.Tolerance      = tolerance;
            double x = (this.Range + 1) * this._cellularFloor.CellSize;

            this._rangeLengthSquared = x * x;
            double lowerBound = UnitConversion.Convert(0.001d, Length_Unit_Types.FEET, this._cellularFloor.UnitType);
            double upperBound = UnitConversion.Convert(5.0d, Length_Unit_Types.FEET, this._cellularFloor.UnitType);

            this._sigma = MathNet.Numerics.RootFinding.RobustNewtonRaphson.FindRoot(this.gaussianPDF, differentialOfGaussianPDF, lowerBound, upperBound);
            //MessageBox.Show("Sigma: " + this.Sigma.ToString() + "\nValue: " + this.gaussianPDF(this.Sigma).ToString());
            this.Filter     = IsovistClippedGaussian.GaussianFilter(this.Range + 1, this._cellularFloor.CellSize, this.Sigma);
            this.RayIndices = IsovistClippedGaussian.LoadRayIndices(this.Range, this._cellularFloor, this.Tolerance);
        }
Example #3
0
        /// <summary>
        /// Gets the filtered values.
        /// </summary>
        /// <param name="spatialData">The spatial 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>Dictionary&lt;Cell, System.Double&gt;.</returns>
        public static Dictionary <Cell, double> GetFilteredValues(ISpatialData spatialData, double[,] filter,
                                                                  Dictionary <Index, Index[]> rayIndices, CellularFloor cellularFloor)
        {
            Cell[] cells = new Cell[spatialData.Data.Count];
            spatialData.Data.Keys.CopyTo(cells, 0);
            double[] values             = new double[spatialData.Data.Count];
            int      neighborhood_range = filter.GetLength(0);

            Parallel.For(0, cells.Length, (I) =>
            {
                values[I] = IsovistClippedGaussian.Apply(spatialData, cells[I], filter, neighborhood_range, rayIndices, cellularFloor);
            });
            Dictionary <Cell, double> filtered = new Dictionary <Cell, double>();

            for (int i = 0; i < cells.Length; i++)
            {
                filtered.Add(cells[i], values[i]);
            }
            return(filtered);
        }
Example #4
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);
        }
Example #5
0
 /// <summary>
 /// Applies the filter on the specified spatial data in parallel.
 /// </summary>
 /// <param name="spatialData">The spatial data.</param>
 /// <param name="name">The name of the filtered data.</param>
 /// <returns>ISpatialData.</returns>
 public ISpatialData ApplyParallel(ISpatialData spatialData, string name)
 {
     return(IsovistClippedGaussian.ApplyParallel(spatialData, name, this.Filter, this.RayIndices, this._cellularFloor));
 }