]> Creatis software - clitk.git/blob - tools/clitkDicomRTStruct2Image.cxx
Precise information about RTStruct statistics in comments and output
[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.vtk_flag) {
44     filter.SetWriteMesh(true);
45   }
46   if (args_info.roiName_given) {
47     filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); 
48     filter.SetOutputImageFilename(args_info.output_arg);
49     filter.Update();  
50   }
51   else if (args_info.roi_given && args_info.roi_arg != -1) {
52     filter.SetROI(s->GetROIFromROINumber(args_info.roi_arg)); 
53     filter.SetOutputImageFilename(args_info.output_arg);
54     filter.Update();  
55   }
56   else {
57     clitk::DicomRT_StructureSet::ROIMapContainer* rois;
58     if (args_info.roiNameSubstr_given)
59       rois = s->GetROIsFromROINameSubstr(args_info.roiNameSubstr_arg);
60     else
61       rois = &s->GetROIs();
62     
63     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
64     if (rois) {
65       for(iter = rois->begin(); iter != rois->end(); iter++) {
66         clitk::DicomRT_ROI::Pointer roi = iter->second;
67         clitk::DicomRTStruct2ImageFilter filter;
68         std::string name = roi->GetName();
69         int num = roi->GetROINumber();
70         filter.SetROI(roi); 
71         filter.SetCropMaskEnabled(args_info.crop_flag);
72         filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
73         if (args_info.vtk_flag) {
74           filter.SetWriteMesh(true);
75         }
76         name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
77         std::string n;
78         if (args_info.mha_flag) {
79           n = std::string(args_info.output_arg).append
80             (clitk::toString(num)).append
81             ("_").append
82             (name).append
83             (".mha");
84         }
85         else {
86           n = std::string(args_info.output_arg).append
87             (clitk::toString(num)).append
88             ("_").append
89             (name).append
90             (".mhd");
91         }
92         if (args_info.verbose_flag) {
93           std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
94         }
95         filter.SetOutputImageFilename(n);
96         filter.Update();  
97       }
98     }
99   }
100 //   else {
101 //     clitk::DicomRT_StructureSet::ROIConstIteratorType iter;
102 //     for(iter = s->GetROIs().begin(); iter != s->GetROIs().end(); iter++) {
103 //       clitk::DicomRT_ROI::Pointer roi = iter->second;
104 //       // Create the filter
105 //       clitk::DicomRTStruct2ImageFilter filter;
106 //       filter.SetCropMaskEnabled(args_info.crop_flag);
107 //       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
108 //       std::string name = roi->GetName();
109 //       int num = roi->GetROINumber();
110 //       filter.SetROI(roi); 
111 //       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
112 //       std::string n = std::string(args_info.output_arg).append
113 //         (clitk::toString(num)).append
114 //         ("_").append
115 //         (name).append
116 //         (".mhd");
117 //       if (args_info.verbose_flag) {
118 //         std::cout << num << " " << roi->GetName() << " num=" << num << " : " << n << std::endl;
119 //       }
120 //       filter.SetOutputImageFilename(n);
121 //       filter.Update();
122 //     }
123
124     /*
125     for(unsigned int i=0; i<s->GetListOfROI().size(); i++) {
126       clitk::DicomRTStruct2ImageFilter filter;
127       filter.SetCropMaskEnabled(args_info.crop_flag);
128       filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
129       std::string name = s->GetListOfROI()[i]->GetName();
130       int num = s->GetListOfROI()[i]->GetROINumber();
131       filter.SetROI(s->GetListOfROI()[i]); 
132       name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
133       std::string n = std::string(args_info.output_arg).append
134         (clitk::toString(num)).append
135         ("_").append
136         (name).append
137         (".mhd");
138       if (args_info.verbose_flag) {
139         std::cout << i << " " << s->GetListOfROI()[i]->GetName() << " num=" << num << " : " << n << std::endl;
140       }
141       filter.SetOutputImageFilename(n);
142       filter.Update();  
143       }*/
144   //}
145
146   // This is the end my friend 
147   return 0;
148 }