ITK  4.4.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  {
52  {
53  return static_cast< TOutput >( A % B );
54  }
55  else
56  {
57  return NumericTraits< TOutput >::max( static_cast<TOutput>(A) );
58  }
59  }
60 
61 };
62 
70 template< typename TInput, typename TOutput >
72 {
73 public:
76  void SetDividend(TOutput dividend) { m_Dividend = dividend; }
77 
78  bool operator!=(const ModulusTransform & other) const
79  {
80  if ( m_Dividend != other.m_Dividend )
81  {
82  return true;
83  }
84  return false;
85  }
86 
87  bool operator==(const ModulusTransform & other) const
88  {
89  return !( *this != other );
90  }
91 
92  inline TOutput operator()(const TInput & x) const
93  {
94  TOutput result = static_cast< TOutput >( x % m_Dividend );
95 
96  return result;
97  }
98 
99 private:
100  TInput m_Dividend;
101 };
102 
103 } // end namespace functor
104 
118 template< typename TInputImage1, class TInputImage2 = TInputImage1, class TOutputImage = TInputImage1 >
119 class ITK_EXPORT ModulusImageFilter:
120  public
121  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
122  Functor::Modulus<
123  typename TInputImage1::PixelType,
124  typename TInputImage2::PixelType,
125  typename TOutputImage::PixelType > >
126 {
127 public:
130  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
132  typename TInputImage1::PixelType,
133  typename TInputImage2::PixelType,
134  typename TOutputImage::PixelType > > Superclass;
135 
138 
139  typedef typename TOutputImage::PixelType OutputPixelType;
140  typedef typename TInputImage1::PixelType InputPixelType;
141 
143  itkNewMacro(Self);
144 
146  itkTypeMacro(ModulusImageFilter,
148 
150  virtual void SetDividend( InputPixelType _arg ) { this->SetConstant2(_arg); }
151  virtual const InputPixelType &GetDividend () const { return this->GetConstant2(); }
153 
154 
155 #ifdef ITK_USE_CONCEPT_CHECKING
156 
157  itkConceptMacro( InputHasNumericTraitsCheck,
159 
161 #endif
162 
163 protected:
165  virtual ~ModulusImageFilter() {}
166 
167 private:
168  ModulusImageFilter(const Self &); //purposely not implemented
169  void operator=(const Self &); //purposely not implemented
170 
171 };
172 } // end namespace itk
173 
174 #ifndef ITK_MANUAL_INSTANTIATION
175 #include "itkModulusImageFilter.hxx"
176 #endif
177 
178 #endif
179