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
    public static int Main(string[] args)
    {
        string filename = args[0];

        vtkGDCMImageReader reader = vtkGDCMImageReader.New();
        vtkStringArray     array  = vtkStringArray.New();

        array.InsertNextValue(filename);

        reader.SetFileNames(array);
        reader.Update();

        //System.Console.Write(reader.GetOutput());

        vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();

        vtkImageViewer2 viewer = vtkImageViewer2.New();

        viewer.SetInput(reader.GetOutput());
        viewer.SetupInteractor(iren);
        viewer.SetSize(600, 600);
        viewer.Render();

        iren.Initialize();
        iren.Start();

        return(0);
    }
Beispiel #3
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 #4
0
        /// <summary>
        /// Load image files into vtkImageData.
        /// </summary>
        /// <param name="path">Path to images.</param>
        /// <param name="extension">Image extension.</param>
        /// <returns></returns>
        public static vtkImageData VTKLoader(string path, string extension)
        {
            /*DEPRECATED!!*/
            //Output
            vtkImageData data = vtkImageData.New();
            //Get files from path
            DirectoryInfo d = new DirectoryInfo(@path);

            FileInfo[] files = d.GetFiles();

            vtkStringArray allfiles = vtkStringArray.New();

            //Iterate over files and read image data
            foreach (FileInfo file in files)
            {
                //Fullfile
                string fullfile = Path.Combine(path, file.Name);
                allfiles.InsertNextValue(fullfile);
            }
            if (extension == ".png")
            {
                vtkPNGReader reader = vtkPNGReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            if (extension == ".jpg")
            {
                vtkJPEGReader reader = vtkJPEGReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            if (extension == ".bmp")
            {
                vtkBMPReader reader = vtkBMPReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            data.SetScalarTypeToUnsignedChar();
            data.Update();
            return(data);
        }
Beispiel #5
0
    public static int Main(string[] args)
    {
        vtkTesting testHelper = vtkTesting.New();

        for (int cc = 0; cc < args.Length; cc++)
        {
            //testHelper.AddArguments(argc,const_cast<const char **>(argv));
            //System.Console.Write( "args: " + args[cc] + "\n" );
            testHelper.AddArgument(args[cc]);
        }
        if (testHelper.IsFlagSpecified("-D") != 0)
        {
            string VTK_DATA_ROOT = vtkGDCMTesting.GetVTKDataRoot();
            if (VTK_DATA_ROOT != null)
            {
                //System.Console.Write( "VTK_DATA_ROOT: " + VTK_DATA_ROOT  + "\n" );
                testHelper.SetDataRoot(VTK_DATA_ROOT);
                testHelper.AddArgument("-D");
                testHelper.AddArgument(VTK_DATA_ROOT);
            }
        }

        string dataRoot = testHelper.GetDataRoot();
        string filename = dataRoot;

        filename += "/Data/mr.001";

        vtkDirectory dir = vtkDirectory.New();

        if (dir.FileIsDirectory(dataRoot) == 0)
        {
            filename = vtkGDCMTesting.GetGDCMDataRoot() + "/test.acr";
        }
        //System.Console.Write( "dataRoot: " + dataRoot + "\n" );
        System.Console.Write("filename being used is: " + filename + "\n");

        vtkGDCMImageReader reader = vtkGDCMImageReader.New();
        vtkStringArray     array  = vtkStringArray.New();

        array.InsertNextValue(filename);
        reader.SetFileNames(array);
        reader.Update();

        System.Console.Write(reader.GetOutput());

        vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();

        vtkRenderer     ren1   = vtkRenderer.New();
        vtkRenderWindow renWin = vtkRenderWindow.New();

        renWin.AddRenderer(ren1);

        vtkImageActor actor = vtkImageActor.New();

        vtkImageMapToWindowLevelColors coronalColors = vtkImageMapToWindowLevelColors.New();

        coronalColors.SetInput(reader.GetOutput());

        actor.SetInput(coronalColors.GetOutput());

        ren1.AddActor(actor);
        iren.SetRenderWindow(renWin);

        iren.Initialize();

        renWin.Render();

        int retVal = testHelper.IsInteractiveModeSpecified();

        if (retVal != 0)
        {
            iren.Start();
        }

        return(0);
    }
Beispiel #6
0
        /// <summary>
        /// Recursive function that finds and
        /// graphs Wikipedia links
        /// </summary>
        /// <param name="g">The graph</param>
        /// <param name="lookupValue">Name of orgin article</param>
        /// <param name="hops">How many degrees of separation from the original article</param>
        private void addLinks(Kitware.VTK.vtkMutableDirectedGraph g, string lookupValue, int hops)
        {
            vtkStringArray label  = (vtkStringArray)g.GetVertexData().GetAbstractArray("label");
            long           parent = label.LookupValue(lookupValue);

            //if lookupValue is not in the graph add it
            if (parent < 0)
            {
                rotateLogo();
                parent = g.AddVertex();
                label.InsertNextValue(lookupValue);
                arrListSmall.Add(lookupValue);
            }
            //Parse Wikipedia for the lookupValue
            string underscores = lookupValue.Replace(' ', '_');

            System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://en.wikipedia.org/wiki/Special:Export/" + underscores);
            webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
            webRequest.Accept      = "text/xml";
            try
            {
                System.Net.HttpWebResponse webResponse    = (System.Net.HttpWebResponse)webRequest.GetResponse();
                System.IO.Stream           responseStream = webResponse.GetResponseStream();
                System.Xml.XmlReader       reader         = new System.Xml.XmlTextReader(responseStream);
                String NS = "http://www.mediawiki.org/xml/export-0.4/";
                System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(reader);
                reader.Close();
                webResponse.Close();
                System.Xml.XPath.XPathNavigator    myXPahtNavigator = doc.CreateNavigator();
                System.Xml.XPath.XPathNodeIterator nodesText        = myXPahtNavigator.SelectDescendants("text", NS, false);

                String fullText = "";
                //Parse the wiki page for links
                while (nodesText.MoveNext())
                {
                    fullText += nodesText.Current.InnerXml + " ";
                }
                System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(fullText, "\\[\\[.*?\\]\\]");
                int max;
                try
                {
                    max = System.Convert.ToInt32(toolStripTextBox2.Text);
                }
                catch (Exception)
                {
                    max = -1;
                }
                int count = 0;
                while (m.Success && ((count < max) || (max < 0)))
                {
                    String s         = m.ToString();
                    int    index     = s.IndexOf('|');
                    String substring = "";
                    if (index > 0)
                    {
                        substring = s.Substring(2, index - 2);
                    }
                    else
                    {
                        substring = s.Substring(2, s.Length - 4);
                    }
                    //if the new substring is not already there add it
                    long v = label.LookupValue(substring);
                    if (v < 0)
                    {
                        rotateLogo();
                        v = g.AddVertex();
                        label.InsertNextValue(substring);
                        arrListSmall.Add(substring);
                        if (hops > 1)
                        {
                            addLinks(g, substring, hops - 1);
                        }
                    }
                    else if (arrListSmall.IndexOf(substring) < 0)
                    {
                        arrListSmall.Add(substring);
                        if (hops > 1)
                        {
                            addLinks(g, substring, hops - 1);
                        }
                    }
                    //Make sure nothing is linked to twice by expanding the graph
                    vtkAdjacentVertexIterator avi = vtkAdjacentVertexIterator.New();
                    g.GetAdjacentVertices((int)parent, avi);
                    m = m.NextMatch();
                    ++count;

                    while (avi.HasNext())
                    {
                        long id = avi.Next();
                        if (id == v)
                        {
                            return;
                        }
                    }
                    rotateLogo();
                    g.AddGraphEdge((int)parent, (int)v);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }