// make a dummy edge with no mapping back to a real edge internal static Edge MakeDummyEdgeFromNodeToItsCluster(AlgorithmDataNodeWrap u, AlgorithmDataNodeWrap v, double length) { var e = new Edge(u.node, v.node) { Length = length, AlgorithmData = new AlgorithmDataEdgeWrap { Source = u.index, Target = v.index } }; return(e); }
internal static GeometryGraph FlatGraph(GeometryGraph graph) { // it is a new graph with clusters replaced by nodes and edges connecting nodes to their parent cluster node var flatGraph = new GeometryGraph(); // from the original graph, foreach node v create a new node u with u.UserData pointing back to v // and set v.AlgorithmData to a wrapper of u foreach (var v in graph.Nodes) { Debug.Assert(!(v is Cluster)); var u = new Node(v.BoundaryCurve.Clone()) { UserData = v }; v.AlgorithmData = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, u); flatGraph.Nodes.Add(u); } double avgLength = 0; foreach (var e in graph.Edges) { avgLength += e.Length; if (e.Source is Cluster || e.Target is Cluster) { continue; } flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); } if (graph.Edges.Count != 0) { avgLength /= graph.Edges.Count; } else { avgLength = 100; } Cluster rootCluster = graph.RootCluster; // create edges from the children of each parent cluster to the parent cluster node foreach (var c in rootCluster.AllClustersDepthFirst()) { if (c == rootCluster) { continue; } if (c.BoundaryCurve == null) { c.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 1, 1, new Point()); } var uOfCluster = new Node(c.BoundaryCurve.Clone()) { UserData = c }; var uuOfCluster = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, uOfCluster); c.AlgorithmData = uuOfCluster; flatGraph.Nodes.Add(uOfCluster); foreach (var v in c.Nodes.Concat(from cc in c.Clusters select(Node) cc)) { flatGraph.Edges.Add( AlgorithmDataEdgeWrap.MakeDummyEdgeFromNodeToItsCluster( v.AlgorithmData as AlgorithmDataNodeWrap, uuOfCluster, avgLength)); } } // mark top-level nodes and clusters foreach (var v in rootCluster.Nodes.Concat(from cc in rootCluster.Clusters select(Node) cc)) { ((AlgorithmDataNodeWrap)v.AlgorithmData).TopLevel = true; } // create edges between clusters foreach (var e in graph.Edges) { if (e.Source is Cluster || e.Target is Cluster) { flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); } } return(flatGraph); }
internal static GeometryGraph FlatGraph(GeometryGraph graph) { // it is a new graph with clusters replaced by nodes and edges connecting nodes to their parent cluster node var flatGraph = new GeometryGraph(); // from the original graph, foreach node v create a new node u with u.UserData pointing back to v // and set v.AlgorithmData to a wrapper of u foreach (var v in graph.Nodes) { Debug.Assert(!(v is Cluster)); var u = new Node(v.BoundaryCurve.Clone()) { UserData = v }; v.AlgorithmData = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, u); flatGraph.Nodes.Add(u); } double avgLength = 0; foreach (var e in graph.Edges) { avgLength += e.Length; if (e.Source is Cluster || e.Target is Cluster) continue; flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); } if (graph.Edges.Count != 0) avgLength /= graph.Edges.Count; else avgLength = 100; Cluster rootCluster = graph.RootCluster; // create edges from the children of each parent cluster to the parent cluster node foreach (var c in rootCluster.AllClustersDepthFirst()) { if (c == rootCluster) continue; if (c.BoundaryCurve == null) c.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(10, 10, 1, 1, new Point()); var uOfCluster = new Node(c.BoundaryCurve.Clone()) {UserData = c}; var uuOfCluster = new AlgorithmDataNodeWrap(flatGraph.Nodes.Count, uOfCluster); c.AlgorithmData = uuOfCluster; flatGraph.Nodes.Add(uOfCluster); foreach (var v in c.Nodes.Concat(from cc in c.Clusters select (Node) cc)) flatGraph.Edges.Add( AlgorithmDataEdgeWrap.MakeDummyEdgeFromNodeToItsCluster( v.AlgorithmData as AlgorithmDataNodeWrap, uuOfCluster, avgLength)); } // mark top-level nodes and clusters foreach (var v in rootCluster.Nodes.Concat(from cc in rootCluster.Clusters select (Node) cc)) ((AlgorithmDataNodeWrap) v.AlgorithmData).TopLevel = true; // create edges between clusters foreach (var e in graph.Edges) if (e.Source is Cluster || e.Target is Cluster) flatGraph.Edges.Add(AlgorithmDataEdgeWrap.MakeEdge(e)); return flatGraph; }
// make a dummy edge with no mapping back to a real edge internal static Edge MakeDummyEdgeFromNodeToItsCluster(AlgorithmDataNodeWrap u, AlgorithmDataNodeWrap v, double length) { var e = new Edge(u.node, v.node) { Length = length, AlgorithmData = new AlgorithmDataEdgeWrap {Source = u.index, Target = v.index} }; return e; }