ANIMA  4.0
animaVectorModelLinearInterpolateImageFunction.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <itkInterpolateImageFunction.h>
4 #include <itkVariableLengthVector.h>
5 
6 namespace anima
7 {
8 
9 template <class TInputImage, class TCoordRep = double>
11  public itk::InterpolateImageFunction<TInputImage,TCoordRep>
12 {
13 public:
16  typedef itk::InterpolateImageFunction<TInputImage,TCoordRep> Superclass;
17  typedef itk::SmartPointer<Self> Pointer;
18  typedef itk::SmartPointer<const Self> ConstPointer;
19 
21  itkNewMacro(Self);
22 
25  InterpolateImageFunction);
26 
28  typedef typename Superclass::InputImageType InputImageType;
29  typedef typename TInputImage::PixelType PixelType;
30  typedef typename Superclass::RealType RealType;
31  typedef typename Superclass::SizeType SizeType;
32 
34  itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);
35 
37  typedef typename Superclass::IndexType IndexType;
38  typedef typename Superclass::IndexValueType IndexValueType;
39 
41  typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
42 
43  typedef typename Superclass::OutputType OutputType;
44  typedef itk::VariableLengthVector <typename TInputImage::IOPixelType> VectorPixelType;
45 
54  virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType & index) const ITK_OVERRIDE;
55 
56  SizeType GetRadius() const override
57  {
58  return SizeType::Filled(1);
59  }
60 
61 protected:
64 
65  template <class T> inline bool isZero(itk::VariableLengthVector <T> &value) const
66  {
67  for (unsigned int i = 0;i < value.GetNumberOfElements();++i)
68  {
69  if (value[i] != 0)
70  return false;
71  }
72 
73  return true;
74  }
75 
76  // Fake method for compilation purposes, should never go in there
77  template <class T> inline bool isZero(T &data) const
78  {
79  itkExceptionMacro("Access to unauthorized zero test method");
80  return true;
81  }
82 
84  template <class T> inline void InitializeZeroPixel(itk::VariableLengthVector <T> &zeroPixel) const
85  {
86  zeroPixel.Fill(0.0);
87  }
88 
90  template <class T> inline void InitializeZeroPixel(T &zeroPixel) const
91  {
92  itkExceptionMacro("Access to unauthorized zero pixel method");
93  zeroPixel = itk::NumericTraits <T>::ZeroValue();
94  }
95 
97  template <class T1, class T2>
98  void AddValue(itk::VariableLengthVector <T1> &input, double weight,
99  itk::VariableLengthVector <T2> &output) const
100  {
101  unsigned int vecDim = input.GetNumberOfElements();
102  for (unsigned int i = 0;i < vecDim;++i)
103  output[i] += weight * input[i];
104  }
105 
107  template <class T1, class T2> void AddValue(T1 &input, double weight, T2 &output) const
108  {
109  itkExceptionMacro("Acces to unauthorized method, check your implementation");
110  }
111 
112 private:
113  VectorModelLinearInterpolateImageFunction(const Self&); //purposely not implemented
114  void operator=(const Self&); //purposely not implemented
115 
117  static const unsigned long m_Neighbors;
118 };
119 
120 } // end namespace itk
121 
void InitializeZeroPixel(T &zeroPixel) const
Utility function to initialize output images pixel to zero for all images except vector images...
itk::InterpolateImageFunction< TInputImage, TCoordRep > Superclass
virtual OutputType EvaluateAtContinuousIndex(const ContinuousIndexType &index) const ITK_OVERRIDE
itk::VariableLengthVector< typename TInputImage::IOPixelType > VectorPixelType
void InitializeZeroPixel(itk::VariableLengthVector< T > &zeroPixel) const
Utility function to initialize output images pixel to zero for vector images.
void AddValue(T1 &input, double weight, T2 &output) const
Utility function to initialize output images pixel to zero for all images except vector images...
void AddValue(itk::VariableLengthVector< T1 > &input, double weight, itk::VariableLengthVector< T2 > &output) const
Utility function to initialize output images pixel to zero for vector images.