vtkWriteDicom.cxx

Go to the documentation of this file.
00001 // This example illustrates how the vtkGdcmWriter vtk class can be
00002 // used in order to:
00003 //
00004 // Usage:
00005 // 
00006 //----------------------------------------------------------------------------
00007 #include <iostream>
00008 
00009 #include <vtkImageMapToColors.h>
00010 #include <vtkLookupTable.h>
00011 #include <vtkImageData.h>
00012 
00013 #include "vtkGdcmReader.h"
00014 #include "vtkGdcmWriter.h"
00015 
00016 #ifndef vtkFloatingPointType
00017 #define vtkFloatingPointType float
00018 #endif
00019 
00020 //----------------------------------------------------------------------------
00021 int main(int argc, char *argv[])
00022 {
00023    if( argc < 3 )
00024    {
00025       return 0;
00026    }
00027   
00028    vtkGdcmReader *reader = vtkGdcmReader::New();
00029    reader->AllowLookupTableOff();
00030    reader->SetFileName( argv[1] );
00031    reader->Update();
00032 
00033    vtkImageData *output;
00034    if( reader->GetLookupTable() )
00035    {
00036       //convert to color:
00037       vtkImageMapToColors *map = vtkImageMapToColors::New ();
00038       map->SetInput (reader->GetOutput());
00039       map->SetLookupTable (reader->GetLookupTable());
00040       map->SetOutputFormatToRGB();
00041       output = map->GetOutput();
00042       map->Delete();
00043    }
00044    else
00045    {
00046       output = reader->GetOutput();
00047    }
00048   
00049    //print debug info:
00050    output->Print(cout);
00051 
00053    // WRITE...
00054    //if you wish you can export dicom to a vtk file 
00055    // this file will have the add of .tmp.dcm extention
00056    std::string fileName = argv[2];
00057    fileName += ".dcm";
00058 
00059    vtkGdcmWriter *writer = vtkGdcmWriter::New();
00060 
00061    // For 3D
00062    writer->SetFileDimensionality(3);
00063    writer->SetFileName(fileName.c_str());
00064    if(argc >= 4)
00065    {
00066       if( strcmp(argv[3],"2D" )==0 )
00067       {
00068          writer->SetFileDimensionality(2);
00069          writer->SetFilePrefix(argv[2]);
00070          writer->SetFilePattern("%s%d.dcm");
00071       }
00072    }
00073 
00074    writer->SetInput(output);
00075    writer->Write();
00077 
00078    // Clean up
00079    writer->Delete();
00080    reader->Delete();
00081 
00082    return 0;
00083 }

Generated on Fri Aug 24 12:59:32 2007 for gdcm by  doxygen 1.4.6