private void MainForm_Shown(object sender, EventArgs e) { // Don't define the model until the screen gets shown for the first time. Otherwise // the map control may end up saving an incorrect screen image. string fileName = Settings.Default.LastFile; if (File.Exists(fileName)) { try { ISpatialData data = CadastralFile.ReadFile(fileName); m_Controller.MapModel = new SimpleMapModel(data); } catch (Exception ex) { MessageBox.Show(ex.Message); } } // All properties are readonly, and by default they will show up in // a pale grey that's difficult to see. Change it to black so the // info can be seen without squinting (the fact that the fields can't // be edited will be apparent when the user tries to do it). Actually, // changing it to black seems to be a special case, where the text // continues to comes out grey. So change it to nearly black. propertyGrid.ViewForeColor = Color.FromArgb(1, 0, 0); //SystemColors.ControlText; // Color.Black; // Ensure the map control has focus, so that things like the ESC key will be recognized //mapControl.Focus(); }
private void Insert(ISpatialData data, int depth) { var path = FindCoveringArea(data.Envelope, depth); var insertNode = path.Last(); insertNode.Add(data); while (--depth >= 0) { if (path[depth].Children.Count > maxEntries) { var newNode = SplitNode(path[depth]); if (depth == 0) { SplitRoot(newNode); } else { path[depth - 1].Add(newNode); } } else { path[depth].ResetEnvelope(); } } }
/// <summary> /// Draw field /// </summary> /// <param name="anyData">Any data.</param> /// <param name="colorSteps">The color steps.</param> /// <param name="transformation">The transformation.</param> private void drawAnyData(ISpatialData anyData, int colorSteps, Func <UV, Point> transformation) { if (this._host.ColorCode.Steps != colorSteps) { this._host.ColorCode.SetSteps(colorSteps); } //set the dimention of the WriteableBitmap and assign it to the scene double _h = ((UIElement)this.Parent).RenderSize.Height; double _w = ((UIElement)this.Parent).RenderSize.Width; this.Scene.Height = _h; this.Scene.Width = _w; this.Scene.Source = null; this._view = null; this._view = BitmapFactory.New((int)_w, (int)_h); this.Scene.Source = _view; //start to draw using (this._view.GetBitmapContext()) { foreach (KeyValuePair <Cell, double> item in anyData.Data) { Point p1 = transformation(item.Key); Point p2 = transformation(item.Key + new UV(this._host.cellularFloor.CellSize, this._host.cellularFloor.CellSize)); var color = this._host.ColorCode.GetColor((item.Value - anyData.Min) / (anyData.Max - anyData.Min)); this._view.FillRectangle((int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y, color); } } }
//空间结构 //------------------ /// <summary> /// 通过SpatialData来创建层次结构 /// </summary> /// <param name="sd"></param> /// <returns></returns> private static ISpatialData FindSubSpatialStructure(ISpatialData sd) { HashSet <string> typeName = new HashSet <string>(); foreach (var p in sd.SubProducts) { if (!typeName.Contains(p.TypeName)) { typeName.Add(p.TypeName); var go = new GameObject(p.TypeName); //Debug.Log(go.name); go.transform.parent = sd.TheGameObject.transform; } p.TheGameObject.transform.parent = sd.TheGameObject.transform.Find(p.TypeName); if (p.DecomposedProducts.Count > 0) { foreach (var dp in p.DecomposedProducts) { dp.TheGameObject.transform.parent = p.TheGameObject.transform; } } } if (sd.SubSpatials.Count == 0) { return(sd); } foreach (var ss in sd.SubSpatials) { ss.TheGameObject.transform.parent = sd.TheGameObject.transform; FindSubSpatialStructure(ss); } return(sd); }
/// <summary> /// Creates a new <c>SimpleMapModel</c> that refers to the specified data. /// </summary> /// <param name="data">The data for the model (not null)</param> /// <exception cref="ArgumentNullException">If null data was supplied</exception> public SimpleMapModel(ISpatialData data) { if (data==null) throw new ArgumentNullException(); m_Data = data; }
/// <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); }
/// <summary> /// Applies the specified spatial data. /// </summary> /// <param name="spatialData">The spatial data.</param> /// <param name="cell">The cell.</param> /// <param name="filter">The filter.</param> /// <param name="neighborhood_range">The neighborhood range.</param> /// <param name="rayIndices">The ray indices.</param> /// <param name="cellularFloor">The cellular floor.</param> /// <returns>System.Double.</returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> private static double Apply(ISpatialData spatialData, Cell cell, double[,] filter, int neighborhood_range, Dictionary <Index, Index[]> rayIndices, CellularFloor cellularFloor) { //the filtered value will be sum/w double sum = 0, w = 0; foreach (Index index in rayIndices.Keys) { //translating the index of the end of the ray var translatedIndex = index + cell.CellToIndex; //check to see if the translated index is valid in the cellular floor if (cellularFloor.ContainsCell(translatedIndex)) { //get the current cell at the end of the ray var currentCell = cellularFloor.Cells[translatedIndex.I, translatedIndex.J]; //ignore the entir ray if the cell does not belong to the original spatialData //this cell serves as a visual barrier if (spatialData.Data.ContainsKey(currentCell)) { //check for visibility along the ray bool isVisible = true; foreach (Index rayIndex in rayIndices[index]) { Index current = cell.CellToIndex + rayIndex; if (!cellularFloor.ContainsCell(current)) { throw new ArgumentOutOfRangeException(current.ToString()); } //if the current cell is not inside the field or it does not belong to the original spatial data // it is considered as a visual block if (cellularFloor.Cells[current.I, current.J].FieldOverlapState != OverlapState.Inside || !spatialData.Data.ContainsKey(cellularFloor.Cells[current.I, current.J])) { //Gaussian.failedRays++; isVisible = false; break; } } if (isVisible) { sum += filter[Math.Abs(index.I), Math.Abs(index.J)] * spatialData.Data[currentCell]; w += filter[Math.Abs(index.I), Math.Abs(index.J)]; } } } } if (sum != 0 && w != 0) { //apply filter on the cell itself sum += spatialData.Data[cell] * filter[0, 0]; w += filter[0, 0]; return(sum / w); } else { return(spatialData.Data[cell]); } }
/// <summary> /// Creates a new <c>SimpleMapModel</c> that refers to the specified data. /// </summary> /// <param name="data">The data for the model (not null)</param> /// <exception cref="ArgumentNullException">If null data was supplied</exception> public SimpleMapModel(ISpatialData data) { if (data == null) { throw new ArgumentNullException(); } m_Data = data; }
void _dataList1_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.data1 = (ISpatialData)this._dataList1.SelectedValue; this._data1Max.Text = this.data1.Max.ToString(); this._data1Min.Text = this.data1.Min.ToString(); var result = new MathNet.Numerics.Statistics.DescriptiveStatistics(this.data1.Data.Values); this._data1Mean.Text = result.Mean.ToString(); this._data1Variance.Text = result.Variance.ToString(); this._boxPlot1.DrawHorizontally(this.data1, 3); this.loadStats(); }
void SelectDataFor2DVisualization_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { this.Okay(); } else if (e.Key == Key.Escape) { this.SelectedSpatialData = null; this.Close(); } }
private void Okay_Click(object sender, RoutedEventArgs e) { foreach (var item in this.dataNames.SelectedItems) { ISpatialData spatialData = item as ISpatialData; if (spatialData != null) { this.AllSelectedSpatialData.Add(spatialData); } } this.Result = true; this.Close(); }
public IDistanceToSpatial CalculateDistanceToSpatial(object query, ISpatialData spatial) { if (query is KnnToPointQuery point) { return(new PointDistanceToSpatial(spatial, point.X, point.Y)); } if (query is KnnToLineSegmentQuery lineSeg) { return(new LineSegmentDistanceToSpatial(spatial, lineSeg.X0, lineSeg.Y0, lineSeg.X1, lineSeg.Y1)); } throw new NotSupportedException(); }
public SpatialDataWrapper(ISpatialData spatialData, double x1, double y1, double?x2, double?y2) { SpatialData = spatialData; if (x2 == null || y2 == null) { CalcBoxSquaredDistToPoint(x1, y1); } else { CalcBoxSquaredDistToLineSegment(x1, y1, x2.Value, y2.Value); } }
/// <summary> /// 递归获取IfcObject的空间结构 /// </summary> /// <param name="parent"></param> /// <param name="cur"></param> /// <returns></returns> private static ISpatialData GetSpatialSturctureData(IIfcObjectDefinition parent, IIfcObjectDefinition cur) { ISpatialData sp = default; var spatialElement = cur as IIfcSpatialStructureElement; if (spatialElement != null) { //获得spatialElement的spatialData sp = InstaniateCurSpatial(spatialElement); if (sp != null) { spatialDatas.Add(sp); //使用 IfcRelContainedInSpatialElement 获取包含的元素 var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements); if (containedElements.Count() > 0) { foreach (var element in containedElements) { //查找到相应的productData var prod = productDatas.Find(p => p.ProductGeometryData.productLabel == element.EntityLabel); if (prod == null) { var go = new GameObject(); var pd = go.AddComponent <ProductData>(); pd.ProductGeometryData = new BimProduct(element.EntityLabel, (short)element.EntityLabel); SetProductData(pd, element); sp.AddProduct(pd); SetDecomposeProduct(pd, element.IsDecomposedBy); } else { SetProductData((ProductData)prod, element); sp.AddProduct(prod); } } } } } foreach (var item in cur.IsDecomposedBy.SelectMany(r => r.RelatedObjects)) { sp.AddSpatial(GetSpatialSturctureData(cur, item)); } return(sp); }
void dataNames_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.dataNames.SelectedIndex == -1) { return; } try { var obj = this.dataNames.SelectedItem; TextBlock selected = obj as TextBlock; if (selected != null) { this.dataNames.SelectedIndex = -1; this._selectedItem.Text = string.Empty; return; } else { string name = (string)this.dataNames.SelectedItem; if (this._host.ContainsSpatialData(name)) { this.SelectedSpatialData = this._host.GetSpatialData(name); this._selectedItem.Text = this.SelectedSpatialData.Name; } } this._useCost.IsChecked = false; if (this.SelectedSpatialData != null && this.SelectedSpatialData.Type != DataType.SpatialData) { this._useCost.IsEnabled = false; this._useCost.IsChecked = false; } else { this._useCost.IsChecked = false; this._useCost.IsEnabled = true; } } catch (Exception error) { MessageBox.Show(error.Report()); } }
/// <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<Cell, System.Double>.</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); }
void _dataSelection_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { foreach (var item in this.dataNames.SelectedItems) { ISpatialData spatialData = item as ISpatialData; if (spatialData != null) { this.AllSelectedSpatialData.Add(spatialData); } } this.Result = true; this.Close(); } else if (e.Key == Key.Escape) { this.Result = false; this.Close(); } }
/// <summary> /// return spatial structure of cur IfcObject /// </summary> /// <param name="father"></param> /// <param name="cur"></param> /// <returns></returns> private static ISpatialData GetSpatialSturcture(IIfcObjectDefinition cur) { ISpatialData spd = default; //whether cur is spatial structure or not if (cur is IIfcSpatialStructureElement spatialElement) { //get spatialElement's spatialData spd = InstantiateCurSpatial(spatialElement); if (spd != null) { //get elements by using IfcRelContainedInSpatialElement var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements); if (containedElements.Count() > 0) { foreach (var element in containedElements) { if (element is IIfcElement) { var eled = InstantiateCurElement(element as IIfcElement); spd.AddRelatedObjects(eled); if (element.IsDecomposedBy != null && element.IsDecomposedBy.Count() > 0) { eled.SetDecomposeProduct(element.IsDecomposedBy); } } } } } } //use IfcRelAggregares to obtain sub spatial structure foreach (var item in cur.IsDecomposedBy.SelectMany(r => r.RelatedObjects)) { spd.AddRelatedObjects(GetSpatialSturcture(item)); } return(spd); }
void _dataNames_SelectionChanged(object sender, SelectionChangedEventArgs e) { ISpatialData spatialDataField = ((ListBox)sender).SelectedItem as ISpatialData; if (spatialDataField == null) { ((ListBox)sender).SelectedIndex = -1; return; } if (this._dataPropertySetter != null) { if (this._grid.Children.Contains(this._dataPropertySetter)) { this._grid.Children.Remove(this._dataPropertySetter); this._dataPropertySetter = null; } } this._dataPropertySetter = new SpatialDataPropertySetting(this._host, spatialDataField); this._grid.Children.Add(this._dataPropertySetter); Grid.SetColumn(this._dataPropertySetter, 1); Grid.SetRow(this._dataPropertySetter, 0); this._dataPropertySetter.Width = this._grid.ColumnDefinitions[1].ActualWidth - 5; this._dataPropertySetter.Height = this._grid.RowDefinitions[0].ActualHeight - 5; }
public void LoadData(ISpatialData data) { this._dataList1.Items.Add(data); this._dataList2.Items.Add(data); }
/// <summary> /// Initializes a new instance of the <see cref="SpatialDataPropertySetting"/> class. /// </summary> /// <param name="host">The main document to which this control belongs.</param> /// <param name="dataField">The data field.</param> public SpatialDataPropertySetting(OSMDocument host, ISpatialData dataField) { InitializeComponent(); this._host = host; this._dataField = dataField; this._spatialDataField = dataField as SpatialDataField; if (this._spatialDataField != null) { this._eventCase.Visibility = System.Windows.Visibility.Collapsed; this._includeCost.IsChecked = this._spatialDataField.UseCostFunctionForEventCapturing; this._includeCost.Checked += _includeCost_Checked; this._includeCost.Unchecked += _includeCost_Unchecked; if (this._spatialDataField.EventCapturingInterval != null) { this._intervalMax.Text = this._spatialDataField.EventCapturingInterval.Maximum.ToString(format); this._intervalMin.Text = this._spatialDataField.EventCapturingInterval.Minimum.ToString(format); this._capture.IsChecked = this._spatialDataField.UseToCaptureEvent; this._outsideInterval.IsChecked = this._spatialDataField.CaptureEventWhenOutsideInterval; } else { this._capture.IsChecked = false; this._capture.IsEnabled = false; this._outsideInterval.IsChecked = false; this._outsideInterval.IsEnabled = false; } this._intervalMin.TextChanged += _intervalMin_TextChanged; this._intervalMax.TextChanged += _intervalMax_TextChanged; this._capture.Checked += _capture_Checked; this._capture.Unchecked += _capture_Unchecked; this._outsideInterval.Checked += _outsideInterval_Checked; this._outsideInterval.Unchecked += _outsideInterval_Unchecked; this._method.Items.Add(CostCalculationMethod.RawValue); this._method.Items.Add(CostCalculationMethod.WrittenFormula); this._method.Items.Add(CostCalculationMethod.Interpolation); if (this._spatialDataField.HasBuiltInRepulsion) { this._method.Items.Add(CostCalculationMethod.BuiltInRepulsion); } this._method.SelectedItem = this._spatialDataField.CostCalculationType; this._method.SelectionChanged += new SelectionChangedEventHandler(_method_SelectionChanged); this._include.IsChecked = this._spatialDataField.IncludeInActivityGeneration; this._vis.Click += new RoutedEventHandler(_vis_Click); } else { this._desirability.Visibility = System.Windows.Visibility.Collapsed; this._setDataCostProperties.Visibility = System.Windows.Visibility.Collapsed; } switch (this._dataField.Type) { case DataType.SpatialData: this._signal.Visibility = System.Windows.Visibility.Collapsed; this._activityTimePeriod.Visibility = System.Windows.Visibility.Collapsed; this._activityEngagementEvent.Visibility = System.Windows.Visibility.Collapsed; this._simulationResult.Visibility = System.Windows.Visibility.Collapsed; this._dataType.Text = "Spatial Data Field"; break; case DataType.ActivityPotentialField: this._signal.Visibility = System.Windows.Visibility.Collapsed; this._simulationResult.Visibility = System.Windows.Visibility.Collapsed; this._eventCase.Visibility = System.Windows.Visibility.Collapsed; this._dataType.Text = "Activity"; this._maximumEngagementTime.TextChanged += new TextChangedEventHandler(activityEngagementTime_TextChanged); this._maximumEngagementTime.Text = ((Activity)this._dataField).MaximumEngagementTime.ToString(format); this._minimumEngagementTime.TextChanged += new TextChangedEventHandler(activityEngagementTime_TextChanged); this._minimumEngagementTime.Text = ((Activity)this._dataField).MinimumEngagementTime.ToString(format); this._captureActivityEvent.IsChecked = ((Activity)this._dataField).UseToCaptureEvent; this._captureActivityEvent.Checked += _captureActivityEvent_Checked; this._captureActivityEvent.Unchecked += _captureActivityEvent_Unchecked; break; case DataType.OccupancyEvent: this._simulationResult.Visibility = System.Windows.Visibility.Collapsed; this._activityTimePeriod.Visibility = System.Windows.Visibility.Collapsed; this._activityEngagementEvent.Visibility = System.Windows.Visibility.Collapsed; EvaluationEvent occupancyEvent = this._dataField as EvaluationEvent; switch (occupancyEvent.EventType) { case EvaluationEventType.Optional: this._dataType.Text = "Optional Occupancy Event"; this._mandatoryEvntInfo.Visibility = System.Windows.Visibility.Collapsed; break; case EvaluationEventType.Mandatory: this._dataType.Text = "Mandatory Occupancy Event"; this._hasActivityEvents.IsChecked = ((MandatoryEvaluationEvent)occupancyEvent).HasActivityEngagementEvent; break; } if (occupancyEvent.HasFrequencies) { try { this.Loaded += drawFrequencies; } catch (Exception error) { MessageBox.Show(error.Report()); } } else { this._signal.Visibility = System.Windows.Visibility.Collapsed; } this._timeStep.Text = occupancyEvent.TimeStep.ToString(format); this._duration.Text = occupancyEvent.Duration.ToString(format); this._likelihood.Text = occupancyEvent.Likelihood.ToString(format); this._timeSamplingRate.Text = occupancyEvent.TimeSamplingRate.ToString(format); this._velocityCap.Text = occupancyEvent.MaximumVelocityMagnitude.ToString(format); this._visibilityAngle.Text = occupancyEvent.VisibilityAngle.ToString(format); this._hasCapturedDataEvents.IsChecked = occupancyEvent.HasCapturedDataEvents; this._hasCapturedVisualEvents.IsChecked = occupancyEvent.HasCapturedVisualEvents; break; case DataType.SimulationResult: this._setDataCostProperties.Visibility = System.Windows.Visibility.Collapsed; this._desirability.Visibility = System.Windows.Visibility.Collapsed; this._signal.Visibility = System.Windows.Visibility.Collapsed; this._activityTimePeriod.Visibility = System.Windows.Visibility.Collapsed; this._activityEngagementEvent.Visibility = System.Windows.Visibility.Collapsed; this._eventCase.Visibility = System.Windows.Visibility.Collapsed; if (this._dataField.GetType() == typeof(SimulationResult)) { this._s_duration.Text = ((SimulationResult)this._dataField).SimulationDuration.ToString(format); this._s_timeStep.Text = ((SimulationResult)this._dataField).TimeStep.ToString(format); this._mandatorySimulationResults.Visibility = System.Windows.Visibility.Collapsed; this._dataType.Text = "Optional Occupancy Simulation Results"; } else //if (this._dataField.GetType() == typeof(MandatorySimulationResult)) { this._s_duration.Text = ((SimulationResult)this._dataField).SimulationDuration.ToString(format); this._s_timeStep.Text = ((SimulationResult)this._dataField).TimeStep.ToString(format); this._distance.Text = ((MandatorySimulationResult)this._dataField).WalkedDistancePerHour.ToString(format); this._walkingTime.Text = ((MandatorySimulationResult)this._dataField).WalkingTime.ToString(percent); this._timeInMainStations.Text = ((MandatorySimulationResult)this._dataField).TimeInMainStations.ToString(percent); this._engagementTime.Text = ((MandatorySimulationResult)this._dataField).ActivityEngagementTime.ToString(percent); this._dataType.Text = "Mandatory Occupancy Simulation Results"; this._sequencesWhichNeededVisualDetection.Text = ((MandatorySimulationResult)this._dataField).SequencesWhichNeededVisualDetection.ToString(); this._averageDelayChanceForVisualDetection.Text = ((MandatorySimulationResult)this._dataField).AverageDelayChanceForVisualDetection.ToString(percent); this._minimumDelayChanceForVisualDetection.Text = ((MandatorySimulationResult)this._dataField).MinimumDelayChanceForVisualDetection.ToString(percent); this._maximumDelayChanceForVisualDetection.Text = ((MandatorySimulationResult)this._dataField).MaximumDelayChanceForVisualDetection.ToString(percent); } break; } this._boxPlot._canvas.Loaded += new RoutedEventHandler(_canvas_Loaded); }
void _apply_Click(object sender, RoutedEventArgs e) { #region input validation double _n = 0; if (!double.TryParse(this._range.Text, out _n)) { MessageBox.Show("'Neighborhood Size' should be a valid number larger than 0", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } int n = (int)_n; if (n < 1) { MessageBox.Show("'Neighborhood Size' should be a valid number larger than 0", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (this.dataNames.SelectedIndex == -1) { MessageBox.Show("Select a data field to continue", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } ISpatialData data = this.dataNames.SelectedItem as ISpatialData; if (data == null) { MessageBox.Show("Cannot cast selection to data!"); return; } if (string.IsNullOrEmpty(this._name.Text) || string.IsNullOrWhiteSpace(this._name.Text)) { MessageBox.Show("Enter a name for the new data field", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } switch (data.Type) { case DataType.SpatialData: if (this._host.cellularFloor.AllSpatialDataFields.ContainsKey(this._name.Text)) { MessageBox.Show("A spatial data field with the given name Already exists.\n Change the name to continue", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } break; case DataType.ActivityPotentialField: if (this._host.AllActivities.ContainsKey(this._name.Text)) { MessageBox.Show("An activity with the given name Already exists.\n Change the name to continue", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } break; case DataType.OccupancyEvent: if (this._host.AllOccupancyEvent.ContainsKey(this._name.Text)) { MessageBox.Show("An occupancy even with the given name Already exists.\n Change the name to continue", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } break; case DataType.SimulationResult: if (this._host.AllSimulationResults.ContainsKey(this._name.Text)) { MessageBox.Show("An simulation result with the given name Already exists.\n Change the name to continue", "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } break; } #endregion //update filter if (this._host.ViewBasedGaussianFilter != null) { if (this._host.ViewBasedGaussianFilter.Range != n) { try { this._host.ViewBasedGaussianFilter = new IsovistClippedGaussian(this._host.cellularFloor, n); } catch (Exception error) { MessageBox.Show(error.Report(), "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } } else { try { this._host.ViewBasedGaussianFilter = new IsovistClippedGaussian(this._host.cellularFloor, n); } catch (Exception error) { MessageBox.Show(error.Report(), "Invalid Input", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } try { //apply filter ISpatialData filteredData = this._host.ViewBasedGaussianFilter.ApplyParallel(data, this._name.Text); //ISpatialData filteredData = this._host.GaussianFilter.Apply(data, this._name.Text); //add new data to the document switch (filteredData.Type) { case DataType.SpatialData: this._host.cellularFloor.AddSpatialDataField(filteredData as SpatialDataField); break; case DataType.ActivityPotentialField: this._host.AddActivity(filteredData as Activity); break; case DataType.OccupancyEvent: this._host.AllOccupancyEvent.Add(filteredData.Name, filteredData as EvaluationEvent); break; case DataType.SimulationResult: this._host.AllSimulationResults.Add(filteredData.Name, filteredData as SimulationResult); break; } } catch (Exception error2) { MessageBox.Show(error2.Report(), "Exception!", MessageBoxButton.OK, MessageBoxImage.Error); } this.Close(); }
/// <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)); }
private VectorTileLayer ProcessPointTile(ISpatialDataSource spatialLayer, int tileX, int tileY, int zoom) { int tileSize = TileSize; RectangleD tileBounds = TileUtil.GetTileLatLonBounds(tileX, tileY, zoom, tileSize); //create a buffer around the tileBounds tileBounds.Inflate(tileBounds.Width * 0.05, tileBounds.Height * 0.05); int simplificationFactor = Math.Min(10, Math.Max(1, SimplificationPixelThreshold)); System.Drawing.Point tilePixelOffset = new System.Drawing.Point((tileX * tileSize), (tileY * tileSize)); using (IEnumerator <ISpatialData> data = spatialLayer.GetData(new BoundingBox() { MinX = tileBounds.Left, MinY = tileBounds.Top, MaxX = tileBounds.Right, MaxY = tileBounds.Bottom })) { GeometryAlgorithms.ClipBounds clipBounds = new GeometryAlgorithms.ClipBounds() { XMin = -20, YMin = -20, XMax = tileSize + 20, YMax = tileSize + 20 }; VectorTileLayer tileLayer = new VectorTileLayer(); tileLayer.Extent = (uint)tileSize; tileLayer.Version = 2; tileLayer.Name = spatialLayer.Name; while (data.MoveNext()) { ISpatialData spatialData = data.Current; VectorTileFeature feature = new VectorTileFeature() { Id = spatialData.Id, Geometry = new List <List <Coordinate> >(), Attributes = new List <AttributeKeyValue>(), GeometryType = Tile.GeomType.Point }; //output the pixel coordinates List <Coordinate> coordinates = new List <Coordinate>(); var recordPoints = spatialData.Geometry; foreach (PointD[] points in recordPoints) { for (int n = 0; n < points.Length; ++n) { Int64 x, y; TileUtil.LLToPixel(points[n], zoom, out x, out y, tileSize); coordinates.Add(new Coordinate((int)(x - tilePixelOffset.X), (int)(y - tilePixelOffset.Y))); } } if (coordinates.Count > 0) { feature.Geometry.Add(coordinates); } //add the record attributes foreach (var keyValue in spatialData.Attributes) { feature.Attributes.Add(new AttributeKeyValue(keyValue.Key, keyValue.Value)); } if (feature.Geometry.Count > 0) { tileLayer.VectorTileFeatures.Add(feature); } } return(tileLayer); } }
private VectorTileLayer ProcessPolygonTile(ISpatialDataSource spatialLayer, int tileX, int tileY, int zoom) { int tileSize = TileSize; RectangleD tileBounds = TileUtil.GetTileLatLonBounds(tileX, tileY, zoom, tileSize); //create a buffer around the tileBounds tileBounds.Inflate(tileBounds.Width * 0.05, tileBounds.Height * 0.05); int simplificationFactor = Math.Min(10, Math.Max(1, SimplificationPixelThreshold)); System.Drawing.Point tilePixelOffset = new System.Drawing.Point((tileX * tileSize), (tileY * tileSize)); using (IEnumerator <ISpatialData> data = spatialLayer.GetData(new BoundingBox() { MinX = tileBounds.Left, MinY = tileBounds.Top, MaxX = tileBounds.Right, MaxY = tileBounds.Bottom })) { GeometryAlgorithms.ClipBounds clipBounds = new GeometryAlgorithms.ClipBounds() { XMin = -20, YMin = -20, XMax = tileSize + 20, YMax = tileSize + 20 }; System.Drawing.Point[] pixelPoints = new System.Drawing.Point[1024]; System.Drawing.Point[] simplifiedPixelPoints = new System.Drawing.Point[1024]; PointD[] pointsBuffer = new PointD[1024]; List <System.Drawing.Point> clippedPolygon = new List <System.Drawing.Point>(); VectorTileLayer tileLayer = new VectorTileLayer(); tileLayer.Extent = (uint)tileSize; tileLayer.Version = 2; tileLayer.Name = spatialLayer.Name; while (data.MoveNext()) { ISpatialData spatialData = data.Current; VectorTileFeature feature = new VectorTileFeature() { Id = spatialData.Id, Geometry = new List <List <Coordinate> >(), Attributes = new List <AttributeKeyValue>(), GeometryType = Tile.GeomType.Polygon }; //get the point data var recordPoints = spatialData.Geometry; int partIndex = 0; foreach (PointD[] points in recordPoints) { //convert to pixel coordinates; if (pixelPoints.Length < points.Length) { pixelPoints = new System.Drawing.Point[points.Length + 10]; simplifiedPixelPoints = new System.Drawing.Point[points.Length + 10]; } for (int n = 0; n < points.Length; ++n) { Int64 x, y; TileUtil.LLToPixel(points[n], zoom, out x, out y, tileSize); pixelPoints[n].X = (int)(x - tilePixelOffset.X); pixelPoints[n].Y = (int)(y - tilePixelOffset.Y); } int outputCount = 0; SimplifyPointData(pixelPoints, null, points.Length, simplificationFactor, simplifiedPixelPoints, null, ref pointsBuffer, ref outputCount); if (outputCount > 1) { GeometryAlgorithms.PolygonClip(simplifiedPixelPoints, outputCount, clipBounds, clippedPolygon); if (clippedPolygon.Count > 0) { //output the clipped polygon List <Coordinate> lineString = new List <Coordinate>(); feature.Geometry.Add(lineString); for (int i = clippedPolygon.Count - 1; i >= 0; --i) { lineString.Add(new Coordinate(clippedPolygon[i].X, clippedPolygon[i].Y)); } } } ++partIndex; } //add the record attributes foreach (var keyValue in spatialData.Attributes) { feature.Attributes.Add(new AttributeKeyValue(keyValue.Key, keyValue.Value)); } if (feature.Geometry.Count > 0) { tileLayer.VectorTileFeatures.Add(feature); } } return(tileLayer); } }
private VectorTileLayer ProcessLineStringTile(ISpatialDataSource spatialLayer, int tileX, int tileY, int zoom) { int tileSize = TileSize; RectangleD tileBounds = TileUtil.GetTileLatLonBounds(tileX, tileY, zoom, tileSize); //create a buffer around the tileBounds tileBounds.Inflate(tileBounds.Width * 0.05, tileBounds.Height * 0.05); int simplificationFactor = Math.Min(10, Math.Max(1, SimplificationPixelThreshold)); System.Drawing.Point tilePixelOffset = new System.Drawing.Point((tileX * tileSize), (tileY * tileSize)); using (IEnumerator <ISpatialData> data = spatialLayer.GetData(new BoundingBox() { MinX = tileBounds.Left, MinY = tileBounds.Top, MaxX = tileBounds.Right, MaxY = tileBounds.Bottom })) { GeometryAlgorithms.ClipBounds clipBounds = new GeometryAlgorithms.ClipBounds() { XMin = -20, YMin = -20, XMax = tileSize + 20, YMax = tileSize + 20 }; bool outputMeasureValues = this.OutputMeasureValues && spatialLayer.HasMeasures; System.Drawing.Point[] pixelPoints = new System.Drawing.Point[1024]; System.Drawing.Point[] simplifiedPixelPoints = new System.Drawing.Point[1024]; double[] simplifiedMeasures = new double[1024]; PointD[] pointsBuffer = new PointD[1024]; VectorTileLayer tileLayer = new VectorTileLayer(); tileLayer.Extent = (uint)tileSize; tileLayer.Version = 2; tileLayer.Name = spatialLayer.Name; //int index = 0; //foreach (int index in indicies) while (data.MoveNext()) { ISpatialData spatialData = data.Current; VectorTileFeature feature = new VectorTileFeature() { Id = spatialData.Id, Geometry = new List <List <Coordinate> >(), Attributes = new List <AttributeKeyValue>() }; //get the point data var recordPoints = spatialData.Geometry; List <double[]> recordMeasures = null; if (outputMeasureValues) { recordMeasures = spatialData.Measures; } List <double> outputMeasures = new List <double>(); int partIndex = 0; foreach (PointD[] points in recordPoints) { double[] measures = recordMeasures != null ? recordMeasures[partIndex] : null; //convert to pixel coordinates; if (pixelPoints.Length < points.Length) { pixelPoints = new System.Drawing.Point[points.Length + 10]; simplifiedPixelPoints = new System.Drawing.Point[points.Length + 10]; simplifiedMeasures = new double[points.Length + 10]; } for (int n = 0; n < points.Length; ++n) { Int64 x, y; TileUtil.LLToPixel(points[n], zoom, out x, out y, tileSize); pixelPoints[n].X = (int)(x - tilePixelOffset.X); pixelPoints[n].Y = (int)(y - tilePixelOffset.Y); } int outputCount = 0; SimplifyPointData(pixelPoints, measures, points.Length, simplificationFactor, simplifiedPixelPoints, simplifiedMeasures, ref pointsBuffer, ref outputCount); //output count may be zero for short records at low zoom levels as //the pixel coordinates wil be a single point after simplification if (outputCount > 0) { List <int> clippedPoints = new List <int>(); List <int> parts = new List <int>(); if (outputMeasureValues) { List <double> clippedMeasures = new List <double>(); GeometryAlgorithms.PolyLineClip(simplifiedPixelPoints, outputCount, clipBounds, clippedPoints, parts, simplifiedMeasures, clippedMeasures); outputMeasures.AddRange(clippedMeasures); } else { GeometryAlgorithms.PolyLineClip(simplifiedPixelPoints, outputCount, clipBounds, clippedPoints, parts); } if (parts.Count > 0) { //output the clipped polyline for (int n = 0; n < parts.Count; ++n) { int index1 = parts[n]; int index2 = n < parts.Count - 1 ? parts[n + 1] : clippedPoints.Count; List <Coordinate> lineString = new List <Coordinate>(); feature.GeometryType = Tile.GeomType.LineString; feature.Geometry.Add(lineString); //clipped points store separate x/y pairs so there will be two values per measure for (int i = index1; i < index2; i += 2) { lineString.Add(new Coordinate(clippedPoints[i], clippedPoints[i + 1])); } } } } ++partIndex; } //add the record attributes foreach (var keyValue in spatialData.Attributes) { feature.Attributes.Add(new AttributeKeyValue(keyValue.Key, keyValue.Value)); } if (outputMeasureValues) { string s = Newtonsoft.Json.JsonConvert.SerializeObject(outputMeasures, new DoubleFormatConverter(4)); feature.Attributes.Add(new AttributeKeyValue(this.MeasuresAttributeName, s)); } if (feature.Geometry.Count > 0) { tileLayer.VectorTileFeatures.Add(feature); } } return(tileLayer); } }
/// <summary> /// Getpotentialses the specified spatial data. /// </summary> /// <param name="spatialData">The spatial data.</param> /// <returns>Dictionary<Cell, System.Double>.</returns> public Dictionary <Cell, double> GetFilteredValues(ISpatialData spatialData) { return(GetFilteredValues(spatialData, this.Filter, this.RayIndices, this._cellularFloor)); }
/// <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); }
internal void Remove(ISpatialData node) { children.Remove(node); ResetEnvelope(); }
public void Add(ISpatialData node) { Children.Add(node); _envelope = Envelope.Extend(node.Envelope); }
internal void Add(ISpatialData node) { children.Add(node); _envelope = Envelope.Extend(node.Envelope); }