1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef __clitkSetBackgroundImageFilter_h
19 #define __clitkSetBackgroundImageFilter_h
20 #include "itkFlexibleBinaryFunctorImageFilter.h"
21 #include "itkNumericTraits.h"
23 #include "clitkCommon.h"
31 template< class TInput, class TMask, class TOutput=TInput >
35 typedef typename itk::NumericTraits< TInput >::AccumulateType AccumulatorType;
37 //SetBackground(): m_OutsideValue(itk::NumericTraits< TOutput >::Zero),m_Fg(false),m_MaskValue( static_cast<TMask>(0) ) {};
40 m_OutsideValue=itk::NumericTraits< TOutput >::Zero;
42 m_MaskValue= static_cast<TMask>(0);
45 bool operator!=( const SetBackground & ) const
49 bool operator==( const SetBackground & other ) const
51 return !(*this != other);
54 inline TOutput operator()( const TInput & A, const TMask & B)
56 // Background mode: set everything = background value
59 if (B == m_MaskValue )
61 return static_cast<TOutput>( m_OutsideValue );
69 // Foreground mode: set everything != foreground value
72 if (B != m_MaskValue )
74 return static_cast<TOutput>( m_OutsideValue );
83 /** Method to explicitly set the outside value of the mask */
84 void SetOutsideValue( const TOutput &outsideValue )
86 m_OutsideValue = static_cast<TOutput>(outsideValue);
89 /** Method to get the outside value of the mask */
90 const TOutput &GetOutsideValue() const
92 return m_OutsideValue;
95 /** Method to explicitly set the relevant value of the mask */
96 void SetMaskValue( const TMask &maskValue )
98 m_MaskValue = static_cast<TMask>(maskValue);
101 /** Method to get the relevant value of the mask */
102 const TMask &GetMaskValue() const
107 /** Method to explicitly set the foreground mode of the mask */
108 void SetForeground( const bool &fg )
113 /** Method to get the foregroundmode of the mask */
114 const bool &GetForeground() const
120 TOutput m_OutsideValue;
127 template <class TInputImage, class TMaskImage, class TOutputImage=TInputImage>
128 class ITK_EXPORT SetBackgroundImageFilter :
130 itk::FlexibleBinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
131 Functor::SetBackground<
132 typename TInputImage::PixelType,
133 typename TMaskImage::PixelType,
134 typename TOutputImage::PixelType> >
139 /** Standard class typedefs. */
140 typedef SetBackgroundImageFilter Self;
141 typedef itk::FlexibleBinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
142 Functor::SetBackground<
143 typename TInputImage::PixelType,
144 typename TMaskImage::PixelType,
145 typename TOutputImage::PixelType>
147 typedef itk::SmartPointer<Self> Pointer;
148 typedef itk::SmartPointer<const Self> ConstPointer;
150 /** Method for creation through the object factory. */
153 /** Runtime information support. */
154 itkTypeMacro(SetBackgroundImageFilter,
155 FlexibleBinaryFunctorImageFilter);
157 /** Method to explicitly set the outside value of the mask. Defaults to 0 */
158 void SetOutsideValue( const typename TOutputImage::PixelType & outsideValue )
160 if( this->GetOutsideValue() != outsideValue )
163 this->GetFunctor().SetOutsideValue( outsideValue );
167 const typename TOutputImage::PixelType & GetOutsideValue() const
169 return this->GetFunctor().GetOutsideValue();
172 /** Method to explicitly set the value of the mask. Defaults to 0 */
173 void SetMaskValue( const typename TMaskImage::PixelType & maskValue )
175 if( this->GetMaskValue() != maskValue )
178 this->GetFunctor().SetMaskValue( maskValue );
182 const typename TMaskImage::PixelType & GetMaskValue() const
184 return this->GetFunctor().GetMaskValue();
187 /** Method to set the foreground mode. Defaults to 0 */
188 void SetForeground( const bool & fg )
190 if( this->GetForeground() != fg )
193 this->GetFunctor().SetForeground( fg );
197 const bool & GetForeground() const
199 return this->GetFunctor().GetForeground();
202 #ifdef ITK_USE_CONCEPT_CHECKING
203 /** Begin concept checking */
204 itkConceptMacro(MaskEqualityComparableCheck,
205 (itk::Concept::EqualityComparable<typename TMaskImage::PixelType>));
206 itkConceptMacro(InputConvertibleToOutputCheck,
207 (itk::Concept::Convertible<typename TInputImage::PixelType,
208 typename TOutputImage::PixelType>));
209 /** End concept checking */
213 SetBackgroundImageFilter() {}
214 virtual ~SetBackgroundImageFilter() {}
216 void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
218 Superclass::PrintSelf(os, indent);
219 os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
220 os << indent << "MaskValue: " << this->GetMaskValue() << std::endl;
221 os << indent << "Foreground mode: " << this->GetForeground() << std::endl;
225 SetBackgroundImageFilter(const Self&); //purposely not implemented
226 void operator=(const Self&); //purposely not implemented
230 } // end namespace clitk