]> Creatis software - clitk.git/blob - tools/clitkImageFillRegion.cxx
removed headers
[clitk.git] / tools / clitkImageFillRegion.cxx
1 #ifndef CLITKIMAGEREGIONFILL_CXX
2 #define CLITKIMAGEREGIONFILL_CXX
3 /**
4    ------------------------------------------------=
5    * @file   clitkImageFillRegion.cxx
6    * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
7    * @date   23 Feb 2008 
8    ------------------------------------------------=*/
9
10 // clitk include
11 #include "clitkImageFillRegion_ggo.h"
12 #include "clitkImageFillRegionGenericFilter.h"
13 #include "clitkIO.h"
14
15 //--------------------------------------------------------------------
16 int main(int argc, char * argv[]) {
17
18   // Init command line
19   GGO(clitkImageFillRegion, args_info);
20   CLITK_INIT;
21
22   // Read image dimension
23   itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
24   unsigned int dim = header->GetNumberOfDimensions();
25   
26   // Main filter
27   clitk::ImageFillRegionGenericFilter filter;
28   filter.SetInputFilename(args_info.input_arg);
29   filter.SetOutputFilename(args_info.output_arg);
30   filter.SetFillPixelValue(args_info.value_arg);
31   
32   if(!args_info.ellips_flag && !args_info.rect_flag)
33     {
34       std::cerr << "ERROR : No type of region specified!"<< std::endl;
35       exit(-1);
36     }
37
38   if(args_info.ellips_flag && args_info.rect_flag)
39     {
40       std::cerr << "ERROR : Multiple types of regions specified!"<< std::endl;
41       exit(-1);
42     }
43
44   if(args_info.rect_flag)
45     {
46       if (args_info.size_given && args_info.start_given) {
47         // Check parameters
48         if (args_info.size_given != dim) {
49           std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
50           exit(-1);
51         }
52         if (args_info.start_given != dim) {
53           std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
54           exit(-1);
55         }
56         filter.SetRegion(args_info.size_arg, args_info.start_arg);
57       }
58       else {
59         std::cerr << "ERROR : both size and start should be given!"<< std::endl;
60         exit(-1);
61       }
62     }
63
64   if(args_info.ellips_flag)
65     {
66       
67       std::vector<double> c, a;
68       if (args_info.center_given) 
69         {
70           if (args_info.center_given != dim) 
71             {
72               std::cerr << "ERROR : image has " << dim << "dimensions, --center should have the same number of values." << std::endl;
73               exit(-1);
74             }
75           for(unsigned int i=0; i<dim; i++) 
76             c.push_back(args_info.center_arg[i]);
77         }
78       
79       if (args_info.axes_given) 
80         {
81           if (args_info.axes_given != dim) 
82             {
83               std::cerr << "ERROR : image has " << dim << "dimensions, --axes should have the same number of values." << std::endl;
84               exit(-1);
85             }
86           for(unsigned int i=0; i<dim; i++) 
87             a.push_back(args_info.axes_arg[i]);
88
89         }
90       else
91         for(unsigned int i=0; i<dim; i++) 
92           a.push_back(10.0);
93       
94       if ((args_info.center_given))
95         filter.SetSphericRegion(a,c);
96       else
97         filter.SetSphericRegion(a);
98     }
99   
100   filter.Update();
101
102   // this is the end my friend  
103   return 0;
104 } // end main
105
106 #endif //define CLITKIMAGEREGIONFILL