go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxConfiguration.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef elxConfiguration_h
19#define elxConfiguration_h
20
21#include "itkObject.h"
22#include "elxBaseComponent.h"
23
26#include <map>
27#include "xoutmain.h"
28
29namespace elastix
30{
31
51 : public itk::Object
52 , public BaseComponent
53{
54public:
56
59 using Superclass1 = itk::Object;
61 using Pointer = itk::SmartPointer<Self>;
62 using ConstPointer = itk::SmartPointer<const Self>;
63
65 itkNewMacro(Self);
66
68 itkTypeMacro(Configuration, itk::Object);
69
71 using CommandLineArgumentMapType = std::map<std::string, std::string>;
72 using CommandLineEntryType = CommandLineArgumentMapType::value_type;
73
75 std::string
76 GetCommandLineArgument(const std::string & key) const;
77
78 void
79 SetCommandLineArgument(const std::string & key, const std::string & value);
80
82 itkGetStringMacro(ParameterFileName);
83 itkSetStringMacro(ParameterFileName);
84
92 virtual int
94
95 virtual int
97
99 virtual bool
100 IsInitialized() const; // to elxconfigurationbase
101
105 itkSetMacro(ElastixLevel, unsigned int);
106 itkGetConstMacro(ElastixLevel, unsigned int);
107
109 itkSetMacro(TotalNumberOfElastixLevels, unsigned int);
110 itkGetConstMacro(TotalNumberOfElastixLevels, unsigned int);
111
112 /***/
113 virtual bool
115 {
116 return this->m_ParameterMapInterface->GetPrintErrorMessages();
117 }
118
119
128 int
129 BeforeAll() override;
130
134 virtual int
136
140 std::size_t
141 CountNumberOfParameterEntries(const std::string & parameterName) const
142 {
143 return this->m_ParameterMapInterface->CountNumberOfParameterEntries(parameterName);
144 }
145
146
148 template <class T>
149 bool
150 ReadParameter(T & parameterValue,
151 const std::string & parameterName,
152 const unsigned int entry_nr,
153 const bool printThisErrorMessage) const
154 {
155 std::string errorMessage = "";
156 bool found = this->m_ParameterMapInterface->ReadParameter(
157 parameterValue, parameterName, entry_nr, printThisErrorMessage, errorMessage);
158 if (!errorMessage.empty())
159 {
160 xl::xout["error"] << errorMessage;
161 }
162
163 return found;
164 }
165
166
168 template <class T>
169 bool
170 ReadParameter(T & parameterValue, const std::string & parameterName, const unsigned int entry_nr) const
171 {
172 std::string errorMessage = "";
173 bool found = this->m_ParameterMapInterface->ReadParameter(parameterValue, parameterName, entry_nr, errorMessage);
174 if (!errorMessage.empty())
175 {
176 xl::xout["error"] << errorMessage;
177 }
178
179 return found;
180 }
181
182
184 template <class T>
185 bool
186 ReadParameter(T & parameterValue,
187 const std::string & parameterName,
188 const std::string & prefix,
189 const unsigned int entry_nr,
190 const int default_entry_nr,
191 const bool printThisErrorMessage) const
192 {
193 std::string errorMessage = "";
194 bool found = this->m_ParameterMapInterface->ReadParameter(
195 parameterValue, parameterName, prefix, entry_nr, default_entry_nr, printThisErrorMessage, errorMessage);
196 if (!errorMessage.empty())
197 {
198 xl::xout["error"] << errorMessage;
199 }
200
201 return found;
202 }
203
204
206 template <class T>
207 bool
208 ReadParameter(T & parameterValue,
209 const std::string & parameterName,
210 const std::string & prefix,
211 const unsigned int entry_nr,
212 const int default_entry_nr) const
213 {
214 std::string errorMessage = "";
215 bool found = this->m_ParameterMapInterface->ReadParameter(
216 parameterValue, parameterName, prefix, entry_nr, default_entry_nr, errorMessage);
217 if (!errorMessage.empty())
218 {
219 xl::xout["error"] << errorMessage;
220 }
221
222 return found;
223 }
224
225
227 bool
228 HasParameter(const std::string & parameterName) const
229 {
230 return m_ParameterMapInterface->HasParameter(parameterName);
231 }
232
233
235 std::vector<std::string>
236 GetValuesOfParameter(const std::string & parameterName) const
237 {
238 return m_ParameterMapInterface->GetValues(parameterName);
239 }
240
241
247 template <typename T>
248 std::unique_ptr<std::vector<T>>
249 RetrieveValuesOfParameter(const std::string & parameterName) const
250 {
251 return m_ParameterMapInterface->RetrieveValues<T>(parameterName);
252 }
253
256 template <typename T>
257 T
258 RetrieveParameterValue(const T & defaultParameterValue,
259 const std::string & parameterName,
260 const unsigned int entry_nr,
261 const bool printThisErrorMessage) const
262 {
263 auto parameterValue = defaultParameterValue;
264 (void)Self::ReadParameter<T>(parameterValue, parameterName, entry_nr, printThisErrorMessage);
265 return parameterValue;
266 }
267
268
271 std::string
272 RetrieveParameterStringValue(const std::string & defaultParameterValue,
273 const std::string & parameterName,
274 const unsigned int entry_nr,
275 const bool printThisErrorMessage) const
276 {
277 return Self::RetrieveParameterValue(defaultParameterValue, parameterName, entry_nr, printThisErrorMessage);
278 }
279
280
282 template <class T>
283 bool
284 ReadParameter(std::vector<T> & parameterValues,
285 const std::string & parameterName,
286 const unsigned int entry_nr_start,
287 const unsigned int entry_nr_end,
288 const bool printThisErrorMessage) const
289 {
290 std::string errorMessage = "";
291 bool found = this->m_ParameterMapInterface->ReadParameter(
292 parameterValues, parameterName, entry_nr_start, entry_nr_end, printThisErrorMessage, errorMessage);
293 if (!errorMessage.empty())
294 {
295 xl::xout["error"] << errorMessage;
296 }
297
298 return found;
299 }
300
301
302protected:
304 ~Configuration() override = default;
305
310 virtual void
312
313private:
315 std::string m_ParameterFileName{};
318
319 bool m_IsInitialized{ false };
320 unsigned int m_ElastixLevel{ 0 };
322};
323
324} // end namespace elastix
325
326#endif // end #ifndef elxConfiguration_h
The BaseComponent class is a class that all elastix components should inherit from.
A class that deals with user given parameters and command line arguments.
void SetCommandLineArgument(const std::string &key, const std::string &value)
virtual int Initialize(const CommandLineArgumentMapType &_arg, const itk::ParameterFileParser::ParameterMapType &inputMap)
bool ReadParameter(T &parameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool printThisErrorMessage) const
bool ReadParameter(T &parameterValue, const std::string &parameterName, const std::string &prefix, const unsigned int entry_nr, const int default_entry_nr) const
ITK_DISALLOW_COPY_AND_MOVE(Configuration)
std::map< std::string, std::string > CommandLineArgumentMapType
itk::SmartPointer< Self > Pointer
virtual void PrintParameterFile() const
itk::SmartPointer< const Self > ConstPointer
std::vector< std::string > GetValuesOfParameter(const std::string &parameterName) const
itk::ParameterFileParser::Pointer m_ParameterFileParser
std::unique_ptr< std::vector< T > > RetrieveValuesOfParameter(const std::string &parameterName) const
bool ReadParameter(T &parameterValue, const std::string &parameterName, const unsigned int entry_nr) const
std::vcl_size_t CountNumberOfParameterEntries(const std::string &parameterName) const
T RetrieveParameterValue(const T &defaultParameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool printThisErrorMessage) const
int BeforeAll() override
virtual bool GetPrintErrorMessages()
bool HasParameter(const std::string &parameterName) const
unsigned int m_TotalNumberOfElastixLevels
itk::ParameterMapInterface::Pointer m_ParameterMapInterface
bool ReadParameter(std::vector< T > &parameterValues, const std::string &parameterName, const unsigned int entry_nr_start, const unsigned int entry_nr_end, const bool printThisErrorMessage) const
CommandLineArgumentMapType m_CommandLineArgumentMap
virtual int Initialize(const CommandLineArgumentMapType &_arg)
virtual bool IsInitialized() const
CommandLineArgumentMapType::value_type CommandLineEntryType
virtual int BeforeAllTransformix()
bool ReadParameter(T &parameterValue, const std::string &parameterName, const std::string &prefix, const unsigned int entry_nr, const int default_entry_nr, const bool printThisErrorMessage) const
~Configuration() override=default
std::string RetrieveParameterStringValue(const std::string &defaultParameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool printThisErrorMessage) const
std::string GetCommandLineArgument(const std::string &key) const
std::map< std::string, ParameterValuesType > ParameterMapType
static Pointer New()


Generated on Wed 12 Apr 2023 for elastix by doxygen 1.9.6 elastix logo