]> Creatis software - STMS.git/blob - Lib/PrePostProcessing/itkSTMS_ArgumentsAnalysis_Spine.hxx
First Relase on creatis's public git!
[STMS.git] / Lib / PrePostProcessing / itkSTMS_ArgumentsAnalysis_Spine.hxx
1 /*
2  #
3  #  File        : itkSTMS_ArgumentsAnalysis_Spine.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_ArgumentsAnalysisSpine_HXX
61 #define itkSTMS_ArgumentsAnalysisSpine_HXX
62
63 #include<iostream>
64 #include <iomanip>
65 #include<string>
66 #include "itkSTMS_ArgumentsAnalysis_Spine.h"
67
68 namespace itkSTMS_Spine
69 {
70 itkSTMS_ArgumentsAnalysis::itkSTMS_ArgumentsAnalysis(int argc, char **argv)
71 {
72     readParams.numTimePoints  = 0;
73     readParams.epsilon        = 0.01;
74     readParams.maxIt          = 100 ;
75     readParams.spScales[0]    = 1.0;
76     readParams.spScales[1]    = 1.0;
77     readParams.spScales[2]    = 1.0;
78     readParams.rScale         = 1.0;
79     readParams.dim            = 3;
80     readParams.merge          = false;
81     readParams.help           = "";
82     readParams.mask           = "";
83     readParams.outFolder      = "";
84     readParams.isOk           = false;
85     readParams.imageExtension = ".nii.gz";
86
87     this->argc = argc;
88     this->argv = argv;
89 }
90
91 void itkSTMS_ArgumentsAnalysis::ParametersDisplay()
92 {
93     std::cout << std::endl <<
94                  std::setw(29) << std::left << "Image dimension"              << ": " << readParams.dim            << std::endl;
95     std::cout << std::setw(29) << std::left << "Mask image"                   << ": " << readParams.mask           << std::endl;
96     std::cout << std::setw(29) << std::left << "Output folder"                << ": " << readParams.outFolder      << std::endl;
97     std::cout << std::setw(29) << std::left << "Nb of time-points"            << ": " << readParams.numTimePoints  << std::endl;
98     std::cout << std::setw(29) << std::left << "X scale"                      << ": " << readParams.spScales[0]    << std::endl;
99     std::cout << std::setw(29) << std::left << "Y scale"                      << ": " << readParams.spScales[1]    << std::endl;
100     std::cout << std::setw(29) << std::left << "Z scale"                      << ": " << readParams.spScales[2]    << std::endl;
101     std::cout << std::setw(29) << std::left << "Range scale"                  << ": " << readParams.rScale         << std::endl;
102     std::cout << std::setw(29) << std::left << "Epsilon"                      << ": " << readParams.epsilon        << std::endl;
103     std::cout << std::setw(29) << std::left << "Maximum number of iterations" << ": " << readParams.maxIt          << std::endl;
104     std::cout << std::setw(29) << std::left << "Images extension"             << ": " << readParams.imageExtension << std::endl;
105     std::cout << std::setw(29) << std::left << "Samples merging"              << ": " << readParams.merge          << std::endl << std::endl;
106 }
107
108 void itkSTMS_ArgumentsAnalysis::ParametersAnalysisInfo()
109 {
110     std::cout << std::endl <<
111                  std::setw(17) << std::left << "--image         " << ": Path to an image of the sequence." << std::endl;
112     std::cout << std::setw(17) << std::left << "--mask"           << ": Binary mask image (optional)" << std::endl;
113     std::cout << std::setw(17) << std::left << "--outFolder"      << ": Output images folder" << std::endl;
114     std::cout << std::setw(17) << std::left << "--imageDimension" << ": Number of spatial components. (Default 3)" << std::endl;
115     std::cout << std::setw(17) << std::left << "--imageExtension" << ": Extension of the images. (Default .nii.gz)" << std::endl;
116     std::cout << std::setw(17) << std::left << "--xScale"         << ": Spatial scale used for the x axis. (Default 1.0)" << std::endl;
117     std::cout << std::setw(17) << std::left << "--yScale"         << ": Spatial scale used for the z axis. (Default 1.0)" << std::endl;
118     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;
119     std::cout << std::setw(17) << std::left << "--rScale"         << ": Range scale used to set the tolerance on the infinity norm. (Default 1.0)" << std::endl;
120     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;
121     std::cout << std::setw(17) << std::left << "--maxIt"          << ": Maximum number of iterations of the STM-S procedure. (Default 100)" << std::endl << std::endl;
122     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;
123     std::cout << std::setw(17) << std::left << "--help"           << ": Usage help" << std::endl << std::endl;
124 }
125
126
127 void itkSTMS_ArgumentsAnalysis::CheckProvidedParameters(){
128
129     if( !readParams.images.empty() & !readParams.outFolder.empty())
130         readParams.isOk = true;
131 }
132
133 void itkSTMS_ArgumentsAnalysis::Update()
134 {
135     int c;
136     bool first_it = true;
137     while (1)
138     {
139         /* getopt_long stores the option index here. */
140         int option_index = 0;
141
142         c = getopt_long (argc, argv, "d:l::o:i::x::y::z::r::e::m::g::h::q::",
143                          long_options, &option_index);
144
145         std::string str;
146
147         switch (c)
148         {
149         case 'd':
150             readParams.images.push_back( std::string(optarg) );
151             break;
152
153         case 'q':
154             readParams.imageExtension = std::string(optarg);
155             break;
156
157         case 'l':
158             readParams.mask = std::string(optarg);
159             break;
160
161         case 'o':
162             readParams.outFolder = std::string(optarg);
163             break;
164
165         case 'i':
166             str = std::string(optarg);
167             readParams.dim = (unsigned int)std::stoi( str );
168             break;
169
170         case 'x':
171             str = std::string(optarg);
172             readParams.spScales[0] = std::stof( str );
173             break;
174
175         case 'y':
176             str = std::string(optarg);
177             readParams.spScales[1] = std::stof( str );
178             break;
179
180         case 'z':
181             str = std::string(optarg);
182             readParams.spScales[2] = std::stof( str );
183             break;
184
185         case 'r':
186             str = std::string(optarg);
187             readParams.rScale = std::stof( str );
188             break;
189
190         case 'e':
191             str = std::string(optarg);
192             readParams.epsilon = std::stof( str );
193             break;
194
195         case 'm':
196            str = std::string(optarg);
197             readParams.maxIt = (unsigned int)std::stoi( str );
198             break;
199
200         case 'g':
201             readParams.merge = true;
202             break;
203
204         case 'h':
205             std::cout << std::endl << "Usage help:";
206             ParametersAnalysisInfo();
207             std::exit( EXIT_SUCCESS );
208             break;
209
210         case '?':
211             std::cout << std::endl << "Usage help:";
212             ParametersAnalysisInfo();
213             std::exit( EXIT_FAILURE );
214             break;
215         }
216
217         if( (c==-1) & first_it )
218         {
219             std::cout << std::endl << "Usage help:";
220             ParametersAnalysisInfo();
221             std::exit( EXIT_SUCCESS );
222         }
223
224         first_it = false;
225
226         /* Detect the end of the options. */
227         if ( (c==-1) & !first_it )
228         {
229             break;
230         }
231     }
232
233     CheckProvidedParameters();
234     if( readParams.isOk )
235     {
236         readParams.numTimePoints = (unsigned int)readParams.images.size();
237         ParametersDisplay();
238     }
239     else
240     {
241         std::cout << std::endl << "All required parameters are not provided";
242         ParametersAnalysisInfo();
243         std::exit( EXIT_FAILURE );
244     }
245 }
246
247 } // end of namespace itkSTMS
248 #endif // itkSTMS_ArgumentsAnalysisSpine_HXX