public static DotGraph ToGraphViz(this GaNumMultivector mv, bool showFullGraph = false, bool showLeafValues = false) { var dotGraph = DotGraph.Directed("Graph"); dotGraph.AddBinaryTree(mv.TermsTree, showFullGraph); if (!showLeafValues) { return(dotGraph); } foreach (var term in mv.Terms) { var parentNodeName = term.Key.PatternToString(mv.VSpaceDimension); var node = dotGraph.AddNode("coef" + parentNodeName); node.SetLabel(term.Value.ToString("G")); node.SetShape(DotNodeShape.Note); node.SetStyle(DotNodeStyle.Solid); node.SetColor(DotColor.Rgb(Color.Black)); node.SetFontColor(DotColor.Rgb(Color.Black)); var dotEdge = node.AddEdgeFrom(parentNodeName); dotEdge.SetArrowHead(DotArrowType.Inv); dotEdge.SetArrowTail(DotArrowType.Inv); dotEdge.SetStyle(DotEdgeStyle.Solid); dotEdge.SetColor(DotColor.Rgb(Color.Black)); dotEdge.SetFontColor(DotColor.Rgb(Color.Black)); } return(dotGraph); }
public static DotGraph ToGraphViz(this GaNumMapBilinearTree bilinearMap, bool showFullGraph = false, bool showLeafValues = false) { var dotGraph = DotGraph.Directed("Graph"); dotGraph.AddQuadTree(bilinearMap.BasisBladesMapTree, showFullGraph); if (!showLeafValues) { return(dotGraph); } foreach (var leafPair in bilinearMap.BasisBladesMapTree.LeafValuePairs) { var dotHtmlTable = DotUtils.Table(); dotHtmlTable.SetBorder(0); dotHtmlTable.SetCellBorder(1); var dotHtmlRow = dotHtmlTable.AddRow(); var mv = leafPair.Item3; foreach (var term in mv.Terms) { var columnTable = DotUtils.Table(); columnTable.SetBorder(0); columnTable.SetCellBorder(0); columnTable.AddRow( term.Key.PatternToString(mv.VSpaceDimension).ToHtmlString() ); columnTable.AddRow(term.Value.ToString("G")); dotHtmlRow.AddCell(columnTable); } var parentNodeName = leafPair.Item1.PatternToString(bilinearMap.DomainVSpaceDimension) + ", " + leafPair.Item2.PatternToString(bilinearMap.DomainVSpaceDimension); var node = dotGraph.AddNode("coef" + parentNodeName); node.SetLabel(dotHtmlTable); node.SetShape(DotNodeShape.Note); node.SetStyle(DotNodeStyle.Solid); node.SetColor(DotColor.Rgb(Color.Black)); node.SetFontColor(DotColor.Rgb(Color.Black)); var dotEdge = node.AddEdgeFrom(parentNodeName); dotEdge.SetArrowHead(DotArrowType.Inv); dotEdge.SetArrowTail(DotArrowType.Inv); dotEdge.SetStyle(DotEdgeStyle.Solid); dotEdge.SetColor(DotColor.Rgb(Color.Black)); dotEdge.SetFontColor(DotColor.Rgb(Color.Black)); } return(dotGraph); }
public static DotGraph AddQuadTree <T>(this DotGraph dotGraph, GMacQuadTree <T> quadTree, bool showFullGraph) { var maxTreeDepth = quadTree.TreeDepth; var activeIDs = quadTree.LeafNodeIDs.ToArray(); var inactiveColor = DotColor.Rgb(Color.Gray); var activeColor = DotColor.Rgb(Color.Black); dotGraph.SetRankDir(DotRankDirection.LeftToRight); dotGraph.SetSplines(DotSplines.Spline); dotGraph.SetOverlap(DotOverlap.False); dotGraph.SetNodeMarginDelta(12); var nodeDefaults = dotGraph.AddNodeDefaults(); nodeDefaults.SetShape(DotNodeShape.Circle); nodeDefaults.SetStyle(DotNodeStyle.Solid); nodeDefaults.SetColor(inactiveColor); nodeDefaults.SetFontColor(inactiveColor); nodeDefaults.SetPenWidth(1.0f); var edgeDefaults = dotGraph.AddEdgeDefaults(); edgeDefaults.SetArrowHead(DotArrowType.Vee); edgeDefaults.SetStyle(DotEdgeStyle.Dashed); edgeDefaults.SetColor(inactiveColor); edgeDefaults.SetFontColor(inactiveColor); edgeDefaults.SetPenWidth(1.0f); var idsStack1 = new Stack <ulong>(); idsStack1.Push(0ul); var idsStack2 = new Stack <ulong>(); idsStack2.Push(0ul); var treeDepthStack = new Stack <int>(); treeDepthStack.Push(maxTreeDepth); var s = "".PadRight(maxTreeDepth, '-'); var dotNodeName = s + ", " + s; var dotNodeLabel = s + '\n' + s; var dotNode = dotGraph.AddNode(dotNodeName); dotNode.SetShape(DotNodeShape.DoubleCircle); dotNode.SetStyle(DotNodeStyle.Solid); dotNode.SetColor(activeColor); dotNode.SetFontColor(activeColor); dotNode.SetPenWidth(2.0f); dotNode.SetLabel(dotNodeLabel); while (idsStack1.Count > 0) { var idPart1 = idsStack1.Pop(); var idPart2 = idsStack2.Pop(); var treeDepth = treeDepthStack.Pop(); var s1 = treeDepth == maxTreeDepth ? "".PadRight(treeDepth, '-') : idPart1.PatternToStringPadRight(maxTreeDepth, treeDepth); var s2 = treeDepth == maxTreeDepth ? "".PadRight(treeDepth, '-') : idPart2.PatternToStringPadRight(maxTreeDepth, treeDepth); dotNodeName = s1 + ", " + s2; dotNode = dotGraph.AddNode(dotNodeName); var childNodesBitMask = 1ul << (treeDepth - 1); //Add child node 00 var childNodeId = Tuple.Create(idPart1, idPart2); var isActive = childNodeId.IsActiveQuadTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, treeDepth - 1, maxTreeDepth, isActive, activeColor ); if (treeDepth > 1) { idsStack1.Push(childNodeId.Item1); idsStack2.Push(childNodeId.Item2); treeDepthStack.Push(treeDepth - 1); } } //Add child node 01 childNodeId = Tuple.Create(idPart1 | childNodesBitMask, idPart2); isActive = childNodeId.IsActiveQuadTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, treeDepth - 1, maxTreeDepth, isActive, activeColor ); if (treeDepth > 1) { idsStack1.Push(childNodeId.Item1); idsStack2.Push(childNodeId.Item2); treeDepthStack.Push(treeDepth - 1); } } //Add child node 10 childNodeId = Tuple.Create(idPart1, idPart2 | childNodesBitMask); isActive = childNodeId.IsActiveQuadTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, treeDepth - 1, maxTreeDepth, isActive, activeColor ); if (treeDepth > 1) { idsStack1.Push(childNodeId.Item1); idsStack2.Push(childNodeId.Item2); treeDepthStack.Push(treeDepth - 1); } } //Add child node 11 childNodeId = Tuple.Create(idPart1 | childNodesBitMask, idPart2 | childNodesBitMask); isActive = childNodeId.IsActiveQuadTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, treeDepth - 1, maxTreeDepth, isActive, activeColor ); if (treeDepth > 1) { idsStack1.Push(childNodeId.Item1); idsStack2.Push(childNodeId.Item2); treeDepthStack.Push(treeDepth - 1); } } } return(dotGraph); }
public static DotGraph AddBinaryTree <T>(this DotGraph dotGraph, GMacBinaryTree <T> quadTree, bool showFullGraph) { var maxTreeDepth = quadTree.TreeDepth; var activeIDs = quadTree.LeafNodeIDs.ToArray(); var inactiveColor = DotColor.Rgb(Color.Gray); var activeColor = DotColor.Rgb(Color.Black); dotGraph.SetRankDir(DotRankDirection.LeftToRight); dotGraph.SetSplines(DotSplines.Spline); dotGraph.SetOverlap(DotOverlap.False); dotGraph.SetNodeMarginDelta(12); var nodeDefaults = dotGraph.AddNodeDefaults(); nodeDefaults.SetShape(DotNodeShape.Circle); nodeDefaults.SetStyle(DotNodeStyle.Solid); nodeDefaults.SetColor(inactiveColor); nodeDefaults.SetFontColor(inactiveColor); nodeDefaults.SetPenWidth(1.0f); var edgeDefaults = dotGraph.AddEdgeDefaults(); edgeDefaults.SetArrowHead(DotArrowType.Vee); edgeDefaults.SetStyle(DotEdgeStyle.Dashed); edgeDefaults.SetColor(inactiveColor); edgeDefaults.SetFontColor(inactiveColor); edgeDefaults.SetPenWidth(1.0f); var idsStack = new Stack <ulong>(); idsStack.Push(0ul); var treeDepthStack = new Stack <int>(); treeDepthStack.Push(maxTreeDepth); var dotNodeName = "".PadRight(maxTreeDepth, '-'); var dotNodeLabel = dotNodeName; var dotNode = dotGraph.AddNode(dotNodeName); dotNode.SetShape(DotNodeShape.DoubleCircle); dotNode.SetStyle(DotNodeStyle.Solid); dotNode.SetColor(activeColor); dotNode.SetFontColor(activeColor); dotNode.SetPenWidth(2.0f); dotNode.SetLabel(dotNodeLabel); while (idsStack.Count > 0) { var parentNodeId = idsStack.Pop(); var parentNodeTreeDepth = treeDepthStack.Pop(); dotNodeName = parentNodeTreeDepth == maxTreeDepth ? "".PadRight(parentNodeTreeDepth, '-') : parentNodeId.PatternToStringPadRight(maxTreeDepth, parentNodeTreeDepth); dotNode = dotGraph.AddNode(dotNodeName); var childNodesBitMask = 1ul << (parentNodeTreeDepth - 1); //Add child node 0 var childNodeId = parentNodeId; var isActive = childNodeId.IsActiveBinaryTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, parentNodeTreeDepth - 1, maxTreeDepth, isActive, activeColor ); if (parentNodeTreeDepth > 1) { idsStack.Push(childNodeId); treeDepthStack.Push(parentNodeTreeDepth - 1); } } //Add child node 1 childNodeId = parentNodeId | childNodesBitMask; isActive = childNodeId.IsActiveBinaryTreeNodeId(childNodesBitMask, activeIDs); if (showFullGraph || isActive) { AddChildNode( dotNode, childNodeId, parentNodeTreeDepth - 1, maxTreeDepth, isActive, activeColor ); if (parentNodeTreeDepth > 1) { idsStack.Push(childNodeId); treeDepthStack.Push(parentNodeTreeDepth - 1); } } } return(dotGraph); }