]> Creatis software - clitk.git/blob - registration/clitkTransformToDeformationFieldSource.h
Debug RTStruct conversion with empty struc
[clitk.git] / registration / clitkTransformToDeformationFieldSource.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 __clitkTransformToDeformationFieldSource_h
19 #define __clitkTransformToDeformationFieldSource_h
20 #include "itkTransform.h"
21 #include "itkImageSource.h"
22
23 namespace clitk
24 {
25
26 /** \class TransformToDeformationFieldSource
27  * \brief Generate a deformation field from a coordinate transform
28  *
29  * This class was inspired on an the itkDeformationFieldImageFilter class.
30  *
31  * Output information (spacing, size and direction) for the output
32  * image should be set. This information has the normal defaults of
33  * unit spacing, zero origin and identity direction. Optionally, the
34  * output information can be obtained from a reference image. If the
35  * reference image is provided and UseReferenceImage is On, then the
36  * spacing, origin and direction of the reference image will be used.
37  *
38  * Since this filter produces an image which is a different size than
39  * its input, it needs to override several of the methods defined
40  * in ProcessObject in order to properly manage the pipeline execution model.
41  * In particular, this filter overrides
42  * ProcessObject::GenerateInputRequestedRegion() and
43  * ProcessObject::GenerateOutputInformation().
44  *
45  * This filter is implemented as a multithreaded filter.  It provides a 
46  * ThreadedGenerateData() method for its implementation.
47  *
48  * \author Marius Staring, Leiden University Medical Center, The Netherlands.
49  *
50  * This class was taken from the Insight Journal paper:
51  * http://hdl.handle.net/1926/1387
52  *
53  * 
54  * \ingroup GeometricTransforms
55  */
56 template <class TOutputImage,
57           class TTransformPrecisionType=double>
58 class ITK_EXPORT TransformToDeformationFieldSource:
59     public itk::ImageSource<TOutputImage>
60 {
61 public:
62   /** Standard class typedefs. */
63   typedef TransformToDeformationFieldSource       Self;
64   typedef itk::ImageSource<TOutputImage>               Superclass;
65   typedef itk::SmartPointer<Self>                      Pointer;
66   typedef itk::SmartPointer<const Self>                ConstPointer;
67
68   typedef TOutputImage                            OutputImageType;
69   typedef typename OutputImageType::Pointer       OutputImagePointer;
70   typedef typename OutputImageType::ConstPointer  OutputImageConstPointer;
71   typedef typename OutputImageType::RegionType    OutputImageRegionType;
72  
73   /** Method for creation through the object factory. */
74   itkNewMacro( Self );
75
76   /** Run-time type information (and related methods). */
77   itkTypeMacro( TransformToDeformationFieldSource, ImageSource );
78
79   /** Number of dimensions. */
80   itkStaticConstMacro( ImageDimension, unsigned int,
81     TOutputImage::ImageDimension );
82
83   /** Typedefs for transform. */
84   typedef itk::Transform<TTransformPrecisionType, 
85     itkGetStaticConstMacro( ImageDimension ), 
86     itkGetStaticConstMacro( ImageDimension )>     TransformType;
87   typedef typename TransformType::ConstPointer    TransformPointerType;
88
89   /** Typedefs for output image. */
90   typedef typename OutputImageType::PixelType     PixelType;
91   // JV
92   itkStaticConstMacro(SpaceDimension, unsigned int,PixelType::Dimension);
93   typedef typename PixelType::ValueType           PixelValueType;
94   typedef typename OutputImageType::RegionType    RegionType;
95   typedef typename RegionType::SizeType           SizeType;
96   typedef typename OutputImageType::IndexType     IndexType;
97   typedef typename OutputImageType::PointType     PointType;
98   typedef typename OutputImageType::SpacingType   SpacingType;
99   typedef typename OutputImageType::PointType     OriginType;
100   typedef typename OutputImageType::DirectionType DirectionType;
101
102   /** Typedefs for base image. */
103   typedef itk::ImageBase< itkGetStaticConstMacro( ImageDimension ) > ImageBaseType;
104   
105   /** Set the coordinate transformation.
106    * Set the coordinate transform to use for resampling.  Note that this must
107    * be in physical coordinates and it is the output-to-input transform, NOT
108    * the input-to-output transform that you might naively expect.  By default
109    * the filter uses an Identity transform. You must provide a different
110    * transform here, before attempting to run the filter, if you do not want to
111    * use the default Identity transform. */
112   itkSetConstObjectMacro( Transform, TransformType ); 
113
114   /** Get a pointer to the coordinate transform. */
115   itkGetConstObjectMacro( Transform, TransformType );
116
117   /** Set the size of the output image. */
118   virtual void SetOutputSize( const SizeType & size );
119
120   /** Get the size of the output image. */
121   virtual const SizeType & GetOutputSize();
122
123   /** Set the start index of the output largest possible region. 
124   * The default is an index of all zeros. */
125   virtual void SetOutputIndex( const IndexType & index );
126
127   /** Get the start index of the output largest possible region. */
128   virtual const IndexType & GetOutputIndex();
129
130   /** Set the region of the output image. */
131   itkSetMacro( OutputRegion, OutputImageRegionType );
132
133   /** Get the region of the output image. */
134   itkGetConstReferenceMacro( OutputRegion, OutputImageRegionType );
135      
136   /** Set the output image spacing. */
137   itkSetMacro( OutputSpacing, SpacingType );
138   virtual void SetOutputSpacing( const double* values );
139
140   /** Get the output image spacing. */
141   itkGetConstReferenceMacro( OutputSpacing, SpacingType );
142
143   /** Set the output image origin. */
144   itkSetMacro( OutputOrigin, OriginType );
145   virtual void SetOutputOrigin( const double* values);
146
147   /** Get the output image origin. */
148   itkGetConstReferenceMacro( OutputOrigin, OriginType );
149
150   /** Set the output direction cosine matrix. */
151   itkSetMacro( OutputDirection, DirectionType );
152   itkGetConstReferenceMacro( OutputDirection, DirectionType );
153
154   /** Helper method to set the output parameters based on this image */
155   void SetOutputParametersFromImage( const ImageBaseType * image );
156   
157   /** DeformationFieldImageFilter produces a vector image. */
158   virtual void GenerateOutputInformation( void );
159
160   /** Just checking if transform is set. */
161   virtual void BeforeThreadedGenerateData( void );
162
163   /** Compute the Modified Time based on changes to the components. */
164   unsigned long GetMTime( void ) const;
165
166   // JV To allow 4D DVF conversion
167 // #ifdef ITK_USE_CONCEPT_CHECKING
168 //   /** Begin concept checking */
169 //   itkStaticConstMacro(PixelDimension, unsigned int,
170 //                       PixelType::Dimension );
171 //   itkConceptMacro(SameDimensionCheck,
172 //     (Concept::SameDimension<ImageDimension,PixelDimension>));
173 //   /** End concept checking */
174 // #endif
175
176 protected:
177   TransformToDeformationFieldSource( );
178   ~TransformToDeformationFieldSource( ) {};
179
180   void PrintSelf( std::ostream& os, itk::Indent indent ) const;
181
182   /** TransformToDeformationFieldSource can be implemented as a multithreaded
183    * filter.
184    */
185   void ThreadedGenerateData(
186     const OutputImageRegionType & outputRegionForThread,
187     int threadId );
188
189   /** Default implementation for resampling that works for any
190    * transformation type.
191    */
192   void NonlinearThreadedGenerateData(
193     const OutputImageRegionType& outputRegionForThread,
194     int threadId );
195
196   /** Faster implementation for resampling that works for with linear
197    *  transformation types. 
198    */
199   void LinearThreadedGenerateData(
200     const OutputImageRegionType & outputRegionForThread,
201     int threadId );
202   
203 private:
204
205   TransformToDeformationFieldSource( const Self& ); //purposely not implemented
206   void operator=( const Self& ); //purposely not implemented
207
208   /** Member variables. */
209   RegionType              m_OutputRegion;      // region of the output image
210   TransformPointerType    m_Transform;         // Coordinate transform to use
211   SpacingType             m_OutputSpacing;     // output image spacing
212   OriginType              m_OutputOrigin;      // output image origin
213   DirectionType           m_OutputDirection;   // output image direction cosines
214
215 }; // end class TransformToDeformationFieldSource
216   
217 } // end namespace clitk
218   
219 #ifndef ITK_MANUAL_INSTANTIATION
220 #include "clitkTransformToDeformationFieldSource.txx"
221 #endif
222   
223 #endif // end #ifndef __clitkTransformToDeformationFieldSource_h