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 "elxlog.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 int
94
95 int
97
99 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 bool
115 {
116 return m_ParameterMapInterface->GetPrintErrorMessages();
117 }
118
119
128 int
129 BeforeAll() override;
130
134 int
136
140 std::size_t
141 CountNumberOfParameterEntries(const std::string & parameterName) const
142 {
143 return 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 produceWarningMessage) const
154 {
155 std::string warningMessage = "";
156 bool found = m_ParameterMapInterface->ReadParameter(
157 parameterValue, parameterName, entry_nr, produceWarningMessage, warningMessage);
158 if (!warningMessage.empty())
159 {
160 log::warn(warningMessage);
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 warningMessage = "";
173 bool found = m_ParameterMapInterface->ReadParameter(parameterValue, parameterName, entry_nr, warningMessage);
174 if (!warningMessage.empty())
175 {
176 log::warn(warningMessage);
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 produceWarningMessage) const
192 {
193 std::string warningMessage = "";
194 bool found = m_ParameterMapInterface->ReadParameter(
195 parameterValue, parameterName, prefix, entry_nr, default_entry_nr, produceWarningMessage, warningMessage);
196 if (!warningMessage.empty())
197 {
198 log::warn(warningMessage);
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 warningMessage = "";
215 bool found = m_ParameterMapInterface->ReadParameter(
216 parameterValue, parameterName, prefix, entry_nr, default_entry_nr, warningMessage);
217 if (!warningMessage.empty())
218 {
219 log::warn(warningMessage);
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 produceWarningMessage) const
262 {
263 auto parameterValue = defaultParameterValue;
264 (void)Self::ReadParameter<T>(parameterValue, parameterName, entry_nr, produceWarningMessage);
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 produceWarningMessage) const
276 {
277 return Self::RetrieveParameterValue(defaultParameterValue, parameterName, entry_nr, produceWarningMessage);
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 produceWarningMessage) const
289 {
290 std::string warningMessage = "";
291 bool found = m_ParameterMapInterface->ReadParameter(
292 parameterValues, parameterName, entry_nr_start, entry_nr_end, produceWarningMessage, warningMessage);
293 if (!warningMessage.empty())
294 {
295 log::warn(warningMessage);
296 }
297
298 return found;
299 }
300
301
302protected:
304 ~Configuration() override = default;
305
310 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)
std::string RetrieveParameterStringValue(const std::string &defaultParameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool produceWarningMessage) 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
itk::SmartPointer< const Self > ConstPointer
std::vector< std::string > GetValuesOfParameter(const std::string &parameterName) const
bool ReadParameter(T &parameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool produceWarningMessage) const
int Initialize(const CommandLineArgumentMapType &_arg)
int Initialize(const CommandLineArgumentMapType &_arg, const itk::ParameterFileParser::ParameterMapType &inputMap)
bool ReadParameter(std::vector< T > &parameterValues, const std::string &parameterName, const unsigned int entry_nr_start, const unsigned int entry_nr_end, const bool produceWarningMessage) const
bool GetPrintErrorMessages() const
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
bool ReadParameter(T &parameterValue, const std::string &parameterName, const std::string &prefix, const unsigned int entry_nr, const int default_entry_nr, const bool produceWarningMessage) const
int BeforeAll() override
bool HasParameter(const std::string &parameterName) const
unsigned int m_TotalNumberOfElastixLevels
const itk::ParameterFileParser::Pointer m_ParameterFileParser
T RetrieveParameterValue(const T &defaultParameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool produceWarningMessage) const
bool IsInitialized() const
void PrintParameterFile() const
CommandLineArgumentMapType m_CommandLineArgumentMap
CommandLineArgumentMapType::value_type CommandLineEntryType
~Configuration() override=default
const itk::ParameterMapInterface::Pointer m_ParameterMapInterface
std::string GetCommandLineArgument(const std::string &key) const
std::map< std::string, ParameterValuesType > ParameterMapType
static Pointer New()


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo