private void draw(IsovistPolygon isovistPolygon) { double scale = this.getScaleFactor(); this._isovistPolygons.Add(isovistPolygon); DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(this.toPoint(isovistPolygon.BoundaryPoints[0]), true, true); for (int i = 1; i < isovistPolygon.BoundaryPoints.Length; i++) { sgc.LineTo(this.toPoint(isovistPolygon.BoundaryPoints[i]), true, true); } } sg.Freeze(); drawingContext.DrawGeometry(this.fillBrush, new Pen(this.boarderBrush, this.boarderThickness / scale), sg); Point center = this.toPoint(isovistPolygon.VantagePoint); var p1 = new Point(center.X - this.centerSize / (2 * scale), center.Y); var p2 = new Point(center.X + this.centerSize / (2 * scale), center.Y); drawingContext.DrawLine(new Pen(this.centerBrush, this.centerSize / scale), p1, p2); } drawingVisual.Drawing.Freeze(); this._children.Add(drawingVisual); }
private void mouseLeftButtonDown_GetPolygonalIsovist(object sender, MouseButtonEventArgs e) { var point = this._host.InverseRenderTransform.Transform(Mouse.GetPosition(this._host.FloorScene)); UV p = new UV(point.X, point.Y); Cell cell = this._host.cellularFloor.FindCell(p); if (cell == null) { MessageBox.Show("Pick a point on the walkable field and try again!\n"); return; } switch (this._host.IsovistBarrierType) { case BarrierType.Visual: if (cell.VisualOverlapState != OverlapState.Outside) { MessageBox.Show("Pick a point outside visual barriers.\nTry again!"); return; } break; case BarrierType.Physical: if (cell.PhysicalOverlapState != OverlapState.Outside) { MessageBox.Show("Pick a point outside physical barriers.\nTry again!"); return; } break; case BarrierType.Field: if (cell.FieldOverlapState != OverlapState.Inside) { MessageBox.Show("Pick a point inside the walkable field.\nTry again!"); return; } break; case BarrierType.BarrierBuffer: if (cell.BarrierBufferOverlapState != OverlapState.Outside) { MessageBox.Show("Pick a point outside barrier buffers.\nTry again!"); return; } break; default: break; } this._children.Clear(); var timer = new System.Diagnostics.Stopwatch(); try { timer.Start(); HashSet <UVLine> blocks = this._host.cellularFloor.PolygonalIsovistVisualObstacles(p, this._host.IsovistDepth, this._host.IsovistBarrierType); BarrierPolygon isovistPolygon = this._host.BIM_To_OSM.IsovistPolygon(p, this._host.IsovistDepth, blocks); IsovistPolygon newIsovistPolygon = new IsovistPolygon(isovistPolygon.BoundaryPoints, p); timer.Stop(); this._host.IsovistInformation = new IsovistInformation(IsovistInformation.IsovistType.Polygonal, timer.Elapsed.TotalMilliseconds, isovistPolygon.GetArea(), isovistPolygon.GetPerimeter()); this.draw(newIsovistPolygon); } catch (Exception error0) { this._host.IsovistInformation = null; MessageBox.Show(error0.Message); } timer = null; }