]> Creatis software - clitk.git/blob - tools/clitkImageFillRegion.cxx
- ok Joel, you are righet, I forgot the file ...
[clitk.git] / tools / clitkImageFillRegion.cxx
1 /*------------------------------------------------------------------------=
2                                                                                 
3   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4   l'Image). All rights reserved. See Doc/License.txt or
5   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
6                                                                                 
7   This software is distributed WITHOUT ANY WARRANTY; without even
8   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9   PURPOSE.  See the above copyright notices for more information.
10                                                                              
11   ------------------------------------------------------------------------=*/
12
13 #ifndef CLITKIMAGEREGIONFILL_CXX
14 #define CLITKIMAGEREGIONFILL_CXX
15
16 /**
17    ------------------------------------------------=
18    * @file   clitkImageFillRegion.cxx
19    * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
20    * @date   23 Feb 2008 
21    ------------------------------------------------=*/
22
23 // clitk include
24 #include "clitkImageFillRegion_ggo.h"
25 #include "clitkImageFillRegionGenericFilter.h"
26 #include "clitkIO.h"
27
28 //--------------------------------------------------------------------
29 int main(int argc, char * argv[]) {
30
31   // Init command line
32   GGO(clitkImageFillRegion, args_info);
33   CLITK_INIT;
34
35   // Read image dimension
36   itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
37   unsigned int dim = header->GetNumberOfDimensions();
38   
39   // Main filter
40   clitk::ImageFillRegionGenericFilter filter;
41   filter.SetInputFilename(args_info.input_arg);
42   filter.SetOutputFilename(args_info.output_arg);
43   filter.SetFillPixelValue(args_info.value_arg);
44   
45   if(!args_info.ellips_flag && !args_info.rect_flag)
46     {
47       std::cerr << "ERROR : No type of region specified!"<< std::endl;
48       exit(-1);
49     }
50
51   if(args_info.ellips_flag && args_info.rect_flag)
52     {
53       std::cerr << "ERROR : Multiple types of regions specified!"<< std::endl;
54       exit(-1);
55     }
56
57   if(args_info.rect_flag)
58     {
59       if (args_info.size_given && args_info.start_given) {
60         // Check parameters
61         if (args_info.size_given != dim) {
62           std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
63           exit(-1);
64         }
65         if (args_info.start_given != dim) {
66           std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
67           exit(-1);
68         }
69         filter.SetRegion(args_info.size_arg, args_info.start_arg);
70       }
71       else {
72         std::cerr << "ERROR : both size and start should be given!"<< std::endl;
73         exit(-1);
74       }
75     }
76
77   if(args_info.ellips_flag)
78     {
79       
80       std::vector<double> c, a;
81       if (args_info.center_given) 
82         {
83           if (args_info.center_given != dim) 
84             {
85               std::cerr << "ERROR : image has " << dim << "dimensions, --center should have the same number of values." << std::endl;
86               exit(-1);
87             }
88           for(unsigned int i=0; i<dim; i++) 
89             c.push_back(args_info.center_arg[i]);
90         }
91       
92       if (args_info.axes_given) 
93         {
94           if (args_info.axes_given != dim) 
95             {
96               std::cerr << "ERROR : image has " << dim << "dimensions, --axes should have the same number of values." << std::endl;
97               exit(-1);
98             }
99           for(unsigned int i=0; i<dim; i++) 
100             a.push_back(args_info.axes_arg[i]);
101
102         }
103       else
104         for(unsigned int i=0; i<dim; i++) 
105           a.push_back(10.0);
106       
107       if ((args_info.center_given))
108         filter.SetSphericRegion(a,c);
109       else
110         filter.SetSphericRegion(a);
111     }
112   
113   filter.Update();
114
115   // this is the end my friend  
116   return 0;
117 } // end main
118
119 #endif //define CLITKIMAGEREGIONFILL