Esempio n. 1
0
        private void ReadPNG()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test     = vtkTesting.New();
            string     root     = test.GetDataRoot();
            string     filePath = System.IO.Path.Combine(root, @"Data\camscene.png");
            //Read the image
            vtkPNGReader reader = vtkPNGReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            reader.SetFileName(filePath);
            reader.Update();
            // Visualize
            vtkImageViewer2 imageViewer = vtkImageViewer2.New();

            imageViewer.SetInputConnection(reader.GetOutputPort());
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            imageViewer.SetRenderer(renderer);
        }
Esempio n. 2
0
        private void WritePNG()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test     = vtkTesting.New();
            string     root     = test.GetDataRoot();
            string     filePath = System.IO.Path.Combine(root, @"Data\test_png.png");

            int[] extent = new int[] { 0, 99, 0, 99, 0, 0 };
            vtkImageCanvasSource2D imageSource = vtkImageCanvasSource2D.New();

            imageSource.SetExtent(extent[0], extent[1], extent[2], extent[3], extent[4], extent[5]);
            imageSource.SetScalarTypeToUnsignedChar();
            imageSource.SetNumberOfScalarComponents(3);
            imageSource.SetDrawColor(127, 45, 255);
            imageSource.FillBox(0, 99, 0, 99);
            imageSource.SetDrawColor(255, 255, 255);
            imageSource.FillBox(40, 70, 20, 50);
            imageSource.Update();

            vtkImageCast castFilter = vtkImageCast.New();

            castFilter.SetOutputScalarTypeToUnsignedChar();
            castFilter.SetInputConnection(imageSource.GetOutputPort());
            castFilter.Update();

            vtkPNGWriter writer = vtkPNGWriter.New();

            writer.SetFileName(filePath);
            writer.SetInputConnection(castFilter.GetOutputPort());
            writer.Write();
            // Read and display file for verification that it was written correctly
            vtkPNGReader reader = vtkPNGReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            reader.SetFileName(filePath);
            reader.Update();

            // Visualize
            vtkImageViewer2 imageViewer = vtkImageViewer2.New();

            imageViewer.SetInputConnection(reader.GetOutputPort());
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            imageViewer.SetRenderer(renderer);
            renderer.ResetCamera();
        }
Esempio n. 3
0
  public static int Main(string[] args)
    {
    string filename = args[0];
    string outfilename = args[1];
    string outfilename2 = args[2];

    vtkGDCMImageReader reader = new Kitware.VTK.GDCM.vtkGDCMImageReader();
    reader.SetFileName( filename );

    // When calling multiple times creation of C# object from the same C++ object it triggers a:
//error: potential refcounting error: Duplicate rawCppThis - weak reference that is still alive. Attempting to add '0x00b2dc10' again.
//       Allowing new wrapped object to take over table key...
//       Original object should *not* have been destroyed while we still had it in our table without notifying us...
    //reader.GetOutput();
    //reader.GetOutput();

    System.Console.WriteLine( reader.ToString() ); // Test the ToString compat with Activiz

    vtkGDCMImageWriter writer = new vtkGDCMImageWriter();
    writer.SetInput( reader.GetOutput() );
    writer.SetFileName( outfilename2 );
    writer.Write();

    System.Console.WriteLine( reader.GetOutput().ToString() ); // Test the ToString compat with Activiz

    System.Console.WriteLine( writer.ToString() ); // Test the ToString compat with Activiz

    vtkPNGWriter pngwriter = new vtkPNGWriter();
    pngwriter.SetInput( reader.GetOutput() );
    pngwriter.SetFileName( outfilename );
    pngwriter.Write();

    // at that point the .Write() should have triggered an Update() on the reader:
    if( reader.GetImageFormat() == vtkgdcm.VTK_LUMINANCE ) // MONOCHROME2
      {
      System.Console.WriteLine( "Image is MONOCHROME2" ); //
      }

    vtkPNGReader bmpreader = new vtkPNGReader();
    bmpreader.SetFileName( outfilename );

    vtkMedicalImageProperties prop = new vtkMedicalImageProperties();
    prop.SetModality( "MR" );

    vtkMatrix4x4 dircos = reader.GetDirectionCosines();
    dircos.Invert();

    vtkGDCMImageWriter writer2 = new vtkGDCMImageWriter();
    writer2.SetFileName( outfilename2 );
    writer2.SetDirectionCosines( dircos );
    writer2.SetMedicalImageProperties( prop );
    writer2.SetInput( bmpreader.GetOutput() );
    writer2.Write();

    return 0;
    }
