Beispiel #1
0
        /// <summary>
        /// Recursive function that creates a level of the file tree
        /// </summary>
        /// <param name="g"></param>
        /// <param name="parent"></param>
        /// <param name="path"></param>
        private void buildTree(vtkMutableDirectedGraph g, long parent, string path)
        {
            vtkStringArray name = (vtkStringArray)g.GetVertexData().GetAbstractArray("name");
            vtkLongLongArray size = (vtkLongLongArray)g.GetVertexData().GetAbstractArray("size");
            vtkStringArray fullpath = (vtkStringArray)g.GetVertexData().GetAbstractArray("path");

            if (Directory.Exists(path))
            {
                long v = 0;
                if (parent == -1)
                {
                    v = g.AddVertex();
                }
                else
                {
                    v = g.AddChild((int)parent);
                }
                string[] pathparts = path.Split('\\');
                int ipaths = pathparts.GetUpperBound(0);
                fullpath.InsertNextValue(path);
                name.InsertNextValue(pathparts[ipaths]);
                size.InsertNextValue(1024);
                this.label1.Text = "Processing " + path;
                this.Update();
                try
                {
                    foreach (string f in Directory.GetFiles(path))
                    {
                        Console.Out.WriteLine(f);
                        buildTree(g, v, f);
                    }

                    foreach (string d in Directory.GetDirectories(path))
                    {
                        Console.Out.WriteLine(d);
                        buildTree(g, v, d);
                    }
                }
                catch (System.Exception excpt)
                {
                    Console.Error.WriteLine(excpt.Message);
                }
            }
            else if (File.Exists(path))
            {
                FileInfo info = new FileInfo(path);

                //Do not graph files smaller than 1K
                if (info.Length > 1024)
                {
                    g.AddChild((int)parent);
                    fullpath.InsertNextValue(path);
                    name.InsertNextValue(Path.GetFileName(path));
                    size.InsertNextValue(info.Length);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Recursive function that creates a level of the file tree
        /// </summary>
        /// <param name="g"></param>
        /// <param name="parent"></param>
        /// <param name="path"></param>
        private void buildTree(vtkMutableDirectedGraph g, long parent, string path)
        {
            vtkStringArray   name     = (vtkStringArray)g.GetVertexData().GetAbstractArray("name");
            vtkLongLongArray size     = (vtkLongLongArray)g.GetVertexData().GetAbstractArray("size");
            vtkStringArray   fullpath = (vtkStringArray)g.GetVertexData().GetAbstractArray("path");

            if (Directory.Exists(path))
            {
                long v = 0;
                if (parent == -1)
                {
                    v = g.AddVertex();
                }
                else
                {
                    v = g.AddChild((int)parent);
                }
                string[] pathparts = path.Split('\\');
                int      ipaths    = pathparts.GetUpperBound(0);
                fullpath.InsertNextValue(path);
                name.InsertNextValue(pathparts[ipaths]);
                size.InsertNextValue(1024);
                this.label1.Text = "Processing " + path;
                this.Update();
                try
                {
                    foreach (string f in Directory.GetFiles(path))
                    {
                        Console.Out.WriteLine(f);
                        buildTree(g, v, f);
                    }

                    foreach (string d in Directory.GetDirectories(path))
                    {
                        Console.Out.WriteLine(d);
                        buildTree(g, v, d);
                    }
                }
                catch (System.Exception excpt)
                {
                    Console.Error.WriteLine(excpt.Message);
                }
            }
            else if (File.Exists(path))
            {
                FileInfo info = new FileInfo(path);

                //Do not graph files smaller than 1K
                if (info.Length > 1024)
                {
                    g.AddChild((int)parent);
                    fullpath.InsertNextValue(path);
                    name.InsertNextValue(Path.GetFileName(path));
                    size.InsertNextValue(info.Length);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Open a folder browser and graph the
        /// selected folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setupView_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog().Equals(DialogResult.OK))
            {
                //Add the view to the render window
                if (!initialized)
                {
                    initialized = true;

                    this.view.GetRenderWindow().SetParentId(
                        this.renWinCTRL.RenderWindow.GetGenericWindowId());
                    this.ResizeTreeMapView();

                    //Add a handler to the view
                    view.SelectionChangedEvt += new vtkObject.vtkObjectEventHandler(this.view_SelectionChangedEvt);
                }

                g = vtkMutableDirectedGraph.New();
                vtkStringArray name = vtkStringArray.New();
                name.SetName("name");
                g.GetVertexData().AddArray(name);
                vtkStringArray path = vtkStringArray.New();
                path.SetName("path");
                g.GetVertexData().SetPedigreeIds(path);
                vtkLongLongArray size = vtkLongLongArray.New();
                size.SetName("size");
                g.GetVertexData().AddArray(size);
                string cur = Directory.GetCurrentDirectory();


                buildTree(g, -1, this.folderBrowserDialog1.SelectedPath);

                this.label1.Text = "Viewing " + this.folderBrowserDialog1.SelectedPath;

                vtkTree t = vtkTree.New();
                t.ShallowCopy(g);

                view.SetLayoutStrategyToSquarify();

                view.SetAreaLabelArrayName("name");
                view.SetAreaHoverArrayName("path");
                view.SetAreaColorArrayName("level");
                view.SetAreaSizeArrayName("size");

                view.AddRepresentationFromInput(t);
                view.GetRenderer().ResetCamera();
                view.Update();
                view.Render();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Event fired when the graph selection is changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void view_SelectionChangedEvt(vtkObject sender, vtkObjectEventArgs e)
        {
            //Get the selection
            vtkDataRepresentation dr   = view.GetRepresentation(0);
            vtkAnnotationLink     al   = dr.GetAnnotationLink();
            vtkSelection          sel  = al.GetCurrentSelection();
            vtkAbstractArray      arr  = null;
            vtkSelectionNode      node = sel.GetNode(0);

            if (null != node)
            {
                arr = node.GetSelectionList();
            }

            vtkIdTypeArray arr1 = (vtkIdTypeArray)arr;

            // Short circuit if nothing is selected...
            int numSelected = (int)arr1.GetNumberOfTuples();

            if (0 == numSelected)
            {
                return;
            }

            vtkStringArray arr2 = ((vtkStringArray)g.GetVertexData().GetAbstractArray("label"));

            //get a pseudo random name if more than one are selected
            string name = arr2.GetValue(
                (int)arr1.GetValue(System.DateTime.Now.Millisecond % numSelected));

            //reset the small arrayList
            arrListSmall = new System.Collections.ArrayList();
            int hops;

            try
            {
                hops = System.Convert.ToInt32(toolStripTextBox3.Text);
            }
            catch (Exception)
            {
                hops = 1;
            }

            toolStripTextBox1.Text = name;
            toolStripTextBox1.Invalidate();
            this.Update();

            //Start the loading graphic and add another renderer on top for the spinning logo
            vtkRenderWindow win = this.renderWindowControl1.RenderWindow;

            win.AddRenderer(logoRenderer);
            win.Render();
            this.webBrowser1.Url = new Uri("http://en.wikipedia.org/wiki/" + name.Replace(" ", "_"));
            //Start the work
            addLinks(g, name, hops);
            //Remove the spinning logo after the work is done
            win.RemoveRenderer(logoRenderer);
            win.Render();
        }
Beispiel #5
0
        /// <summary>
        /// Clears the graph and makes a new one
        /// </summary>
        private void createNewGraph()
        {
            String lookupValue = toolStripTextBox1.Text;

            //clean up any old graph views in the renderer
            vtkMutableDirectedGraph g_temp = g;

            g = vtkMutableDirectedGraph.New();
            if (g_temp != null)
            {
                g_temp.Dispose();
            }
            //reset array lists
            arrListSmall = new System.Collections.ArrayList();
            vtkStringArray label = vtkStringArray.New();

            label.SetName("label");
            //give the graph a starting point
            g.GetVertexData().AddArray(label);
            g.AddVertex();
            label.InsertNextValue(lookupValue);
            arrListSmall.Add(lookupValue);
            int hops;

            try
            {
                hops = System.Convert.ToInt32(toolStripTextBox3.Text);
            }
            catch (Exception)
            {
                hops = 1;
            }
            //Start the loading graphic and switch renderers
            vtkRenderWindow win = this.renderWindowControl1.RenderWindow;

            win.AddRenderer(logoRenderer);
            win.Render();

            this.webBrowser1.Url = new Uri("http://en.wikipedia.org/wiki/" + lookupValue.Replace(" ", "_"));
            //Start the work
            addLinks(g, lookupValue, hops);
            //Go back to the graph view after the work is done
            win.RemoveRenderer(logoRenderer);

            //Setup the view properties
            view.SetLayoutStrategyToSimple2D();
            view.AddRepresentationFromInput(g);
            view.SetVertexLabelArrayName("label");
            view.VertexLabelVisibilityOn();
            view.SetVertexColorArrayName("VertexDegree");
            view.ColorVerticesOn();
            view.GetRenderer().ResetCamera();
            view.Update();
        }
Beispiel #6
0
        /// <summary>
        /// Clears the graph and makes a new one
        /// </summary>
        private void createNewGraph()
        {
            String lookupValue = toolStripTextBox1.Text;

            //clean up any old graph views in the renderer
            vtkMutableDirectedGraph g_temp = g;
            g = vtkMutableDirectedGraph.New();
            if (g_temp != null)
            {
                g_temp.Dispose();
            }
            //reset array lists
            arrListSmall = new System.Collections.ArrayList();
            vtkStringArray label = vtkStringArray.New();
            label.SetName("label");
            //give the graph a starting point
            g.GetVertexData().AddArray(label);
            g.AddVertex();
            label.InsertNextValue(lookupValue);
            arrListSmall.Add(lookupValue);
            int hops;
            try
            {
                hops = System.Convert.ToInt32(toolStripTextBox3.Text);
            }
            catch (Exception)
            {
                hops = 1;
            }
            //Start the loading graphic and switch renderers
            vtkRenderWindow win = this.renderWindowControl1.RenderWindow;
            win.AddRenderer(logoRenderer);
            win.Render();

            this.webBrowser1.Url = new Uri("http://en.wikipedia.org/wiki/" + lookupValue.Replace(" ", "_"));
            //Start the work
            addLinks(g, lookupValue, hops);
            //Go back to the graph view after the work is done
            win.RemoveRenderer(logoRenderer);

            //Setup the view properties
            view.SetLayoutStrategyToSimple2D();
            view.AddRepresentationFromInput(g);
            view.SetVertexLabelArrayName("label");
            view.VertexLabelVisibilityOn();
            view.SetVertexColorArrayName("VertexDegree");
            view.ColorVerticesOn();
            view.GetRenderer().ResetCamera();
            view.Update();
        }
Beispiel #7
0
        /// <summary>
        /// Open a folder browser and graph the 
        /// selected folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setupView_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog().Equals(DialogResult.OK))
            {
                //Add the view to the render window
                if (!initialized)
                {
                    initialized = true;

                    this.view.GetRenderWindow().SetParentId(
                      this.renWinCTRL.RenderWindow.GetGenericWindowId());
                    this.ResizeTreeMapView();

                    //Add a handler to the view
                    view.SelectionChangedEvt += new vtkObject.vtkObjectEventHandler(this.view_SelectionChangedEvt);
                }

                g = vtkMutableDirectedGraph.New();
                vtkStringArray name = vtkStringArray.New();
                name.SetName("name");
                g.GetVertexData().AddArray(name);
                vtkStringArray path = vtkStringArray.New();
                path.SetName("path");
                g.GetVertexData().SetPedigreeIds(path);
                vtkLongLongArray size = vtkLongLongArray.New();
                size.SetName("size");
                g.GetVertexData().AddArray(size);
                string cur = Directory.GetCurrentDirectory();

                buildTree(g, -1, this.folderBrowserDialog1.SelectedPath);

                this.label1.Text = "Viewing "+this.folderBrowserDialog1.SelectedPath;

                vtkTree t = vtkTree.New();
                t.ShallowCopy(g);

                view.SetLayoutStrategyToSquarify();

                view.SetAreaLabelArrayName("name");
                view.SetAreaHoverArrayName("path");
                view.SetAreaColorArrayName("level");
                view.SetAreaSizeArrayName("size");

                view.AddRepresentationFromInput(t);
                view.GetRenderer().ResetCamera();
                view.Update();
                view.Render();
            }
        }