Пример #1
0
        public void IsovistFromPointReturnsExceptionIfOriginPointIsInsideInternalPolygonTest()
        {
            // Create obstruction
            Polygon internals = Rectangle.ByWidthLength(5, 5) as Polygon;

            // Create origin point
            Point originPoint = Point.ByCoordinates(0, 0);

            Assert.Throws <ApplicationException>(() => Isovist.FromPoint(new List <Polygon> {
                layoutPolygon
            }, new List <Polygon> {
                internals
            }, originPoint));
        }
Пример #2
0
        public void IsovistFromPointReturnsCorrectSurfaceAreaTest()
        {
            // Create origin point
            Point originPoint = layoutPolygon.Center();

            // Create isovist form the origin point
            Surface isovist = Isovist.FromPoint(new List <Polygon> {
                layoutPolygon
            }, new List <Polygon> {
                layoutPolygon
            }, originPoint);

            // Checks if the area of the isovist is equal to the area of the layout
            // as there are no obstructions the entire layout should be visible from the origin point
            Assert.AreEqual(isovist.Area, Surface.ByPatch(layoutPolygon).Area);
        }
Пример #3
0
        public void IsovistFromPointDetectsObstructionsInLayoutTest()
        {
            // Create obstruction
            Polygon internals = Rectangle.ByWidthLength(5, 5) as Polygon;

            // Create origin point
            Point originPoint = Point.ByCoordinates(3, 3);

            // Create isovist form the origin point
            Surface isovist = Isovist.FromPoint(new List <Polygon> {
                layoutPolygon
            }, new List <Polygon> {
                internals
            }, originPoint);

            // Checks that the area returned by the isovist is not equal to the area of the layout
            // and that the isovist does not intersect the midpoint of the obstacle.
            Assert.AreNotEqual(Surface.ByPatch(layoutPolygon).Area, isovist.Area);
            Assert.False(isovist.DoesIntersect(internals.Center()));
        }
Пример #4
0
        private void draw(Isovist isovist)
        {
            this._children.Clear();
            this._edges.Clear();
            this._escapeRoutes.Clear();
            var boundaries = isovist.GetBoundary(this._host.cellularFloor);

            this._edges.Add(isovist.VantageCell, boundaries);
            double        scale = this.getScaleFactor();
            Point         p1 = new Point(), p2 = new Point();
            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                StreamGeometry sg = new StreamGeometry();
                using (StreamGeometryContext sgc = sg.Open())
                {
                    foreach (BarrierPolygon item in boundaries)
                    {
                        sgc.BeginFigure(new Point(item.BoundaryPoints[0].U, item.BoundaryPoints[0].V), true, true);
                        foreach (var uv in item.BoundaryPoints)
                        {
                            sgc.LineTo(new Point(uv.U, uv.V), true, true);
                        }
                    }
                }
                drawingContext.DrawGeometry(this._fillBrush, null, sg);
                Pen pen = new Pen(this._centerBrush, this._host.cellularFloor.CellSize);
                p1.X = isovist.VantageCell.U;
                p1.Y = isovist.VantageCell.V + this._host.cellularFloor.CellSize / 2;
                p2.X = isovist.VantageCell.U + this._host.cellularFloor.CellSize;
                p2.Y = isovist.VantageCell.V + this._host.cellularFloor.CellSize / 2;
                drawingContext.DrawLine(pen, p1, p2);
            }
            drawingVisual.Drawing.Freeze();
            this._children.Add(drawingVisual);
        }
Пример #5
0
        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;
        }
Пример #6
0
        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 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());
            }
        }