00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __elxConfiguration_H__
00016 #define __elxConfiguration_H__
00017
00018 #include "itkObject.h"
00019 #include "elxBaseComponent.h"
00020
00021 #include "itkParameterFileParser.h"
00022 #include "itkParameterMapInterface.h"
00023 #include <map>
00024 #include "xoutmain.h"
00025
00026
00027 namespace elastix
00028 {
00029
00048 class Configuration : public itk::Object, public BaseComponent
00049 {
00050 public:
00051
00053 typedef Configuration Self;
00054 typedef itk::Object Superclass1;
00055 typedef BaseComponent Superclass2;
00056 typedef itk::SmartPointer<Self> Pointer;
00057 typedef itk::SmartPointer<const Self> ConstPointer;
00058
00060 itkNewMacro( Self );
00061
00063 itkTypeMacro( Configuration, itk::Object );
00064
00066 typedef std::map<std::string, std::string> CommandLineArgumentMapType;
00067 typedef CommandLineArgumentMapType::value_type CommandLineEntryType;
00068
00070 typedef itk::ParameterFileParser ParameterFileParserType;
00071 typedef ParameterFileParserType::Pointer ParameterFileParserPointer;
00072 typedef itk::ParameterMapInterface ParameterMapInterfaceType;
00073 typedef ParameterMapInterfaceType::Pointer ParameterMapInterfacePointer;
00074
00076 const std::string GetCommandLineArgument( const std::string & key ) const;
00077 void SetCommandLineArgument( const std::string & key, const std::string & value );
00078
00080 itkGetStringMacro( ParameterFileName );
00081 itkSetStringMacro( ParameterFileName );
00082
00090 virtual int Initialize( const CommandLineArgumentMapType & _arg );
00091
00093 virtual bool IsInitialized( void ) const;
00094
00098 itkSetMacro( ElastixLevel, unsigned int );
00099 itkGetConstMacro( ElastixLevel, unsigned int );
00100
00102 itkSetMacro( TotalNumberOfElastixLevels, unsigned int );
00103 itkGetConstMacro( TotalNumberOfElastixLevels, unsigned int );
00104
00105
00106 virtual bool GetPrintErrorMessages( void )
00107 {
00108 return this->m_ParameterMapInterface->GetPrintErrorMessages();
00109 }
00110
00119 virtual int BeforeAll( void );
00120
00124 virtual int BeforeAllTransformix( void );
00125
00126
00130 std::size_t CountNumberOfParameterEntries(
00131 const std::string & parameterName ) const
00132 {
00133 return this->m_ParameterMapInterface->CountNumberOfParameterEntries(
00134 parameterName );
00135 }
00136
00138 template <class T>
00139 bool ReadParameter( T & parameterValue, const std::string & parameterName,
00140 const unsigned int entry_nr, const bool printThisErrorMessage )
00141 {
00142 std::string errorMessage = "";
00143 bool found = this->m_ParameterMapInterface->ReadParameter(
00144 parameterValue, parameterName, entry_nr,
00145 printThisErrorMessage, errorMessage );
00146 if ( errorMessage != "" )
00147 {
00148 xl::xout["error"] << errorMessage;
00149 }
00150
00151 return found;
00152 }
00153
00155 template <class T>
00156 bool ReadParameter( T & parameterValue, const std::string & parameterName,
00157 const unsigned int entry_nr )
00158 {
00159 std::string errorMessage = "";
00160 bool found = this->m_ParameterMapInterface->ReadParameter(
00161 parameterValue, parameterName, entry_nr, errorMessage );
00162 if ( errorMessage != "" )
00163 {
00164 xl::xout["error"] << errorMessage;
00165 }
00166
00167 return found;
00168 }
00169
00171 template <class T>
00172 bool ReadParameter( T & parameterValue, const std::string & parameterName,
00173 const std::string & prefix,
00174 const unsigned int entry_nr, const int default_entry_nr,
00175 const bool printThisErrorMessage ) const
00176 {
00177 std::string errorMessage = "";
00178 bool found = this->m_ParameterMapInterface->ReadParameter(
00179 parameterValue, parameterName, prefix, entry_nr, default_entry_nr,
00180 printThisErrorMessage, errorMessage );
00181 if ( errorMessage != "" )
00182 {
00183 xl::xout["error"] << errorMessage;
00184 }
00185
00186 return found;
00187 }
00188
00190 template <class T>
00191 bool ReadParameter( T & parameterValue, const std::string & parameterName,
00192 const std::string & prefix,
00193 const unsigned int entry_nr, const int default_entry_nr ) const
00194 {
00195 std::string errorMessage = "";
00196 bool found = this->m_ParameterMapInterface->ReadParameter(
00197 parameterValue, parameterName, prefix, entry_nr, default_entry_nr,
00198 errorMessage );
00199 if ( errorMessage != "" )
00200 {
00201 xl::xout["error"] << errorMessage;
00202 }
00203
00204 return found;
00205 }
00206
00208 template <class T>
00209 bool ReadParameter( std::vector<T> & parameterValues,
00210 const std::string & parameterName,
00211 const unsigned int entry_nr_start,
00212 const unsigned int entry_nr_end,
00213 const bool printThisErrorMessage ) const
00214 {
00215 std::string errorMessage = "";
00216 bool found = this->m_ParameterMapInterface->ReadParameter(
00217 parameterValues, parameterName, entry_nr_start, entry_nr_end,
00218 printThisErrorMessage, errorMessage );
00219 if ( errorMessage != "" )
00220 {
00221 xl::xout["error"] << errorMessage;
00222 }
00223
00224 return found;
00225 }
00226
00227 protected:
00228
00229 Configuration();
00230 virtual ~Configuration() {};
00231
00236 virtual void PrintParameterFile( void ) const;
00237
00238 private:
00239
00240 Configuration( const Self& );
00241 void operator=( const Self& );
00242
00243 CommandLineArgumentMapType m_CommandLineArgumentMap;
00244 std::string m_ParameterFileName;
00245 ParameterFileParserPointer m_ParameterFileParser;
00246 ParameterMapInterfacePointer m_ParameterMapInterface;
00247
00248 bool m_IsInitialized;
00249 unsigned int m_ElastixLevel;
00250 unsigned int m_TotalNumberOfElastixLevels;
00251
00252 };
00253
00254
00255 }
00256
00257
00258 #endif // end #ifndef __elxConfiguration_H__
00259