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