Ejemplo n.º 1
0
        public static void WriteImageData(string imageDataPath, string connectiveAirwayVtpPath, vtkImageData imagedata)
        {
            vtkMetaImageWriter write = new vtkMetaImageWriter();

            write.SetFileName(imageDataPath);
            write.SetInput(imagedata);
            write.Write();
            write.Dispose();
            try
            {
                VMTKUtil.DoMarchingCubeNotConnective(imageDataPath, connectiveAirwayVtpPath, 1);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                throw;
            }

            //vtkPolyData polyData = MarchingCubeImageData(imagedata, 1);

            //vtkXMLPolyDataWriter writepolyData = new vtkXMLPolyDataWriter();
            //writepolyData.SetFileName(airwayVtpPath);
            //writepolyData.SetInput(polyData);
            //writepolyData.Write();
        }
Ejemplo n.º 2
0
        public static void WriteImageData(string imageDataPath, vtkImageData imagedata)
        {
            vtkMetaImageWriter write = new vtkMetaImageWriter();

            write.SetFileName(imageDataPath);
            write.SetInput(imagedata);
            write.Write();
            write.Dispose();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
    public static int ProcessOneMHDMD5(string filename)
    {
        vtkGDCMImageReader reader = vtkGDCMImageReader.New();

        reader.FileLowerLeftOn();
        reader.DebugOff();
        int canread = reader.CanReadFile(filename);

        if (canread == 0)
        {
            string refms = gdcm.Testing.GetMediaStorageFromFile(filename);
            if (gdcm.MediaStorage.IsImage(gdcm.MediaStorage.GetMSType(refms)))
            {
                System.Console.Write("Problem with file: " + filename + "\n");
                return(1);
            }
            // not an image
            return(0);
        }

        reader.SetFileName(filename);
        reader.Update();

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

        vtkMetaImageWriter writer = vtkMetaImageWriter.New();

        writer.SetCompression(false);
        writer.SetInput(reader.GetOutput());
        string subdir = "MetaImageMD5Activiz";
        string tmpdir = gdcm.Testing.GetTempDirectory(subdir);

        if (!gdcm.PosixEmulation.FileIsDirectory(tmpdir))
        {
            gdcm.PosixEmulation.MakeDirectory(tmpdir);
        }
        string mhdfile = gdcm.Testing.GetTempFilename(filename, subdir);

        string rawfile = mhdfile;

        mhdfile += ".mhd";
        rawfile += ".raw";
        writer.SetFileName(mhdfile);
        writer.Write();

        string digestmhd = gdcm.Testing.ComputeFileMD5(mhdfile);
        string digestraw = gdcm.Testing.ComputeFileMD5(rawfile);

        string mhdref = vtkGDCMTesting.GetMHDMD5FromFile(filename);
        string rawref = vtkGDCMTesting.GetRAWMD5FromFile(filename);

        if (mhdref != digestmhd)
        {
            System.Console.Write("Problem with mhd file: " + filename + "\n");
            System.Console.Write(digestmhd);
            System.Console.Write("\n");
            System.Console.Write(mhdref);
            System.Console.Write("\n");
            return(1);
        }
        if (rawref != digestraw)
        {
            System.Console.Write("Problem with raw file: " + filename + "\n");
            System.Console.Write(digestraw);
            System.Console.Write("\n");
            System.Console.Write(rawref);
            System.Console.Write("\n");
            return(1);
        }

        return(0);
    }