]> Creatis software - clitk.git/blob - tools/clitkImageFillRegion.cxx
Reformatted using new coding style
[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
36   // Init command line
37   GGO(clitkImageFillRegion, args_info);
38   CLITK_INIT;
39
40   // Read image dimension
41   itk::ImageIOBase::Pointer header = clitk::readImageHeader(args_info.input_arg);
42   unsigned int dim = header->GetNumberOfDimensions();
43
44   // Main filter
45   clitk::ImageFillRegionGenericFilter filter;
46   filter.SetInputFilename(args_info.input_arg);
47   filter.SetOutputFilename(args_info.output_arg);
48   filter.SetFillPixelValue(args_info.value_arg);
49
50   if(!args_info.ellips_flag && !args_info.rect_flag) {
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     std::cerr << "ERROR : Multiple types of regions specified!"<< std::endl;
57     exit(-1);
58   }
59
60   if(args_info.rect_flag) {
61     if (args_info.size_given && args_info.start_given) {
62       // Check parameters
63       if (args_info.size_given != dim) {
64         std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
65         exit(-1);
66       }
67       if (args_info.start_given != dim) {
68         std::cerr << "ERROR : image has " << dim << "dimensions, --size should have the same number of values." << std::endl;
69         exit(-1);
70       }
71       filter.SetRegion(args_info.size_arg, args_info.start_arg);
72     } else {
73       std::cerr << "ERROR : both size and start should be given!"<< std::endl;
74       exit(-1);
75     }
76   }
77
78   if(args_info.ellips_flag) {
79
80     std::vector<double> c, a;
81     if (args_info.center_given) {
82       if (args_info.center_given != dim) {
83         std::cerr << "ERROR : image has " << dim << "dimensions, --center should have the same number of values." << std::endl;
84         exit(-1);
85       }
86       for(unsigned int i=0; i<dim; i++)
87         c.push_back(args_info.center_arg[i]);
88     }
89
90     if (args_info.axes_given) {
91       if (args_info.axes_given != dim) {
92         std::cerr << "ERROR : image has " << dim << "dimensions, --axes should have the same number of values." << std::endl;
93         exit(-1);
94       }
95       for(unsigned int i=0; i<dim; i++)
96         a.push_back(args_info.axes_arg[i]);
97
98     } else
99       for(unsigned int i=0; i<dim; i++)
100         a.push_back(10.0);
101
102     if ((args_info.center_given))
103       filter.SetSphericRegion(a,c);
104     else
105       filter.SetSphericRegion(a);
106   }
107
108   filter.Update();
109
110   // this is the end my friend
111   return 0;
112 } // end main
113
114 #endif //define CLITKIMAGEREGIONFILL