Esempio n. 4
0
        /// <summary>
        /// Loads the Squirrel model and textures
        /// into the algorithms and textures
        /// </summary>
        public void loadSquirrel()
        {
            //Set a predefined position for the eyes
            //that matches the .blend file
            eyeX = 0.076;
            eyeY = -0.178;
            eyeZ = 0.675;

            //load the squirrel model and textures if
            //they are not already loaded
            if (!squirrelLoaded)
            {
                squirrelReader.SetFileName("../../../models/squirrel.vtk");
                squirrelReader.Update();
                squirrelEyeReader.SetFileName("../../../models/squirrel_eyeR.vtk");
                squirrelEyeReader.Update();
                squirrelEyeReader2.SetFileName("../../../models/squirrel_eyeL.vtk");
                squirrelEyeReader2.Update();
                squirrelColorReader.SetFileName("../../../textures/squirrel_skin_col.png");
                squirrelColorReader.Update();
                squirrelEyeColorReader.SetFileName("../../../textures/squirrel_eyeR.png");
                squirrelEyeColorReader.Update();
                squirrelEyeColorReader2.SetFileName("../../../textures/squirrel_eyeL.png");
                squirrelEyeColorReader2.Update();
                squirrelLoaded = true;
            }

            //Set the algorithms and textures to the
            //ouput of the readers
            eyeColorTexture1.InterpolateOn();
            eyeColorTexture1.SetInputConnection(squirrelEyeColorReader.GetOutputPort());

            deciEyeColorTexture1.InterpolateOn();
            deciEyeColorTexture1.SetInputConnection(squirrelEyeColorReader.GetOutputPort());

            eyeColorTexture2.InterpolateOn();
            eyeColorTexture2.SetInputConnection(squirrelEyeColorReader2.GetOutputPort());

            deciEyeColorTexture2.InterpolateOn();
            deciEyeColorTexture2.SetInputConnection(squirrelEyeColorReader2.GetOutputPort());

            animalColorTexture.InterpolateOn();
            animalColorTexture.SetInputConnection(squirrelColorReader.GetOutputPort());

            deciAnimalColorTexture.InterpolateOn();
            deciAnimalColorTexture.SetInputConnection(squirrelColorReader.GetOutputPort());

            eyeData2 = squirrelEyeReader2.GetOutputPort();
            eyeData1 = squirrelEyeReader.GetOutputPort();

            animalData = squirrelReader.GetOutputPort();
        }
Esempio n. 5
0
        /// <summary>
        /// Loads the Chinchilla model and textures
        /// into the algorithms and textures
        /// </summary>
        public void loadChinchilla()
        {
            //Set a predefined position for the eyes
            //that matches the .blend file
            eyeX = 0.052;
            eyeY = -0.144;
            eyeZ = 0.424;

            //load the chinchilla model and textures if
            //they are not already loaded
            if (!chinchillaLoaded)
            {
                chinchillaReader.SetFileName("../../../models/chinchilla.vtk");
                chinchillaReader.Update();
                chinchillaEyeReader.SetFileName("../../../models/chinchilla_eye.vtk");
                chinchillaEyeReader.Update();
                chinchillaColorReader.SetFileName("../../../textures/chinchilla_skin_col.png");
                chinchillaColorReader.Update();
                chinchillaEyeColorReader.SetFileName("../../../textures/chinchilla_eye.png");
                chinchillaEyeColorReader.Update();
                chinchillaLoaded = true;
            }

            //Set the algorithms and textures to the
            //ouput of the readers
            animalData = chinchillaReader.GetOutputPort();

            eyeData1 = chinchillaEyeReader.GetOutputPort();
            eyeData2 = eyeData1;

            animalColorTexture.InterpolateOn();
            animalColorTexture.SetInputConnection(chinchillaColorReader.GetOutputPort());

            deciAnimalColorTexture.InterpolateOn();
            deciAnimalColorTexture.SetInputConnection(chinchillaColorReader.GetOutputPort());

            eyeColorTexture1.InterpolateOn();
            eyeColorTexture1.SetInputConnection(chinchillaEyeColorReader.GetOutputPort());

            deciEyeColorTexture1.InterpolateOn();
            deciEyeColorTexture1.SetInputConnection(chinchillaEyeColorReader.GetOutputPort());

            eyeColorTexture2.InterpolateOn();
            eyeColorTexture2.SetInputConnection(chinchillaEyeColorReader.GetOutputPort());

            deciEyeColorTexture2.InterpolateOn();
            deciEyeColorTexture2.SetInputConnection(chinchillaEyeColorReader.GetOutputPort());
        }
