ANIMA  4.0
animaOrientedModelBaseResampleImageFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
5 #include <itkVectorImage.h>
6 #include <itkInterpolateImageFunction.h>
7 
8 #include <itkMatrixOffsetTransformBase.h>
9 
10 namespace anima
11 {
12 
13 template <typename TImageType, typename TInterpolatorPrecisionType=double>
15  public anima::MaskedImageToImageFilter <TImageType, TImageType>
16 {
17 public:
20  typedef TImageType InputImageType;
21  typedef TImageType TOutputImage;
22  itkStaticConstMacro(ImageDimension, unsigned int,InputImageType::ImageDimension);
23 
24  typedef itk::Image <unsigned char, itkGetStaticConstMacro(ImageDimension)> GeometryImageType;
25  typedef typename GeometryImageType::Pointer GeometryImagePointer;
26 
28  typedef itk::SmartPointer<Self> Pointer;
29  typedef itk::SmartPointer<const Self> ConstPointer;
30 
31  typedef itk::InterpolateImageFunction<InputImageType, TInterpolatorPrecisionType> InterpolatorType;
32  typedef typename InterpolatorType::Pointer InterpolatorPointer;
33 
34  typedef typename InterpolatorType::ContinuousIndexType ContinuousIndexType;
35  typedef typename InterpolatorType::PointType PointType;
36 
39 
40  typedef typename InputImageType::PixelType InputPixelType;
41  typedef typename InputImageType::PointType InputPointType;
42  typedef typename InputImageType::IndexType InputIndexType;
43 
45  typedef typename InputImageType::Pointer InputImagePointer;
46  typedef typename TOutputImage::Pointer OutputImagePointer;
47  typedef typename TOutputImage::RegionType OutputImageRegionType;
48 
49  typedef itk::Transform <TInterpolatorPrecisionType,
50  itkGetStaticConstMacro(ImageDimension),
51  itkGetStaticConstMacro(ImageDimension)> TransformType;
52 
53  typedef typename TransformType::Pointer TransformPointer;
54 
55  itkSetObjectMacro(Transform,TransformType)
56  itkGetObjectMacro(Transform,TransformType)
57 
58  itkSetMacro(Interpolator,InterpolatorPointer)
59  itkGetMacro(Interpolator,InterpolatorType *)
60 
61  itkGetMacro(FiniteStrainReorientation, bool)
62  itkSetMacro(FiniteStrainReorientation, bool)
63 
64  typedef typename TOutputImage::SpacingType SpacingType;
65  typedef typename TOutputImage::PointType OriginPointType;
66  typedef typename TOutputImage::DirectionType DirectionType;
67  typedef typename TOutputImage::RegionType RegionType;
68 
69  itkSetMacro(OutputSpacing, SpacingType)
70  itkGetConstReferenceMacro(OutputSpacing, SpacingType)
71 
72  itkSetMacro(OutputOrigin, OriginPointType)
73  itkGetConstReferenceMacro(OutputOrigin, OriginPointType)
74 
75  itkSetMacro(OutputDirection, DirectionType)
76  itkGetConstReferenceMacro(OutputDirection, DirectionType)
77 
78  itkSetMacro(OutputLargestPossibleRegion, RegionType)
79  itkGetConstReferenceMacro(OutputLargestPossibleRegion, RegionType)
80 
81 protected:
83  {
84  m_Transform = 0;
85  m_Interpolator = 0;
86 
87  m_FiniteStrainReorientation = true;
88  }
89 
91 
92  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
93  virtual void GenerateOutputInformation() ITK_OVERRIDE;
94 
95  virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
96  void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE;
97 
98  virtual unsigned int GetOutputVectorLength();
99 
100  template <class T>
101  inline bool isZero(itk::VariableLengthVector <T> &dataVec)
102  {
103  unsigned int vectorSize = dataVec.GetNumberOfElements();
104 
105  for (unsigned int i = 0;i < vectorSize;++i)
106  {
107  if (dataVec[i] != 0)
108  return false;
109  }
110 
111  return true;
112  }
113 
114  // Fake method for compilation purposes, should never go in there
115  template <class T> inline bool isZero(T &data)
116  {
117  itkExceptionMacro("Access to unauthorized method");
118  return true;
119  }
120 
122  template <class T> inline void InitializeZeroPixel(itk::VariableLengthVector <T> &zeroPixel)
123  {
124  zeroPixel.Fill(0.0);
125  }
126 
128  template <class T> inline void InitializeZeroPixel(T &zeroPixel)
129  {
130  zeroPixel = itk::NumericTraits <T>::ZeroValue();
131  }
132 
133  void LinearThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, unsigned int threadId);
134  void NonLinearThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, unsigned int threadId);
135 
140  vnl_matrix <double> ComputeLinearJacobianMatrix();
141 
146  void ComputeLocalJacobianMatrix(InputIndexType &index, vnl_matrix <double> &reorientationMatrix);
147 
149  virtual void InitializeInterpolator();
150 
155  virtual void ComputeRotationParametersFromReorientationMatrix(vnl_matrix <double> &reorientationMatrix,
156  vnl_matrix <double> &modelOrientationMatrix);
157 
159  virtual void ReorientInterpolatedModel(const InputPixelType &interpolatedModel, vnl_matrix <double> &modelOrientationMatrix,
160  InputPixelType &orientedModel, itk::ThreadIdType threadId) = 0;
161 
162 private:
163  ITK_DISALLOW_COPY_AND_ASSIGN(OrientedModelBaseResampleImageFilter);
164 
165  TransformPointer m_Transform;
166  bool m_FiniteStrainReorientation;
167  InterpolatorPointer m_Interpolator;
168 
169  SpacingType m_OutputSpacing;
170  OriginPointType m_OutputOrigin;
171  DirectionType m_OutputDirection;
172  RegionType m_OutputLargestPossibleRegion;
173 
174  InputIndexType m_StartIndDef, m_EndIndDef;
175 };
176 
177 } // end namespace anima
178 
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
virtual void ReorientInterpolatedModel(const InputPixelType &interpolatedModel, vnl_matrix< double > &modelOrientationMatrix, InputPixelType &orientedModel, itk::ThreadIdType threadId)=0
Needs to be implemented in sub-classes, does the actual re-orientation of the model.
void ComputeLocalJacobianMatrix(InputIndexType &index, vnl_matrix< double > &reorientationMatrix)
void InitializeZeroPixel(itk::VariableLengthVector< T > &zeroPixel)
Utility function to initialize output images pixel to zero for vector images.
virtual void InitializeInterpolator()
Initializes the default interpolator, might change in derived classes.
void LinearThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, unsigned int threadId)
anima::MaskedImageToImageFilter< TImageType, TImageType > Superclass
itk::InterpolateImageFunction< InputImageType, TInterpolatorPrecisionType > InterpolatorType
itkGetObjectMacro(Transform, TransformType) virtual void SetInterpolator(InterpolatorPointer _arg)
void NonLinearThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, unsigned int threadId)
itk::Image< unsigned char, itkGetStaticConstMacro(ImageDimension)> GeometryImageType
virtual void ComputeRotationParametersFromReorientationMatrix(vnl_matrix< double > &reorientationMatrix, vnl_matrix< double > &modelOrientationMatrix)
void InitializeZeroPixel(T &zeroPixel)
Utility function to initialize output images pixel to zero for all images except vector images...
itk::Transform< TInterpolatorPrecisionType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension)> TransformType