]> Creatis software - gdcm.git/blob - vtk/vtkWriteDicom.cxx
Fix mistypings
[gdcm.git] / vtk / vtkWriteDicom.cxx
1 // This example illustrates how the vtkGdcmWriter vtk class can be
2 // used in order to:
3 //
4 // Usage:
5 // 
6 //----------------------------------------------------------------------------
7 #include <iostream>
8
9 #include <vtkImageMapToColors.h>
10 #include <vtkLookupTable.h>
11 #include <vtkImageData.h>
12
13 #include "vtkGdcmReader.h"
14 #include "vtkGdcmWriter.h"
15
16 #ifndef vtkFloatingPointType
17 #define vtkFloatingPointType float
18 #endif
19
20 //----------------------------------------------------------------------------
21 int main(int argc, char *argv[])
22 {
23    if( argc < 3 )
24    {
25       return 0;
26    }
27   
28    vtkGdcmReader *reader = vtkGdcmReader::New();
29    reader->AllowLookupTableOff();
30    reader->SetFileName( argv[1] );
31    reader->Update();
32
33    vtkImageData *output;
34    if( reader->GetLookupTable() )
35    {
36       //convert to color:
37       vtkImageMapToColors *map = vtkImageMapToColors::New ();
38       map->SetInput (reader->GetOutput());
39       map->SetLookupTable (reader->GetLookupTable());
40       map->SetOutputFormatToRGB();
41       output = map->GetOutput();
42       map->Delete();
43    }
44    else
45    {
46       output = reader->GetOutput();
47    }
48   
49    //print debug info:
50    output->Print(cout);
51
52    //////////////////////////////////////////////////////////
53    // WRITE...
54    //if you wish you can export dicom to a vtk file 
55    // this file will have the add of .tmp.dcm extention
56    std::string fileName = argv[2];
57    fileName += ".dcm";
58
59    vtkGdcmWriter *writer = vtkGdcmWriter::New();
60
61    // For 3D
62    writer->SetFileDimensionality(3);
63    writer->SetFileName(fileName.c_str());
64    if(argc >= 4)
65    {
66       if( strcmp(argv[3],"2D" )==0 )
67       {
68          writer->SetFileDimensionality(2);
69          writer->SetFilePrefix(argv[2]);
70          writer->SetFilePattern("%s%d.dcm");
71       }
72    }
73
74    writer->SetInput(output);
75    writer->Write();
76    //////////////////////////////////////////////////////////
77
78    // Clean up
79    writer->Delete();
80    reader->Delete();
81
82    return 0;
83 }