]> Creatis software - clitk.git/blob - registration/clitkMultiResolutionPDEDeformableRegistration.h
Debug RTStruct conversion with empty struc
[clitk.git] / registration / clitkMultiResolutionPDEDeformableRegistration.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef __clitkMultiResolutionPDEDeformableRegistration_h
19 #define __clitkMultiResolutionPDEDeformableRegistration_h
20 #include "itkImage.h"
21 #include "itkImageToImageFilter.h"
22 #include "itkPDEDeformableRegistrationFilter.h"
23 #include "itkDemonsRegistrationFilter.h"
24 #include "itkMultiResolutionPyramidImageFilter.h"
25 #include "itkVectorResampleImageFilter.h"
26 #include "itkRecursiveGaussianImageFilter.h"
27 #include <vector>
28
29 namespace clitk
30 {
31
32 template <class TFixedImage, class TMovingImage, class TDeformationField, class  TRealType = float>
33 class ITK_EXPORT MultiResolutionPDEDeformableRegistration :
34     public itk::ImageToImageFilter <TDeformationField, TDeformationField>
35 {
36 public:
37   /** Standard class typedefs */
38   typedef MultiResolutionPDEDeformableRegistration Self;
39   typedef itk::ImageToImageFilter<TDeformationField, TDeformationField>  Superclass;
40   typedef itk::SmartPointer<Self>  Pointer;
41   typedef itk::SmartPointer<const Self>  ConstPointer;
42
43   /** Method for creation through the object factory. */
44   itkNewMacro(Self);
45
46   /** Run-time type information (and related methods). */
47   itkTypeMacro( MultiResolutionPDEDeformableRegistration, 
48                 ImageToImageFilter );
49
50   /** Fixed image type. */
51   typedef TFixedImage FixedImageType;
52   typedef typename FixedImageType::Pointer FixedImagePointer;
53   typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
54
55   /** Moving image type. */
56   typedef TMovingImage MovingImageType;
57   typedef typename MovingImageType::Pointer MovingImagePointer;
58   typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
59
60   /** Deformation field image type. */
61   typedef TDeformationField DeformationFieldType;
62   typedef typename DeformationFieldType::Pointer DeformationFieldPointer;
63
64   /** ImageDimension. */
65   itkStaticConstMacro(ImageDimension, unsigned int,
66                       FixedImageType::ImageDimension);
67
68   /** Internal float image type. */
69   typedef itk::Image<TRealType,itkGetStaticConstMacro(ImageDimension)> FloatImageType;
70
71   /** The internal registration type. */
72   typedef itk::PDEDeformableRegistrationFilter<
73     FloatImageType, FloatImageType, DeformationFieldType > RegistrationType;
74   typedef typename RegistrationType::Pointer RegistrationPointer;
75
76   /** The default registration type. */
77   typedef itk::DemonsRegistrationFilter<
78     FloatImageType, FloatImageType, DeformationFieldType > DefaultRegistrationType;
79
80   /** The fixed multi-resolution image pyramid type. */
81   typedef itk::MultiResolutionPyramidImageFilter<
82     FixedImageType, FloatImageType > FixedImagePyramidType;
83   typedef typename FixedImagePyramidType::Pointer FixedImagePyramidPointer;
84
85   /** The moving multi-resolution image pyramid type. */
86 typedef itk::MultiResolutionPyramidImageFilter<
87     MovingImageType, FloatImageType > MovingImagePyramidType;
88   typedef typename MovingImagePyramidType::Pointer MovingImagePyramidPointer;
89    
90   /** The deformation field expander type. */
91 typedef itk::VectorResampleImageFilter<
92     DeformationFieldType, DeformationFieldType > FieldExpanderType;
93   typedef typename FieldExpanderType::Pointer  FieldExpanderPointer;
94
95   /** Set the fixed image. */
96   virtual void SetFixedImage( const FixedImageType * ptr );
97
98   /** Get the fixed image. */
99   const FixedImageType * GetFixedImage(void) const;
100
101   /** Set the moving image. */
102   virtual void SetMovingImage( const MovingImageType * ptr );
103
104   /** Get the moving image. */
105   const MovingImageType * GetMovingImage(void) const;
106
107   /** Set initial deformation field to be used as is (no smoothing, no
108    *  subsampling at the coarsest level of the pyramid. */
109   virtual void SetInitialDeformationField( DeformationFieldType * ptr )
110   {
111     this->m_InitialDeformationField=ptr;
112   }
113
114   /** Set initial deformation field. No assumption is made on the
115    *  input. It will therefore be smoothed and resampled to match the
116    *  images characteristics at the coarsest level of the pyramid. */
117   virtual void SetArbitraryInitialDeformationField( DeformationFieldType * ptr )
118   {
119     this->SetInput( ptr ); 
120   }
121   
122   /** Get output deformation field. */
123   const DeformationFieldType * GetDeformationField(void)
124   { return this->GetOutput(); }
125
126   /** Get the number of valid inputs.  For
127    * MultiResolutionPDEDeformableRegistration, this checks whether the
128    * fixed and moving images have been set. While
129    * MultiResolutionPDEDeformableRegistration can take a third input
130    * as an initial deformation field, this input is not a required input.
131    */
132   virtual std::vector<itk::SmartPointer<itk::DataObject> >::size_type GetNumberOfValidRequiredInputs() const;
133
134   /** Set the internal registrator. */
135   itkSetObjectMacro( RegistrationFilter, RegistrationType );
136
137   /** Get the internal registrator. */
138   itkGetObjectMacro( RegistrationFilter, RegistrationType );
139   
140   /** Set the fixed image pyramid. */
141   itkSetObjectMacro( FixedImagePyramid, FixedImagePyramidType );
142
143   /** Get the fixed image pyramid. */
144   itkGetObjectMacro( FixedImagePyramid, FixedImagePyramidType );
145
146   /** Set the moving image pyramid. */
147   itkSetObjectMacro( MovingImagePyramid, MovingImagePyramidType );
148
149   /** Get the moving image pyramid. */
150   itkGetObjectMacro( MovingImagePyramid, MovingImagePyramidType );
151
152   /** Set number of multi-resolution levels. */
153   virtual void SetNumberOfLevels( unsigned int num );
154
155   /** Get number of multi-resolution levels. */
156   itkGetConstReferenceMacro( NumberOfLevels, unsigned int );
157
158   /** Get the current resolution level being processed. */
159   itkGetConstReferenceMacro( CurrentLevel, unsigned int );
160
161   /** Set number of iterations per multi-resolution levels. */
162   itkSetVectorMacro( NumberOfIterations, unsigned int, m_NumberOfLevels );
163
164   /** Set the moving image pyramid. */
165   itkSetObjectMacro( FieldExpander, FieldExpanderType );
166
167   /** Get the moving image pyramid. */
168   itkGetObjectMacro( FieldExpander, FieldExpanderType );
169
170   /** Get number of iterations per multi-resolution levels. */
171   virtual const unsigned int * GetNumberOfIterations() const
172   { return &(m_NumberOfIterations[0]); }
173
174   /** Stop the registration after the current iteration. */
175   virtual void StopRegistration();
176
177 protected:
178   MultiResolutionPDEDeformableRegistration();
179   ~MultiResolutionPDEDeformableRegistration() {}
180 void PrintSelf(std::ostream& os, itk::Indent indent) const;
181
182   /** Generate output data by performing the registration
183    * at each resolution level. */
184   virtual void GenerateData();
185
186   /** The current implementation of this class does not support
187    * streaming. As such it requires the largest possible region
188    * for the moving, fixed and input deformation field. */
189   virtual void GenerateInputRequestedRegion();
190
191   /** By default, the output deformation field has the same
192    * spacing, origin and LargestPossibleRegion as the input/initial
193    * deformation field.
194    *
195    * If the initial deformation field is not set, the output
196    * information is copied from the fixed image. */
197   virtual void GenerateOutputInformation();
198
199   /** The current implementation of this class does not supprot
200    * streaming. As such it produces the output for the largest
201    * possible region. */
202   virtual void EnlargeOutputRequestedRegion( itk::DataObject *ptr );
203
204   /** This method returns true to indicate that the registration should
205    * terminate at the current resolution level. */
206   virtual bool Halt();
207
208 private:
209   MultiResolutionPDEDeformableRegistration(const Self&); //purposely not implemented
210   void operator=(const Self&); //purposely not implemented
211   
212   RegistrationPointer        m_RegistrationFilter;
213   FixedImagePyramidPointer   m_FixedImagePyramid;
214   MovingImagePyramidPointer  m_MovingImagePyramid;
215   FieldExpanderPointer       m_FieldExpander;
216   DeformationFieldPointer    m_InitialDeformationField;
217
218   unsigned int               m_NumberOfLevels;
219   unsigned int               m_CurrentLevel;
220   std::vector<unsigned int>  m_NumberOfIterations;
221
222   /** Flag to indicate user stop registration request. */
223   bool                      m_StopRegistrationFlag;
224
225 };
226
227
228 } // end namespace clitk
229
230 #ifndef ITK_MANUAL_INSTANTIATION
231 #include "clitkMultiResolutionPDEDeformableRegistration.txx"
232 #endif
233
234
235 #endif