ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkAbsoluteValueDifferenceImageFilter.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 __itkAbsoluteValueDifferenceImageFilter_h
00019 #define __itkAbsoluteValueDifferenceImageFilter_h
00020 
00021 #include "itkBinaryFunctorImageFilter.h"
00022 #include "itkConceptChecking.h"
00023 
00024 namespace itk
00025 {
00054 namespace Functor
00055 {
00056 template< class TInput1, class TInput2, class TOutput >
00057 class AbsoluteValueDifference2
00058 {
00059 public:
00060   AbsoluteValueDifference2() {}
00061   ~AbsoluteValueDifference2() {}
00062   bool operator!=(const AbsoluteValueDifference2 &) const
00063   {
00064     return false;
00065   }
00066 
00067   bool operator==(const AbsoluteValueDifference2 & other) const
00068   {
00069     return !( *this != other );
00070   }
00071 
00072   inline TOutput operator()(const TInput1 & A,
00073                             const TInput2 & B) const
00074   {
00075     const double dA = static_cast< double >( A );
00076     const double dB = static_cast< double >( B );
00077     const double diff = dA - dB;
00078     const double absdiff = ( diff > 0.0 ) ? diff : -diff;
00079 
00080     return static_cast< TOutput >( absdiff );
00081   }
00082 };
00083 }
00084 
00085 template< class TInputImage1, class TInputImage2, class TOutputImage >
00086 class ITK_EXPORT AbsoluteValueDifferenceImageFilter:
00087   public
00088   BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00089                             Functor::AbsoluteValueDifference2<
00090                               typename TInputImage1::PixelType,
00091                               typename TInputImage2::PixelType,
00092                               typename TOutputImage::PixelType >   >
00093 {
00094 public:
00096   typedef AbsoluteValueDifferenceImageFilter Self;
00097   typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00098                                     Functor::AbsoluteValueDifference2<
00099                                       typename TInputImage1::PixelType,
00100                                       typename TInputImage2::PixelType,
00101                                       typename TOutputImage::PixelType >
00102                                     >  Superclass;
00103 
00104   typedef SmartPointer< Self >       Pointer;
00105   typedef SmartPointer< const Self > ConstPointer;
00106 
00108   itkNewMacro(Self);
00109 
00111   itkTypeMacro(AbsoluteValueDifferenceImageFilter,
00112                BinaryFunctorImageFilter);
00113 
00114 #ifdef ITK_USE_CONCEPT_CHECKING
00115 
00116   itkConceptMacro( Input1CovertibleToDoubleCheck,
00117                    ( Concept::Convertible< typename TInputImage1::PixelType, double > ) );
00118   itkConceptMacro( Input2ConvertibleToDoubleCheck,
00119                    ( Concept::Convertible< typename TInputImage2::PixelType, double > ) );
00120   itkConceptMacro( DoubleCovertibleToOutputCheck,
00121                    ( Concept::Convertible< double, typename TOutputImage::PixelType > ) );
00122 
00124 #endif
00125 protected:
00126   AbsoluteValueDifferenceImageFilter() {}
00127   virtual ~AbsoluteValueDifferenceImageFilter() {}
00128 private:
00129   AbsoluteValueDifferenceImageFilter(const Self &); //purposely not implemented
00130   void operator=(const Self &);                     //purposely not implemented
00131 };
00132 } // end namespace itk
00134 
00135 #endif
00136