Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
    public static int Main(string[] args)
    {
        string             filename = args[0];
        vtkGDCMImageReader reader   = vtkGDCMImageReader.New();

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

        vtkMedicalImageProperties prop = reader.GetMedicalImageProperties();

        System.Console.WriteLine(prop.GetPatientName());              //

        if (reader.GetImageFormat() == vtkgdcm.vtkgdcm.VTK_LUMINANCE) // MONOCHROME2
        {
            System.Console.WriteLine("Image is MONOCHROME2");         //
        }

        // Just for fun, invert the direction cosines, output should reflect that:
        vtkMatrix4x4 dircos = reader.GetDirectionCosines();

        dircos.Invert();

        string             outfilename = args[1];
        vtkGDCMImageWriter writer      = vtkGDCMImageWriter.New();

        writer.SetMedicalImageProperties(reader.GetMedicalImageProperties());
        writer.SetDirectionCosines(dircos);
        writer.SetShift(reader.GetShift());
        writer.SetScale(reader.GetScale());
        writer.SetImageFormat(reader.GetImageFormat());
        writer.SetFileName(outfilename);
        //writer.SetInputConnection( reader.GetOutputPort() ); // new
        writer.SetInput(reader.GetOutput()); // old
        writer.Write();

        return(0);
    }
Ejemplo n.º 3
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);
    }