/// <summary> /// Operation of horizontal O-tree. Calculates coordinates and takes one compaction step. /// </summary> /// <returns>Vertical constraint graph</returns> private Graph ToVerticalConstraintGraph() { //Empty module representing the root of the tree Module root = new Module(-1, null); _modules.Add(-1, root); _oTree.ModuleSequence.Insert(0, -1); //Stack containing module labels for parent module calculation Stack <int> stack = new Stack <int>(); stack.Push(-1); //Vertical contsraint graph Graph constraintGraph = new Graph(_oTree.ModuleSequence); //Actual parent and child module Module parent = root; Module child; //Horizontal contour for quick y-coordinate calculation Contour contour = new HorizontalContour(root); //Index of child module in ModuleSequence int childIndex = 0; foreach (Bit bit in _oTree.DfsSequence) { //Forth step in DFS traversing, coordinates need to be calcuted if (bit == 0) { child = _modules[_oTree.ModuleSequence[++childIndex]]; //In horizontal O-tree, child module is on the rigth side of the parent module and adjacent with it child.X = parent.X + parent.Width; //Finding the minimum y-coordinate child.Y = contour.FindMax(child.X + child.Width); //There is an egde in the vertical constraint graph, where the minimum is found constraintGraph.AddEdge(contour.WhereMax.Name, child.Name, child.X); //Updating contour contour.Update(child); //Now child module is the actual parent parent = child; stack.Push(parent.Name); } //Back step in DFS traversing else { //Updating parent module and the insertation index of the contour stack.Pop(); parent = _modules[stack.Peek()]; contour.InsertationIndex = contour.ModuleSequence.IndexOf(parent); } } //Removing root module _modules.Remove(-1); _oTree.ModuleSequence.RemoveAt(0); return(constraintGraph); }
/// <summary> /// Operation of horizontal O-tree. Calculates coordinates and takes one compaction step. /// </summary> /// <returns>Vertical constraint graph</returns> private Graph ToVerticalConstraintGraph() { //Empty module representing the root of the tree Module root = new Module(-1, null); _modules.Add(-1, root); _oTree.ModuleSequence.Insert(0, -1); //Stack containing module labels for parent module calculation Stack<int> stack = new Stack<int>(); stack.Push(-1); //Vertical contsraint graph Graph constraintGraph = new Graph(_oTree.ModuleSequence); //Actual parent and child module Module parent = root; Module child; //Horizontal contour for quick y-coordinate calculation Contour contour = new HorizontalContour(root); //Index of child module in ModuleSequence int childIndex = 0; foreach (Bit bit in _oTree.DfsSequence) { //Forth step in DFS traversing, coordinates need to be calcuted if (bit == 0) { child = _modules[_oTree.ModuleSequence[++childIndex]]; //In horizontal O-tree, child module is on the rigth side of the parent module and adjacent with it child.X = parent.X + parent.Width; //Finding the minimum y-coordinate child.Y = contour.FindMax(child.X + child.Width); //There is an egde in the vertical constraint graph, where the minimum is found constraintGraph.AddEdge(contour.WhereMax.Name, child.Name, child.X); //Updating contour contour.Update(child); //Now child module is the actual parent parent = child; stack.Push(parent.Name); } //Back step in DFS traversing else { //Updating parent module and the insertation index of the contour stack.Pop(); parent = _modules[stack.Peek()]; contour.InsertationIndex = contour.ModuleSequence.IndexOf(parent); } } //Removing root module _modules.Remove(-1); _oTree.ModuleSequence.RemoveAt(0); return constraintGraph; }