From 9c1d9afdf7f7f89aecc989b0a159d22a3745cfe2 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Tue, 26 Feb 2013 10:07:56 +0100 Subject: [PATCH] new tool: clitkDicomRTDose2Image - takes into account the scale factor not used by clitkDicom2Image --- tools/CMakeLists.txt | 5 ++ tools/clitkDicomRTDose2Image.cxx | 99 ++++++++++++++++++++++++++++++++ tools/clitkDicomRTDose2Image.ggo | 8 +++ 3 files changed, 112 insertions(+) create mode 100644 tools/clitkDicomRTDose2Image.cxx create mode 100644 tools/clitkDicomRTDose2Image.ggo diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 7193772..edc6864 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -34,6 +34,11 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkDicom2Image clitkCommon ${ITK_LIBRARIES}) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDicom2Image) + WRAP_GGO(clitkDicomRTDose2Image_GGO_C clitkDicomRTDose2Image.ggo) + ADD_EXECUTABLE(clitkDicomRTDose2Image clitkDicomRTDose2Image.cxx ${clitkDicomRTDose2Image_GGO_C}) + TARGET_LINK_LIBRARIES(clitkDicomRTDose2Image clitkCommon ${ITK_LIBRARIES}) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDicomRTDose2Image) + WRAP_GGO(clitkDicomWave2Text_GGO_C clitkDicomWave2Text.ggo) ADD_EXECUTABLE(clitkDicomWave2Text clitkDicomWave2Text.cxx ${clitkDicomWave2Text_GGO_C}) TARGET_LINK_LIBRARIES(clitkDicomWave2Text clitkCommon ${ITK_LIBRARIES}) diff --git a/tools/clitkDicomRTDose2Image.cxx b/tools/clitkDicomRTDose2Image.cxx new file mode 100644 index 0000000..ba068d2 --- /dev/null +++ b/tools/clitkDicomRTDose2Image.cxx @@ -0,0 +1,99 @@ +// clitk includes +#include "clitkDicomRTDose2Image_ggo.h" +#include "clitkCommon.h" +#include "clitkImageCommon.h" +#include "itkImageFileReader.h" +#include "itkImageFileWriter.h" +#include +#if GDCM_MAJOR_VERSION == 2 + #include + #include + #include +#endif + +//==================================================================== +int main(int argc, char * argv[]) +{ + // init command line + GGO(clitkDicomRTDose2Image, args_info); + //=========================================== + // Read write serie + + const unsigned int Dim = 3; + typedef unsigned int ImageValueType; + typedef itk::Image ImageType; + typedef itk::ImageFileReader ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(args_info.input_arg); + reader->Update(); + + ImageType::Pointer image = reader->GetOutput(); + + typedef float DoseValueType; + typedef itk::Image DoseImageType; + DoseImageType::Pointer output_image = DoseImageType::New(); + output_image->SetOrigin(image->GetOrigin()); + output_image->SetSpacing(image->GetSpacing()); + output_image->SetDirection(image->GetDirection()); + output_image->SetRegions(image->GetLargestPossibleRegion()); + output_image->Allocate(); + + typedef itk::ImageRegionConstIterator InputIteratorType; + InputIteratorType it_in(image, image->GetLargestPossibleRegion()); + it_in.GoToBegin(); + + typedef itk::ImageRegionIterator OutputIteratorType; + OutputIteratorType it_out(output_image, output_image->GetLargestPossibleRegion()); + it_out.GoToBegin(); + + double dose_scale = 1; + std::string modality; +#if GDCM_MAJOR_VERSION == 2 + if (args_info.verbose_flag) + std::cout << "Using GDCM-2.x" << std::endl; + gdcm::Reader hreader; + hreader.SetFileName(args_info.input_arg); + hreader.Read(); + gdcm::DataSet& ds = hreader.GetFile().GetDataSet(); + gdcm::Attribute<0x0008, 0x0060> attr_modality; + attr_modality.SetFromDataSet(ds); + modality = attr_modality.GetValue(); + if (modality != "RTDOSE") { + FATAL("Dicom modality (0x0008, 0x0060) must be RTDOSE.\n"); + } + gdcm::Attribute<0x3004, 0x000e> attr_dose_grid_scaling; + attr_dose_grid_scaling.SetFromDataSet(ds); + dose_scale = attr_dose_grid_scaling.GetValue(); +#else + if (args_info.verbose_flag) + std::cout << "Not using GDCM-2.x" << std::endl; + gdcm::File *header = new gdcm::File(); + header->SetFileName(input_files[i]); + header->SetMaxSizeLoadEntry(16384); // required ? + header->Load(); + modality = atof(header->GetEntryValue(0x0008, 0x0060).c_str()); + if (modality != "RTDOSE") { + FATAL("Dicom modality (0x0008, 0x0060) must be RTDOSE.\n"); + } + dose_scale = atof(header->GetEntryValue(0x3004,0x000e).c_str()); +#endif + + if (args_info.verbose_flag) { + std::cout << "Dose Grid Scaling is " << dose_scale << std::endl; + } + + while (!it_in.IsAtEnd()) { + it_out.Set(it_in.Get() * dose_scale); + ++it_in; + ++it_out; + } + + typedef itk::ImageFileWriter WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(output_image); + writer->SetFileName(args_info.output_arg); + writer->Update(); + + return 0; +} \ No newline at end of file diff --git a/tools/clitkDicomRTDose2Image.ggo b/tools/clitkDicomRTDose2Image.ggo new file mode 100644 index 0000000..4b3c5fb --- /dev/null +++ b/tools/clitkDicomRTDose2Image.ggo @@ -0,0 +1,8 @@ +# file clitkDicomRTDose2Image.ggo +package "clitk" +version "Try to convert a DICOM RTDOSE file into an image (.hdr, .vox...)" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes -- 2.47.1