2 #include "clitkDicomRTDose2Image_ggo.h"
3 #include "clitkCommon.h"
4 #include "clitkImageCommon.h"
5 #include "itkImageFileReader.h"
6 #include "itkImageFileWriter.h"
8 #if GDCM_MAJOR_VERSION == 2
9 #include <gdcmImageHelper.h>
10 #include <gdcmAttribute.h>
11 #include <gdcmReader.h>
14 //====================================================================
15 int main(int argc, char * argv[])
18 GGO(clitkDicomRTDose2Image, args_info);
19 //===========================================
22 const unsigned int Dim = 3;
23 typedef unsigned int ImageValueType;
24 typedef itk::Image<ImageValueType, Dim> ImageType;
25 typedef itk::ImageFileReader<ImageType> ReaderType;
27 ReaderType::Pointer reader = ReaderType::New();
28 reader->SetFileName(args_info.input_arg);
31 ImageType::Pointer image = reader->GetOutput();
33 typedef float DoseValueType;
34 typedef itk::Image<DoseValueType, Dim> DoseImageType;
35 DoseImageType::Pointer output_image = DoseImageType::New();
36 output_image->SetOrigin(image->GetOrigin());
37 output_image->SetSpacing(image->GetSpacing());
38 output_image->SetDirection(image->GetDirection());
39 output_image->SetRegions(image->GetLargestPossibleRegion());
40 output_image->Allocate();
42 typedef itk::ImageRegionConstIterator<ImageType> InputIteratorType;
43 InputIteratorType it_in(image, image->GetLargestPossibleRegion());
46 typedef itk::ImageRegionIterator<DoseImageType> OutputIteratorType;
47 OutputIteratorType it_out(output_image, output_image->GetLargestPossibleRegion());
50 double dose_scale = 1;
52 #if GDCM_MAJOR_VERSION == 2
53 if (args_info.verbose_flag)
54 std::cout << "Using GDCM-2.x" << std::endl;
56 hreader.SetFileName(args_info.input_arg);
58 gdcm::DataSet& ds = hreader.GetFile().GetDataSet();
59 gdcm::Attribute<0x0008, 0x0060> attr_modality;
60 attr_modality.SetFromDataSet(ds);
61 modality = attr_modality.GetValue();
62 if (modality != "RTDOSE") {
63 FATAL("Dicom modality (0x0008, 0x0060) must be RTDOSE.\n");
65 gdcm::Attribute<0x3004, 0x000e> attr_dose_grid_scaling;
66 attr_dose_grid_scaling.SetFromDataSet(ds);
67 dose_scale = attr_dose_grid_scaling.GetValue();
69 if (args_info.verbose_flag)
70 std::cout << "Not using GDCM-2.x" << std::endl;
71 gdcm::File *header = new gdcm::File();
72 header->SetFileName(input_files[i]);
73 header->SetMaxSizeLoadEntry(16384); // required ?
75 modality = atof(header->GetEntryValue(0x0008, 0x0060).c_str());
76 if (modality != "RTDOSE") {
77 FATAL("Dicom modality (0x0008, 0x0060) must be RTDOSE.\n");
79 dose_scale = atof(header->GetEntryValue(0x3004,0x000e).c_str());
82 if (args_info.verbose_flag) {
83 std::cout << "Dose Grid Scaling is " << dose_scale << std::endl;
86 while (!it_in.IsAtEnd()) {
87 it_out.Set(it_in.Get() * dose_scale);
92 typedef itk::ImageFileWriter<DoseImageType> WriterType;
93 WriterType::Pointer writer = WriterType::New();
94 writer->SetInput(output_image);
95 writer->SetFileName(args_info.output_arg);