ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkNaryAddImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkNaryAddImageFilter_h
19 #define __itkNaryAddImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
33 template< class TInput, class TOutput >
34 class Add1
35 {
36 public:
38  Add1() {}
39  ~Add1() {}
40  inline TOutput operator()(const std::vector< TInput > & B) const
41  {
44 
45  for ( unsigned int i = 0; i < B.size(); i++ )
46  {
47  sum += static_cast< AccumulatorType >( B[i] );
48  }
49  return static_cast< TOutput >( sum );
50  }
51 
52  bool operator==(const Add1 &) const
53  {
54  return true;
55  }
56 
57  bool operator!=(const Add1 &) const
58  {
59  return false;
60  }
61 };
62 }
97 template< class TInputImage, class TOutputImage >
98 class ITK_EXPORT NaryAddImageFilter:
99  public
100  NaryFunctorImageFilter< TInputImage, TOutputImage,
101  Functor::Add1< typename TInputImage::PixelType, typename TInputImage::PixelType > >
102 {
103 public:
106  typedef NaryFunctorImageFilter<
107  TInputImage, TOutputImage,
108  Functor::Add1< typename TInputImage::PixelType,
109  typename TInputImage::PixelType > > Superclass;
110 
113 
115  itkNewMacro(Self);
116 
118  itkTypeMacro(NaryAddImageFilter,
120 
121 #ifdef ITK_USE_CONCEPT_CHECKING
122 
123  itkConceptMacro( InputConvertibleToOutputCheck,
124  ( Concept::Convertible< typename TInputImage::PixelType,
125  typename TOutputImage::PixelType > ) );
126  itkConceptMacro( InputHasZeroCheck,
128 
130 #endif
131 protected:
133  virtual ~NaryAddImageFilter() {}
134 private:
135  NaryAddImageFilter(const Self &); //purposely not implemented
136  void operator=(const Self &); //purposely not implemented
137 };
138 } // end namespace itk
140 
141 #endif
142