go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxElastixTemplate.h
Go to the documentation of this file.
00001 /*======================================================================
00002 
00003   This file is part of the elastix software.
00004 
00005   Copyright (c) University Medical Center Utrecht. All rights reserved.
00006   See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
00007   details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE. See the above copyright notices for more information.
00012 
00013 ======================================================================*/
00014 
00015 #ifndef __elxElastixTemplate_h
00016 #define __elxElastixTemplate_h
00017 
00018 #include "elxElastixBase.h"
00019 #include "itkObject.h"
00020 
00021 #include "itkObjectFactory.h"
00022 #include "itkCommand.h"
00023 #include "itkImage.h"
00024 #include "itkImageFileReader.h"
00025 #include "itkImageToImageMetric.h"
00026 
00027 #include "elxRegistrationBase.h"
00028 #include "elxFixedImagePyramidBase.h"
00029 #include "elxMovingImagePyramidBase.h"
00030 #include "elxInterpolatorBase.h"
00031 #include "elxImageSamplerBase.h"
00032 #include "elxMetricBase.h"
00033 #include "elxOptimizerBase.h"
00034 #include "elxResamplerBase.h"
00035 #include "elxResampleInterpolatorBase.h"
00036 #include "elxTransformBase.h"
00037 
00038 #include "elxTimer.h"
00039 
00040 #include <sstream>
00041 #include <fstream>
00042 
00057 #define elxGetBaseMacro(_name,_elxbasetype) \
00058   virtual _elxbasetype * GetElx##_name##Base (void) const \
00059   { \
00060     return this->GetElx##_name##Base( 0 );\
00061   }\
00062   _elxbasetype * GetElx##_name##Base ( unsigned int idx ) const \
00063   { \
00064     if ( idx < this->GetNumberOf##_name##s() ) \
00065     { \
00066       return dynamic_cast<_elxbasetype *>( \
00067         this->Get##_name##Container()->ElementAt(idx).GetPointer() );\
00068     } \
00069     return 0; \
00070   }
00071 //end elxGetBaseMacro
00072 
00073 
00074 namespace elastix
00075 {
00076 using namespace itk;
00077 
00111 template <class TFixedImage, class TMovingImage>
00112   class ElastixTemplate : public Object, public ElastixBase
00113 {
00114 public:
00115 
00117   typedef ElastixTemplate           Self;
00118   typedef Object                    Superclass1;
00119   typedef ElastixBase               Superclass2;
00120   typedef SmartPointer<Self>        Pointer;
00121   typedef SmartPointer<const Self>  ConstPointer;
00122 
00124   itkNewMacro( Self );
00125 
00127   itkTypeMacro( ElastixTemplate, Object );
00128 
00130   typedef Superclass2::ConfigurationType                            ConfigurationType;
00131   typedef Superclass2::ConfigurationPointer                         ConfigurationPointer;
00132   typedef Superclass2::ObjectType                                   ObjectType; //for the components
00133   typedef Superclass2::DataObjectType                               DataObjectType; //for the images
00134   typedef Superclass2::ObjectPointer                                ObjectPointer;
00135   typedef Superclass2::DataObjectPointer                            DataObjectPointer;
00136   typedef Superclass2::ObjectContainerType                          ObjectContainerType;
00137   typedef Superclass2::DataObjectContainerType                      DataObjectContainerType;
00138   typedef Superclass2::FileNameContainerType                        FileNameContainerType;
00139   typedef Superclass2::ObjectContainerPointer                       ObjectContainerPointer;
00140   typedef Superclass2::DataObjectContainerPointer                   DataObjectContainerPointer;
00141   typedef Superclass2::FileNameContainerPointer                     FileNameContainerPointer;
00142 
00144   typedef TFixedImage                                               FixedImageType;
00145   typedef TMovingImage                                              MovingImageType;
00146   typedef typename FixedImageType::Pointer                          FixedImagePointer;
00147   typedef typename MovingImageType::Pointer                         MovingImagePointer;
00148 
00150   itkStaticConstMacro( Dimension,       unsigned int, FixedImageType::ImageDimension );
00151   itkStaticConstMacro( FixedDimension,  unsigned int, FixedImageType::ImageDimension );
00152   itkStaticConstMacro( MovingDimension, unsigned int, MovingImageType::ImageDimension );
00153 
00155   typedef unsigned char                                             MaskPixelType;
00156   typedef Image<MaskPixelType, FixedDimension>                      FixedMaskType;
00157   typedef Image<MaskPixelType, MovingDimension>                     MovingMaskType;
00158   typedef typename FixedMaskType::Pointer                           FixedMaskPointer;
00159   typedef typename MovingMaskType::Pointer                          MovingMaskPointer;
00160 
00162   typedef typename FixedImageType::DirectionType                    FixedImageDirectionType;
00163 
00165   typedef CostFunction::ParametersValueType   CoordRepType; // double
00166 
00168   typedef BaseComponent                                             BaseComponentType;
00169 
00171   typedef void (BaseComponentType::*PtrToMemberFunction)(void);
00172   typedef int (BaseComponentType::*PtrToMemberFunction2)(void);
00173 
00175   typedef SimpleMemberCommand<Self>                                 BeforeEachResolutionCommandType;
00176   typedef SimpleMemberCommand<Self>                                 AfterEachResolutionCommandType;
00177   typedef SimpleMemberCommand<Self>                                 AfterEachIterationCommandType;
00178   typedef typename BeforeEachResolutionCommandType::Pointer         BeforeEachResolutionCommandPointer;
00179   typedef typename AfterEachResolutionCommandType::Pointer          AfterEachResolutionCommandPointer;
00180   typedef typename AfterEachIterationCommandType::Pointer           AfterEachIterationCommandPointer;
00181 
00183   typedef FixedImagePyramidBase<Self>                               FixedImagePyramidBaseType;
00184   typedef MovingImagePyramidBase<Self>                              MovingImagePyramidBaseType;
00185   typedef InterpolatorBase<Self>                                    InterpolatorBaseType;
00186   typedef elx::ImageSamplerBase<Self>                               ImageSamplerBaseType;
00187   typedef MetricBase<Self>                                          MetricBaseType;
00188   typedef OptimizerBase<Self>                                       OptimizerBaseType;
00189   typedef RegistrationBase<Self>                                    RegistrationBaseType;
00190   typedef ResamplerBase<Self>                                       ResamplerBaseType;
00191   typedef ResampleInterpolatorBase<Self>                            ResampleInterpolatorBaseType;
00192   typedef elx::TransformBase<Self>                                  TransformBaseType;
00193 
00195   typedef tmr::Timer                                                TimerType;
00196   typedef TimerType::Pointer                                        TimerPointer;
00197 
00202   typedef MovingImageType                                           InputImageType;
00203   typedef MovingImageType                                           OutputImageType;
00204 
00208   elxGetBaseMacro( FixedImagePyramid, FixedImagePyramidBaseType );
00209   elxGetBaseMacro( MovingImagePyramid, MovingImagePyramidBaseType );
00210   elxGetBaseMacro( Interpolator, InterpolatorBaseType );
00211   elxGetBaseMacro( ImageSampler, ImageSamplerBaseType );
00212   elxGetBaseMacro( Metric, MetricBaseType );
00213   elxGetBaseMacro( Optimizer, OptimizerBaseType );
00214   elxGetBaseMacro( Registration, RegistrationBaseType );
00215   elxGetBaseMacro( Resampler, ResamplerBaseType );
00216   elxGetBaseMacro( ResampleInterpolator, ResampleInterpolatorBaseType );
00217   elxGetBaseMacro( Transform, TransformBaseType );
00218 
00222   virtual FixedImageType * GetFixedImage( void ) const
00223   {
00224     return this->GetFixedImage( 0 );
00225   }
00226   virtual FixedImageType * GetFixedImage( unsigned int idx ) const;
00227   virtual MovingImageType * GetMovingImage( void ) const
00228   {
00229     return this->GetMovingImage( 0 );
00230   }
00231   virtual MovingImageType * GetMovingImage( unsigned int idx ) const;
00232 
00236   virtual FixedMaskType * GetFixedMask( void ) const
00237   {
00238     return this->GetFixedMask( 0 );
00239   }
00240   virtual FixedMaskType * GetFixedMask( unsigned int idx ) const;
00241   virtual MovingMaskType * GetMovingMask( void ) const
00242   {
00243     return this->GetMovingMask( 0 );
00244   }
00245   virtual MovingMaskType * GetMovingMask( unsigned int idx ) const;
00246 
00251   virtual int Run( void );
00252   virtual int ApplyTransform( void );
00253 
00255   virtual int BeforeAll( void );
00256   virtual int BeforeAllTransformix( void );
00257   virtual void BeforeRegistration( void );
00258   virtual void BeforeEachResolution( void );
00259   virtual void AfterEachResolution( void );
00260   virtual void AfterEachIteration( void );
00261   virtual void AfterRegistration( void );
00262 
00264   itkGetConstMacro( IterationCounter, unsigned int );
00265 
00267   itkGetStringMacro( CurrentTransformParameterFileName );
00268 
00273   virtual bool GetOriginalFixedImageDirection( FixedImageDirectionType & direction ) const;
00274 
00275 protected:
00276 
00277   ElastixTemplate();
00278   virtual ~ElastixTemplate(){};
00279 
00281   typedef typename Superclass2::MultipleImageLoader<FixedImageType>   FixedImageLoaderType;
00282   typedef typename Superclass2::MultipleImageLoader<MovingImageType>  MovingImageLoaderType;
00283   typedef typename Superclass2::MultipleImageLoader<FixedMaskType>    FixedMaskLoaderType;
00284   typedef typename Superclass2::MultipleImageLoader<MovingMaskType>   MovingMaskLoaderType;
00285 
00287   BeforeEachResolutionCommandPointer  m_BeforeEachResolutionCommand;
00288   AfterEachIterationCommandPointer    m_AfterEachIterationCommand;
00289   AfterEachResolutionCommandPointer   m_AfterEachResolutionCommand;
00290 
00292   TimerPointer m_Timer0;
00293   TimerPointer m_IterationTimer;
00294   TimerPointer m_ResolutionTimer;
00295 
00297   std::string m_CurrentTransformParameterFileName;
00298 
00300   unsigned int m_IterationCounter;
00301 
00303   virtual void CreateTransformParameterFile( const std::string FileName,
00304     const bool ToLog );
00305 
00307   virtual void OpenIterationInfoFile( void );
00308   std::ofstream m_IterationInfoFile;
00309 
00323   void CallInEachComponent( PtrToMemberFunction func );
00324   int CallInEachComponentInt( PtrToMemberFunction2 func );
00325 
00330   virtual void ConfigureComponents( Self * This );
00331 
00333   virtual void SetOriginalFixedImageDirection( const FixedImageDirectionType & arg );
00334 
00335 private:
00336 
00337   ElastixTemplate( const Self& ); // purposely not implemented
00338   void operator=( const Self& );  // purposely not implemented
00339 
00340   }; // end class ElastixTemplate
00341 
00342 
00343 } // end namespace elastix
00344 
00345 
00346 #undef elxGetBaseMacro
00347 
00348 #ifndef ITK_MANUAL_INSTANTIATION
00349 #include "elxElastixTemplate.hxx"
00350 #endif
00351 
00352 #endif // end #ifndef __elxElastixTemplate_h
00353 


Generated on 11-05-2012 for elastix by doxygen 1.7.6.1 elastix logo