]> Creatis software - gdcm.git/blob - vtk/vtkWriteDicom.cxx
* vtk/vtkGdcmWriter.[h|cxx] : add a first version of vtkGdcmWriter
[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 < 2 )
24       return 0;
25   
26    vtkGdcmReader *reader = vtkGdcmReader::New();
27    reader->AllowLookupTableOff();
28
29    if( argc == 2 )
30       reader->SetFileName( argv[1] );
31    else
32       for(int i=1; i< argc; i++)
33          reader->AddFileName( argv[i] );
34
35    reader->Update();
36
37    vtkImageData *output;
38    if( reader->GetLookupTable() )
39    {
40       //convert to color:
41       vtkImageMapToColors *map = vtkImageMapToColors::New ();
42       map->SetInput (reader->GetOutput());
43       map->SetLookupTable (reader->GetLookupTable());
44       map->SetOutputFormatToRGB();
45       output = map->GetOutput();
46       map->Delete();
47    }
48    else
49    {
50       output = reader->GetOutput();
51    }
52   
53    //print debug info:
54    output->Print( cout );
55
56    //////////////////////////////////////////////////////////
57    // WRITE...
58    //if you wish you can export dicom to a vtk file 
59    // this file will have the add of .tmp.dcm extention
60    std::string fileName = argv[1];
61    fileName += ".tmp.dcm";
62
63    vtkGdcmWriter *writer = vtkGdcmWriter::New();
64    writer->SetFileName(fileName.c_str());
65    writer->SetInput(output);
66    writer->Write();
67    //////////////////////////////////////////////////////////
68
69    // Clean up
70    writer->Delete();
71    reader->Delete();
72
73    return 0;
74 }