]> Creatis software - STMS.git/blob - Lib/PrePostProcessing/itkSTMS_ArgumentsAnalysis.hxx
First Relase on creatis's public git!
[STMS.git] / Lib / PrePostProcessing / itkSTMS_ArgumentsAnalysis.hxx
1 /*
2  #
3  #  File        : itkSTMS_ArgumentsAnalysis.hxx
4  #                ( C++ header file - STMS )
5  #
6  #  Description : STMS lib that implements the STMS filter and clustering.
7  #                This file is a part of the STMS Library project.
8  #                ( https://www.creatis.insa-lyon.fr/site7/fr/realisations )
9  #
10  #  [1] S. Mure, Grenier, T., Meier, S., Guttmann, R. G., et Benoit-Cattin, H.,
11  #       « Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification »,
12  #       Pattern Recognition Letters, vol. 68, Part 1, p. 48 - 55, 2015.
13  #
14  #  Copyright   : Thomas GRENIER - Simon MURE
15  #                ( https://www.creatis.insa-lyon.fr/~grenier/ )
16  #
17  #  License     : CeCILL C
18  #                ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.txt )
19  #
20  #  This software is governed by the CeCILL  license under French law and
21  #  abiding by the rules of distribution of free software.  You can  use,
22  #  modify and/ or redistribute the software under the terms of the CeCILL
23  #  license as circulated by CEA, CNRS and INRIA at the following URL
24  #  "http://www.cecill.info".
25  #
26  #  As a counterpart to the access to the source code and  rights to copy,
27  #  modify and redistribute granted by the license, users are provided only
28  #  with a limited warranty  and the software's author,  the holder of the
29  #  economic rights,  and the successive licensors  have only  limited
30  #  liability.
31  #
32  #  In this respect, the user's attention is drawn to the risks associated
33  #  with loading,  using,  modifying and/or developing or reproducing the
34  #  software by the user in light of its specific status of free software,
35  #  that may mean  that it is complicated to manipulate,  and  that  also
36  #  therefore means  that it is reserved for developers  and  experienced
37  #  professionals having in-depth computer knowledge. Users are therefore
38  #  encouraged to load and test the software's suitability as regards their
39  #  requirements in conditions enabling the security of their systems and/or
40  #  data to be ensured and,  more generally, to use and operate it in the
41  #  same conditions as regards security.
42  #
43  #  The fact that you are presently reading this means that you have had
44  #  knowledge of the CeCILL license and that you accept its terms.
45  #
46 */
47 /* Please don't forget to cite our work :
48   @article {MURE-15a,
49     title = {Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification},
50     journal = {Pattern Recognition Letters},
51     volume = {68, Part 1},
52     year = {2015},
53     pages = {48 - 55},
54     issn = {0167-8655},
55     doi = {http://dx.doi.org/10.1016/j.patrec.2015.07.021},
56     url = {http://www.sciencedirect.com/science/article/pii/S0167865515002305},
57     author = {S. Mure and T Grenier and Meier, S. and Guttmann, R.G. and H. Benoit-Cattin}
58 }
59 */
60 #ifndef itkSTMS_ArgumentsAnalysis_HXX
61 #define itkSTMS_ArgumentsAnalysis_HXX
62
63 #include <iomanip>
64 #include <string>
65 #include "itkSTMS_ArgumentsAnalysis.h"
66
67 namespace itkSTMS
68 {
69 itkSTMS_ArgumentsAnalysis::itkSTMS_ArgumentsAnalysis(int argc, char **argv)
70 {
71     readParams.expDescription = "";
72     readParams.numTimePoints  = 0;
73     readParams.startTimePoint = 1;
74     readParams.epsilon        = 0.01;
75     readParams.maxIt          = 100 ;
76     readParams.spScales[0]    = 1.0;
77     readParams.spScales[1]    = 1.0;
78     readParams.spScales[2]    = 1.0;
79     readParams.rScale         = 1.0;
80     readParams.dim            = 3;
81     readParams.merge          = false;
82     readParams.help           = "";
83     readParams.isOk           = false;
84
85     this->argc = argc;
86     this->argv = argv;
87 }
88
89 void itkSTMS_ArgumentsAnalysis::ParametersDisplay()
90 {
91     std::cout << std::endl <<
92                  std::setw(29) << std::left << "Experiment description"       << ": " << readParams.expDescription << std::endl;
93     std::cout << std::setw(29) << std::left << "Image dimension"              << ": " << readParams.dim            << std::endl;
94     std::cout << std::setw(29) << std::left << "Number of time-points"        << ": " << readParams.numTimePoints  << std::endl;
95     std::cout << std::setw(29) << std::left << "Staring time point"           << ": " << readParams.startTimePoint << std::endl;
96     std::cout << std::setw(29) << std::left << "X scale"                      << ": " << readParams.spScales[0]    << std::endl;
97     std::cout << std::setw(29) << std::left << "Y scale"                      << ": " << readParams.spScales[1]    << std::endl;
98     std::cout << std::setw(29) << std::left << "Z scale"                      << ": " << readParams.spScales[2]    << std::endl;
99     std::cout << std::setw(29) << std::left << "Range scale"                  << ": " << readParams.rScale         << std::endl;
100     std::cout << std::setw(29) << std::left << "Epsilon"                      << ": " << readParams.epsilon        << std::endl;
101     std::cout << std::setw(29) << std::left << "Maximum number of iterations" << ": " << readParams.maxIt          << std::endl;
102     std::cout << std::setw(29) << std::left << "Samples merging"              << ": " << readParams.merge          << std::endl << std::endl;
103 }
104
105 void itkSTMS_ArgumentsAnalysis::ParametersAnalysisInfo()
106 {
107     std::cout << std::endl <<
108                  std::setw(17) << std::left << "--expDescription" << ": Path to the XML file used to generate the image sequence." << std::endl;
109     std::cout << std::setw(17) << std::left << "--imageDimension" << ": Number of spatial components. (Default 3)" << std::endl;
110     std::cout << std::setw(17) << std::left << "--numTimePoints"  << ": Number of time-points." << std::endl;
111     std::cout << std::setw(17) << std::left << "--startTimePoint" << ": Starting time point (default is 0)" << std::endl;
112     std::cout << std::setw(17) << std::left << "--xScale"         << ": Spatial scale used for the x axis. (Default 1.0)" << std::endl;
113     std::cout << std::setw(17) << std::left << "--yScale"         << ": Spatial scale used for the z axis. (Default 1.0)" << std::endl;
114     std::cout << std::setw(17) << std::left << "--zScale"         << ": Spatial scale used for the z axis. Optional when using 2D images. (Default 1.0)" << std::endl;
115     std::cout << std::setw(17) << std::left << "--rScale"         << ": Range scale used to set the tolerance on the infinity norm. (Default 1.0)" << std::endl;
116     std::cout << std::setw(17) << std::left << "--epsilon"        << ": Stopping criteria of the STM-S procedure. Minimum global displacement of the samples. (Default 0.01)" << std::endl;
117     std::cout << std::setw(17) << std::left << "--maxIt"          << ": Maximum number of iterations of the STM-S procedure. (Default 100)" << std::endl << std::endl;
118     std::cout << std::setw(17) << std::left << "--merge"          << ": Specify if the samples are merged during the STMS procedure. No merging by default, no argument is needed after --merge." << std::endl << std::endl;
119     std::cout << std::setw(17) << std::left << "--help"           << ": Usage help" << std::endl << std::endl;
120 }
121
122
123 void itkSTMS_ArgumentsAnalysis::CheckProvidedParameters(){
124
125     if( readParams.expDescription != "")
126         readParams.isOk = true;
127 }
128
129 void itkSTMS_ArgumentsAnalysis::Update()
130 {
131     int c;
132     bool first_it = true;
133     while (1)
134     {
135         /* getopt_long stores the option index here. */
136         int option_index = 0;
137
138         c = getopt_long (argc, argv, "d:i::n:x::y::z::r::e::m::g::h::s::",
139                          long_options, &option_index);
140
141         std::string str;
142
143         switch (c)
144         {
145         case 'd':
146             readParams.expDescription = std::string(optarg);
147             break;
148
149         case 'i':
150             str = std::string(optarg);
151             readParams.dim = (unsigned int)std::stoi( str );
152             break;
153
154         case 'n':
155             str = std::string(optarg);
156             readParams.numTimePoints = (unsigned int)std::stoi( str );
157             break;
158
159        case 's':
160             str = std::string(optarg);
161             readParams.startTimePoint = (unsigned int)std::stoi( str );
162             break;
163
164         case 'x':
165             str = std::string(optarg);
166             readParams.spScales[0] = std::stof( str );
167             break;
168
169         case 'y':
170             str = std::string(optarg);
171             readParams.spScales[1] = std::stof( str );
172             break;
173
174         case 'z':
175             str = std::string(optarg);
176             readParams.spScales[2] = std::stof( str );
177             break;
178
179         case 'r':
180             str = std::string(optarg);
181             readParams.rScale = std::stof( str );
182             break;
183
184         case 'e':
185             str = std::string(optarg);
186             readParams.epsilon = std::stof( str );
187             break;
188
189         case 'm':
190            str = std::string(optarg);
191             readParams.maxIt = (unsigned int)std::stoi( str );
192             break;
193
194         case 'g':
195             readParams.merge = true;
196             break;
197
198         case 'h':
199             std::cout << std::endl << "Usage help:";
200             ParametersAnalysisInfo();
201             std::exit( EXIT_SUCCESS );
202             break;
203
204         case '?':
205             std::cout << std::endl << "Usage help:";
206             ParametersAnalysisInfo();
207             std::exit( EXIT_FAILURE );
208             break;
209         }
210
211         if( (c==-1) & first_it )
212         {
213             std::cout << std::endl << "Usage help:";
214             ParametersAnalysisInfo();
215             std::exit( EXIT_SUCCESS );
216         }
217
218         first_it = false;
219
220         /* Detect the end of the options. */
221         if ( (c==-1) & !first_it )
222         {
223             break;
224         }
225     }
226
227     CheckProvidedParameters();
228     if( readParams.isOk )
229     {
230         ParametersDisplay();
231     }
232     else
233     {
234         std::cout << std::endl << "All required parameters are not provided";
235         ParametersAnalysisInfo();
236         std::exit( EXIT_FAILURE );
237     }
238 }
239
240 } // end of namespace itkSTMS
241 #endif // itkSTMS_ArgumentsAnalysis_HXX