ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkConstrainedValueAdditionImageFilter.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 __itkConstrainedValueAdditionImageFilter_h
00019 #define __itkConstrainedValueAdditionImageFilter_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 ConstrainedValueAddition
00035 {
00036 public:
00037   ConstrainedValueAddition() {}
00038   ~ConstrainedValueAddition() {}
00039   bool operator!=(const ConstrainedValueAddition &) const
00040   {
00041     return false;
00042   }
00044 
00045   bool operator==(const ConstrainedValueAddition & other) const
00046   {
00047     return !( *this != other );
00048   }
00049 
00050   inline TOutput operator()(const TInput1 & A,
00051                             const TInput2 & B) const
00052   {
00053     const double dA = static_cast< double >( A );
00054     const double dB = static_cast< double >( B );
00055     const double add = dA + dB;
00056     const double cadd1 = ( add < NumericTraits< TOutput >::max() ) ?
00057                          add : NumericTraits< TOutput >::max();
00058     const double cadd2 = ( cadd1 > NumericTraits< TOutput >::NonpositiveMin() ) ?
00059                          cadd1 : NumericTraits< TOutput >::NonpositiveMin();
00060 
00061     return static_cast< TOutput >( cadd2 );
00062   }
00063 };
00064 }
00095 template< class TInputImage1, class TInputImage2, class TOutputImage >
00096 class ITK_EXPORT ConstrainedValueAdditionImageFilter:
00097   public
00098   BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00099                             Functor::ConstrainedValueAddition<
00100                               typename TInputImage1::PixelType,
00101                               typename TInputImage2::PixelType,
00102                               typename TOutputImage::PixelType >   >
00103 {
00104 public:
00106   typedef ConstrainedValueAdditionImageFilter Self;
00107   typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00108                                     Functor::ConstrainedValueAddition<
00109                                       typename TInputImage1::PixelType,
00110                                       typename TInputImage2::PixelType,
00111                                       typename TOutputImage::PixelType > >
00112   Superclass;
00113   typedef SmartPointer< Self >       Pointer;
00114   typedef SmartPointer< const Self > ConstPointer;
00115 
00117   itkNewMacro(Self);
00118 
00120   itkTypeMacro(ConstrainedValueAdditionImageFilter,
00121                BinaryFunctorImageFilter);
00122 
00123 #ifdef ITK_USE_CONCEPT_CHECKING
00124 
00125   itkConceptMacro( Input1ConvertibleToDoubleCheck,
00126                    ( Concept::Convertible< typename TInputImage1::PixelType, double > ) );
00127   itkConceptMacro( Input2ConvertibleToDoubleCheck,
00128                    ( Concept::Convertible< typename TInputImage2::PixelType, double > ) );
00129   itkConceptMacro( DoubleConvertibleToOutputCastCheck,
00130                    ( Concept::Convertible< double, typename TOutputImage::PixelType > ) );
00131   itkConceptMacro( DoubleLessThanOutputCheck,
00132                    ( Concept::LessThanComparable< double, typename TOutputImage::PixelType > ) );
00133 
00135 #endif
00136 protected:
00137   ConstrainedValueAdditionImageFilter() {}
00138   virtual ~ConstrainedValueAdditionImageFilter() {}
00139 private:
00140   ConstrainedValueAdditionImageFilter(const Self &); //purposely not implemented
00141   void operator=(const Self &);                      //purposely not implemented
00142 };
00143 } // end namespace itk
00145 
00146 #endif
00147