1 #ifndef __clitkSetBackgroundImageFilter_h
2 #define __clitkSetBackgroundImageFilter_h
3 #include "itkBinaryFunctorImageFilter.h"
4 #include "itkNumericTraits.h"
12 template< class TInput, class TMask, class TOutput=TInput >
16 typedef typename itk::NumericTraits< TInput >::AccumulateType AccumulatorType;
18 //SetBackground(): m_OutsideValue(itk::NumericTraits< TOutput >::Zero),m_Fg(false),m_MaskValue( static_cast<TMask>(0) ) {};
21 m_OutsideValue=itk::NumericTraits< TOutput >::Zero;
23 m_MaskValue= static_cast<TMask>(0);
26 bool operator!=( const SetBackground & ) const
30 bool operator==( const SetBackground & other ) const
32 return !(*this != other);
35 inline TOutput operator()( const TInput & A, const TMask & B)
37 // Background mode: set everything = background value
40 if (B == m_MaskValue )
42 return static_cast<TOutput>( m_OutsideValue );
50 // Foreground mode: set everything != foreground value
53 if (B != m_MaskValue )
55 return static_cast<TOutput>( m_OutsideValue );
64 /** Method to explicitly set the outside value of the mask */
65 void SetOutsideValue( const TOutput &outsideValue )
67 m_OutsideValue = static_cast<TOutput>(outsideValue);
70 /** Method to get the outside value of the mask */
71 const TOutput &GetOutsideValue() const
73 return m_OutsideValue;
76 /** Method to explicitly set the relevant value of the mask */
77 void SetMaskValue( const TMask &maskValue )
79 m_MaskValue = static_cast<TMask>(maskValue);
82 /** Method to get the relevant value of the mask */
83 const TMask &GetMaskValue() const
88 /** Method to explicitly set the foreground mode of the mask */
89 void SetForeground( const bool &fg )
94 /** Method to get the foregroundmode of the mask */
95 const bool &GetForeground() const
101 TOutput m_OutsideValue;
108 template <class TInputImage, class TMaskImage, class TOutputImage=TInputImage>
109 class ITK_EXPORT SetBackgroundImageFilter :
111 itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
112 Functor::SetBackground<
113 typename TInputImage::PixelType,
114 typename TMaskImage::PixelType,
115 typename TOutputImage::PixelType> >
120 /** Standard class typedefs. */
121 typedef SetBackgroundImageFilter Self;
122 typedef itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
123 Functor::SetBackground<
124 typename TInputImage::PixelType,
125 typename TMaskImage::PixelType,
126 typename TOutputImage::PixelType>
128 typedef itk::SmartPointer<Self> Pointer;
129 typedef itk::SmartPointer<const Self> ConstPointer;
131 /** Method for creation through the object factory. */
134 /** Runtime information support. */
135 itkTypeMacro(SetBackgroundImageFilter,
136 BinaryFunctorImageFilter);
138 /** Method to explicitly set the outside value of the mask. Defaults to 0 */
139 void SetOutsideValue( const typename TOutputImage::PixelType & outsideValue )
141 if( this->GetOutsideValue() != outsideValue )
144 this->GetFunctor().SetOutsideValue( outsideValue );
148 const typename TOutputImage::PixelType & GetOutsideValue() const
150 return this->GetFunctor().GetOutsideValue();
153 /** Method to explicitly set the value of the mask. Defaults to 0 */
154 void SetMaskValue( const typename TMaskImage::PixelType & maskValue )
156 if( this->GetMaskValue() != maskValue )
159 this->GetFunctor().SetMaskValue( maskValue );
163 const typename TMaskImage::PixelType & GetMaskValue() const
165 return this->GetFunctor().GetMaskValue();
168 /** Method to set the foreground mode. Defaults to 0 */
169 void SetForeground( const bool & fg )
171 if( this->GetForeground() != fg )
174 this->GetFunctor().SetForeground( fg );
178 const bool & GetForeground() const
180 return this->GetFunctor().GetForeground();
183 #ifdef ITK_USE_CONCEPT_CHECKING
184 /** Begin concept checking */
185 itkConceptMacro(MaskEqualityComparableCheck,
186 (itk::Concept::EqualityComparable<typename TMaskImage::PixelType>));
187 itkConceptMacro(InputConvertibleToOutputCheck,
188 (itk::Concept::Convertible<typename TInputImage::PixelType,
189 typename TOutputImage::PixelType>));
190 /** End concept checking */
194 SetBackgroundImageFilter() {}
195 virtual ~SetBackgroundImageFilter() {}
197 void PrintSelf(std::ostream &os, itk::Indent indent) const
199 Superclass::PrintSelf(os, indent);
200 os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
201 os << indent << "MaskValue: " << this->GetMaskValue() << std::endl;
202 os << indent << "Foreground mode: " << this->GetForeground() << std::endl;
206 SetBackgroundImageFilter(const Self&); //purposely not implemented
207 void operator=(const Self&); //purposely not implemented
211 } // end namespace clitk