ANIMA  4.0
animaResampleImageFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkFixedArray.h>
4 #include <itkTransform.h>
5 #include <itkImageFunction.h>
6 #include <itkImageRegionIterator.h>
7 #include <itkImageToImageFilter.h>
8 #include <itkInterpolateImageFunction.h>
9 #include <itkMatrixOffsetTransformBase.h>
10 #include <itkSize.h>
11 
12 namespace anima
13 {
14 
15 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType=double>
16 class ResampleImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
17 {
18 public:
21  typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass;
22  typedef itk::SmartPointer<Self> Pointer;
23  typedef itk::SmartPointer<const Self> ConstPointer;
24 
25  typedef TInputImage InputImageType;
26  typedef TOutputImage OutputImageType;
27  typedef typename InputImageType::Pointer InputImagePointer;
28  typedef typename InputImageType::ConstPointer InputImageConstPointer;
29  typedef typename OutputImageType::Pointer OutputImagePointer;
30  typedef typename InputImageType::RegionType InputImageRegionType;
31  typedef typename InputImageType::IndexType InputIndexType;
32 
34  itkNewMacro(Self)
35 
36 
37  itkTypeMacro(ResampleImageFilter, itk::ImageToImageFilter)
38 
39 
40  itkStaticConstMacro(ImageDimension, unsigned int,
41  TOutputImage::ImageDimension);
42  itkStaticConstMacro(InputImageDimension, unsigned int,
43  TInputImage::ImageDimension);
44 
46  typedef itk::Transform<TInterpolatorPrecisionType,
47  itkGetStaticConstMacro(ImageDimension),
48  itkGetStaticConstMacro(ImageDimension)> TransformType;
49  typedef typename TransformType::ConstPointer TransformPointerType;
50 
51  typedef itk::MatrixOffsetTransformBase <TInterpolatorPrecisionType,
52  itkGetStaticConstMacro(ImageDimension),
53  itkGetStaticConstMacro(ImageDimension)> MatrixTransformType;
54 
56  typedef itk::InterpolateImageFunction<InputImageType, TInterpolatorPrecisionType> InterpolatorType;
57  typedef typename InterpolatorType::Pointer InterpolatorPointerType;
58 
60  typedef itk::Size<itkGetStaticConstMacro(ImageDimension)> SizeType;
61 
63  typedef typename TOutputImage::IndexType IndexType;
64 
66  typedef typename InterpolatorType::PointType PointType;
67  //typedef typename TOutputImage::PointType PointType;
68 
70  typedef typename TOutputImage::PixelType PixelType;
71  typedef typename TInputImage::PixelType InputPixelType;
72 
74  typedef typename TOutputImage::RegionType OutputImageRegionType;
75 
77  typedef typename TOutputImage::SpacingType SpacingType;
78  typedef typename TOutputImage::PointType OriginPointType;
79  typedef typename TOutputImage::DirectionType DirectionType;
80 
82  typedef itk::ImageBase<itkGetStaticConstMacro(ImageDimension)> ImageBaseType;
83 
91  void SetTransform(TransformType *transform);
92 
94  itkGetConstObjectMacro(Transform, TransformType)
95 
96 
102  itkSetObjectMacro(Interpolator, InterpolatorType)
103 
104 
105  itkGetConstObjectMacro(Interpolator, InterpolatorType)
106 
107 
108  itkSetMacro(Size, SizeType)
109 
110 
111  itkGetConstReferenceMacro(Size, SizeType)
112 
113 
115  itkSetMacro(DefaultPixelValue, PixelType)
116 
117 
118  itkGetConstReferenceMacro(DefaultPixelValue, PixelType)
119 
120 
121  itkSetMacro(OutputSpacing, SpacingType)
122  virtual void SetOutputSpacing(const double* values);
123 
125  itkGetConstReferenceMacro(OutputSpacing, SpacingType)
126 
127 
128  itkSetMacro(OutputOrigin, OriginPointType)
129  virtual void SetOutputOrigin(const double* values);
130 
132  itkGetConstReferenceMacro(OutputOrigin, OriginPointType)
133 
134 
135  itkSetMacro(OutputDirection, DirectionType)
136  itkGetConstReferenceMacro(OutputDirection, DirectionType)
137 
138 
139  void SetOutputParametersFromImage ( const ImageBaseType * image );
140 
143  itkSetMacro(OutputStartIndex, IndexType)
144 
145 
146  itkGetConstReferenceMacro(OutputStartIndex, IndexType)
147 
148 
154  void SetReferenceImage (const TOutputImage *image);
155  const TOutputImage * GetReferenceImage() const;
156 
157  itkSetMacro(UseReferenceImage, bool)
158  itkBooleanMacro(UseReferenceImage)
159  itkGetConstMacro(UseReferenceImage, bool)
160 
161 
166  virtual void GenerateOutputInformation() ITK_OVERRIDE;
167 
173  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
174 
177  virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
178 
181  virtual void AfterThreadedGenerateData() ITK_OVERRIDE;
182 
184  itk::ModifiedTimeType GetMTime() const ITK_OVERRIDE;
185 
186  void SetScaleIntensitiesWithJacobian(bool scale) {m_ScaleIntensitiesWithJacobian = scale;}
187 
188 protected:
190  virtual ~ResampleImageFilter() {}
191 
192  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;
193 
194  void DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread) ITK_OVERRIDE;
195 
197  double ComputeLocalJacobianValue(const InputIndexType &index);
198 
199  virtual itk::LightObject::Pointer InternalClone() const ITK_OVERRIDE;
200 
201 private:
202  ITK_DISALLOW_COPY_AND_ASSIGN(ResampleImageFilter);
203 
204  SizeType m_Size; // Size of the output image
205  TransformPointerType m_Transform; // Coordinate transform to use
206  InterpolatorPointerType m_Interpolator; // Image function for interpolation
207  PixelType m_DefaultPixelValue; // default pixel value if the point is outside the image
208  SpacingType m_OutputSpacing; // output image spacing
209  OriginPointType m_OutputOrigin; // output image origin
210  DirectionType m_OutputDirection; // output image direction cosines
211  IndexType m_OutputStartIndex; // output image start index
212  bool m_UseReferenceImage;
213 
214  bool m_ScaleIntensitiesWithJacobian;
215  bool m_LinearTransform;
216 };
217 
218 } // end namespace anima
219 
static const unsigned int ImageDimension
InputImageType::ConstPointer InputImageConstPointer
TOutputImage::DirectionType DirectionType
InterpolatorType::PointType PointType
virtual void AfterThreadedGenerateData() ITK_OVERRIDE
itk::Size< itkGetStaticConstMacro(ImageDimension)> SizeType
InputImageType::Pointer InputImagePointer
TOutputImage::PointType OriginPointType
itk::ImageBase< itkGetStaticConstMacro(ImageDimension)> ImageBaseType
const TOutputImage * GetReferenceImage() const
InterpolatorType::Pointer InterpolatorPointerType
InputImageType::RegionType InputImageRegionType
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
OutputImageType::Pointer OutputImagePointer
virtual void SetOutputSpacing(SpacingType _arg)
itk::SmartPointer< Self > Pointer
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
TOutputImage::IndexType IndexType
virtual itk::LightObject::Pointer InternalClone() const ITK_OVERRIDE
TOutputImage::PixelType PixelType
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
TInputImage::PixelType InputPixelType
static const unsigned int InputImageDimension
TOutputImage::SpacingType SpacingType
TOutputImage::RegionType OutputImageRegionType
itk::InterpolateImageFunction< InputImageType, TInterpolatorPrecisionType > InterpolatorType
void SetScaleIntensitiesWithJacobian(bool scale)
void SetReferenceImage(const TOutputImage *image)
itk::MatrixOffsetTransformBase< TInterpolatorPrecisionType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension)> MatrixTransformType
TransformType::ConstPointer TransformPointerType
itk::Transform< TInterpolatorPrecisionType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension)> TransformType
virtual void GenerateOutputInformation() ITK_OVERRIDE
virtual void GenerateInputRequestedRegion() ITK_OVERRIDE
itk::SmartPointer< const Self > ConstPointer
void SetTransform(TransformType *transform)
itk::ModifiedTimeType GetMTime() const ITK_OVERRIDE
double ComputeLocalJacobianValue(const InputIndexType &index)
InputImageType::IndexType InputIndexType
void SetOutputParametersFromImage(const ImageBaseType *image)
virtual void SetOutputOrigin(OriginPointType _arg)