]> Creatis software - STMS.git/blob - Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx
output 2D as png file
[STMS.git] / Lib / PrePostProcessing / itkSTMS_XMLFileParser.hxx
1 /*
2  #
3  #  File        : itkSTMS_XMLFileParser.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_XMLFileParser_HXX
61 #define itkSTMS_XMLFileParser_HXX
62
63 #include "itkSTMS_XMLFileParser.h"
64
65 namespace itkSTMS
66 {
67 itkSTMS_XMLFileParser::itkSTMS_XMLFileParser()
68 {
69     xmlParams.experimentPath     = "";
70     xmlParams.imageExtension     = "";
71     xmlParams.outputImageExtension = "";
72     xmlParams.outputClassExtension = "";
73     xmlParams.inputCommonRoot    = "";
74     xmlParams.inputFolder        = "";
75     xmlParams.maskImage          = "";
76     xmlParams.outputFolder       = "";
77     xmlParams.outputCommonRoot   = "";
78     xmlParams.outputCSV          = "";
79 }
80
81
82 void itkSTMS_XMLFileParser::Update()
83 {
84     parser = InputType::New();
85     parser->SetFileName( this->fileName );
86     parser->Update();
87
88     DomObject = parser->GetOutput();
89     if ( DomObject->GetName() != "STMS_ProcessInfo" )
90     {
91         std::cout << std::endl << std::endl <<  "Unrecognized input XML document! STMS_ProcessInfo expected" << std::endl << std::endl;
92         std::exit( EXIT_FAILURE );
93     }
94
95     // Read common parameters
96     xmlParams.experimentPath = DomObject->GetAttribute( "experimentPath" );
97     if ( xmlParams.experimentPath == "" )
98     {
99         std::cout << std::endl << std::endl <<  "experimentPath not found" << std::endl << std::endl;
100         std::exit( EXIT_FAILURE );
101     }
102
103     xmlParams.imageExtension = DomObject->GetAttribute( "imageExtension" );
104     if ( xmlParams.imageExtension == "" )
105     {
106         std::cout << std::endl << std::endl <<  "imageExtension not found" << std::endl << std::endl;
107         std::exit( EXIT_FAILURE );
108     }
109
110     xmlParams.outputImageExtension = DomObject->GetAttribute( "outputImageExtension" );
111     if ( xmlParams.outputImageExtension == "" )
112     {
113         std::cout << std::endl << std::endl <<  "outputImageExtension not set, using same as input (imageExtension) : "<< xmlParams.imageExtension << std::endl << std::endl;
114         xmlParams.outputImageExtension = xmlParams.imageExtension;
115     }
116
117     xmlParams.outputClassExtension = DomObject->GetAttribute( "outputClassExtension" );
118     if ( xmlParams.outputClassExtension == "" )
119     {
120         std::cout << std::endl << std::endl <<  "outputClassExtension not set, .nii (nifti) used by default" << std::endl << std::endl;
121         xmlParams.outputClassExtension = ".nii";
122     }
123
124
125     // Read input parameters
126     listInput = DomObject->GetChild( "listInput" );
127     xmlParams.inputFolder = listInput->GetAttribute( "inputFolder" );
128     if ( xmlParams.inputFolder == "" )
129     {
130         std::cout << std::endl << std::endl <<  "inputFolder not found" << std::endl << std::endl;
131         std::exit( EXIT_FAILURE );
132     }
133
134     xmlParams.inputCommonRoot = listInput->GetAttribute( "commonRoot" );
135     if ( xmlParams.inputCommonRoot == "" )
136     {
137         std::cout << std::endl << std::endl <<  "inputCommonRoot not found" << std::endl << std::endl;
138         std::exit( EXIT_FAILURE );
139     }
140
141     xmlParams.maskImage = listInput->GetAttribute( "maskImage" );
142     if ( xmlParams.maskImage == "" )
143     {
144         std::cout << std::endl << std::endl <<  "maskImage not found" << std::endl << std::endl;
145         std::exit( EXIT_FAILURE );
146     }
147
148     // Read output parameters
149     listOutput = DomObject->GetChild( "listOutput" );
150     xmlParams.outputFolder = listOutput->GetAttribute( "outputFolder" );
151     if ( xmlParams.outputFolder == "" )
152     {
153         std::cout << std::endl << std::endl <<  "outputFolder not found" << std::endl << std::endl;
154         std::exit( EXIT_FAILURE );
155     }
156
157     xmlParams.outputCommonRoot = listOutput->GetAttribute( "commonRoot" );
158     if ( xmlParams.outputCommonRoot == "" )
159     {
160         std::cout << std::endl << std::endl <<  "outputCommonRoot not found" << std::endl << std::endl;
161         std::exit( EXIT_FAILURE );
162     }
163
164     xmlParams.outputCSV = listOutput->GetAttribute( "outputCSV" );
165     if ( xmlParams.outputCSV == "" )
166     {
167         std::cout << std::endl << std::endl <<  "outputCSV not set: no CSV file will be created" << std::endl << std::endl;
168     }
169
170 }
171 } // end of namespace itkSTMS
172 #endif // itkSTMS_XMLFileParser_HXX