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 __clitkTransformToDeformationFieldSource_h
19 #define __clitkTransformToDeformationFieldSource_h
20 #include "itkTransform.h"
21 #include "itkImageSource.h"
26 /** \class TransformToDeformationFieldSource
27 * \brief Generate a deformation field from a coordinate transform
29 * This class was inspired on an the itkDeformationFieldImageFilter class.
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.
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().
45 * This filter is implemented as a multithreaded filter. It provides a
46 * ThreadedGenerateData() method for its implementation.
48 * \author Marius Staring, Leiden University Medical Center, The Netherlands.
50 * This class was taken from the Insight Journal paper:
51 * http://hdl.handle.net/1926/1387
54 * \ingroup GeometricTransforms
56 template <class TOutputImage,
57 class TTransformPrecisionType=double>
58 class ITK_EXPORT TransformToDeformationFieldSource:
59 public itk::ImageSource<TOutputImage>
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;
68 typedef TOutputImage OutputImageType;
69 typedef typename OutputImageType::Pointer OutputImagePointer;
70 typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
71 typedef typename OutputImageType::RegionType OutputImageRegionType;
73 /** Method for creation through the object factory. */
76 /** Run-time type information (and related methods). */
77 itkTypeMacro( TransformToDeformationFieldSource, ImageSource );
79 /** Number of dimensions. */
80 itkStaticConstMacro( ImageDimension, unsigned int,
81 TOutputImage::ImageDimension );
83 /** Typedefs for transform. */
84 typedef itk::Transform<TTransformPrecisionType,
85 itkGetStaticConstMacro( ImageDimension ),
86 itkGetStaticConstMacro( ImageDimension )> TransformType;
87 typedef typename TransformType::ConstPointer TransformPointerType;
89 /** Typedefs for output image. */
90 typedef typename OutputImageType::PixelType PixelType;
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;
102 /** Typedefs for base image. */
103 typedef itk::ImageBase< itkGetStaticConstMacro( ImageDimension ) > ImageBaseType;
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 );
114 /** Get a pointer to the coordinate transform. */
115 itkGetConstObjectMacro( Transform, TransformType );
117 /** Set the size of the output image. */
118 virtual void SetOutputSize( const SizeType & size );
120 /** Get the size of the output image. */
121 virtual const SizeType & GetOutputSize();
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 );
127 /** Get the start index of the output largest possible region. */
128 virtual const IndexType & GetOutputIndex();
130 /** Set the region of the output image. */
131 itkSetMacro( OutputRegion, OutputImageRegionType );
133 /** Get the region of the output image. */
134 itkGetConstReferenceMacro( OutputRegion, OutputImageRegionType );
136 /** Set the output image spacing. */
137 itkSetMacro( OutputSpacing, SpacingType );
138 virtual void SetOutputSpacing( const double* values );
140 /** Get the output image spacing. */
141 itkGetConstReferenceMacro( OutputSpacing, SpacingType );
143 /** Set the output image origin. */
144 itkSetMacro( OutputOrigin, OriginType );
145 virtual void SetOutputOrigin( const double* values);
147 /** Get the output image origin. */
148 itkGetConstReferenceMacro( OutputOrigin, OriginType );
150 /** Set the output direction cosine matrix. */
151 itkSetMacro( OutputDirection, DirectionType );
152 itkGetConstReferenceMacro( OutputDirection, DirectionType );
154 /** Helper method to set the output parameters based on this image */
155 void SetOutputParametersFromImage( const ImageBaseType * image );
157 /** DeformationFieldImageFilter produces a vector image. */
158 virtual void GenerateOutputInformation( void );
160 /** Just checking if transform is set. */
161 virtual void BeforeThreadedGenerateData( void );
163 /** Compute the Modified Time based on changes to the components. */
164 unsigned long GetMTime( void ) const;
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 */
177 TransformToDeformationFieldSource( );
178 ~TransformToDeformationFieldSource( ) {};
180 void PrintSelf( std::ostream& os, itk::Indent indent ) const;
182 /** TransformToDeformationFieldSource can be implemented as a multithreaded
185 void ThreadedGenerateData(
186 const OutputImageRegionType & outputRegionForThread,
189 /** Default implementation for resampling that works for any
190 * transformation type.
192 void NonlinearThreadedGenerateData(
193 const OutputImageRegionType& outputRegionForThread,
196 /** Faster implementation for resampling that works for with linear
197 * transformation types.
199 void LinearThreadedGenerateData(
200 const OutputImageRegionType & outputRegionForThread,
205 TransformToDeformationFieldSource( const Self& ); //purposely not implemented
206 void operator=( const Self& ); //purposely not implemented
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
215 }; // end class TransformToDeformationFieldSource
217 } // end namespace clitk
219 #ifndef ITK_MANUAL_INSTANTIATION
220 #include "clitkTransformToDeformationFieldSource.txx"
223 #endif // end #ifndef __clitkTransformToDeformationFieldSource_h