]> Creatis software - clitk.git/blob - tools/clitkImageFillRegion.cxx
500f1a6c9037b0d824ceb98375a75f86c7e3c92c
[clitk.git] / tools / clitkImageFillRegion.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef CLITKIMAGEREGIONFILL_CXX
19 #define CLITKIMAGEREGIONFILL_CXX
20 /**
21    ------------------------------------------------=
22    * @file   clitkImageFillRegion.cxx
23    * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24    * @date   23 Feb 2008 
25    ------------------------------------------------=*/
26
27 // clitk include
28 #include "clitkImageFillRegion_ggo.h"
29 #include "clitkImageFillRegionGenericFilter.h"
30 #include "clitkIO.h"
31
32 //--------------------------------------------------------------------
33 int main(int argc, char * argv[]) {
34
35   // Init command line
36   GGO(clitkImageFillRegion, args_info);
37   CLITK_INIT;
38
39   // Read image dimension
40   itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
41   unsigned int dim = header->GetNumberOfDimensions();
42   
43   // Main filter
44   clitk::ImageFillRegionGenericFilter filter;
45   filter.SetInputFilename(args_info.input_arg);
46   filter.SetOutputFilename(args_info.output_arg);
47   filter.SetFillPixelValue(args_info.value_arg);
48   
49   if(!args_info.ellips_flag && !args_info.rect_flag)
50     {
51       std::cerr << "ERROR : No type of region specified!"<< std::endl;
52       exit(-1);
53     }
54
55   if(args_info.ellips_flag && args_info.rect_flag)
56     {
57       std::cerr << "ERROR : Multiple types of regions specified!"<< std::endl;
58       exit(-1);
59     }
60
61   if(args_info.rect_flag)
62     {
63       if (args_info.size_given && args_info.start_given) {
64         // Check parameters
65         if (args_info.size_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         if (args_info.start_given != dim) {
70           std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
71           exit(-1);
72         }
73         filter.SetRegion(args_info.size_arg, args_info.start_arg);
74       }
75       else {
76         std::cerr << "ERROR : both size and start should be given!"<< std::endl;
77         exit(-1);
78       }
79     }
80
81   if(args_info.ellips_flag)
82     {
83       
84       std::vector<double> c, a;
85       if (args_info.center_given) 
86         {
87           if (args_info.center_given != dim) 
88             {
89               std::cerr << "ERROR : image has " << dim << "dimensions, --center should have the same number of values." << std::endl;
90               exit(-1);
91             }
92           for(unsigned int i=0; i<dim; i++) 
93             c.push_back(args_info.center_arg[i]);
94         }
95       
96       if (args_info.axes_given) 
97         {
98           if (args_info.axes_given != dim) 
99             {
100               std::cerr << "ERROR : image has " << dim << "dimensions, --axes should have the same number of values." << std::endl;
101               exit(-1);
102             }
103           for(unsigned int i=0; i<dim; i++) 
104             a.push_back(args_info.axes_arg[i]);
105
106         }
107       else
108         for(unsigned int i=0; i<dim; i++) 
109           a.push_back(10.0);
110       
111       if ((args_info.center_given))
112         filter.SetSphericRegion(a,c);
113       else
114         filter.SetSphericRegion(a);
115     }
116   
117   filter.Update();
118
119   // this is the end my friend  
120   return 0;
121 } // end main
122
123 #endif //define CLITKIMAGEREGIONFILL