示例#1
0
        public static Dictionary <string, object> FromOrigin(
            DSGeom.Point origin,
            List <DSGeom.Point> points,
            List <DSGeom.Polygon> boundary,
            [DefaultArgument("[]")] List <DSGeom.Polygon> obstacles)
        {
            DSGeom.Polygon isovist = IsovistPolygon(boundary, obstacles, origin);
            GTGeom.Polygon gPol    = GTGeom.Polygon.ByVertices(isovist.Points.Select(p => GTGeom.Vertex.ByCoordinates(p.X, p.Y, p.Z)).ToList());

            List <DSGeom.Point> visPoints = new List <DSGeom.Point>();
            double totalPoints            = points.Count;
            double visibilityAmount       = 0;

            foreach (DSGeom.Point point in points)
            {
                GTGeom.Vertex vertex = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

                if (gPol.ContainsVertex(vertex))
                {
                    ++visibilityAmount;
                    visPoints.Add(point);
                }
            }
            isovist.Dispose();

            return(new Dictionary <string, object>()
            {
                { scoreOutputPort, (1 / totalPoints) * visibilityAmount },
                { geometryOutputPort, visPoints }
            });
        }
示例#2
0
        private static DSGeom.Polygon IsovistPolygon(
            List <DSGeom.Polygon> boundary,
            List <DSGeom.Polygon> obstacles,
            DSGeom.Point point)
        {
            BaseGraph baseGraph = BaseGraph.ByBoundaryAndInternalPolygons(boundary, obstacles);

            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }

            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            GTGeom.Vertex origin = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

            List <GTGeom.Vertex> vertices = VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            List <DSGeom.Point>  points   = vertices.Select(v => GTGeom.Points.ToPoint(v)).ToList();

            var polygon = DSGeom.Polygon.ByPoints(points);

            // if polygon is self intersecting, make new polygon
            if (polygon.SelfIntersections().Length > 0)
            {
                points.Add(point);
                polygon = DSGeom.Polygon.ByPoints(points);
            }
            return(polygon);
        }
示例#3
0
        public static DSGeom.Surface FromPoint(
            List <DSGeom.Polygon> boundary,
            [DefaultArgument("[]")] List <DSGeom.Polygon> internals,
            DSGeom.Point point)
        {
            BaseGraph baseGraph = BaseGraph.ByBoundaryAndInternalPolygons(boundary, internals);

            if (baseGraph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            GTGeom.Vertex origin = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

            List <GTGeom.Vertex> vertices = VisibilityGraph.VertexVisibility(origin, baseGraph.graph);
            List <DSGeom.Point>  points   = vertices.Select(v => GTGeom.Points.ToPoint(v)).ToList();

            var polygon = DSGeom.Polygon.ByPoints(points);

            // if polygon is self intersecting, make new polygon
            if (polygon.SelfIntersections().Length > 0)
            {
                points.Add(point);
                polygon = DSGeom.Polygon.ByPoints(points);
            }
            DSGeom.Surface surface = DSGeom.Surface.ByPatch(polygon);
            polygon.Dispose();
            points.ForEach(p => p.Dispose());

            return(surface);
        }
示例#4
0
 internal static void AddColouredVertex(
     IRenderPackage package,
     GTGeom.Vertex vertex,
     DSCore.Color color)
 {
     package.AddPointVertex(vertex.X, vertex.Y, vertex.Z);
     package.AddPointVertexColor(color.Red, color.Green, color.Blue, color.Alpha);
 }
示例#5
0
        public static Dictionary <string, object> OfPointsFromOrigin(
            Point origin,
            List <Point> points,
            List <Polygon> boundary,
            [DefaultArgument("[]")] List <Polygon> obstructions = null)
        {
            if (origin is null)
            {
                throw new ArgumentNullException(nameof(origin));
            }
            if (points is null || points.Count == 0)
            {
                throw new ArgumentNullException(nameof(points));
            }
            if (obstructions == null)
            {
                obstructions = new List <Polygon>();
            }

            Polygon isovist = IsovistPolygon(origin, obstructions, boundary);

            GTGeom.Polygon isovistPolygon = GTGeom.Polygon.ByVertices(isovist.Points.Select(p => GTGeom.Vertex.ByCoordinates(p.X, p.Y, p.Z)).ToList());

            var    visiblePoints    = new List <Point>();
            double totalPoints      = points.Count;
            double visibilityAmount = 0;

            for (var i = 0; i < points.Count; i++)
            {
                var           point  = points[i];
                GTGeom.Vertex vertex = GTGeom.Vertex.ByCoordinates(point.X, point.Y, point.Z);

                if (isovistPolygon.ContainsVertex(vertex))
                {
                    ++visibilityAmount;
                    visiblePoints.Add(point);
                }
            }
            isovist.Dispose();

            var visibilityPercentageScore = (1 / totalPoints) * visibilityAmount * 100;

            return(new Dictionary <string, object>()
            {
                { percentageVisibleOutputPort, visibilityPercentageScore },
                { visibleItemsOutputPort, visiblePoints }
            });
        }
        public static BaseGraph ByLines(List <DSGeom.Line> lines)
        {
            if (lines is null || lines.Count == 0)
            {
                throw new ArgumentNullException(nameof(lines));
            }
            var g = new BaseGraph();

            for (var i = 0; i < lines.Count; i++)
            {
                var           line  = lines[i];
                GTGeom.Vertex start = GTGeom.Points.ToVertex(line.StartPoint);
                GTGeom.Vertex end   = GTGeom.Points.ToVertex(line.EndPoint);
                g.graph.AddEdge(GTGeom.Edge.ByStartVertexEndVertex(start, end));
            }
            return(g);
        }
示例#7
0
        public static BaseGraph ByLines(List <DSGeom.Line> lines)
        {
            if (lines == null)
            {
                throw new NullReferenceException("lines");
            }
            BaseGraph g = new BaseGraph()
            {
                graph = new Graph()
            };

            foreach (DSGeom.Line line in lines)
            {
                GTGeom.Vertex start = GTGeom.Points.ToVertex(line.StartPoint);
                GTGeom.Vertex end   = GTGeom.Points.ToVertex(line.EndPoint);
                g.graph.AddEdge(GTGeom.Edge.ByStartVertexEndVertex(start, end));
            }
            return(g);
        }