Beispiel #1
0
        void drawRandomTree()
        {
            Random rnd=new Random();

            t=Tree.Generate(genType,
                            depth :rnd.Next(4,10),
                            maxBreadth : rnd.Next(40,100), // 5
                            numFirstChildren :5,
                            maxNodes :-1);

            //t.root.Visible=false;

            maxDepth=t.root.GetMaxDepth();
            GenerateDepthMap(); // calculate colors for each depth

            rootX=this.splitContainer1.Panel2.Width/2;
            rootY=this.splitContainer1.Panel2.Height/2;

            radiusY=40;// rndTreeParams.Next(40,50);
            radiusX=radiusY;

            branchingDist=1;

            Tree.LayoutRadial(t,radiusX,radiusY,rootX,rootY,branchingDist,grow: false);

            branches=rnd.Next(2)==1?true:false;

            Render();
        }
        void drawRandomTree()
        {
            t=Tree.Generate(gen_type,
                            depth: tree_depth,
                            max_breadth: tree_breadth, // 40,100
                            num_first_children : -1,
                            max_nodes : -1);

            //t.root.Visible=false;

            depthMap=DepthMap.Generate(t.MaxDepth, rand);

            t.Root.Point.X = this.splitContainer1.Panel2.Width / 2;
            t.Root.Point.Y = this.splitContainer1.Panel2.Height / 2;

            radius = new PointF();
            radius.Y = (float)branch_radius;
            radius.X=radius.Y;

#if RADIAL
            t.LayoutRadial2D(radius, edge_length, layout_type, chkGrow.Checked);
#else
            t.LayoutTopDown2D(radius, edge_length, layout_type, chkGrow.Checked);
#endif

            Render();
        }
        public static Tree BuildFS(string root_dir, renderNodeFunct renderNode)
        {
            TNode c;
            TNode n;
            FileInfo fi;
            Type ty;

            var di = new DirectoryInfo(root_dir);
            var k = new TraversalListIDS<TNode>(TraversalType.DepthFirst);
            var t = new Tree(new TNode());

            t.MaxDepth = t.Root.Level = 0;
            t.Root.Data = di;
            k.Add(t.Root);

            while (k.Count > 0)
            {
                c = k.Take();
                renderNode(t,c);

                ty = c.Data.GetType();

                if (ty == typeof(DirectoryInfo))
                {
                    di = (DirectoryInfo)c.Data;

                    foreach (var dir in di.GetDirectories())
                    {
                        n = new TNode();
                        n.Level = c.Level + 1;
                        if (n.Level > t.MaxDepth) t.MaxDepth = n.Level;
                        n.Parent = c;
                        c.Children.Add(n);
                        n.Data = dir;
                        k.Add(n);
                    }
                    //foreach (var file in di.GetFiles())
                    //{
                    //    n = new TNode();
                    //    n.Level = c.Level + 1;
                    //    if (n.Level > t.MaxDepth) t.MaxDepth = n.Level;
                    //    n.Parent = c;
                    //    c.Children.Add(n);
                    //    n.Data = file;
                    //}
                }
                else if (ty == typeof(FileInfo))
                {
                    fi = (FileInfo)c.Data;
                }
            }

            return t;
        }
Beispiel #4
0
        public Tree CreateSpanningTree()
        {
            Tree t;
            TNode root;

            root=new TNode();
            root.Children=this.Roots;

            t=new Tree(root);

            return t;
        }
        void fsTreeRenderNode(Tree owner, TNode c)
        {
            if (owner.MaxDepth == 0) return;

            t = owner;
            t.Root.Point.X = this.splitContainer1.Panel2.Width / 2;
            t.Root.Point.Y = this.splitContainer1.Panel2.Height / 2;
            t.UpdateAttributes();
            depthMap = DepthMap.Generate(t.MaxDepth, rand);
#if RADIAL
            t.LayoutRadial2D(radius, edge_length, layout_type, chkGrow.Checked);
#else
            t.LayoutTopDown2D(radius, edge_length, layout_type, chkGrow.Checked);
#endif

            Redraw(false);
        }
 void buildFSTree()
 {
     this.GetContext().Clear(ClearColor);
     t = IOTreeProvider.BuildFS("C:\\dev", fsTreeRenderNode);
 }
