go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxElastixBase.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 
28 #ifndef __elxElastixBase_h
29 #define __elxElastixBase_h
30 
31 #include "elxBaseComponent.h"
32 #include "elxComponentDatabase.h"
33 #include "elxConfiguration.h"
34 #include "itkObject.h"
35 #include "itkDataObject.h"
36 #include "elxMacro.h"
37 #include "xoutmain.h"
38 #include "itkVectorContainer.h"
39 #include "itkImageFileReader.h"
40 #include "itkChangeInformationImageFilter.h"
41 
42 #include <fstream>
43 #include <iomanip>
44 
51 #define elxGetObjectMacro( _name, _type ) \
52  virtual _type * Get##_name( void ) const \
53  { \
54  return this->m_##_name.GetPointer(); \
55  }
56 //end elxGetObjectMacro
57 
58 #define elxSetObjectMacro( _name, _type ) \
59  virtual void Set##_name( _type * _arg ) \
60  { \
61  if( this->m_##_name != _arg ) \
62  { \
63  this->m_##_name = _arg; \
64  this->GetAsITKBaseType()->Modified(); \
65  } \
66  }
67 //end elxSetObjectMacro
68 
70 #define elxGetNumberOfMacro( _name ) \
71  virtual unsigned int GetNumberOf##_name##s( void ) const \
72  { \
73  if( this->Get##_name##Container() != 0 ) \
74  { \
75  return this->Get##_name##Container()->Size(); \
76  } \
77  return 0; \
78  }
79 // end elxGetNumberOfMacro
80 
81 namespace elastix
82 {
144 {
145 public:
146 
148  typedef ElastixBase Self;
150 
154  typedef itk::Object ObjectType; //for the components
155  typedef ObjectType::Pointer ObjectPointer;
156  typedef itk::DataObject DataObjectType; //for the images
157  typedef DataObjectType::Pointer DataObjectPointer;
158  typedef itk::VectorContainer<
159  unsigned int, ObjectPointer > ObjectContainerType;
160  typedef ObjectContainerType::Pointer ObjectContainerPointer;
161  typedef itk::VectorContainer<
162  unsigned int, DataObjectPointer > DataObjectContainerType;
163  typedef DataObjectContainerType::Pointer DataObjectContainerPointer;
164  typedef itk::VectorContainer<
165  unsigned int, std::string > FileNameContainerType;
166  typedef FileNameContainerType::Pointer FileNameContainerPointer;
167 
172  typedef std::vector< double > FlatDirectionCosinesType;
173 
176 
180  typedef itk::Object ITKBaseType;
181 
183  virtual ITKBaseType * GetAsITKBaseType( void )
184  {
185  return dynamic_cast< ITKBaseType * >( this );
186  }
187 
188 
190  elxGetObjectMacro( Configuration, ConfigurationType );
191  elxSetObjectMacro( Configuration, ConfigurationType );
192 
194  virtual void SetDBIndex( DBIndexType _arg );
195 
196  virtual DBIndexType GetDBIndex( void )
197  {
198  return this->m_DBIndex;
199  }
200 
201 
206  elxGetObjectMacro( ComponentDatabase, ComponentDatabaseType );
207  elxSetObjectMacro( ComponentDatabase, ComponentDatabaseType );
208 
213  elxGetObjectMacro( RegistrationContainer, ObjectContainerType );
214  elxGetObjectMacro( FixedImagePyramidContainer, ObjectContainerType );
215  elxGetObjectMacro( MovingImagePyramidContainer, ObjectContainerType );
216  elxGetObjectMacro( InterpolatorContainer, ObjectContainerType );
217  elxGetObjectMacro( ImageSamplerContainer, ObjectContainerType );
218  elxGetObjectMacro( MetricContainer, ObjectContainerType );
219  elxGetObjectMacro( OptimizerContainer, ObjectContainerType );
220  elxGetObjectMacro( ResamplerContainer, ObjectContainerType );
221  elxGetObjectMacro( ResampleInterpolatorContainer, ObjectContainerType );
222  elxGetObjectMacro( TransformContainer, ObjectContainerType );
223 
228  elxSetObjectMacro( RegistrationContainer, ObjectContainerType );
229  elxSetObjectMacro( FixedImagePyramidContainer, ObjectContainerType );
230  elxSetObjectMacro( MovingImagePyramidContainer, ObjectContainerType );
231  elxSetObjectMacro( InterpolatorContainer, ObjectContainerType );
232  elxSetObjectMacro( ImageSamplerContainer, ObjectContainerType );
233  elxSetObjectMacro( MetricContainer, ObjectContainerType );
234  elxSetObjectMacro( OptimizerContainer, ObjectContainerType );
235  elxSetObjectMacro( ResamplerContainer, ObjectContainerType );
236  elxSetObjectMacro( ResampleInterpolatorContainer, ObjectContainerType );
237  elxSetObjectMacro( TransformContainer, ObjectContainerType );
238 
240  elxGetObjectMacro( FixedImageContainer, DataObjectContainerType );
241  elxGetObjectMacro( MovingImageContainer, DataObjectContainerType );
242  elxSetObjectMacro( FixedImageContainer, DataObjectContainerType );
243  elxSetObjectMacro( MovingImageContainer, DataObjectContainerType );
244 
246  elxGetObjectMacro( FixedMaskContainer, DataObjectContainerType );
247  elxGetObjectMacro( MovingMaskContainer, DataObjectContainerType );
248  elxSetObjectMacro( FixedMaskContainer, DataObjectContainerType );
249  elxSetObjectMacro( MovingMaskContainer, DataObjectContainerType );
250 
252  elxGetObjectMacro( ResultImageContainer, DataObjectContainerType );
253  elxSetObjectMacro( ResultImageContainer, DataObjectContainerType );
254 
258  elxGetObjectMacro( FixedImageFileNameContainer, FileNameContainerType );
259  elxGetObjectMacro( MovingImageFileNameContainer, FileNameContainerType );
260  elxSetObjectMacro( FixedImageFileNameContainer, FileNameContainerType );
261  elxSetObjectMacro( MovingImageFileNameContainer, FileNameContainerType );
262 
266  elxGetObjectMacro( FixedMaskFileNameContainer, FileNameContainerType );
267  elxGetObjectMacro( MovingMaskFileNameContainer, FileNameContainerType );
268  elxSetObjectMacro( FixedMaskFileNameContainer, FileNameContainerType );
269  elxSetObjectMacro( MovingMaskFileNameContainer, FileNameContainerType );
270 
272  elxGetNumberOfMacro( Registration );
273  elxGetNumberOfMacro( FixedImagePyramid );
274  elxGetNumberOfMacro( MovingImagePyramid );
275  elxGetNumberOfMacro( Interpolator );
276  elxGetNumberOfMacro( ImageSampler );
277  elxGetNumberOfMacro( Metric );
278  elxGetNumberOfMacro( Optimizer );
279  elxGetNumberOfMacro( Resampler );
280  elxGetNumberOfMacro( ResampleInterpolator );
281  elxGetNumberOfMacro( Transform );
282  elxGetNumberOfMacro( FixedImage );
283  elxGetNumberOfMacro( MovingImage );
284  elxGetNumberOfMacro( FixedImageFileName );
285  elxGetNumberOfMacro( MovingImageFileName );
286  elxGetNumberOfMacro( FixedMask );
287  elxGetNumberOfMacro( MovingMask );
288  elxGetNumberOfMacro( FixedMaskFileName );
289  elxGetNumberOfMacro( MovingMaskFileName );
290  elxGetNumberOfMacro( ResultImage );
291 
296  elxSetObjectMacro( InitialTransform, ObjectType );
297  elxGetObjectMacro( InitialTransform, ObjectType );
298 
305  elxSetObjectMacro( FinalTransform, ObjectType );
306  elxGetObjectMacro( FinalTransform, ObjectType );
307 
309  virtual int Run( void ) = 0;
310 
312  virtual int ApplyTransform( void ) = 0;
313 
317  virtual int BeforeAllBase( void );
318 
322  virtual int BeforeAllTransformixBase( void );
323 
327  virtual void BeforeRegistrationBase( void );
328 
329  virtual void AfterRegistrationBase( void );
330 
335  virtual int GetDefaultOutputPrecision( void ) const
336  {
337  return this->m_DefaultOutputPrecision;
338  }
339 
340 
344  virtual bool GetUseDirectionCosines( void ) const;
345 
349  const FlatDirectionCosinesType & arg );
350 
351  virtual const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat( void ) const;
352 
354  virtual void CreateTransformParametersMap( void ) = 0;
355 
357  virtual ParameterMapType GetTransformParametersMap( void ) const = 0;
358 
360  virtual void SetConfigurations( std::vector< ConfigurationPointer > & configurations ) = 0;
361 
362 protected:
363 
364  ElastixBase();
365  virtual ~ElastixBase() {}
366 
367  ConfigurationPointer m_Configuration;
368  DBIndexType m_DBIndex;
369  ComponentDatabasePointer m_ComponentDatabase;
370 
371  FlatDirectionCosinesType m_OriginalFixedImageDirection;
372 
385  template< class TImage >
387  {
388 public:
389 
390  typedef TImage ImageType;
391  typedef typename ImageType::Pointer ImagePointer;
392  typedef itk::ImageFileReader< ImageType > ImageReaderType;
393  typedef typename ImageReaderType::Pointer ImageReaderPointer;
394  typedef typename ImageType::DirectionType DirectionType;
395  typedef itk::ChangeInformationImageFilter< ImageType > ChangeInfoFilterType;
396  typedef typename ChangeInfoFilterType::Pointer ChangeInfoFilterPointer;
397 
398  static DataObjectContainerPointer GenerateImageContainer(
399  FileNameContainerType * fileNameContainer, const std::string & imageDescription,
400  bool useDirectionCosines, DirectionType * originalDirectionCosines = NULL )
401  {
402  DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
403 
405  for( unsigned int i = 0; i < fileNameContainer->Size(); ++i )
406  {
408  ImageReaderPointer imageReader = ImageReaderType::New();
409  imageReader->SetFileName( fileNameContainer->ElementAt( i ).c_str() );
410  ChangeInfoFilterPointer infoChanger = ChangeInfoFilterType::New();
411  DirectionType direction;
412  direction.SetIdentity();
413  infoChanger->SetOutputDirection( direction );
414  infoChanger->SetChangeDirection( !useDirectionCosines );
415  infoChanger->SetInput( imageReader->GetOutput() );
416 
418  try
419  {
420  infoChanger->Update();
421  }
422  catch( itk::ExceptionObject & excp )
423  {
425  std::string err_str = excp.GetDescription();
426  err_str += "\nError occurred while reading the image described as "
427  + imageDescription + ", with file name " + imageReader->GetFileName() + "\n";
428  excp.SetDescription( err_str );
430  throw excp;
431  }
432 
434  ImagePointer image = infoChanger->GetOutput();
435  imageContainer->CreateElementAt( i ) = image.GetPointer();
436 
438  if( originalDirectionCosines )
439  {
440  *originalDirectionCosines = imageReader->GetOutput()->GetDirection();
441  }
442 
443  } // end for i
444 
445  return imageContainer;
446 
447  } // end static method GenerateImageContainer
448 
449 
451  static DataObjectContainerPointer GenerateImageContainer( DataObjectPointer image )
452  {
454  DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
455 
457  imageContainer->CreateElementAt( 0 ) = image;
458 
460  return imageContainer;
461 
462  } // GenerateImageContainer()
463 
464 
467 
468  };
469 
471  {
472 public:
473 
475  static DataObjectContainerPointer GenerateImageContainer(
476  DataObjectPointer image )
477  {
478  unsigned int j = 0; //container with only one image for now
479 
481  DataObjectContainerPointer imageContainer = DataObjectContainerType::New();
482 
484  imageContainer->CreateElementAt( j ) = image;
485 
487  return imageContainer;
488  } // end GenerateImageContainer()
489 
490 
494  };
495 
496 private:
497 
498  ElastixBase( const Self & ); // purposely not implemented
499  void operator=( const Self & ); // purposely not implemented
500 
502 
504 
508  ObjectContainerPointer m_FixedImagePyramidContainer;
509  ObjectContainerPointer m_MovingImagePyramidContainer;
510  ObjectContainerPointer m_InterpolatorContainer;
511  ObjectContainerPointer m_ImageSamplerContainer;
512  ObjectContainerPointer m_MetricContainer;
513  ObjectContainerPointer m_OptimizerContainer;
514  ObjectContainerPointer m_RegistrationContainer;
515  ObjectContainerPointer m_ResamplerContainer;
516  ObjectContainerPointer m_ResampleInterpolatorContainer;
517  ObjectContainerPointer m_TransformContainer;
518 
520  DataObjectContainerPointer m_FixedImageContainer;
521  DataObjectContainerPointer m_MovingImageContainer;
522  DataObjectContainerPointer m_FixedMaskContainer;
523  DataObjectContainerPointer m_MovingMaskContainer;
524 
526  DataObjectContainerPointer m_ResultImageContainer;
527 
529  FileNameContainerPointer m_FixedImageFileNameContainer;
530  FileNameContainerPointer m_MovingImageFileNameContainer;
531  FileNameContainerPointer m_FixedMaskFileNameContainer;
532  FileNameContainerPointer m_MovingMaskFileNameContainer;
533 
535  ObjectPointer m_InitialTransform;
536  ObjectPointer m_FinalTransform;
537 
540 
548  FileNameContainerPointer GenerateFileNameContainer(
549  const std::string & optionkey,
550  int & errorcode,
551  bool printerrors,
552  bool printinfo ) const;
553 
554 };
555 
556 } // end namespace elastix
557 
558 #undef elxGetObjectMacro
559 #undef elxSetObjectMacro
560 #undef elxGetNumberOfMacro
561 
562 #endif // end #ifndef __elxElastixBase_h
elxSetObjectMacro(Configuration, ConfigurationType)
itk::ChangeInformationImageFilter< ImageType > ChangeInfoFilterType
static DataObjectContainerPointer GenerateImageContainer(DataObjectPointer image)
ObjectContainerPointer m_InterpolatorContainer
DataObjectContainerType::Pointer DataObjectContainerPointer
virtual DBIndexType GetDBIndex(void)
BaseComponent Superclass
static DataObjectContainerPointer GenerateImageContainer(DataObjectPointer image)
itk::VectorContainer< unsigned int, std::string > FileNameContainerType
virtual bool GetUseDirectionCosines(void) const
ComponentDatabase ComponentDatabaseType
ComponentDatabaseType::IndexType DBIndexType
xl::xoutrow_type m_IterationInfo
virtual void SetConfigurations(std::vector< ConfigurationPointer > &configurations)=0
Configuration ConfigurationType
DataObjectContainerPointer m_MovingImageContainer
ObjectContainerPointer m_MetricContainer
itk::SmartPointer< Self > Pointer
DataObjectContainerPointer m_ResultImageContainer
itk::DataObject DataObjectType
virtual int BeforeAllBase(void)
virtual void CreateTransformParametersMap(void)=0
FileNameContainerPointer m_MovingMaskFileNameContainer
The xoutrow class can easily generate tables.
Definition: xoutrow.h:42
The BaseComponent class is a class that all elastix components should inherit from.
ObjectContainerPointer m_OptimizerContainer
FileNameContainerPointer GenerateFileNameContainer(const std::string &optionkey, int &errorcode, bool printerrors, bool printinfo) const
std::vector< double > FlatDirectionCosinesType
itk::VectorContainer< unsigned int, ObjectPointer > ObjectContainerType
ObjectContainerPointer m_FixedImagePyramidContainer
ParameterFileParser::ParameterMapType ParameterMapType
virtual void AfterRegistrationBase(void)
ObjectContainerPointer m_TransformContainer
ObjectContainerPointer m_ImageSamplerContainer
elxGetNumberOfMacro(Registration)
elxGetObjectMacro(Configuration, ConfigurationType)
FileNameContainerType::Pointer FileNameContainerPointer
virtual ParameterMapType GetTransformParametersMap(void) const =0
virtual void SetOriginalFixedImageDirectionFlat(const FlatDirectionCosinesType &arg)
static DataObjectContainerPointer GenerateImageContainer(FileNameContainerType *fileNameContainer, const std::string &imageDescription, bool useDirectionCosines, DirectionType *originalDirectionCosines=NULL)
ObjectContainerPointer m_MovingImagePyramidContainer
virtual void SetDBIndex(DBIndexType _arg)
ChangeInfoFilterType::Pointer ChangeInfoFilterPointer
ComponentDatabaseType::Pointer ComponentDatabasePointer
ImageReaderType::Pointer ImageReaderPointer
itk::ParameterMapInterface::ParameterMapType ParameterMapType
DataObjectContainerPointer m_FixedMaskContainer
FlatDirectionCosinesType m_OriginalFixedImageDirection
itk::SmartPointer< Self > Pointer
virtual int BeforeAllTransformixBase(void)
FileNameContainerPointer m_FixedImageFileNameContainer
ObjectPointer m_InitialTransform
virtual int ApplyTransform(void)=0
ObjectContainerType::Pointer ObjectContainerPointer
void operator=(const Self &)
ObjectPointer m_FinalTransform
ConfigurationPointer m_Configuration
virtual const FlatDirectionCosinesType & GetOriginalFixedImageDirectionFlat(void) const
virtual int GetDefaultOutputPrecision(void) const
A class that deals with user given parameters and command line arguments.
FileNameContainerPointer m_MovingImageFileNameContainer
ObjectContainerPointer m_RegistrationContainer
DataObjectContainerPointer m_MovingMaskContainer
The ComponentDatabase class is a class that stores the New() functions of all components.
DataObjectType::Pointer DataObjectPointer
FileNameContainerPointer m_FixedMaskFileNameContainer
ObjectContainerPointer m_ResamplerContainer
ConfigurationType::Pointer ConfigurationPointer
itk::ImageFileReader< ImageType > ImageReaderType
ObjectContainerPointer m_ResampleInterpolatorContainer
itk::VectorContainer< unsigned int, DataObjectPointer > DataObjectContainerType
virtual void BeforeRegistrationBase(void)
ObjectType::Pointer ObjectPointer
This class creates an interface for elastix.
virtual int Run(void)=0
virtual ITKBaseType * GetAsITKBaseType(void)
ComponentDatabasePointer m_ComponentDatabase
DataObjectContainerPointer m_FixedImageContainer


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo