]> Creatis software - clitk.git/blob - tools/clitkDicomRTStruct2Image.cxx
04564a016f4e63a55f9a717378ee8bfa2cec9a66
[clitk.git] / tools / clitkDicomRTStruct2Image.cxx
1 /*=========================================================================
2   Program:         vv http://www.creatis.insa-lyon.fr/rio/vv
3   Main authors :   XX XX XX
4
5   Authors belongs to: 
6   - University of LYON           http://www.universite-lyon.fr/
7   - Léon Bérard cancer center    http://www.centreleonberard.fr
8   - CREATIS CNRS laboratory      http://www.creatis.insa-lyon.fr
9
10   This software is distributed WITHOUT ANY WARRANTY; without even
11   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12   PURPOSE.  See the copyright notices for more information.
13
14   It is distributed under dual licence
15   - BSD       http://www.opensource.org/licenses/bsd-license.php
16   - CeCILL-B  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17
18   =========================================================================*/
19
20 #include "clitkDicomRTStruct2ImageFilter.h"
21 #include "clitkDicomRT_StructureSet.h"
22 #include "clitkDicomRTStruct2Image_ggo.h"
23 #include "clitkIO.h"
24
25 //--------------------------------------------------------------------
26 int main(int argc, char * argv[]) {
27
28   // Init command line
29   GGO(clitkDicomRTStruct2Image, args_info);
30   CLITK_INIT;
31
32   // Read and display information
33   clitk::DicomRT_StructureSet::Pointer s = clitk::DicomRT_StructureSet::New();
34   s->Read(args_info.input_arg);
35   if (args_info.verboseFile_flag) {
36     s->Print(std::cout);
37   }
38   
39   // New filter to convert to binary image
40   clitk::DicomRTStruct2ImageFilter filter;
41   filter.SetCropMaskEnabled(args_info.crop_flag);
42   filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
43   if (args_info.roiName_given) {
44     filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); 
45     filter.SetOutputImageFilename(args_info.output_arg);
46     filter.Update();  
47   }
48   else if (args_info.roi_given && args_info.roi_arg != -1) {
49     filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); 
50     filter.SetOutputImageFilename(args_info.output_arg);
51     filter.Update();  
52   }
53   else {
54     clitk::DicomRT_StructureSet::ROIMapContainer* rois;
55     if (args_info.roiNameSubstr_given)
56       rois = s->GetROIsFromROINameSubstr(args_info.roiNameSubstr_arg);
57     else
58       rois = &s->GetROIs();
59     
60     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
61     if (rois) {
62       for(iter = rois->begin(); iter != rois->end(); iter++) {
63         clitk::DicomRT_ROI::Pointer roi = iter->second;
64         clitk::DicomRTStruct2ImageFilter filter;
65         std::string name = roi->GetName();
66         int num = roi->GetROINumber();
67         filter.SetROI(roi); 
68         filter.SetCropMaskEnabled(args_info.crop_flag);
69         filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
70         name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
71         std::string n = std::string(args_info.output_arg).append
72           (clitk::toString(num)).append
73           ("_").append
74           (name).append
75           (".mhd");
76         if (args_info.verbose_flag) {
77           std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
78         }
79         filter.SetOutputImageFilename(n);
80         filter.Update();  
81       }
82     }
83   }
84 //   else {
85 //     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
86 //     for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) {
87 //       clitk::DicomRT_ROI::Pointer roi = iter->second;
88 //       // Create the filter
89 //       clitk::DicomRTStruct2ImageFilter filter;
90 //       filter.SetCropMaskEnabled(args_info.crop_flag);
91 //       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
92 //       std::string name = roi->GetName();
93 //       int num = roi->GetROINumber();
94 //       filter.SetROI(roi); 
95 //       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
96 //       std::string n = std::string(args_info.output_arg).append
97 //         (clitk::toString(num)).append
98 //         ("_").append
99 //         (name).append
100 //         (".mhd");
101 //       if (args_info.verbose_flag) {
102 //         std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
103 //       }
104 //       filter.SetOutputImageFilename(n);
105 //       filter.Update();
106 //     }
107
108     /*
109     for(unsigned int i=0; i<s->GetListOfROI().size(); i++) {
110       clitk::DicomRTStruct2ImageFilter filter;
111       filter.SetCropMaskEnabled(args_info.crop_flag);
112       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
113       std::string name = s->GetListOfROI()[i]->GetName();
114       int num = s->GetListOfROI()[i]->GetROINumber();
115       filter.SetROI(s->GetListOfROI()[i]); 
116       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
117       std::string n = std::string(args_info.output_arg).append
118         (clitk::toString(num)).append
119         ("_").append
120         (name).append
121         (".mhd");
122       if (args_info.verbose_flag) {
123         std::cout << i << " " << s->GetListOfROI()[i]->GetName() << " num=" << num << " : " << n << std::endl;
124       }
125       filter.SetOutputImageFilename(n);
126       filter.Update();  
127       }*/
128   //}
129
130   // This is the end my friend 
131   return 0;
132 }