ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkAddImageFilter.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 __itkAddImageFilter_h
00019 #define __itkAddImageFilter_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 = TInput1, class TOutput = TInput1 >
00034 class Add2
00035 {
00036 public:
00037   typedef typename NumericTraits< TInput1 >::AccumulateType AccumulatorType;
00038   Add2() {}
00039   ~Add2() {}
00040   bool operator!=(const Add2 &) const
00041   {
00042     return false;
00043   }
00045 
00046   bool operator==(const Add2 & other) const
00047   {
00048     return !( *this != other );
00049   }
00050 
00051   inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
00052   {
00053     const AccumulatorType sum = A;
00054 
00055     return static_cast< TOutput >( sum + B );
00056   }
00057 };
00058 }
00109 template< class TInputImage1, class TInputImage2 = TInputImage1, class TOutputImage = TInputImage1 >
00110 class ITK_EXPORT AddImageFilter:
00111   public
00112   BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00113                             Functor::Add2<
00114                               typename TInputImage1::PixelType,
00115                               typename TInputImage2::PixelType,
00116                               typename TOutputImage::PixelType >   >
00117 
00118 {
00119 public:
00121   typedef AddImageFilter Self;
00122   typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
00123                                     Functor::Add2<
00124                                       typename TInputImage1::PixelType,
00125                                       typename TInputImage2::PixelType,
00126                                       typename TOutputImage::PixelType > > Superclass;
00127 
00128   typedef SmartPointer< Self >       Pointer;
00129   typedef SmartPointer< const Self > ConstPointer;
00130 
00132   itkNewMacro(Self);
00133 
00135   itkTypeMacro(AddImageFilter,
00136                BinaryFunctorImageFilter);
00137 
00138 #ifdef ITK_USE_CONCEPT_CHECKING
00139 
00140   itkConceptMacro( Input1Input2OutputAdditiveOperatorsCheck,
00141                    ( Concept::AdditiveOperators< typename TInputImage1::PixelType,
00142                                                  typename TInputImage2::PixelType,
00143                                                  typename TOutputImage::PixelType > ) );
00144 
00146 #endif
00147 protected:
00148   AddImageFilter() {}
00149   virtual ~AddImageFilter() {}
00150 private:
00151   AddImageFilter(const Self &); //purposely not implemented
00152   void operator=(const Self &); //purposely not implemented
00153 };
00154 } // end namespace itk
00156 
00157 #endif
00158