コード例 #1
0
    public static int Main(string[] args)
    {
        string VTK_DATA_ROOT = vtkGDCMTesting.GetVTKDataRoot();

        vtkVolume16Reader reader = vtkVolume16Reader.New();

        reader.SetDataDimensions(64, 64);
        reader.SetDataByteOrderToLittleEndian();
        reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter");
        reader.SetImageRange(1, 93);
        reader.SetDataSpacing(3.2, 3.2, 1.5);

        vtkImageCast cast = vtkImageCast.New();

        cast.SetInputConnection(reader.GetOutputPort());
        cast.SetOutputScalarTypeToUnsignedChar();

        // By default this is creating a Multiframe Grayscale Word Secondary Capture Image Storage
        vtkGDCMImageWriter writer = vtkGDCMImageWriter.New();

        writer.SetFileName("headsq.dcm");
        writer.SetInputConnection(reader.GetOutputPort());
        // cast -> Multiframe Grayscale Byte Secondary Capture Image Storage
        // writer.SetInputConnection( cast.GetOutputPort() );
        writer.SetFileDimensionality(3);
        writer.Write();

        return(0);
    }
コード例 #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();
        }
コード例 #3
0
        private void WriteMetaImage()
        {
            // 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_mha.mhd");
            string     filePathRaw = System.IO.Path.Combine(root, @"Data\test_mha.raw");
            // Create an image
            vtkImageMandelbrotSource source = vtkImageMandelbrotSource.New();

            source.Update();

            vtkImageCast castFilter = vtkImageCast.New();

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

            vtkMetaImageWriter writer = vtkMetaImageWriter.New();

            writer.SetInputConnection(castFilter.GetOutputPort());
            writer.SetFileName(filePath);
            writer.SetRAWFileName(filePathRaw);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkMetaImageReader reader = vtkMetaImageReader.New();

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

            actor.SetInput(reader.GetOutput());

            // Visualize
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
        }