Beispiel #7
0
        /// <summary>
        /// Generates a random tree
        /// </summary>
        /// <param name="depth">desired depth of tree</param>
        /// <returns>
        /// A newly generated Tree of specified degree "maxBreadth"
        /// </returns>
        public static Tree Generate(TraversalType type, 
            int depth, int maxBreadth, int numFirstChildren = -1, int maxNodes = -1)
        {
            Tree t;
            TNode r;
            TNode c;
            Random rnd;
            int breadth;
            int d;
            bool finished;
            int i;
            TNode child;
            TraversalListIDS<TNode> ids=new TraversalListIDS<TNode>(type);
            int count;

            rnd=new Random();
            r=new TNode();
            t=new Tree(r);
            finished=false;
            r.Level=1;
            count=0;

            ids.Add(r);

            while(ids.Count > 0 && finished == false)
            {
                c=ids.Get();

                // generate new level of arbirary children until desired depth is reached

                if(c.Level==1)
                {
                    if(numFirstChildren<=0)
                    {
                        breadth=rnd.Next(maxBreadth)+1;
                    }
                    else
                    {
                        breadth=numFirstChildren;
                    }
                }
                else
                {
                    breadth=rnd.Next(maxBreadth)+1;
                }

                for(i = 0; i < breadth; i++)
                {
                    child=new TNode();
                    child.Parent=c;
                    child.Level=c.Level+1;
                    child.ChildIndex = i;

                    count++;
                    c.Children.Add(child);

                    ids.Add(child);
                }

                // finished when reached desired number of nodes or reached desired depth
                if(maxNodes > 0)
                {
                    finished=count>=maxNodes;
                }
                else
                {
                    finished=c.Level==depth;
                }

            }

            return t;
        }
Beispiel #8
0
        public static void LayoutRadial(Tree t,
            double radiusX,double radiusY,
            double rootX,double rootY,
            double branchingDist,
            bool grow=false)
        {
            List<TNode> nodes=new List<TNode>();

            t.root.angle=0;
            t.root.rightBisector=0;
            t.root.rightTangent=0;
            t.root.leftBisector=TWO_PI;
            t.root.leftTangent=TWO_PI;

            nodes.Add(t.root);

            LayoutRadial(nodes,radiusX,radiusY,rootX,rootY,branchingDist,grow);

            t.root.x=rootX;
            t.root.y=rootY;
        }
Beispiel #9
0
        /// <summary>
        /// Generates a random tree
        /// </summary>
        /// <param name="depth">desired depth of tree</param>
        /// <returns>
        /// A newly generated Tree of specified degree "maxBreadth"
        /// </returns>
        public static Tree Generate(TraversalType gen_mechanism,
            int depth,
            int max_breadth,
            int num_first_children = -1,
            int max_nodes = -1)
        {
            Tree t = new Tree { Root = new TNode { Level = 1 } };

            Random rnd = new Random();
            int breadth;
            int i;
            TNode child;
            var k = new TraversalListIDS<TNode>(gen_mechanism);
            var visited = new Hashtable();
            bool finished = false;
            TNode c;

            k.Add(t.Root);

            while (k.Count > 0 && finished == false)
            {
                // generate new level of arbirary children until desired depth is reached

                c = k.Take();

                // finished when reached desired number of nodes or reached desired depth
                if (max_nodes > 0)
                {
                    finished = t.Count >= max_nodes;
                }
                else
                {
                    finished = c.Level == depth + 1;
                }

                if (!finished && (gen_mechanism == TraversalType.DepthFirst || !visited.ContainsKey(c)))
                {
                    if (gen_mechanism == TraversalType.BreadthFirst)
                        visited.Add(c, 0);

                    if (c.Level == 1)
                    {
                        if (num_first_children == -1)
                        {
                            breadth = rnd.Next(1, max_breadth + 1);
                        }
                        else
                        {
                            breadth = num_first_children;
                        }
                    }
                    else
                    {
                        breadth = rnd.Next(1, max_breadth + 1);
                        //if(c.Level==4){
                        //    breadth = 1000;
                        //}

                        //if (c.Level == depth)
                        //{
                        //    breadth = 255;
                        //}
                    }

                    for (i = 0; i < breadth; i++)
                    {
                        child = new TNode();
                        child.Parent = c;
                        child.Level = c.Level + 1;
                        child.ChildIndex = i;

                        if (child.Level > t.MaxDepth) t.MaxDepth = child.Level;

                        t.Count++;
                        c.Children.Add(child);

                        k.Add(child);
                    }
                }
            }

            return t;
        }