DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkMultiplyByConstantVectorImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMultiplyByConstantVectorImageFilter_h
19 #define __itkMultiplyByConstantVectorImageFilter_h
20 
21 #include "itkUnaryFunctorImageFilter.h"
22 
23 namespace itk
24 {
35 namespace Functor
36 {
37 template <class TInput, class TConstantVector, class TOutput=TInput>
39 {
40 public:
42  {
43  }
44 
46  {
47  }
48 
49  bool operator!=(const MultiplyByConstantVector & other) const
50  {
51  return !( *this == other );
52  }
53 
54  bool operator==(const MultiplyByConstantVector & other) const
55  {
56  return other.m_ConstantVector == m_ConstantVector;
57  }
58 
59  inline TOutput operator()(const TInput & A) const
60  {
61  // Because the user has to specify the constant we don't
62  // check if the cte is not 0;
63 
64  unsigned int vectorSize = A.GetSize();
65  TOutput value;
66  value.SetSize( vectorSize );
67 
68  for( unsigned int i = 0; i < vectorSize; i++ )
69  {
70  value[i] = A[i] * m_ConstantVector[i];
71  }
72  return value;
73  }
74 
75  void SetConstantVector(const TConstantVector& ct)
76  {
77  this->m_ConstantVector = ct;
78  }
79 
80  const TConstantVector & GetConstantVector() const
81  {
82  return m_ConstantVector;
83  }
84 
85  TConstantVector m_ConstantVector;
86 };
87 }
88 
89 template <class TInputImage, class TConstantVector, class TOutputImage=TInputImage>
91  public
92  UnaryFunctorImageFilter<TInputImage, TOutputImage,
93  Functor::MultiplyByConstantVector<
94  typename TInputImage::PixelType, TConstantVector,
95  typename TOutputImage::PixelType> >
96 {
97 public:
100  typedef UnaryFunctorImageFilter<
101  TInputImage, TOutputImage,
103  typename TInputImage::PixelType, TConstantVector,
104  typename TOutputImage::PixelType> > Superclass;
105 
106  typedef SmartPointer<Self> Pointer;
107  typedef SmartPointer<const Self> ConstPointer;
108 
110  itkNewMacro( Self );
111 
113  itkTypeMacro( MultiplyByConstantVectorImageFilter, UnaryFunctorImageFilter );
114 
116  void SetConstantVector( const TConstantVector& ct )
117  {
118  if( ct != this->GetFunctor().GetConstantVector() )
119  {
120  this->GetFunctor().SetConstantVector( ct );
121  this->Modified();
122  }
123  }
124 
125  const TConstantVector & GetConstantVector() const
126  {
127  return this->GetFunctor().GetConstantVector();
128  }
129 
130 protected:
132  {
133  }
134 
136  {
137  }
138 
139  void PrintSelf(std::ostream & os, Indent indent ) const
140  {
141  Superclass::PrintSelf( os, indent );
142 
143  os << indent << "Constant Vector: " << this->GetConstantVector() << std::endl;
144  }
145 
146 private:
147  MultiplyByConstantVectorImageFilter(const Self &); // purposely not implemented
148  void operator=(const Self &); // purposely not implemented
149 };
150 } // end namespace itk
151 
152 #endif
void PrintSelf(std::ostream &os, Indent indent) const
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::MultiplyByConstantVector< typename TInputImage::PixelType, TConstantVector, typename TOutputImage::PixelType > > Superclass
bool operator!=(const MultiplyByConstantVector &other) const
bool operator==(const MultiplyByConstantVector &other) const