]> Creatis software - clitk.git/blob - tools/clitkDicomRTStruct2Image.cxx
clitkDicomRTStruct2Image: new features
[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
24 //--------------------------------------------------------------------
25 int main(int argc, char * argv[]) {
26
27   // Init command line
28   GGO(clitkDicomRTStruct2Image, args_info);
29
30   // Read and display information
31   clitk::DicomRT_StructureSet::Pointer s = clitk::DicomRT_StructureSet::New();
32   s->Read(args_info.input_arg);
33   if (args_info.verboseFile_flag) {
34     s->Print(std::cout);
35   }
36   
37   // New filter to convert to binary image
38   clitk::DicomRTStruct2ImageFilter filter;
39   filter.SetCropMaskEnabled(args_info.crop_flag);
40   filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
41   if (args_info.roiName_given) {
42     filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); 
43     filter.SetOutputImageFilename(args_info.output_arg);
44     filter.Update();  
45   }
46   else if (args_info.roi_given && args_info.roi_arg != -1) {
47     filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); 
48     filter.SetOutputImageFilename(args_info.output_arg);
49     filter.Update();  
50   }
51   else {
52     clitk::DicomRT_StructureSet::ROIMapContainer* rois;
53     if (args_info.roiNameSubstr_given)
54       rois = s->GetROIsFromROINameSubstr(args_info.roiNameSubstr_arg);
55     else
56       rois = &s->GetROIs();
57     
58     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
59     if (rois) {
60       for(iter = rois->begin(); iter != rois->end(); iter++) {
61         clitk::DicomRT_ROI::Pointer roi = iter->second;
62         clitk::DicomRTStruct2ImageFilter filter;
63         std::string name = roi->GetName();
64         int num = roi->GetROINumber();
65         filter.SetROI(roi); 
66         filter.SetCropMaskEnabled(args_info.crop_flag);
67         filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
68         name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
69         std::string n = std::string(args_info.output_arg).append
70           (clitk::toString(num)).append
71           ("_").append
72           (name).append
73           (".mhd");
74         if (args_info.verbose_flag) {
75           std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
76         }
77         filter.SetOutputImageFilename(n);
78         filter.Update();  
79       }
80     }
81   }
82 //   else {
83 //     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
84 //     for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) {
85 //       clitk::DicomRT_ROI::Pointer roi = iter->second;
86 //       // Create the filter
87 //       clitk::DicomRTStruct2ImageFilter filter;
88 //       filter.SetCropMaskEnabled(args_info.crop_flag);
89 //       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
90 //       std::string name = roi->GetName();
91 //       int num = roi->GetROINumber();
92 //       filter.SetROI(roi); 
93 //       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
94 //       std::string n = std::string(args_info.output_arg).append
95 //         (clitk::toString(num)).append
96 //         ("_").append
97 //         (name).append
98 //         (".mhd");
99 //       if (args_info.verbose_flag) {
100 //         std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
101 //       }
102 //       filter.SetOutputImageFilename(n);
103 //       filter.Update();
104 //     }
105
106     /*
107     for(unsigned int i=0; i<s->GetListOfROI().size(); i++) {
108       clitk::DicomRTStruct2ImageFilter filter;
109       filter.SetCropMaskEnabled(args_info.crop_flag);
110       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
111       std::string name = s->GetListOfROI()[i]->GetName();
112       int num = s->GetListOfROI()[i]->GetROINumber();
113       filter.SetROI(s->GetListOfROI()[i]); 
114       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
115       std::string n = std::string(args_info.output_arg).append
116         (clitk::toString(num)).append
117         ("_").append
118         (name).append
119         (".mhd");
120       if (args_info.verbose_flag) {
121         std::cout << i << " " << s->GetListOfROI()[i]->GetName() << " num=" << num << " : " << n << std::endl;
122       }
123       filter.SetOutputImageFilename(n);
124       filter.Update();  
125       }*/
126   //}
127
128   // This is the end my friend 
129   return 0;
130 }