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