]> Creatis software - clitk.git/commitdiff
Allow to insert several images/contours at one time
authorDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Wed, 12 Jun 2013 14:56:33 +0000 (16:56 +0200)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Wed, 12 Jun 2013 14:56:33 +0000 (16:56 +0200)
common/clitkImage2DicomRTStructFilter.h
common/clitkImage2DicomRTStructFilter.txx
tools/clitkImage2DicomRTStruct.cxx
tools/clitkImage2DicomRTStruct.ggo

index 924bcc01db3d458a8add1d10daf712939c0e0835..d570934d046f96f2d9f0e39ba4a8e180c44ad1f9 100644 (file)
@@ -41,25 +41,23 @@ namespace clitk {
     typedef typename clitk::DicomRT_StructureSet::Pointer DicomRTStructPointer;
 
     // Set inputs
-    itkSetMacro(Input, ImagePointer);
-    itkGetConstMacro(Input, ImagePointer);
+    itkSetMacro(InputFilenames, std::vector<std::string> );
     itkSetMacro(StructureSetFilename, std::string);
     itkSetMacro(DicomFolder, std::string);
     itkSetMacro(OutputFilename, std::string);
-    void SetROIName(std::string name, std::string type);
+    void SetROIType(std::string type);
     itkSetMacro(ThresholdValue, PixelType);
     
     // Run filter
     void Update();    
     
   protected:
-    ImagePointer m_Input;
     std::string m_StructureSetFilename;
     std::string m_DicomFolder;
     std::string m_OutputFilename;
-    std::string m_ROIName;
     std::string m_ROIType;
     PixelType m_ThresholdValue;
+    std::vector<std::string> m_InputFilenames;
   };
   //--------------------------------------------------------------------
 
index 1b241a99824a233a094058f1b8196d09c4e99772..248451d8fac4e0dff6ac74b2b1316750226037a0 100644 (file)
@@ -45,6 +45,7 @@
 #include "vtkCamera.h"
 #include "vtkProperty.h"
 #include "vtkProperty2D.h"
+#include <vtksys/SystemTools.hxx>
 
 // itk
 #include <itkImage.h>
@@ -76,9 +77,8 @@ clitk::Image2DicomRTStructFilter<PixelType>::~Image2DicomRTStructFilter()
 //--------------------------------------------------------------------
 template<class PixelType>
 void
-clitk::Image2DicomRTStructFilter<PixelType>::SetROIName(std::string name, std::string type)
+clitk::Image2DicomRTStructFilter<PixelType>::SetROIType(std::string type)
 {
-  m_ROIName = name;
   m_ROIType = type;
 }
 //--------------------------------------------------------------------
@@ -112,9 +112,13 @@ void clitk::Image2DicomRTStructFilter<PixelType>::Update()
               << p->GetNumberOfStructureSetROIs() << std::endl;
   }
   
+
+  // number of additional contours
+  int m = m_InputFilenames.size();
+
   // Init writer
   vtkGDCMPolyDataWriter * writer = vtkGDCMPolyDataWriter::New();
-  int numMasks = reader->GetNumberOfOutputPorts() + 1;//add one more
+  int numMasks = reader->GetNumberOfOutputPorts() + m;
   writer->SetNumberOfInputPorts(numMasks);    
   writer->SetFileName(m_OutputFilename.c_str());
   writer->SetMedicalImageProperties(reader->GetMedicalImageProperties());
@@ -128,18 +132,46 @@ void clitk::Image2DicomRTStructFilter<PixelType>::Update()
   roiTypes->SetNumberOfValues(numMasks);
   
   // Convert the image into a mesh
