1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
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
21 #include "itkImageToImageFilter.h"
22 #include "itkPDEDeformableRegistrationFilter.h"
23 #include "itkDemonsRegistrationFilter.h"
24 #include "itkMultiResolutionPyramidImageFilter.h"
25 #include "itkVectorResampleImageFilter.h"
26 #include "itkRecursiveGaussianImageFilter.h"
32 template <class TFixedImage, class TMovingImage, class TDeformationField, class TRealType = float>
33 class ITK_EXPORT MultiResolutionPDEDeformableRegistration :
34 public itk::ImageToImageFilter <TDeformationField, TDeformationField>
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;
43 /** Method for creation through the object factory. */
46 /** Run-time type information (and related methods). */
47 itkTypeMacro( MultiResolutionPDEDeformableRegistration,
50 /** Fixed image type. */
51 typedef TFixedImage FixedImageType;
52 typedef typename FixedImageType::Pointer FixedImagePointer;
53 typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
55 /** Moving image type. */
56 typedef TMovingImage MovingImageType;
57 typedef typename MovingImageType::Pointer MovingImagePointer;
58 typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
60 /** Deformation field image type. */
61 typedef TDeformationField DeformationFieldType;
62 typedef typename DeformationFieldType::Pointer DeformationFieldPointer;
64 /** ImageDimension. */
65 itkStaticConstMacro(ImageDimension, unsigned int,
66 FixedImageType::ImageDimension);
68 /** Internal float image type. */
69 typedef itk::Image<TRealType,itkGetStaticConstMacro(ImageDimension)> FloatImageType;
71 /** The internal registration type. */
72 typedef itk::PDEDeformableRegistrationFilter<
73 FloatImageType, FloatImageType, DeformationFieldType > RegistrationType;
74 typedef typename RegistrationType::Pointer RegistrationPointer;
76 /** The default registration type. */
77 typedef itk::DemonsRegistrationFilter<
78 FloatImageType, FloatImageType, DeformationFieldType > DefaultRegistrationType;
80 /** The fixed multi-resolution image pyramid type. */
81 typedef itk::MultiResolutionPyramidImageFilter<
82 FixedImageType, FloatImageType > FixedImagePyramidType;
83 typedef typename FixedImagePyramidType::Pointer FixedImagePyramidPointer;
85 /** The moving multi-resolution image pyramid type. */
86 typedef itk::MultiResolutionPyramidImageFilter<
87 MovingImageType, FloatImageType > MovingImagePyramidType;
88 typedef typename MovingImagePyramidType::Pointer MovingImagePyramidPointer;
90 /** The deformation field expander type. */
91 typedef itk::VectorResampleImageFilter<
92 DeformationFieldType, DeformationFieldType > FieldExpanderType;
93 typedef typename FieldExpanderType::Pointer FieldExpanderPointer;
95 /** Set the fixed image. */
96 virtual void SetFixedImage( const FixedImageType * ptr );
98 /** Get the fixed image. */
99 const FixedImageType * GetFixedImage(void) const;
101 /** Set the moving image. */
102 virtual void SetMovingImage( const MovingImageType * ptr );
104 /** Get the moving image. */
105 const MovingImageType * GetMovingImage(void) const;
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 )
111 this->m_InitialDeformationField=ptr;
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 )
119 this->SetInput( ptr );
122 /** Get output deformation field. */
123 const DeformationFieldType * GetDeformationField(void)
124 { return this->GetOutput(); }
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.
132 virtual std::vector<itk::SmartPointer<itk::DataObject> >::size_type GetNumberOfValidRequiredInputs() const;
134 /** Set the internal registrator. */
135 itkSetObjectMacro( RegistrationFilter, RegistrationType );
137 /** Get the internal registrator. */
138 itkGetObjectMacro( RegistrationFilter, RegistrationType );
140 /** Set the fixed image pyramid. */
141 itkSetObjectMacro( FixedImagePyramid, FixedImagePyramidType );
143 /** Get the fixed image pyramid. */
144 itkGetObjectMacro( FixedImagePyramid, FixedImagePyramidType );
146 /** Set the moving image pyramid. */
147 itkSetObjectMacro( MovingImagePyramid, MovingImagePyramidType );
149 /** Get the moving image pyramid. */
150 itkGetObjectMacro( MovingImagePyramid, MovingImagePyramidType );
152 /** Set number of multi-resolution levels. */
153 virtual void SetNumberOfLevels( unsigned int num );
155 /** Get number of multi-resolution levels. */
156 itkGetConstReferenceMacro( NumberOfLevels, unsigned int );
158 /** Get the current resolution level being processed. */
159 itkGetConstReferenceMacro( CurrentLevel, unsigned int );
161 /** Set number of iterations per multi-resolution levels. */
162 itkSetVectorMacro( NumberOfIterations, unsigned int, m_NumberOfLevels );
164 /** Set the moving image pyramid. */
165 itkSetObjectMacro( FieldExpander, FieldExpanderType );
167 /** Get the moving image pyramid. */
168 itkGetObjectMacro( FieldExpander, FieldExpanderType );
170 /** Get number of iterations per multi-resolution levels. */
171 virtual const unsigned int * GetNumberOfIterations() const
172 { return &(m_NumberOfIterations[0]); }
174 /** Stop the registration after the current iteration. */
175 virtual void StopRegistration();
178 MultiResolutionPDEDeformableRegistration();
179 ~MultiResolutionPDEDeformableRegistration() {}
180 void PrintSelf(std::ostream& os, itk::Indent indent) const;
182 /** Generate output data by performing the registration
183 * at each resolution level. */
184 virtual void GenerateData();
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();
191 /** By default, the output deformation field has the same
192 * spacing, origin and LargestPossibleRegion as the input/initial
195 * If the initial deformation field is not set, the output
196 * information is copied from the fixed image. */
197 virtual void GenerateOutputInformation();
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 );
204 /** This method returns true to indicate that the registration should
205 * terminate at the current resolution level. */
209 MultiResolutionPDEDeformableRegistration(const Self&); //purposely not implemented
210 void operator=(const Self&); //purposely not implemented
212 RegistrationPointer m_RegistrationFilter;
213 FixedImagePyramidPointer m_FixedImagePyramid;
214 MovingImagePyramidPointer m_MovingImagePyramid;
215 FieldExpanderPointer m_FieldExpander;
216 DeformationFieldPointer m_InitialDeformationField;
218 unsigned int m_NumberOfLevels;
219 unsigned int m_CurrentLevel;
220 std::vector<unsigned int> m_NumberOfIterations;
222 /** Flag to indicate user stop registration request. */
223 bool m_StopRegistrationFlag;
228 } // end namespace clitk
230 #ifndef ITK_MANUAL_INSTANTIATION
231 #include "clitkMultiResolutionPDEDeformableRegistration.txx"