private static Graph ConstructGraph <TBounds, TPayload>(this BalancedBoundingTree <TBounds, TPayload> tree, int depth) where TBounds : IComparable <TBounds>, IEquatable <TBounds> { Graph graph = Graph.Undirected; if (depth > 0) { graph = tree.Root.AddToGraph(graph, depth); } return(graph); }
public static async Task Write <TBounds, TPayload>(this BalancedBoundingTree <TBounds, TPayload> tree, int depth, string directory, string fileName, ILogger logger = null) where TBounds : IComparable <TBounds>, IEquatable <TBounds> { var graph = tree.ConstructGraph(depth); DirectoryInfo dir = new DirectoryInfo(directory); dir.Create(); string graphVizBin = @"C:\Program Files (x86)\Graphviz2.38\bin"; IRenderer renderer = new Renderer(graphVizBin); using (Stream file = File.Create(directory + fileName)) { await renderer.RunAsync( graph, file, RendererLayouts.Dot, RendererFormats.Png, CancellationToken.None); } logger?.Debug("Graph written to: file://" + directory + fileName); }
private static Graph AddToGraph <TBounds, TPayload>(this BalancedBoundingTree <TBounds, TPayload> .BalancedBoundingNode node, Graph graph, int depth) where TBounds : IComparable <TBounds>, IEquatable <TBounds> { if (!ReferenceEquals(node.LowerTree, BalancedBoundingTree <TBounds, TPayload> .Nil)) { graph = graph.Add(EdgeStatement.For(node.ToString(), node.LowerTree.ToString())); if (depth > 0) { graph = node.LowerTree.AddToGraph(graph, depth - 1); } } if (!ReferenceEquals(node.UpperTree, BalancedBoundingTree <TBounds, TPayload> .Nil)) { graph = graph.Add(EdgeStatement.For(node.ToString(), node.UpperTree.ToString())); if (depth > 0) { graph = node.UpperTree.AddToGraph(graph, depth - 1); } } return(graph); }