ITK  4.6.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< typename TInput1, typename TInput2, typename 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, typename TInputImage2 = TInputImage1, typename TOutputImage = TInputImage1 >
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  // Begin concept checking
157  itkConceptMacro( InputHasNumericTraitsCheck,
159  // End concept checking
160 #endif
161 
162 protected:
164  virtual ~ModulusImageFilter() {}
165 
166 private:
167  ModulusImageFilter(const Self &); //purposely not implemented
168  void operator=(const Self &); //purposely not implemented
169 
170 };
171 } // end namespace itk
172 
173 #ifndef ITK_MANUAL_INSTANTIATION
174 #include "itkModulusImageFilter.hxx"
175 #endif
176 
177 #endif
bool operator!=(const Modulus &) const
void operator=(const Self &)
Computes the modulus (x % dividend) pixel-wise.
TOutputImage::PixelType OutputPixelType
TOutput operator()(const TInput &x) const
SmartPointer< Self > Pointer
void SetDividend(TOutput dividend)
bool operator==(const Modulus &other) const
bool operator==(const ModulusTransform &other) const
Base class for all process objects that output image data.
SmartPointer< const Self > ConstPointer
static T max(const T &)
virtual void SetDividend(InputPixelType _arg)
TInputImage1::PixelType InputPixelType
virtual const InputPixelType & GetDividend() const
Implements pixel-wise generic operation on one image.
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::Modulus< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
bool operator!=(const ModulusTransform &other) const
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
Implements pixel-wise generic operation of two images, or of an image and a constant.
TOutput operator()(const TInput1 &A, const TInput2 &B) const