1 #ifndef __clitkSetBackgroundImageFilter_h
2 #define __clitkSetBackgroundImageFilter_h
4 #include "itkBinaryFunctorImageFilter.h"
5 #include "itkNumericTraits.h"
13 template< class TInput, class TMask, class TOutput=TInput >
17 typedef typename itk::NumericTraits< TInput >::AccumulateType AccumulatorType;
19 //SetBackground(): m_OutsideValue(itk::NumericTraits< TOutput >::Zero),m_Fg(false),m_MaskValue( static_cast<TMask>(0) ) {};
22 m_OutsideValue=itk::NumericTraits< TOutput >::Zero;
24 m_MaskValue= static_cast<TMask>(0);
27 bool operator!=( const SetBackground & ) const
31 bool operator==( const SetBackground & other ) const
33 return !(*this != other);
36 inline TOutput operator()( const TInput & A, const TMask & B)
38 // Background mode: set everything = background value
41 if (B == m_MaskValue )
43 return static_cast<TOutput>( m_OutsideValue );
51 // Foreground mode: set everything != foreground value
54 if (B != m_MaskValue )
56 return static_cast<TOutput>( m_OutsideValue );
65 /** Method to explicitly set the outside value of the mask */
66 void SetOutsideValue( const TOutput &outsideValue )
68 m_OutsideValue = static_cast<TOutput>(outsideValue);
71 /** Method to get the outside value of the mask */
72 const TOutput &GetOutsideValue() const
74 return m_OutsideValue;
77 /** Method to explicitly set the relevant value of the mask */
78 void SetMaskValue( const TMask &maskValue )
80 m_MaskValue = static_cast<TMask>(maskValue);
83 /** Method to get the relevant value of the mask */
84 const TMask &GetMaskValue() const
89 /** Method to explicitly set the foreground mode of the mask */
90 void SetForeground( const bool &fg )
95 /** Method to get the foregroundmode of the mask */
96 const bool &GetForeground() const
102 TOutput m_OutsideValue;
109 template <class TInputImage, class TMaskImage, class TOutputImage=TInputImage>
110 class ITK_EXPORT SetBackgroundImageFilter :
112 itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
113 Functor::SetBackground<
114 typename TInputImage::PixelType,
115 typename TMaskImage::PixelType,
116 typename TOutputImage::PixelType> >
121 /** Standard class typedefs. */
122 typedef SetBackgroundImageFilter Self;
123 typedef itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
124 Functor::SetBackground<
125 typename TInputImage::PixelType,
126 typename TMaskImage::PixelType,
127 typename TOutputImage::PixelType>
129 typedef itk::SmartPointer<Self> Pointer;
130 typedef itk::SmartPointer<const Self> ConstPointer;
132 /** Method for creation through the object factory. */
135 /** Runtime information support. */
136 itkTypeMacro(SetBackgroundImageFilter,
137 BinaryFunctorImageFilter);
139 /** Method to explicitly set the outside value of the mask. Defaults to 0 */
140 void SetOutsideValue( const typename TOutputImage::PixelType & outsideValue )
142 if( this->GetOutsideValue() != outsideValue )
145 this->GetFunctor().SetOutsideValue( outsideValue );
149 const typename TOutputImage::PixelType & GetOutsideValue() const
151 return this->GetFunctor().GetOutsideValue();
154 /** Method to explicitly set the value of the mask. Defaults to 0 */
155 void SetMaskValue( const typename TMaskImage::PixelType & maskValue )
157 if( this->GetMaskValue() != maskValue )
160 this->GetFunctor().SetMaskValue( maskValue );
164 const typename TMaskImage::PixelType & GetMaskValue() const
166 return this->GetFunctor().GetMaskValue();
169 /** Method to set the foreground mode. Defaults to 0 */
170 void SetForeground( const bool & fg )
172 if( this->GetForeground() != fg )
175 this->GetFunctor().SetForeground( fg );
179 const bool & GetForeground() const
181 return this->GetFunctor().GetForeground();
184 #ifdef ITK_USE_CONCEPT_CHECKING
185 /** Begin concept checking */
186 itkConceptMacro(MaskEqualityComparableCheck,
187 (itk::Concept::EqualityComparable<typename TMaskImage::PixelType>));
188 itkConceptMacro(InputConvertibleToOutputCheck,
189 (itk::Concept::Convertible<typename TInputImage::PixelType,
190 typename TOutputImage::PixelType>));
191 /** End concept checking */
195 SetBackgroundImageFilter() {}
196 virtual ~SetBackgroundImageFilter() {}
198 void PrintSelf(std::ostream &os, itk::Indent indent) const
200 Superclass::PrintSelf(os, indent);
201 os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
202 os << indent << "MaskValue: " << this->GetMaskValue() << std::endl;
203 os << indent << "Foreground mode: " << this->GetForeground() << std::endl;
207 SetBackgroundImageFilter(const Self&); //purposely not implemented
208 void operator=(const Self&); //purposely not implemented
212 } // end namespace clitk