]> Creatis software - clitk.git/commitdiff
new tool: clitkDicomRTDose2Image
authorRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Tue, 26 Feb 2013 09:07:56 +0000 (10:07 +0100)
committerRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Tue, 26 Feb 2013 09:07:56 +0000 (10:07 +0100)
- takes into account the scale factor not used by clitkDicom2Image

tools/CMakeLists.txt
tools/clitkDicomRTDose2Image.cxx [new file with mode: 0644]
tools/clitkDicomRTDose2Image.ggo [new file with mode: 0644]

index 71937728a25aea7f049db5e22bf1a9dbed95b14e..edc6864f1d2cb00cedcb80f07779ae0367a7cbd5 100644 (file)
@@ -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 (file)
index 0000000..ba068d2
--- /dev/null
@@ -0,0 +1,99 @@
+// clitk includes
+#include "clitkDicomRTDose2Image_ggo.h"
+#include "clitkCommon.h"
+#include "clitkImageCommon.h"
+#include "itkImageFileReader.h"
+#include "itkImageFileWriter.h"
+#include <gdcmFile.h>
+#if GDCM_MAJOR_VERSION == 2
+  #include <gdcmImageHelper.h>
+  #include <gdcmAttribute.h>
+  #include <gdcmReader.h>
+#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<ImageValueType, Dim> ImageType;
+  typedef itk::ImageFileReader<ImageType> 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<DoseValueType, Dim> 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<ImageType> InputIteratorType;
+  InputIteratorType it_in(image, image->GetLargestPossibleRegion());
+  it_in.GoToBegin();
+
+  typedef itk::ImageRegionIterator<DoseImageType> 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<DoseImageType> 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 (file)
index 0000000..4b3c5fb
--- /dev/null
@@ -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