ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkModulusImageFilter.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 __itkModulusImageFilter_h
19 #define __itkModulusImageFilter_h
20 
22 
23 namespace itk
24 {
25 namespace Functor
26 {
27 
32 template< class TInput1, class TInput2, class TOutput >
33 class Modulus
34 {
35 public:
36  Modulus() { }
37  ~Modulus() {}
38 
39  bool operator!=(const Modulus &) const
40  {
41  return false;
42  }
43 
44  bool operator==(const Modulus & other) const
45  {
46  return !( *this != other );
47  }
48 
49  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
50  {
51  TOutput result = static_cast< TOutput >( A % B );
52 
53  return result;
54  }
55 
56 };
57 
65 template< typename TInput, typename TOutput >
67 {
68 public:
71  void SetDividend(TOutput dividend) { m_Dividend = dividend; }
72 
73  bool operator!=(const ModulusTransform & other) const
74  {
75  if ( m_Dividend != other.m_Dividend )
76  {
77  return true;
78  }
79  return false;
80  }
81 
82  bool operator==(const ModulusTransform & other) const
83  {
84  return !( *this != other );
85  }
86 
87  inline TOutput operator()(const TInput & x) const
88  {
89  TOutput result = static_cast< TOutput >( x % m_Dividend );
90 
91  return result;
92  }
93 
94 private:
95  TInput m_Dividend;
96 };
97 
98 } // end namespace functor
99 
111 template< typename TInputImage1, class TInputImage2 = TInputImage1, class TOutputImage = TInputImage1 >
112 class ITK_EXPORT ModulusImageFilter:
113  public
114  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
115  Functor::Modulus<
116  typename TInputImage1::PixelType,
117  typename TInputImage2::PixelType,
118  typename TOutputImage::PixelType > >
119 {
120 public:
123  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
125  typename TInputImage1::PixelType,
126  typename TInputImage2::PixelType,
127  typename TOutputImage::PixelType > > Superclass;
128 
131 
132  typedef typename TOutputImage::PixelType OutputPixelType;
133  typedef typename TInputImage1::PixelType InputPixelType;
134 
136  itkNewMacro(Self);
137 
139  itkTypeMacro(ModulusImageFilter,
141 
143  virtual void SetDividend( InputPixelType _arg ) { this->SetConstant2(_arg); }
144  virtual const InputPixelType &GetDividend () const { return this->GetConstant2(); }
146 
147 
148 #ifdef ITK_USE_CONCEPT_CHECKING
149 
150  itkConceptMacro( InputHasNumericTraitsCheck,
152 
154 #endif
155 
156 protected:
158  virtual ~ModulusImageFilter() {}
159 
160 private:
161  ModulusImageFilter(const Self &); //purposely not implemented
162  void operator=(const Self &); //purposely not implemented
163 
164 };
165 } // end namespace itk
166 
167 #ifndef ITK_MANUAL_INSTANTIATION
168 #include "itkModulusImageFilter.hxx"
169 #endif
170 
171 #endif
172