Exemplo n.º 1
0
        /// <summary>
        /// Operation of vertical O-tree. Calculates coordinates and takes one compaction step.
        /// </summary>
        /// <returns>Horizontal constraint graph</returns>
        private Graph ToHorizontalConstraintGraph()
        {
            //Empty module representing the root of the tree
            Module root = new Module(-1, null, 0);
            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;

            //Vertical contour for quick x-coordinate calculation
            Contour contour = new VerticalContour(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 vertical O-tree, child module is on the top of parent module and adjacent with it
                    child.Y = parent.Y + parent.Height;
                    //Finding the minimum x-coordinate
                    child.X = contour.FindMax(child.Y + child.Height);

                    //There is an egde in the horizontal constraint graph, where the minimum is found
                    constraintGraph.AddEdge(contour.WhereMax.Name, child.Name, child.Y);

                    //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 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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Operation of vertical O-tree. Calculates coordinates and takes one compaction step.
        /// </summary>
        /// <returns>Horizontal constraint graph</returns>
        private Graph ToHorizontalConstraintGraph()
        {
            //Empty module representing the root of the tree
            Module root = new Module(-1, null, 0);

            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;

            //Vertical contour for quick x-coordinate calculation
            Contour contour = new VerticalContour(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 vertical O-tree, child module is on the top of parent module and adjacent with it
                    child.Y = parent.Y + parent.Height;
                    //Finding the minimum x-coordinate
                    child.X = contour.FindMax(child.Y + child.Height);

                    //There is an egde in the horizontal constraint graph, where the minimum is found
                    constraintGraph.AddEdge(contour.WhereMax.Name, child.Name, child.Y);

                    //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 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);
        }