Esempio n. 6
0
        /// <summary>
        /// Loads the Flying Squirrel model and textures
        /// into the algorithms and textures
        /// </summary>
        public void loadFlyingSquirrel()
        {
            //Set a predefined position for the eyes
            //that matches the .blend file
            eyeX = 0.054;
            eyeY = -0.189;
            eyeZ = 0.427;

            //load the flyingsquirrel model and textures if
            //they are not already loaded
            if (!flyingSquirrelLoaded)
            {
                flyingSquirrelReader.SetFileName("../../../models/flyingsquirrel.vtk");
                flyingSquirrelReader.Update();
                flyingSquirreleyeReader.SetFileName("../../../models/flyingsquirrel_eye.vtk");
                flyingSquirreleyeReader.Update();
                flyingSquirrelColorReader.SetFileName("../../../textures/flyingsquirrel_skin_col.png");
                flyingSquirrelColorReader.Update();
                flyingSquirrelEyeColorReader.SetFileName("../../../textures/flyingsquirrel_eye.png");
                flyingSquirrelEyeColorReader.Update();
                flyingSquirrelLoaded = true;
            }

            //Set the algorithms and textures to the
            //ouput of the readers
            animalData = flyingSquirrelReader.GetOutputPort();

            eyeData1 = flyingSquirreleyeReader.GetOutputPort();
            eyeData2 = eyeData1;

            animalColorTexture.InterpolateOn();
            animalColorTexture.SetInputConnection(flyingSquirrelColorReader.GetOutputPort());

            deciAnimalColorTexture.InterpolateOn();
            deciAnimalColorTexture.SetInputConnection(flyingSquirrelColorReader.GetOutputPort());

            eyeColorTexture1.InterpolateOn();
            eyeColorTexture1.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort());

            deciEyeColorTexture1.InterpolateOn();
            deciEyeColorTexture1.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort());

            eyeColorTexture2.InterpolateOn();
            eyeColorTexture2.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort());

            deciEyeColorTexture2.InterpolateOn();
            deciEyeColorTexture2.SetInputConnection(flyingSquirrelEyeColorReader.GetOutputPort());
        }
Esempio n. 7
0
        /// <summary>
        /// Loads the Rabbit model and textures
        /// into the algorithms and textures
        /// </summary>
        public void loadRabbit()
        {
            //Set a predefined position for the eyes
            //that matches the .blend file
            eyeX = 0.057;
            eyeY = -0.311;
            eyeZ = 1.879;

            //load the rabbit model and textures if
            //they are not already loaded
            if (!rabbitLoaded)
            {
                rabbitReader.SetFileName("../../../models/rabbit.vtk");
                rabbitReader.Update();
                eyeReader.SetFileName("../../../models/rabbit_eye.vtk");
                eyeReader.Update();
                rabbitColorReader.SetFileName("../../../textures/rabbit_skin_col.png");
                rabbitColorReader.Update();
                eyeColorReader.SetFileName("../../../textures/rabbit_eye.png");
                eyeColorReader.Update();
                rabbitLoaded = true;
            }
            //Set the algorithms and textures to the
            //ouput of the readers
            animalData = rabbitReader.GetOutputPort();

            eyeData1 = eyeReader.GetOutputPort();
            eyeData2 = eyeData1;

            animalColorTexture.InterpolateOn();
            animalColorTexture.SetInputConnection(rabbitColorReader.GetOutputPort());

            deciAnimalColorTexture.InterpolateOn();
            deciAnimalColorTexture.SetInputConnection(rabbitColorReader.GetOutputPort());

            eyeColorTexture1.InterpolateOn();
            eyeColorTexture1.SetInputConnection(eyeColorReader.GetOutputPort());

            deciEyeColorTexture1.InterpolateOn();
            deciEyeColorTexture1.SetInputConnection(eyeColorReader.GetOutputPort());

            eyeColorTexture2.InterpolateOn();
            eyeColorTexture2.SetInputConnection(eyeColorReader.GetOutputPort());

            deciEyeColorTexture2.InterpolateOn();
            deciEyeColorTexture2.SetInputConnection(eyeColorReader.GetOutputPort());
        }
Esempio n. 8
0
    public static int Main(string[] args)
    {
        string filename    = args[0];
        string outfilename = args[1];

        // Step 1. Test SWIG -> Activiz
        vtkGDCMImageReader reader = vtkGDCMImageReader.New();

        reader.SetFileName(filename);
        //reader.Update(); // DO NOT call Update to check pipeline execution

        Kitware.VTK.vtkImageData imgout = ConnectSWIGToActiviz(reader.GetOutput());

        System.Console.WriteLine(imgout.ToString()); // not initialized as expected

        vtkPNGWriter writer = new vtkPNGWriter();

        writer.SetInput(imgout);
        writer.SetFileName(outfilename);
        writer.Write();

        // Step 2. Test Activiz -> SWIG
        vtkPNGReader bmpreader = new vtkPNGReader();

        bmpreader.SetFileName(outfilename);
        //bmpreader.Update(); // DO NOT update to check pipeline execution

        System.Console.WriteLine(bmpreader.GetOutput().ToString()); // not initialized as expected

        vtkgdcm.vtkImageData imgout2 = ConnectActivizToSWIG(bmpreader.GetOutput());

        System.Console.WriteLine(imgout2.ToString()); // not initialized as expected


        Kitware.VTK.vtkMedicalImageProperties prop = new Kitware.VTK.vtkMedicalImageProperties();
        prop.SetModality("MR");

        string             outfilename2 = args[2];
        vtkGDCMImageWriter writer2      = vtkGDCMImageWriter.New();

        writer2.SetMedicalImageProperties(prop.CastToActiviz());
        writer2.SetFileName(outfilename2);
        writer2.SetInput(imgout2);
        writer2.Write();

        return(0);
    }
