ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
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 __itkNaryAddImageFilter_h 00019 #define __itkNaryAddImageFilter_h 00020 00021 #include "itkNaryFunctorImageFilter.h" 00022 #include "itkNumericTraits.h" 00023 00024 namespace itk 00025 { 00026 namespace Functor 00027 { 00033 template< class TInput, class TOutput > 00034 class Add1 00035 { 00036 public: 00037 typedef typename NumericTraits< TInput >::AccumulateType AccumulatorType; 00038 Add1() {} 00039 ~Add1() {} 00040 inline TOutput operator()(const std::vector< TInput > & B) const 00041 { 00042 AccumulatorType sum = NumericTraits< TOutput >::Zero; 00044 00045 for ( unsigned int i = 0; i < B.size(); i++ ) 00046 { 00047 sum += static_cast< AccumulatorType >( B[i] ); 00048 } 00049 return static_cast< TOutput >( sum ); 00050 } 00051 00052 bool operator==(const Add1 &) const 00053 { 00054 return true; 00055 } 00056 00057 bool operator!=(const Add1 &) const 00058 { 00059 return false; 00060 } 00061 }; 00062 } 00097 template< class TInputImage, class TOutputImage > 00098 class ITK_EXPORT NaryAddImageFilter: 00099 public 00100 NaryFunctorImageFilter< TInputImage, TOutputImage, 00101 Functor::Add1< typename TInputImage::PixelType, typename TInputImage::PixelType > > 00102 { 00103 public: 00105 typedef NaryAddImageFilter Self; 00106 typedef NaryFunctorImageFilter< 00107 TInputImage, TOutputImage, 00108 Functor::Add1< typename TInputImage::PixelType, 00109 typename TInputImage::PixelType > > Superclass; 00110 00111 typedef SmartPointer< Self > Pointer; 00112 typedef SmartPointer< const Self > ConstPointer; 00113 00115 itkNewMacro(Self); 00116 00118 itkTypeMacro(NaryAddImageFilter, 00119 NaryFunctorImageFilter); 00120 00121 #ifdef ITK_USE_CONCEPT_CHECKING 00122 00123 itkConceptMacro( InputConvertibleToOutputCheck, 00124 ( Concept::Convertible< typename TInputImage::PixelType, 00125 typename TOutputImage::PixelType > ) ); 00126 itkConceptMacro( InputHasZeroCheck, 00127 ( Concept::HasZero< typename TInputImage::PixelType > ) ); 00128 00130 #endif 00131 protected: 00132 NaryAddImageFilter() {} 00133 virtual ~NaryAddImageFilter() {} 00134 private: 00135 NaryAddImageFilter(const Self &); //purposely not implemented 00136 void operator=(const Self &); //purposely not implemented 00137 }; 00138 } // end namespace itk 00140 00141 #endif 00142