-  typedef clitk::BinaryImageToMeshFilter<ImageType> BinaryImageToMeshFilterType;
-  typename BinaryImageToMeshFilterType::Pointer convert = BinaryImageToMeshFilterType::New();
-  convert->SetThresholdValue(m_ThresholdValue);
-  convert->SetInput(m_Input);
-  convert->Update();
-  vtkPolyData* mesh = convert->GetOutputMesh();
-  if (GetVerboseFlag()) {
-    std::cout << "Mesh has " << mesh->GetNumberOfLines() << " lines." << std::endl;
+  std::vector<vtkSmartPointer<vtkPolyData> > meshes;
+  std::vector<std::string> m_ROINames;
+  meshes.resize(m);
+  m_ROINames.resize(m);
+  for(unsigned int i=0; i<m; i++) {
+    
+    // read image
+    //    typedef float PixelType;
+    //typedef itk::Image<PixelType, 3> ImageType;
+    ImagePointer input = clitk::readImage<ImageType>(m_InputFilenames[i], false);
+
+    std::ostringstream oss;
+    oss << vtksys::SystemTools::
+      GetFilenameName(vtksys::SystemTools::GetFilenameWithoutLastExtension(m_InputFilenames[i]));
+    std::string name = oss.str();
+    m_ROINames[i] = name;
+    
+    // convert to mesh
+    typedef clitk::BinaryImageToMeshFilter<ImageType> BinaryImageToMeshFilterType;
+    typename BinaryImageToMeshFilterType::Pointer convert = BinaryImageToMeshFilterType::New();
+    convert->SetThresholdValue(m_ThresholdValue);
+    convert->SetInput(input);
+    convert->Update();
+    meshes[i] = convert->GetOutputMesh();
+    if (GetVerboseFlag()) {
+      std::cout << "Mesh has " << meshes[i]->GetNumberOfLines() << " lines." << std::endl;
+    }
+    
+    /*
+    // debug mesh write  FIXME
+    vtkSmartPointer<vtkPolyDataWriter> wr = vtkSmartPointer<vtkPolyDataWriter>::New();
+    wr->SetInputConnection(convert->GetOutputPort()); //psurface->GetOutputPort()
+    wr->SetFileName("bidon.obj");
+    wr->Update();
+    wr->Write();
+    */
   }
-
+    
   // Copy previous contours
-  for (unsigned int i = 0; i < numMasks-1; ++i) {
+  for (unsigned int i = 0; i < numMasks-m; ++i) {
     writer->SetInput(i, reader->GetOutput(i));
     std::string theString = reader->GetRTStructSetProperties()->GetStructureSetROIName(i);
     roiNames->InsertValue(i, theString);
@@ -149,13 +181,14 @@ void clitk::Image2DicomRTStructFilter<PixelType>::Update()
     roiTypes->InsertValue(i, theString);
   }  
 
-  // Add new one
-  int last = numMasks-1;
-  writer->SetInput(last, mesh);
-  roiNames->InsertValue(last, m_ROIName);
-  roiAlgorithms->InsertValue(last, "CLITK_CREATED");
-  roiTypes->InsertValue(last, m_ROIType);
-
+  // Add new ones
+  for (unsigned int i = numMasks-m; i < numMasks; ++i) {
+    writer->SetInput(i, meshes[i-numMasks+m]);
+    roiNames->InsertValue(i, m_ROINames[i-numMasks+m]);
+    roiAlgorithms->InsertValue(i, "CLITK_CREATED");
+    roiTypes->InsertValue(i, m_ROIType);
+  }
+    
   /*
   //  Visu DEBUG
   vtkPolyDataMapper *cubeMapper = vtkPolyDataMapper::New();
index 264eb05c6bdba56199f07081a43efe8969307a3f..a82b0ec539b158fd55d945b2c3e294acfb1173ba 100644 (file)
@@ -27,19 +27,20 @@ int main(int argc, char * argv[]) {
   // Init command line
   GGO(clitkImage2DicomRTStruct, args_info);
 
-  // Read initial 3D image
-  typedef float PixelType;
-  typedef itk::Image<PixelType, 3> ImageType;
-  ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
+  // Set initial 3D image filenames
+  std::vector<std::string> filenames;
+  for(unsigned int i=0; i< args_info.input_given; i++)
+    filenames.push_back(args_info.input_arg[i]);
 
   // Create a filter to convert image into dicomRTStruct and write to disk
+  typedef float PixelType;
   clitk::Image2DicomRTStructFilter<PixelType> filter;
   filter.SetVerboseFlag(args_info.verbose_flag);
-  filter.SetInput(input);
+  filter.SetInputFilenames(filenames);
   filter.SetDicomFolder(args_info.dicom_arg);
   filter.SetStructureSetFilename(args_info.rtstruct_arg);
   filter.SetOutputFilename(args_info.output_arg);
-  filter.SetROIName(args_info.roiname_arg, args_info.roitype_arg);
+  filter.SetROIType(args_info.roitype_arg);
   filter.SetThresholdValue(args_info.threshold_arg);
   filter.Update();
 
index 928d11b5ed4ca205abf494253d62f7a3d6981b45..70f85b28daaea76ac94fa711ca13951f1fa05c67 100644 (file)
@@ -5,12 +5,11 @@ version "Add a (binary) image inside a DICOM RT Structure Set (contours)"
 option "config"                 - "Config file"                     string     no
 option "verbose"         v "Verbose"                        flag       off
 
-option "input"          i "Input image file (binary image) to be converted into contours"  string      yes
+option "input"          i "Input image file (binary image) to be converted into contours"  string multiple yes
 option "rtstruct"       r "Input rt struct"                  string    yes
 option "dicom"          d "Input folder where the initial dicom ct is"                 string  yes
 option "output"                 o "Output DicomRT filename"          string    yes
 
 option "threshold"       t "Threshold for binary image"                         float   no default = "0.5"
-option "roiname"        - "Name of the roi added into the rt-struct"           string  yes
 option "roitype"        - "Name of the type of roi added into the rt-struct"   string  no default = "ORGAN"