1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __elxElastixMain_h
#define __elxElastixMain_h
#include "elxComponentDatabase.h"
#include "elxComponentLoader.h"
#include "elxElastixBase.h"
#include "itkObject.h"
#include <iostream>
#include <fstream>
#include "itkParameterMapInterface.h"
#ifdef ELASTIX_USE_OPENCL
#include "itkOpenCLContext.h"
#endif
namespace elastix
{
///
/// ********************** Global Functions **********************
///
/// NB: not part of the ElastixMain class.
///
/**
* function xoutSetup
* Configure the xl::xout variable, which has to be used for
* for writing messages. The function adds some default fields,
* such as "warning", "error", "standard", "logonly" and "coutonly",
* and it sets the outputs to std::cout and/or a logfile.
*
* The method takes a logfile name as its input argument.
* It returns 0 if everything went ok. 1 otherwise.
*/
extern int xoutSetup( const char * logfilename, bool setupLogging, bool setupCout );
/**
* \class ElastixMain
* \brief A class with all functionality to configure elastix.
*
* The ElastixMain initializes the MyConfiguration class with the
* parameters and commandline arguments. After this, the class loads
* and creates all components and sets them in ElastixTemplate.
*
* \parameter FixedImageDimension: the dimension of the fixed image. \n
* example: <tt>(FixedImageDimension 2)</tt>\n
* \parameter MovingImageDimension: the dimension of the fixed image. \n
* example: <tt>(MovingImageDimension 2)</tt>\n
* \parameter FixedInternalImagePixelType: the pixel type of the internal
* fixed image representation. The fixed image is automatically converted
* to this type.\n
* example: <tt>(FixedInternalImagePixelType "float")</tt>\n
* Default/recommended: "float"\n
* \parameter MovingInternalImagePixelType: the pixel type of the internal
* moving image representation. The moving image is automatically converted
* to this type.\n
* example: <tt>(MovingInternalImagePixelType "float")</tt>\n
* Default/recommended: "float"\n
*
* \transformparameter FixedImageDimension: the dimension of the fixed image. \n
* example: <tt>(FixedImageDimension 2)</tt>\n
* \transformparameter MovingImageDimension: the dimension of the fixed image. \n
* example: <tt>(MovingImageDimension 2)</tt>\n
* \transformparameter FixedInternalImagePixelType: the pixel type of the internal
* fixed image representation. The fixed image is automatically converted
* to this type.\n
* example: <tt>(FixedInternalImagePixelType "float")</tt>\n
* Default/recommended: "float"\n
* \transformparameter MovingInternalImagePixelType: the pixel type of the internal
* moving image representation. The moving image is automatically converted
* to this type.\n
* example: <tt>(MovingInternalImagePixelType "float")</tt>\n
* Default/recommended: "float"\n
*
* \ingroup Kernel
*/
class ElastixMain : public itk::Object
{
public:
/** Standard itk. */
typedef ElastixMain Self;
typedef itk::Object Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro( Self );
/** Run-time type information (and related methods). */
itkTypeMacro( ElastixMain, Object );
/** Typedef's.*/
/** ITK base objects. */
typedef itk::Object ObjectType;
typedef ObjectType::Pointer ObjectPointer;
typedef itk::DataObject DataObjectType;
typedef DataObjectType::Pointer DataObjectPointer;
/** elastix components. */
typedef ElastixBase ElastixBaseType;
typedef ElastixBase::ConfigurationType ConfigurationType;
typedef ConfigurationType::CommandLineArgumentMapType ArgumentMapType;
typedef ConfigurationType::Pointer ConfigurationPointer;
typedef ElastixBase::ObjectContainerType ObjectContainerType;
typedef ElastixBase::DataObjectContainerType DataObjectContainerType;
typedef ElastixBase::ObjectContainerPointer ObjectContainerPointer;
typedef ElastixBase::DataObjectContainerPointer DataObjectContainerPointer;
typedef ElastixBase::FlatDirectionCosinesType FlatDirectionCosinesType;
/** Typedefs for the database that holds pointers to New() functions.
* Those functions are used to instantiate components, such as the metric etc.
*/
typedef ComponentDatabase ComponentDatabaseType;
typedef ComponentDatabaseType::Pointer ComponentDatabasePointer;
typedef ComponentDatabaseType::PtrToCreator PtrToCreator;
typedef ComponentDatabaseType::ComponentDescriptionType ComponentDescriptionType;
typedef ComponentDatabaseType::PixelTypeDescriptionType PixelTypeDescriptionType;
typedef ComponentDatabaseType::ImageDimensionType ImageDimensionType;
typedef ComponentDatabaseType::IndexType DBIndexType;
/** Typedef for class that populates a ComponentDatabase. */
typedef ComponentLoader ComponentLoaderType;
typedef ComponentLoaderType::Pointer ComponentLoaderPointer;
/** Typedef that is used in the elastix dll version. */
typedef itk::ParameterMapInterface::ParameterMapType ParameterMapType;
/** Set/Get functions for the description of the image type. */
itkSetMacro( FixedImagePixelType, PixelTypeDescriptionType );
itkSetMacro( MovingImagePixelType, PixelTypeDescriptionType );
itkSetMacro( FixedImageDimension, ImageDimensionType );
itkSetMacro( MovingImageDimension, ImageDimensionType );
itkGetMacro( FixedImagePixelType, PixelTypeDescriptionType );
itkGetMacro( MovingImagePixelType, PixelTypeDescriptionType );
itkGetMacro( FixedImageDimension, ImageDimensionType );
itkGetMacro( MovingImageDimension, ImageDimensionType );
/** Set/Get functions for the fixed and moving images
* (if these are not used, elastix tries to read them from disk,
* according to the command line parameters).
*/
itkSetObjectMacro( FixedImageContainer, DataObjectContainerType );
itkSetObjectMacro( MovingImageContainer, DataObjectContainerType );
itkGetObjectMacro( FixedImageContainer, DataObjectContainerType );
itkGetObjectMacro( MovingImageContainer, DataObjectContainerType );
/** Set/Get functions for the fixed and moving masks
* (if these are not used, elastix tries to read them from disk,
* according to the command line parameters).
*/
itkSetObjectMacro( FixedMaskContainer, DataObjectContainerType );
itkSetObjectMacro( MovingMaskContainer, DataObjectContainerType );
itkGetObjectMacro( FixedMaskContainer, DataObjectContainerType );
itkGetObjectMacro( MovingMaskContainer, DataObjectContainerType );
/** Set/Get functions for the result images
* (if these are not used, elastix tries to read them from disk,
* according to the command line parameters).
*/
itkSetObjectMacro( ResultImageContainer, DataObjectContainerType );
itkGetObjectMacro( ResultImageContainer, DataObjectContainerType );
itkSetObjectMacro( ResultDeformationFieldContainer, DataObjectContainerType );
itkGetObjectMacro( ResultDeformationFieldContainer, DataObjectContainerType );
/** Set/Get the configuration object. */
itkSetObjectMacro( Configuration, ConfigurationType );
itkGetObjectMacro( Configuration, ConfigurationType );
/** Functions to get pointers to the elastix components.
* The components are returned as Object::Pointer.
* Before calling this functions, call run().
*/
itkGetObjectMacro( Elastix, ObjectType );
/** Convenience function that returns the elastix component as
* a pointer to an ElastixBaseType. Use only after having called run()!
*/
virtual ElastixBaseType * GetElastixBase( void ) const;
/** Get the final transform (the result of running elastix).
* You may pass this as an InitialTransform in an other instantiation
* of ElastixMain.
* Only valid after calling Run()!
*/
itkGetObjectMacro( FinalTransform, ObjectType );
/** Set/Get the initial transform
* the type is ObjectType, but the pointer should actually point
* to an itk::Transform type (or inherited from that one).
*/
itkSetObjectMacro( InitialTransform, ObjectType );
itkGetObjectMacro( InitialTransform, ObjectType );
/** Set/Get the original fixed image direction as a flat array
* (d11 d21 d31 d21 d22 etc ) */
virtual void SetOriginalFixedImageDirectionFlat(
const FlatDirectionCosinesType & arg );
virtual const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat( void ) const;
/** Get and Set the elastix level. */
void SetElastixLevel( unsigned int level );
unsigned int GetElastixLevel( void );
/** Get and Set the total number of elastix levels. */
void SetTotalNumberOfElastixLevels( unsigned int levels );
unsigned int GetTotalNumberOfElastixLevels( void );
/** Returns the Index that is used in elx::ComponentDatabase. */
itkGetConstMacro( DBIndex, DBIndexType );
/** Enter the command line parameters, which were given by the user,
* if elastix.exe is used to do a registration.
* The Configuration object will be initialized in this way.
*/
virtual void EnterCommandLineArguments( ArgumentMapType & argmap );
virtual void EnterCommandLineArguments( ArgumentMapType & argmap,
ParameterMapType & inputMap );
// Version used when elastix is used as a library.
virtual void EnterCommandLineArguments( ArgumentMapType & argmap,
std::vector< ParameterMapType > & inputMaps );
/** Start the registration
* run() without command line parameters; it assumes that
* EnterCommandLineParameters has been invoked already, or that
* m_Configuration is initialized in a different way.
*/
virtual int Run( void );
/** Start the registration
* this version of 'run' first calls this->EnterCommandLineParameters(argc,argv)
* and then calls run().
*/
virtual int Run( ArgumentMapType & argmap );
virtual int Run( ArgumentMapType & argmap, ParameterMapType & inputMap );
/** Set process priority, which is read from the command line arguments.
* Syntax:
* -priority \<high, belownormal\>
*/
virtual void SetProcessPriority( void ) const;
/** Set maximum number of threads, which is read from the command line arguments.
* Syntax:
* -threads \<int\>
*/
virtual void SetMaximumNumberOfThreads( void ) const;
/** Functions to get/set the ComponentDatabase. */
static ComponentDatabase * GetComponentDatabase( void )
{
return s_CDB.GetPointer();
}
static void SetComponentDatabase( ComponentDatabase * arg )
{
if( s_CDB != arg )
{
s_CDB = arg;
}
}
/** GetTransformParametersMap */
virtual ParameterMapType GetTransformParametersMap( void ) const;
static void UnloadComponents( void );
protected:
ElastixMain();
virtual ~ElastixMain();
/** A pointer to elastix as an itk::object. In run() this
* pointer will be assigned to an ElastixTemplate<>.
*/
ObjectPointer m_Elastix;
/** The configuration object, containing the parameters and command-line arguments. */
ConfigurationPointer m_Configuration;
/** A vector of configuration objects, needed when transformix is used as library. */
std::vector< ConfigurationPointer > m_Configurations;
/** Description of the ImageTypes. */
PixelTypeDescriptionType m_FixedImagePixelType;
ImageDimensionType m_FixedImageDimension;
PixelTypeDescriptionType m_MovingImagePixelType;
ImageDimensionType m_MovingImageDimension;
DBIndexType m_DBIndex;
/** The images and masks. */
DataObjectContainerPointer m_FixedImageContainer;
DataObjectContainerPointer m_MovingImageContainer;
DataObjectContainerPointer m_FixedMaskContainer;
DataObjectContainerPointer m_MovingMaskContainer;
DataObjectContainerPointer m_ResultImageContainer;
DataObjectContainerPointer m_ResultDeformationFieldContainer;
/** A transform that is the result of registration. */
ObjectPointer m_FinalTransform;
/** The initial transform. */
ObjectPointer m_InitialTransform;
/** Transformation parameters map containing parameters that is the
* result of registration.
*/
ParameterMapType m_TransformParametersMap;
FlatDirectionCosinesType m_OriginalFixedImageDirection;
static ComponentDatabasePointer s_CDB;
static ComponentLoaderPointer s_ComponentLoader;
virtual int LoadComponents( void );
/** InitDBIndex sets m_DBIndex by asking the ImageTypes
* from the Configuration object and obtaining the corresponding
* DB index from the ComponentDatabase.
*/
virtual int InitDBIndex( void );
/** Create a component. Make sure InitDBIndex has been called before.
* The input is a string, e.g. "MattesMutualInformation".
*/
virtual ObjectPointer CreateComponent( const ComponentDescriptionType & name );
/** Create components. Reads from the configuration object (using the provided key)
* the names of the components to create and store their instantiations in the
* provided ObjectContainer.
* The errorcode remains what it was if no error occurred. Otherwise it's set to 1.
* The 'key' is the entry inspected in the parameter file
* A component named 'defaultComponentName' is used when the key is not found
* in the parameter file. If "" is used, no default is assumed, and an error
* is given when the component was not specified. If the flag mandatoryComponent
* is set to false, no error is given, because the component may not be needed
* anyway.
*
* NB: this function should never be called with:
* ( !mandatoryComponent && defaultComponentName != "" ) == true
*
*/
virtual ObjectContainerPointer CreateComponents(
const ComponentDescriptionType & key,
const ComponentDescriptionType & defaultComponentName,
int & errorcode,
bool mandatoryComponent = true );
/** Helper function to obtain information from images on disk. */
void GetImageInformationFromFile( const std::string & filename,
ImageDimensionType & imageDimension ) const;
private:
ElastixMain( const Self & ); // purposely not implemented
void operator=( const Self & ); // purposely not implemented
};
} // end namespace elastix
#endif // end #ifndef __elxElastixMain_h
|