/// <summary> /// Adds specific lines as Edges to the visibility graph /// </summary> /// <param name="visibilityGraph">VisibilityGraph Graph</param> /// <param name="edges">Lines to add as new Edges</param> /// <returns></returns> public static VisibilityGraph AddEdges(VisibilityGraph visibilityGraph, List <Edge> edges) { if (edges == null) { throw new NullReferenceException("Edges"); } List <Vertex> singleVertices = new List <Vertex>(); foreach (Edge e in edges) { if (!singleVertices.Contains(e.StartVertex)) { singleVertices.Add(e.StartVertex); } if (!singleVertices.Contains(e.EndVertex)) { singleVertices.Add(e.EndVertex); } } VisibilityGraph updatedGraph = (VisibilityGraph)visibilityGraph.Clone(); if (singleVertices.Any()) { updatedGraph = AddVertices(visibilityGraph, singleVertices); } foreach (Edge e in edges) { updatedGraph.AddEdge(e); } return(updatedGraph); }
/// <summary> /// Adds specific points as gVertices to the VisibilityGraph Graph /// </summary> /// <param name="visibilityGraph">VisibilityGraph Graph</param> /// <param name="vertices">Points to add as gVertices</param> /// <returns></returns> public static VisibilityGraph AddVertices(VisibilityGraph visibilityGraph, List <gVertex> vertices, bool reducedGraph = true) { //TODO: Seems that original graph gets updated as well if (vertices == null) { throw new NullReferenceException("vertices"); } VisibilityGraph newVisGraph = (VisibilityGraph)visibilityGraph.Clone(); List <gVertex> singleVertices = new List <gVertex>(); foreach (gVertex v in vertices) { if (newVisGraph.Contains(v)) { continue; } gEdge closestEdge = newVisGraph.baseGraph.edges.OrderBy(e => e.DistanceTo(v)).First(); if (!gBase.Threshold(closestEdge.DistanceTo(v), 0)) { singleVertices.Add(v); } else if (v.OnEdge(closestEdge.StartVertex, closestEdge.EndVertex)) { v.polygonId = closestEdge.StartVertex.polygonId; newVisGraph.baseGraph.polygons[v.polygonId] = newVisGraph.baseGraph.polygons[v.polygonId].AddVertex(v, closestEdge); singleVertices.Add(v); } } newVisGraph.baseGraph.ResetEdgesFromPolygons(); foreach (gVertex centre in singleVertices) { foreach (gVertex v in VisibleVertices(centre, newVisGraph.baseGraph, null, null, singleVertices, false, reducedGraph)) { newVisGraph.AddEdge(new gEdge(centre, v)); } } return(newVisGraph); }
/// <summary> /// Adds specific points as Vertices to the VisibilityGraph Graph /// </summary> /// <param name="visibilityGraph">VisibilityGraph Graph</param> /// <param name="vertices">Points to add as gVertices</param> /// <returns></returns> public static VisibilityGraph AddVertices(VisibilityGraph visibilityGraph, List <Vertex> vertices, bool reducedGraph = true) { if (vertices == null) { throw new NullReferenceException("Vertices"); } VisibilityGraph newVisGraph = (VisibilityGraph)visibilityGraph.Clone(); List <Vertex> singleVertices = new List <Vertex>(); foreach (Vertex vertex in vertices) { if (newVisGraph.Contains(vertex)) { continue; } Edge closestEdge = newVisGraph.baseGraph.Edges.OrderBy(e => e.DistanceTo(vertex)).First(); if (!closestEdge.DistanceTo(vertex).AlmostEqualTo(0)) { singleVertices.Add(vertex); } else if (vertex.OnEdge(closestEdge.StartVertex, closestEdge.EndVertex)) { int polygonId = closestEdge.StartVertex.Parent.Id; newVisGraph.baseGraph._polygonsDict[polygonId] = newVisGraph.baseGraph._polygonsDict[polygonId].AddVertex(vertex, closestEdge); singleVertices.Add(vertex); } } newVisGraph.baseGraph.ResetEdgesFromPolygons(); foreach (Vertex centre in singleVertices) { foreach (Vertex v in VisibleVertices(centre, newVisGraph.baseGraph, null, null, singleVertices, false, reducedGraph)) { newVisGraph.AddEdge(Edge.ByStartVertexEndVertex(centre, v)); } } return(newVisGraph); }