DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkMultiplyByConstantMatrixVectorImageFilter.h
Go to the documentation of this file.
1 
11 #ifndef __itkMultiplyByConstantMatrixVectorImageFilter_h
12 #define __itkMultiplyByConstantMatrixVectorImageFilter_h
13 
14 #include "itkUnaryFunctorImageFilter.h"
15 #include "utlNDArray.h"
16 
17 namespace itk
18 {
29 namespace Functor
30 {
31 template <class TInput, class TMatrix, class TOutput=TInput>
33 {
34 public:
35  typedef typename TInput::ValueType InputValueType;
36  typedef typename TOutput::ValueType OutputValueType;
38 
40  {
41  }
42 
44  {
45  }
46 
47  bool operator!=(const MultiplyByConstantMatrix & other) const
48  {
49  return !( *this == other );
50  }
51 
52  bool operator==(const MultiplyByConstantMatrix & other) const
53  {
54  return other.m_ConstantMatrix == m_ConstantMatrix;
55  }
56 
57  inline TOutput operator()(const TInput & A)
58  {
59  // Because the user has to specify the constant we don't
60  // check if the cte is not 0;
61  VectorType vectorInput(A.GetSize());
62  VectorType vectorOutput(m_ConstantMatrix.Rows());
63  TOutput out;
64  out.SetSize( m_ConstantMatrix.Rows() );
65 
66  utl::VectorToVector<TInput, VectorType>(A, vectorInput, A.Size());
67  utl::ProductUtlMv(m_ConstantMatrix, vectorInput, vectorOutput );
68  utl::VectorToVector<VectorType, TOutput>(vectorOutput, out, vectorOutput.Size());
69 
70  return out;
71  }
72 
73  void SetConstantMatrix(const TMatrix& ct)
74  {
75  this->m_ConstantMatrix = ct;
76  }
77 
78  const TMatrix & GetConstantMatrix() const
79  {
80  return m_ConstantMatrix;
81  }
82 
84  {
85  return m_ConstantMatrix.Rows();
86  }
87 
89 };
90 }
91 
92 template <class TInputImage, class TConstantMatrix, class TOutputImage=TInputImage>
94  public
95  UnaryFunctorImageFilter<TInputImage, TOutputImage,
96  Functor::MultiplyByConstantMatrix<
97  typename TInputImage::PixelType, TConstantMatrix,
98  typename TOutputImage::PixelType> >
99 {
100 public:
103  typedef UnaryFunctorImageFilter<
104  TInputImage, TOutputImage,
106  typename TInputImage::PixelType, TConstantMatrix,
107  typename TOutputImage::PixelType> > Superclass;
108 
109  typedef SmartPointer<Self> Pointer;
110  typedef SmartPointer<const Self> ConstPointer;
111 
113  itkNewMacro( Self );
114 
116  itkTypeMacro( MultiplyByConstantMatrixVectorImageFilter, UnaryFunctorImageFilter );
117 
119  void SetConstantMatrix(const TConstantMatrix& ct )
120  {
121  if( ct != this->GetFunctor().GetConstantMatrix() )
122  {
123  this->GetFunctor().SetConstantMatrix( ct );
124  this->Modified();
125  }
126  }
127 
128  const TConstantMatrix & GetConstantMatrix() const
129  {
130  return this->GetFunctor().GetConstantMatrix();
131  }
132 
133 protected:
135  {
136  }
137 
139  {
140  }
141 
143  {
144  Superclass::GenerateOutputInformation();
145  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
146  unsigned dim = this->GetFunctor().GetNumberOfComponentsPerPixelInOutput();
147  outputPtr->SetNumberOfComponentsPerPixel(dim);
148  }
149 
150  void PrintSelf(std::ostream & os, Indent indent ) const ITK_OVERRIDE
151  {
152  Superclass::PrintSelf( os, indent );
153  os << indent << "Constant Matrix : " << this->GetConstantMatrix() << std::endl;
154  }
155 
156 private:
157  MultiplyByConstantMatrixVectorImageFilter(const Self &); // purposely not implemented
158  void operator=(const Self &); // purposely not implemented
159 };
160 } // end namespace itk
161 
162 
163 #endif
NDArray is a N-Dimensional array class (row-major, c version)
Definition: utlFunctors.h:131
bool operator==(const MultiplyByConstantMatrix &other) const
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
In each vxoel, multiply the input vector by a matrix.
bool operator!=(const MultiplyByConstantMatrix &other) const
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::MultiplyByConstantMatrix< typename TInputImage::PixelType, TConstantMatrix, typename TOutputImage::PixelType > > Superclass
void ProductUtlMv(const utl::NDArray< T, 2 > &A, const utl::NDArray< T, 1 > &b, utl::NDArray< T, 1 > &c, const double alpha=1.0, const double beta=0.0)