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 __itkWeightedAddImageFilter_h 00019 #define __itkWeightedAddImageFilter_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 WeightedAdd2 00035 { 00036 public: 00037 typedef typename NumericTraits< TInput1 >::AccumulateType AccumulatorType; 00038 typedef typename NumericTraits< TInput1 >::RealType RealType; 00039 WeightedAdd2() {} 00040 ~WeightedAdd2() {} 00041 bool operator!=(const WeightedAdd2 & other) const 00042 { 00043 if ( m_Alpha != other.m_Alpha ) 00044 { 00045 return true; 00046 } 00047 return false; 00048 } 00050 00051 bool operator==(const WeightedAdd2 & other) const 00052 { 00053 return !( *this != other ); 00054 } 00055 00056 inline TOutput operator()(const TInput1 & A, const TInput2 & B) const 00057 { 00058 const RealType sum1 = A * m_Alpha; 00059 const RealType sum2 = B * m_Beta; 00060 00061 return static_cast< TOutput >( sum1 + sum2 ); 00062 } 00063 00064 void SetAlpha(RealType alpha) 00065 { 00066 m_Alpha = alpha; 00067 m_Beta = NumericTraits< RealType >::One - m_Alpha; 00068 } 00069 00070 RealType GetAlpha() const 00071 { 00072 return m_Alpha; 00073 } 00074 00075 private: 00076 RealType m_Alpha; 00077 RealType m_Beta; // auxiliary var to avoid a subtraction at every pixel 00078 }; 00079 } 00113 template< class TInputImage1, class TInputImage2, class TOutputImage > 00114 class ITK_EXPORT WeightedAddImageFilter: 00115 public 00116 BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, 00117 Functor::WeightedAdd2< 00118 typename TInputImage1::PixelType, 00119 typename TInputImage2::PixelType, 00120 typename TOutputImage::PixelType > > 00121 00122 { 00123 public: 00125 typedef WeightedAddImageFilter Self; 00126 typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, 00127 Functor::WeightedAdd2< 00128 typename TInputImage1::PixelType, 00129 typename TInputImage2::PixelType, 00130 typename TOutputImage::PixelType > 00131 > Superclass; 00132 00133 typedef SmartPointer< Self > Pointer; 00134 typedef SmartPointer< const Self > ConstPointer; 00135 00136 typedef typename Superclass::FunctorType FunctorType; 00137 typedef typename FunctorType::RealType RealType; 00138 00140 itkNewMacro(Self); 00141 00143 itkTypeMacro(WeightedAddImageFilter, 00144 BinaryFunctorImageFilter); 00145 00147 void SetAlpha(RealType alpha) 00148 { 00149 this->GetFunctor().SetAlpha(alpha); 00150 this->Modified(); 00151 } 00153 00154 #ifdef ITK_USE_CONCEPT_CHECKING 00155 00156 itkConceptMacro( Input1HasNumericTraitsCheck, 00157 ( Concept::HasNumericTraits< typename TInputImage1::PixelType > ) ); 00158 itkConceptMacro( Input1RealTypeMultiplyCheck, 00159 ( Concept::MultiplyOperator< typename TInputImage1::PixelType, 00160 RealType, RealType > ) ); 00161 itkConceptMacro( Input2RealTypeMultiplyCheck, 00162 ( Concept::MultiplyOperator< typename TInputImage2::PixelType, 00163 RealType, RealType > ) ); 00164 00166 #endif 00167 protected: 00168 WeightedAddImageFilter() {} 00169 virtual ~WeightedAddImageFilter() {} 00170 private: 00171 WeightedAddImageFilter(const Self &); //purposely not implemented 00172 void operator=(const Self &); //purposely not implemented 00173 }; 00174 } // end namespace itk 00176 00177 #endif 00178