Esempio n. 1
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);
    }
Esempio n. 2
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        try
        {
            bool fail_on_image_diff = false;

            //Prefix Content is: ""
            int argc = 0;
            if (argv != null)
            {
                argc = argv.Length;
            }

            // setup some common things for testing[]
            vtkMath.RandomSeed(6);
            // create the testing class to do the work[]
            rtTester = new vtkTesting();
            for (int i = 1; i < argc; i++)
            {
                rtTester.AddArgument(argv[i]);

                if (argv[i] == "--fail-on-image-diff")
                {
                    fail_on_image_diff = true;
                }
            }

            // string auto_path = "";
            //
            VTK_DATA_ROOT = rtTester.GetDataRoot();

            // load in the script[]
            if (0 == argv.Length)
            {
                test = GetTestNameInteractively();
            }
            else
            {
                test = argv[0];
            }

            //The class that we are about to execute the test in
            System.Type t = System.Type.GetType(test + "Class");
            if (null == t)
            {
                throw new System.ArgumentException(System.String.Format(
                                                       "error: could not create a Type object for '{0}'...\n\n{1}\n{2}\n{3}\n{4}\n\n{5}\n\n",
                                                       test + "Class",
                                                       "Typo?",
                                                       "Did you follow the C# test driver naming convention?",
                                                       "Did you add the test to the CMakeLists.txt file?",
                                                       "Did you reconfigure/rebuild after adding the test?",
                                                       "Test 'method' name should equal 'file name without extension'... Test 'public class' name should be the same but with 'Class' appended..."
                                                       ));
            }


            // set the default threshold, the Tcl script may change this[]
            threshold = -1;

            executeMethod(t, "Setthreshold", new object[] { threshold });
            executeMethod(t, "SetVTK_DATA_ROOT", new object[] { VTK_DATA_ROOT });

            //run the test
            executeMethod(t, test, new object[] { argv });

            tempRenderWindowInteractor = (vtkRenderWindowInteractor)executeMethod(t, "Getiren", new object[] { });
            tempRenderWindow           = (vtkRenderWindow)executeMethod(t, "GetrenWin", new object[] { });
            tempViewer = (vtkObject)executeMethod(t, "Getviewer", new object[] { });
            tempw2i    = (vtkWindowToImageFilter)executeMethod(t, "Getw2i", new object[] { });

            //update the threshold from what the test made it
            threshold = (int)executeMethod(t, "Getthreshold", new object[] { });
            if (tempRenderWindowInteractor != null)
            {
                tempRenderWindow.Render();
            }

            // run the event loop quickly to map any tkwidget windows[]
            // current directory[]
            rtResult = 0;
            if (fail_on_image_diff && rtTester.IsValidImageSpecified() != 0)
            {
                // look for a renderWindow ImageWindow or ImageViewer[]
                // first check for some common names[]
                if (tempRenderWindow != null)
                {
                    rtTester.SetRenderWindow(tempRenderWindow);
                    if ((threshold) == -1)
                    {
                        threshold = 10;
                    }
                }
                else
                {
                    if ((threshold) == -1)
                    {
                        threshold = 5;
                    }
                    if (tempViewer != null)
                    {
                        if (tempViewer.IsA("vtkImageViewer") != 0)
                        {
                            tempRenderWindow = ((vtkImageViewer)tempViewer).GetRenderWindow();
                        }
                        else if (tempViewer.IsA("vtkImageViewer2") != 0)
                        {
                            tempRenderWindow = ((vtkImageViewer2)tempViewer).GetRenderWindow();
                        }
                        else
                        {
                            throw new System.Exception("");
                        }
                        rtTester.SetRenderWindow(tempRenderWindow);

                        if (tempViewer.IsA("vtkImageViewer") != 0)
                        {
                            ((vtkImageViewer)tempViewer).Render();
                        }
                        else if (tempViewer.IsA("vtkImageViewer2") != 0)
                        {
                            ((vtkImageViewer2)tempViewer).Render();
                        }
                    }
                    else
                    {
                        tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetimgWin", new object[] { });
                        if (tempRenderWindow != null)
                        {
                            rtTester.SetRenderWindow(tempRenderWindow);
                            tempRenderWindow.Render();
                        }
                    }
                }

                if (tempRenderWindow == null)
                {
                    throw new System.Exception("tempRenderWindow cannot be null for IsValidImageSpecified case...");
                }

                rtResult = rtTester.RegressionTest(threshold);
            }

            if (rtTester.IsInteractiveModeSpecified() != 0)
            {
                if (tempRenderWindowInteractor != null)
                {
                    tempRenderWindowInteractor.Start();
                }
            }

            // Force other objects that may have holds on the render window
            // to let go:
            //
            rtTester.SetRenderWindow(null);
            if (null != tempw2i)
            {
                tempw2i.SetInput(null);
            }

            executeMethod(t, "deleteAllVTKObjects", new object[] { });
            deleteAllVTKObjects();

            // Force a garbage collection prior to exiting the test
            // so that any memory leaks reported are likely to be
            // *actual* leaks of some sort rather than false reports:
            //
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();

            // Fail the tests that have image diffs if fail_on_image_diff is on:
            //
            if (fail_on_image_diff && 0 == rtResult)
            {
                throw new System.Exception("error: image RegressionTest failed");
            }

            // Test finished without throwing any exceptions...
            // Therefore, it passed. Exit with a zero ExitCode.
            //
            System.Environment.ExitCode = 0;
        }
        catch (System.Exception exc)
        {
            // Catch anything, spit it out to the console so it can be captured
            // by ctest. Exit with a non-zero ExitCode.
            //
            System.Console.Error.WriteLine("================================================================================");
            System.Console.Error.WriteLine("");
            System.Console.Error.WriteLine("TclToCsScript C# test driver caught System.Exception:");
            System.Console.Error.WriteLine("");
            System.Console.Error.WriteLine("{0}", exc.ToString());
            System.Console.Error.WriteLine("");
            System.Console.Error.WriteLine("================================================================================");
            System.Console.Error.WriteLine("");
            System.Environment.ExitCode = 2345;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void Main(String[] argv)
    {
        try
        {
          bool fail_on_image_diff = false;

          //Prefix Content is: ""
          int argc = 0;
          if (argv != null)
          {
        argc = argv.Length;
          }

          // setup some common things for testing[]
          vtkMath.RandomSeed(6);
          // create the testing class to do the work[]
          rtTester = new vtkTesting();
          for (int i = 1; i < argc; i++)
          {
        rtTester.AddArgument(argv[i]);

        if (argv[i] == "--fail-on-image-diff")
        {
          fail_on_image_diff = true;
        }
          }

          // string auto_path = "";
          //
          VTK_DATA_ROOT = rtTester.GetDataRoot();

          // load in the script[]
          if (0 == argv.Length)
          {
        test = GetTestNameInteractively();
          }
          else
          {
        test = argv[0];
          }

          //The class that we are about to execute the test in
          System.Type t = System.Type.GetType(test + "Class");
          if (null == t)
          {
        throw new System.ArgumentException(System.String.Format(
              "error: could not create a Type object for '{0}'...\n\n{1}\n{2}\n{3}\n{4}\n\n{5}\n\n",
              test + "Class",
              "Typo?",
              "Did you follow the C# test driver naming convention?",
              "Did you add the test to the CMakeLists.txt file?",
              "Did you reconfigure/rebuild after adding the test?",
              "Test 'method' name should equal 'file name without extension'... Test 'public class' name should be the same but with 'Class' appended..."
              ));
          }

          // set the default threshold, the Tcl script may change this[]
          threshold = -1;

          executeMethod(t, "Setthreshold", new object[] { threshold });
          executeMethod(t, "SetVTK_DATA_ROOT", new object[] { VTK_DATA_ROOT });

          //run the test
          executeMethod(t, test, new object[] { argv });

          tempRenderWindowInteractor = (vtkRenderWindowInteractor)executeMethod(t, "Getiren", new object[] { });
          tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetrenWin", new object[] { });
          tempViewer = (vtkObject)executeMethod(t, "Getviewer", new object[] { });
          tempw2i = (vtkWindowToImageFilter)executeMethod(t, "Getw2i", new object[] { });

          //update the threshold from what the test made it
          threshold = (int)executeMethod(t, "Getthreshold", new object[] { });
          if (tempRenderWindowInteractor != null)
          {
        tempRenderWindow.Render();
          }

          // run the event loop quickly to map any tkwidget windows[]
          // current directory[]
          rtResult = 0;
          if (fail_on_image_diff && rtTester.IsValidImageSpecified() != 0)
          {
        // look for a renderWindow ImageWindow or ImageViewer[]
        // first check for some common names[]
        if (tempRenderWindow != null)
        {
          rtTester.SetRenderWindow(tempRenderWindow);
          if ((threshold) == -1)
          {
            threshold = 10;
          }
        }
        else
        {
          if ((threshold) == -1)
          {
            threshold = 5;
          }
          if (tempViewer != null)
          {
            if (tempViewer.IsA("vtkImageViewer") != 0)
            {
              tempRenderWindow = ((vtkImageViewer)tempViewer).GetRenderWindow();
            }
            else if (tempViewer.IsA("vtkImageViewer2") != 0)
            {
              tempRenderWindow = ((vtkImageViewer2)tempViewer).GetRenderWindow();
            }
            else
            {
              throw new System.Exception("");
            }
            rtTester.SetRenderWindow(tempRenderWindow);

            if (tempViewer.IsA("vtkImageViewer") != 0)
            {
              ((vtkImageViewer)tempViewer).Render();
            }
            else if (tempViewer.IsA("vtkImageViewer2") != 0)
            {
              ((vtkImageViewer2)tempViewer).Render();
            }
          }
          else
          {
            tempRenderWindow = (vtkRenderWindow)executeMethod(t, "GetimgWin", new object[] { });
            if (tempRenderWindow != null)
            {
              rtTester.SetRenderWindow(tempRenderWindow);
              tempRenderWindow.Render();
            }
          }
        }

        if (tempRenderWindow == null)
        {
          throw new System.Exception("tempRenderWindow cannot be null for IsValidImageSpecified case...");
        }

        rtResult = rtTester.RegressionTest(threshold);
          }

          if (rtTester.IsInteractiveModeSpecified() != 0)
          {
        if (tempRenderWindowInteractor != null)
        {
          tempRenderWindowInteractor.Start();
        }
          }

          // Force other objects that may have holds on the render window
          // to let go:
          //
          rtTester.SetRenderWindow(null);
          if (null != tempw2i)
          {
        tempw2i.SetInput(null);
          }

          executeMethod(t, "deleteAllVTKObjects", new object[] { });
          deleteAllVTKObjects();

          // Force a garbage collection prior to exiting the test
          // so that any memory leaks reported are likely to be
          // *actual* leaks of some sort rather than false reports:
          //
          System.GC.Collect();
          System.GC.WaitForPendingFinalizers();

          // Fail the tests that have image diffs if fail_on_image_diff is on:
          //
          if (fail_on_image_diff && 0 == rtResult)
          {
        throw new System.Exception("error: image RegressionTest failed");
          }

          // Test finished without throwing any exceptions...
          // Therefore, it passed. Exit with a zero ExitCode.
          //
          System.Environment.ExitCode = 0;
        }
        catch (System.Exception exc)
        {
          // Catch anything, spit it out to the console so it can be captured
          // by ctest. Exit with a non-zero ExitCode.
          //
          System.Console.Error.WriteLine("================================================================================");
          System.Console.Error.WriteLine("");
          System.Console.Error.WriteLine("TclToCsScript C# test driver caught System.Exception:");
          System.Console.Error.WriteLine("");
          System.Console.Error.WriteLine("{0}", exc.ToString());
          System.Console.Error.WriteLine("");
          System.Console.Error.WriteLine("================================================================================");
          System.Console.Error.WriteLine("");
          System.Environment.ExitCode = 2345;
        }
    }