ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkModulusImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkModulusImageFilter_h
00019 #define __itkModulusImageFilter_h
00020 
00021 #include "itkUnaryFunctorImageFilter.h"
00022 
00023 namespace itk
00024 {
00025 namespace Functor
00026 {
00027 template< typename TInput, typename  TOutput >
00028 class ModulusTransform
00029 {
00030 public:
00031   ModulusTransform() { m_Dividend = 5; }
00032   ~ModulusTransform() {}
00033   void SetDividend(TOutput dividend) { m_Dividend = dividend; }
00034 
00035   bool operator!=(const ModulusTransform & other) const
00036   {
00037     if ( m_Dividend != other.m_Dividend )
00038       {
00039       return true;
00040       }
00041     return false;
00042   }
00043 
00044   bool operator==(const ModulusTransform & other) const
00045   {
00046     return !( *this != other );
00047   }
00048 
00049   inline TOutput operator()(const TInput & x) const
00050   {
00051     TOutput result = static_cast< TOutput >( x % m_Dividend );
00052 
00053     return result;
00054   }
00055 
00056 private:
00057   TInput m_Dividend;
00058 };
00059 }  // end namespace functor
00060 
00072 template< typename  TInputImage, typename  TOutputImage = TInputImage >
00073 class ITK_EXPORT ModulusImageFilter:
00074   public
00075   UnaryFunctorImageFilter< TInputImage, TOutputImage,
00076                            Functor::ModulusTransform<
00077                              typename TInputImage::PixelType,
00078                              typename TOutputImage::PixelType >   >
00079 {
00080 public:
00082   typedef ModulusImageFilter Self;
00083   typedef UnaryFunctorImageFilter<
00084     TInputImage, TOutputImage,
00085     Functor::ModulusTransform<
00086       typename TInputImage::PixelType,
00087       typename TOutputImage::PixelType > >  Superclass;
00088 
00089   typedef SmartPointer< Self >       Pointer;
00090   typedef SmartPointer< const Self > ConstPointer;
00091 
00092   typedef typename TOutputImage::PixelType                   OutputPixelType;
00093   typedef typename TInputImage::PixelType                    InputPixelType;
00094   typedef typename NumericTraits< InputPixelType >::RealType RealType;
00095 
00097   itkNewMacro(Self);
00098 
00100   itkTypeMacro(ModulusImageFilter,
00101                UnaryFunctorImageFilter);
00102 
00104   itkSetMacro(Dividend, InputPixelType);
00105   itkGetConstReferenceMacro(Dividend, InputPixelType);
00107 
00109   void PrintSelf(std::ostream & os, Indent indent) const;
00110 
00112   void BeforeThreadedGenerateData(void);
00113 
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115 
00116   itkConceptMacro( InputHasNumericTraitsCheck,
00117                    ( Concept::HasNumericTraits< InputPixelType > ) );
00118 
00120 #endif
00121 protected:
00122   ModulusImageFilter();
00123   virtual ~ModulusImageFilter() {}
00124 private:
00125   ModulusImageFilter(const Self &); //purposely not implemented
00126   void operator=(const Self &);     //purposely not implemented
00128 
00129   InputPixelType m_Dividend;
00130 };
00131 } // end namespace itk
00132 
00133 #ifndef ITK_MANUAL_INSTANTIATION
00134 #include "itkModulusImageFilter.hxx"
00135 #endif
00136 
00137 #endif
00138