ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkWeightedAddImageFilter.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 itkWeightedAddImageFilter_h
19 #define itkWeightedAddImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
33 template< typename TInput1, typename TInput2, typename TOutput >
35 {
36 public:
39  WeightedAdd2() : m_Alpha(0.0), m_Beta(0.0) {}
41  bool operator!=(const WeightedAdd2 & other) const
42  {
43  if ( m_Alpha != other.m_Alpha )
44  {
45  return true;
46  }
47  return false;
48  }
50 
51  bool operator==(const WeightedAdd2 & other) const
52  {
53  return !( *this != other );
54  }
55 
56  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
57  {
58  const RealType sum1 = A * m_Alpha;
59  const RealType sum2 = B * m_Beta;
60 
61  return static_cast< TOutput >( sum1 + sum2 );
62  }
63 
64  void SetAlpha(RealType alpha)
65  {
66  m_Alpha = alpha;
68  }
69 
71  {
72  return m_Alpha;
73  }
74 
75 private:
77  RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel
78 };
79 }
113 template< typename TInputImage1, typename TInputImage2, typename TOutputImage >
115  public
116  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
117  Functor::WeightedAdd2<
118  typename TInputImage1::PixelType,
119  typename TInputImage2::PixelType,
120  typename TOutputImage::PixelType > >
121 
122 {
123 public:
126  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
128  typename TInputImage1::PixelType,
129  typename TInputImage2::PixelType,
130  typename TOutputImage::PixelType >
132 
135 
137  typedef typename FunctorType::RealType RealType;
138 
140  itkNewMacro(Self);
141 
143  itkTypeMacro(WeightedAddImageFilter,
145 
147  void SetAlpha(RealType alpha)
148  {
149  this->GetFunctor().SetAlpha(alpha);
150  this->Modified();
151  }
153 
156  {
157  return this->GetFunctor().GetAlpha();
158  }
159 
160 #ifdef ITK_USE_CONCEPT_CHECKING
161  // Begin concept checking
162  itkConceptMacro( Input1HasNumericTraitsCheck,
164  itkConceptMacro( Input1RealTypeMultiplyCheck,
165  ( Concept::MultiplyOperator< typename TInputImage1::PixelType,
166  RealType, RealType > ) );
167  itkConceptMacro( Input2RealTypeMultiplyCheck,
168  ( Concept::MultiplyOperator< typename TInputImage2::PixelType,
169  RealType, RealType > ) );
170  // End concept checking
171 #endif
172 
173 protected:
176 
177 private:
178  WeightedAddImageFilter(const Self &); //purposely not implemented
179  void operator=(const Self &); //purposely not implemented
180 };
181 } // end namespace itk
182 
183 #endif
NumericTraits< TInput1 >::RealType RealType
SmartPointer< const Self > ConstPointer
Computes a weighted sum of two images pixel-wise.
void operator=(const Self &)
Base class for all process objects that output image data.
virtual void Modified() const
bool operator!=(const WeightedAdd2 &other) const
NumericTraits< TInput1 >::AccumulateType AccumulatorType
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::WeightedAdd2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
TOutput operator()(const TInput1 &A, const TInput2 &B) const
bool operator==(const WeightedAdd2 &other) const
Define additional traits for native types such as int or float.
#define itkConceptMacro(name, concept)
Implements pixel-wise generic operation of two images, or of an image and a constant.