ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkDivideImageFilter.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 __itkDivideImageFilter_h
00019 #define __itkDivideImageFilter_h
00020 
00021 #include "itkBinaryFunctorImageFilter.h"
00022 #include "itkNumericTraits.h"
00023 
00024 namespace itk
00025 {
00026 namespace Functor
00027 {
00033 template< class TInput1, class TInput2, class TOutput >
00034 class Div
00035 {
00036 public:
00037   Div() {}
00038   ~Div() {}
00039   bool operator!=(const Div &) const
00040   {
00041     return false;
00042   }
00044 
00045   bool operator==(const Div & other) const
00046   {
00047     return !( *this != other );
00048   }
00049 
00050   inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
00051   {
00052     if ( B != (TInput2)0 )
00053       {
00054       return (TOutput)( A / B );
00055       }
00056     else
00057       {
00058       return NumericTraits< TOutput >::max(A);
00059       }
00060   }
00061 };
00062 }
00080 template< class TInputImage1, class TInputImage2, class TOutputImage >
00081 class ITK_EXPORT DivideImageFilter:
00082   public
00083   BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00084                             Functor::Div<
00085                               typename TInputImage1::PixelType,
00086                               typename TInputImage2::PixelType,
00087                               typename TOutputImage::PixelType >   >
00088 {
00089 public:
00093   typedef DivideImageFilter Self;
00094 
00098   typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00099                                     Functor::Div<
00100                                       typename TInputImage1::PixelType,
00101                                       typename TInputImage2::PixelType,
00102                                       typename TOutputImage::PixelType >
00103                                     > Superclass;
00104 
00108   typedef SmartPointer< Self >       Pointer;
00109   typedef SmartPointer< const Self > ConstPointer;
00110 
00114   itkNewMacro(Self);
00115 
00117   itkTypeMacro(DivideImageFilter,
00118                BinaryFunctorImageFilter);
00119 
00120 #ifdef ITK_USE_CONCEPT_CHECKING
00121 
00122   itkConceptMacro( IntConvertibleToInput2Check,
00123                    ( Concept::Convertible< int, typename TInputImage2::PixelType > ) );
00124   itkConceptMacro( Input1Input2OutputDivisionOperatorsCheck,
00125                    ( Concept::DivisionOperators< typename TInputImage1::PixelType,
00126                                                  typename TInputImage2::PixelType,
00127                                                  typename TOutputImage::PixelType > ) );
00128 
00130 #endif
00131 protected:
00132   DivideImageFilter() {}
00133   virtual ~DivideImageFilter() {}
00135 
00136   void GenerateData()
00137     {
00138     const typename Superclass::DecoratedInput2ImagePixelType *input
00139        = dynamic_cast< const typename Superclass::DecoratedInput2ImagePixelType * >(
00140         this->ProcessObject::GetInput(1) );
00141     if( input != NULL && input->Get() == itk::NumericTraits< typename TInputImage2::PixelType >::Zero )
00142       {
00143       itkGenericExceptionMacro(<<"The constant value used as denominator should not be set to zero");
00144       }
00145     else
00146       {
00147       Superclass::GenerateData();
00148       }
00149     }
00150 
00151 private:
00152   DivideImageFilter(const Self &); //purposely not implemented
00153   void operator=(const Self &); //purposely not implemented
00154 
00155 };
00156 } // end namespace itk
00157 
00158 #endif
00159