/// <summary> /// Computes the isovist at the specified depth of view. /// </summary> /// <param name="depth">The depth of view.</param> /// <param name="typeOfBarrier">The type of barrier.</param> /// <param name="cellularFloor">The cellularFloor.</param> /// <param name="Tolerance">The tolerance.</param> public void Compute(double depth, BarrierType typeOfBarrier, CellularFloor cellularFloor, double Tolerance = OSMDocument.AbsoluteTolerance) { var isovist = CellularIsovistCalculator.GetIsovist(this.VantageCell + new UV(cellularFloor.CellSize / 2, cellularFloor.CellSize / 2), depth, typeOfBarrier, cellularFloor, Tolerance); this.VisibleCells = isovist.VisibleCells; }
//step 2 /// <summary> /// Computes the destinations in a parallel thread /// </summary> /// <param name="externalDepth">The external depth of view.</param> /// <param name="desiredNumber">The desired number of destinations to keep after simplification.</param> /// <param name="cellularFloor">The cellular floor.</param> /// <param name="staticCost">The static cost.</param> /// <param name="Tolerance">The tolerance.</param> public void ComputeDestinations(double externalDepth, int desiredNumber, CellularFloor cellularFloor, Dictionary <Cell, double> staticCost, double Tolerance = OSMDocument.AbsoluteTolerance) { AgentEscapeRoutes agentScapeRoutes = null; try { agentScapeRoutes = CellularIsovistCalculator.GetAgentEscapeRoutes(this.VantageCell, externalDepth, desiredNumber, cellularFloor, staticCost, Tolerance); } catch (Exception er) { this.Error = er.Report(); } if (agentScapeRoutes == null) { this._destinations = null; } else { this._destinations = agentScapeRoutes.Destinations; } }
private void getCellularIsovist_MouseLeftButtonDown(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; } var timer = new System.Diagnostics.Stopwatch(); try { timer.Start(); Isovist isovist = CellularIsovistCalculator.GetIsovist(p, this._host.IsovistDepth, this._host.IsovistBarrierType, this._host.cellularFloor); //Isovist isovist = CellularIsovistCalculator.GetIsovist(p,this._host.isoDepth, BarrierType.BarrierBuffer, this._host.cellularFloor); timer.Stop(); this._host.IsovistInformation = new IsovistInformation(IsovistInformation.IsovistType.Cellular, timer.Elapsed.TotalMilliseconds, isovist.GetArea(this._host.cellularFloor.CellSize), double.NaN); this.draw(isovist); } catch (Exception error1) { this._host.IsovistInformation = null; MessageBox.Show(error1.Report()); } timer = null; }
private void drawInRevit() { this._host.Hide(); UV p = this._host.OSM_to_BIM.PickPoint("Pick a vantage point to draw cellular Isovist"); 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!"); this._host.ShowDialog(); return; } break; case BarrierType.Physical: if (cell.PhysicalOverlapState != OverlapState.Outside) { MessageBox.Show("Pick a point outside physical barriers.\nTry again!"); this._host.ShowDialog(); return; } break; case BarrierType.Field: if (cell.FieldOverlapState != OverlapState.Inside) { MessageBox.Show("Pick a point inside the walkable field.\nTry again!"); this._host.ShowDialog(); return; } break; case BarrierType.BarrierBuffer: if (cell.BarrierBufferOverlapState != OverlapState.Outside) { MessageBox.Show("Pick a point outside barrier buffers.\nTry again!"); this._host.ShowDialog(); return; } break; default: break; } Isovist isovist = null; var timer = new System.Diagnostics.Stopwatch(); try { timer.Start(); isovist = CellularIsovistCalculator.GetIsovist(p, this._host.IsovistDepth, this._host.IsovistBarrierType, this._host.cellularFloor); timer.Stop(); this._host.IsovistInformation = new IsovistInformation(IsovistInformation.IsovistType.Cellular, timer.Elapsed.TotalMilliseconds, isovist.GetArea(this._host.cellularFloor.CellSize), double.NaN); } catch (Exception error0) { this._host.IsovistInformation = null; MessageBox.Show(error0.Report()); } timer = null; if (isovist != null) { try { var boundaries = isovist.GetBoundary(this._host.cellularFloor); double elevation = this._host.BIM_To_OSM.PlanElevation; foreach (var item in boundaries) { this._host.OSM_to_BIM.VisualizePolygon(item.BoundaryPoints, elevation); } } catch (Exception error1) { MessageBox.Show(error1.Report()); } } this._host.ShowDialog(); }
private void getEscapeRoute_MouseLeftButtonDown(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; } try { IsovistEscapeRoutes escapeRoutes = null; switch (this._escapeRouteType) { case EscapeRouteType.All: escapeRoutes = CellularIsovistCalculator.GetAllEscapeRoute(p, this._host.IsovistDepth, this._host.IsovistBarrierType, this._host.cellularFloor); this._children.Clear(); this._edges.Clear(); this._escapeRoutes.Clear(); this.draw(escapeRoutes); break; case EscapeRouteType.WeightedAndSimplified: escapeRoutes = CellularIsovistCalculator.GetWeightedSimplifiedEscapeRoute(p, this._host.AgentIsovistExternalDepth, this._host.IsovistBarrierType, this._host.cellularFloor, this._staticCosts, this._host.MaximumNumberOfDestinations); this._children.Clear(); this._edges.Clear(); this._escapeRoutes.Clear(); this.draw(escapeRoutes); break; default: break; } } catch (Exception error1) { this._host.IsovistInformation = null; MessageBox.Show(error1.Report()); } }
private void updateDestination() { try { //update the destination AgentEscapeRoutes escapeRoute = null; var vantageCell = this._cellularFloor.FindCell(this.CurrentState.Location); if (!this._escapeRouts.ContainsKey(vantageCell)) { try { escapeRoute = CellularIsovistCalculator.GetAgentEscapeRoutes( vantageCell, this._isovistExternalRadius, this._destinationCount, this._cellularFloor, this._staticCost, 0.0000001d); } catch (Exception) { //throw new ArgumentException("Escape Routes cannot be calculated for the agent training!"); //MessageBox.Show(e.Report()); //try //{ // escapeRoute = CellularIsovistCalculator.GetAgentEscapeRoutes( // vantageCell, // this._isovistRadius, // this._destinationCount, // this._cellularFloor, // this._staticCost, // 0.0000001d); //} //catch (Exception) { } } if (escapeRoute == null) { return; } this._escapeRouts.Add(vantageCell, escapeRoute); } else { escapeRoute = this._escapeRouts[vantageCell]; } this.DecisionMakingPeriod = this.DecisionMakingPeriodDistribution.Sample(); this.WalkTime = 0.0d; //updating desired state //filtering the destinations to those in the cone of vision var visibleDestinationList = new List <AgentCellDestination>(); foreach (var item in escapeRoute.Destinations) { UV direction = item.Destination - this.CurrentState.Location; direction.Unitize(); if (direction.DotProduct(this.CurrentState.Direction) >= this.VisibilityCosineFactor) { visibleDestinationList.Add(item); } } AgentCellDestination[] destinations; if (visibleDestinationList.Count > 0) { destinations = visibleDestinationList.ToArray(); visibleDestinationList.Clear(); visibleDestinationList = null; } else { destinations = escapeRoute.Destinations; } double[] normalizedAngleCost = new double[destinations.Length]; //between zero and 1 for (int i = 0; i < destinations.Length; i++) { UV direction = destinations[i].Destination - this.CurrentState.Location; direction.Unitize(); normalizedAngleCost[i] = (direction.DotProduct(this.CurrentState.Direction) + 1) / 2; } double[] weighted = new double[destinations.Length]; double sum = 0; for (int i = 0; i < destinations.Length; i++) { weighted[i] = this.AngleDistributionLambdaFactor * Math.Exp(-this.AngleDistributionLambdaFactor * normalizedAngleCost[i]) + this.DesirabilityDistributionLambdaFactor * Math.Exp(-this.DesirabilityDistributionLambdaFactor * destinations[i].DesirabilityCost); sum += weighted[i]; } double selected = this._random.NextDouble() * sum; sum = 0; int selectedIndex = 0; for (int i = 0; i < destinations.Length; i++) { sum += weighted[i]; if (sum > selected) { selectedIndex = i; break; } } this.Destination = destinations[selectedIndex].Destination; } catch (Exception) { //MessageBox.Show(e.Report()); } }
private void endBtn_Click(object sender, RoutedEventArgs e) { this._host.CommandReset.Click -= endBtn_Click; this._host.Menues.IsEnabled = true; this._host.UIMessage.Visibility = Visibility.Hidden; //this.JGraphMode = false; this._host.Cursor = Cursors.Arrow; this._host.FloorScene.MouseLeftButtonDown -= FloorScene_MouseLeftButtonDown; try { #region Create Graph HashSet <UV> pnts = new HashSet <UV>(); TriangleNet.Behavior behavior = new Behavior(); TriangleNet.Mesh t_mesh = new TriangleNet.Mesh(); TriangleNet.Geometry.InputGeometry geom = new TriangleNet.Geometry.InputGeometry(); foreach (Node node in JGNodes) { TriangleNet.Data.Vertex vertex = new TriangleNet.Data.Vertex(node.Coordinates.U, node.Coordinates.V, 0); geom.AddPoint(vertex); pnts.Add(node.Coordinates); } t_mesh.Triangulate(geom); var graph = new JGGraph(pnts); foreach (var item in t_mesh.Triangles) { UV a = null; var vrtx = t_mesh.GetVertex(item.P0); if (vrtx != null) { a = new UV(vrtx.X, vrtx.Y); } UV b = null; vrtx = t_mesh.GetVertex(item.P1); if (vrtx != null) { b = new UV(vrtx.X, vrtx.Y); } UV c = null; vrtx = t_mesh.GetVertex(item.P2); if (vrtx != null) { c = new UV(vrtx.X, vrtx.Y); } if (a != null && b != null) { graph.AddConnection(a, b); } if (a != null && c != null) { graph.AddConnection(a, c); } if (c != null && b != null) { graph.AddConnection(c, b); } } #endregion #region Remove Edges with isovists at the ends that do not overlap this.edges = graph.ToEdges(); Dictionary <int, Isovist> IsovistGuid = new Dictionary <int, Isovist>(); foreach (JGVertex item in graph.Vertices) { double x = double.NegativeInfinity; foreach (JGVertex vertex in item.Connections) { var y = item.Point.DistanceTo(vertex.Point); if (y > x) { x = y; } } var isovist = CellularIsovistCalculator.GetIsovist(item.Point, x, BarrierType.Visual, this._host.cellularFloor); IsovistGuid.Add(item.Point.GetHashCode(), isovist); } HashSet <JGEdge> visibleVertexes = new HashSet <JGEdge>(); foreach (JGEdge item in this.edges) { Isovist v1 = null; IsovistGuid.TryGetValue(item.P1.GetHashCode(), out v1); Isovist v2 = null; IsovistGuid.TryGetValue(item.P2.GetHashCode(), out v2); if (v1 != null && v2 != null) { if (v2.VisibleCells.Overlaps(v1.VisibleCells)) { visibleVertexes.Add(item); } } } #endregion #region setting the edges JGEdge.LineToEdgeGuide.Clear(); foreach (JGEdge edge in this.edges) { edge.Clear(); } this.edges = visibleVertexes.ToList <JGEdge>(); foreach (JGEdge item in this.edges) { item.Draw(); } #endregion //cleaning up the used data t_mesh = null; graph = null; geom.Clear(); geom = null; visibleVertexes = null; IsovistGuid = null; //enabling edit mode this.EditGraph.IsEnabled = true; this.DrawJG.IsEnabled = true; this.Hide_show_Menu.IsEnabled = true; this.CreateCovexGraph.Header = "Reset Convex Graph"; } catch (Exception error) { MessageBox.Show(error.Report()); } }