1 // This example illustrates how the vtkGdcmWriter vtk class can be
6 //----------------------------------------------------------------------------
9 #include <vtkImageMapToColors.h>
10 #include <vtkLookupTable.h>
11 #include <vtkImageData.h>
13 #include "vtkGdcmReader.h"
14 #include "vtkGdcmWriter.h"
16 #ifndef vtkFloatingPointType
17 #define vtkFloatingPointType float
20 #include "gdcmArgMgr.h" // for Argument Manager functions
23 //----------------------------------------------------------------------------
24 int main(int argc, char *argv[])
27 " \n vtkWriteDicomExtended : \n",
28 " Reads a DICOM file and re writes it according to user's requirements. ",
30 " usage: vtkWriteDicomExtended filein=dicom file to read ",
31 " [filecontent = ] [2D] ",
32 " [noshadowseq][noshadow][noseq] ",
34 " filecontent = 1 : USER_OWN_IMAGE ",
35 " = 2 : FILTERED_IMAGE ",
36 " = 3 : CREATED_IMAGE ",
37 " = 4 : UNMODIFIED_PIXELS_IMAGE ",
38 " noshadowseq: user doesn't want to load Private Sequences ",
39 " noshadow : user doesn't want to load Private groups (odd number) ",
40 " noseq : user doesn't want to load Sequences ",
41 " debug : user wants to run the program in 'debug mode' ",
45 // Initialize Arguments Manager
46 GDCM_NAME_SPACE::ArgMgr *am= new GDCM_NAME_SPACE::ArgMgr(argc, argv);
48 if (argc == 1 || am->ArgMgrDefined("usage") )
50 am->ArgMgrUsage(usage); // Display 'usage'
55 int loadMode = GDCM_NAME_SPACE::LD_ALL;
56 if ( am->ArgMgrDefined("noshadowseq") )
57 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
60 if ( am->ArgMgrDefined("noshadow") )
61 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
62 if ( am->ArgMgrDefined("noseq") )
63 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
66 int filecontent = am->ArgMgrGetInt("filecontent", 1);
68 char *filein = am->ArgMgrWantString("filein",usage);
69 char *fileout = (char *)(am->ArgMgrGetString("fileout","fileout"));
71 if (am->ArgMgrDefined("debug"))
72 GDCM_NAME_SPACE::Debug::DebugOn();
74 int deuxD = am->ArgMgrDefined("2D");
76 /* if unused Param we give up */
77 if ( am->ArgMgrPrintUnusedLabels() )
79 am->ArgMgrUsage(usage);
84 // ------------------------------------------------------------
85 std::vector<GDCM_NAME_SPACE::File* > cfl;
87 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
88 f->SetFileName(filein);
92 vtkGdcmReader *reader = vtkGdcmReader::New();
93 reader->AllowLookupTableOff();
94 //reader->SetFileName( filein );
95 // in order not to parse twice the input file.
96 reader->SetCoherentFileList(&cfl);
100 if( reader->GetLookupTable() )
103 vtkImageMapToColors *map = vtkImageMapToColors::New ();
104 map->SetInput (reader->GetOutput());
105 map->SetLookupTable (reader->GetLookupTable());
106 map->SetOutputFormatToRGB();
107 output = map->GetOutput();
112 output = reader->GetOutput();
118 //////////////////////////////////////////////////////////
120 //if you wish you can export dicom to a vtk file
121 // this file will have the add of .tmp.dcm extention
123 std::string fileName(filein);
124 vtkGdcmWriter *writer = vtkGdcmWriter::New();
129 writer->SetContentTypeToUserOwnImage();
130 fileName = fileName + "_UserOwnImage.dcm";
134 writer->SetContentTypeToFilteredImage();
135 writer->SetGdcmFile( f );
136 fileName = fileName + "_FilteredImage.dcm";
140 writer->SetContentTypeToUserCreatedImage();
141 writer->SetGdcmFile( f );
142 fileName = fileName + "_UserCreatedImage.dcm";
146 writer->SetContentTypeToUserCreatedImage();
147 writer->SetGdcmFile( f );
148 fileName = fileName + "_UnmodifiedPixelsImage.dcm";
152 /// \todo : fix stupid generated image names (later : JPRx)
156 writer->SetFileDimensionality(2);
157 writer->SetFilePrefix(fileout);
158 writer->SetFilePattern("%s%d.dcm");
164 writer->SetFileDimensionality(3);
165 writer->SetFileName(fileName.c_str());
168 writer->SetInput(output);
170 //////////////////////////////////////////////////////////