Esempio n. 9
0
    public static int Main(string[] args)
    {
        string filename = args[0];
        string outfilename = args[1];

        // Step 1. Test SWIG -> Activiz
        vtkGDCMImageReader reader = vtkGDCMImageReader.New();
        reader.SetFileName( filename );
        //reader.Update(); // DO NOT call Update to check pipeline execution

        Kitware.VTK.vtkImageData imgout = ConnectSWIGToActiviz(reader.GetOutput());

        System.Console.WriteLine( imgout.ToString() ); // not initialized as expected

        vtkPNGWriter writer = new vtkPNGWriter();
        writer.SetInput( imgout );
        writer.SetFileName( outfilename );
        writer.Write();

        // Step 2. Test Activiz -> SWIG
        vtkPNGReader bmpreader = new vtkPNGReader();
        bmpreader.SetFileName( outfilename );
        //bmpreader.Update(); // DO NOT update to check pipeline execution

        System.Console.WriteLine( bmpreader.GetOutput().ToString() ); // not initialized as expected

        vtkgdcm.vtkImageData imgout2 = ConnectActivizToSWIG(bmpreader.GetOutput());

        System.Console.WriteLine( imgout2.ToString() ); // not initialized as expected

        Kitware.VTK.vtkMedicalImageProperties prop = new Kitware.VTK.vtkMedicalImageProperties();
        prop.SetModality( "MR" );

        string outfilename2 = args[2];
        vtkGDCMImageWriter writer2 = vtkGDCMImageWriter.New();
        writer2.SetMedicalImageProperties( prop.CastToActiviz() );
        writer2.SetFileName( outfilename2 );
        writer2.SetInput( imgout2 );
        writer2.Write();

        return 0;
    }
Esempio n. 10
0
    public static int Main(string[] args)
    {
        string filename     = args[0];
        string outfilename  = args[1];
        string outfilename2 = args[2];

        vtkgdcm.vtkGDCMImageReader reader = new vtkgdcm.vtkGDCMImageReader();
        reader.SetFileName(filename);

        // When calling multiple times creation of C# object from the same C++ object it triggers a:
//error: potential refcounting error: Duplicate rawCppThis - weak reference that is still alive. Attempting to add '0x00b2dc10' again.
//       Allowing new wrapped object to take over table key...
//       Original object should *not* have been destroyed while we still had it in our table without notifying us...
        //reader.GetOutput();
        //reader.GetOutput();

        System.Console.WriteLine(reader.ToString()); // Test the ToString compat with Activiz

        vtkGDCMImageWriter writer = new vtkGDCMImageWriter();

        writer.SetInput(reader.GetOutput());
        writer.SetFileName(outfilename2);
        writer.Write();

        System.Console.WriteLine(reader.GetOutput().ToString()); // Test the ToString compat with Activiz

        System.Console.WriteLine(writer.ToString());             // Test the ToString compat with Activiz

        vtkPNGWriter pngwriter = new vtkPNGWriter();

        pngwriter.SetInput(reader.GetOutput());
        pngwriter.SetFileName(outfilename);
        pngwriter.Write();

        // at that point the .Write() should have triggered an Update() on the reader:
        if (reader.GetImageFormat() == vtkgdcm.vtkgdcm.VTK_LUMINANCE) // MONOCHROME2
        {
            System.Console.WriteLine("Image is MONOCHROME2");         //
        }

        vtkPNGReader bmpreader = new vtkPNGReader();

        bmpreader.SetFileName(outfilename);

        vtkMedicalImageProperties prop = new vtkMedicalImageProperties();

        prop.SetModality("MR");

        vtkMatrix4x4 dircos = reader.GetDirectionCosines();

        dircos.Invert();

        vtkGDCMImageWriter writer2 = new vtkGDCMImageWriter();

        writer2.SetFileName(outfilename2);
        writer2.SetDirectionCosines(dircos);
        writer2.SetMedicalImageProperties(prop);
        writer2.SetInput(bmpreader.GetOutput());
        writer2.Write();

        return(0);
    }