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 "itkBinaryFunctorImageFilter.h"
21 #include "itkNumericTraits.h"
29 template< class TInput, class TMask, class TOutput=TInput >
33 typedef typename itk::NumericTraits< TInput >::AccumulateType AccumulatorType;
35 //SetBackground(): m_OutsideValue(itk::NumericTraits< TOutput >::Zero),m_Fg(false),m_MaskValue( static_cast<TMask>(0) ) {};
38 m_OutsideValue=itk::NumericTraits< TOutput >::Zero;
40 m_MaskValue= static_cast<TMask>(0);
43 bool operator!=( const SetBackground & ) const
47 bool operator==( const SetBackground & other ) const
49 return !(*this != other);
52 inline TOutput operator()( const TInput & A, const TMask & B)
54 // Background mode: set everything = background value
57 if (B == m_MaskValue )
59 return static_cast<TOutput>( m_OutsideValue );
67 // Foreground mode: set everything != foreground value
70 if (B != m_MaskValue )
72 return static_cast<TOutput>( m_OutsideValue );
81 /** Method to explicitly set the outside value of the mask */
82 void SetOutsideValue( const TOutput &outsideValue )
84 m_OutsideValue = static_cast<TOutput>(outsideValue);
87 /** Method to get the outside value of the mask */
88 const TOutput &GetOutsideValue() const
90 return m_OutsideValue;
93 /** Method to explicitly set the relevant value of the mask */
94 void SetMaskValue( const TMask &maskValue )
96 m_MaskValue = static_cast<TMask>(maskValue);
99 /** Method to get the relevant value of the mask */
100 const TMask &GetMaskValue() const
105 /** Method to explicitly set the foreground mode of the mask */
106 void SetForeground( const bool &fg )
111 /** Method to get the foregroundmode of the mask */
112 const bool &GetForeground() const
118 TOutput m_OutsideValue;
125 template <class TInputImage, class TMaskImage, class TOutputImage=TInputImage>
126 class ITK_EXPORT SetBackgroundImageFilter :
128 itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
129 Functor::SetBackground<
130 typename TInputImage::PixelType,
131 typename TMaskImage::PixelType,
132 typename TOutputImage::PixelType> >
137 /** Standard class typedefs. */
138 typedef SetBackgroundImageFilter Self;
139 typedef itk::BinaryFunctorImageFilter<TInputImage,TMaskImage,TOutputImage,
140 Functor::SetBackground<
141 typename TInputImage::PixelType,
142 typename TMaskImage::PixelType,
143 typename TOutputImage::PixelType>
145 typedef itk::SmartPointer<Self> Pointer;
146 typedef itk::SmartPointer<const Self> ConstPointer;
148 /** Method for creation through the object factory. */
151 /** Runtime information support. */
152 itkTypeMacro(SetBackgroundImageFilter,
153 BinaryFunctorImageFilter);
155 /** Method to explicitly set the outside value of the mask. Defaults to 0 */
156 void SetOutsideValue( const typename TOutputImage::PixelType & outsideValue )
158 if( this->GetOutsideValue() != outsideValue )
161 this->GetFunctor().SetOutsideValue( outsideValue );
165 const typename TOutputImage::PixelType & GetOutsideValue() const
167 return this->GetFunctor().GetOutsideValue();
170 /** Method to explicitly set the value of the mask. Defaults to 0 */
171 void SetMaskValue( const typename TMaskImage::PixelType & maskValue )
173 if( this->GetMaskValue() != maskValue )
176 this->GetFunctor().SetMaskValue( maskValue );
180 const typename TMaskImage::PixelType & GetMaskValue() const
182 return this->GetFunctor().GetMaskValue();
185 /** Method to set the foreground mode. Defaults to 0 */
186 void SetForeground( const bool & fg )
188 if( this->GetForeground() != fg )
191 this->GetFunctor().SetForeground( fg );
195 const bool & GetForeground() const
197 return this->GetFunctor().GetForeground();
200 #ifdef ITK_USE_CONCEPT_CHECKING
201 /** Begin concept checking */
202 itkConceptMacro(MaskEqualityComparableCheck,
203 (itk::Concept::EqualityComparable<typename TMaskImage::PixelType>));
204 itkConceptMacro(InputConvertibleToOutputCheck,
205 (itk::Concept::Convertible<typename TInputImage::PixelType,
206 typename TOutputImage::PixelType>));
207 /** End concept checking */
211 SetBackgroundImageFilter() {}
212 virtual ~SetBackgroundImageFilter() {}
214 void PrintSelf(std::ostream &os, itk::Indent indent) const
216 Superclass::PrintSelf(os, indent);
217 os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
218 os << indent << "MaskValue: " << this->GetMaskValue() << std::endl;
219 os << indent << "Foreground mode: " << this->GetForeground() << std::endl;
223 SetBackgroundImageFilter(const Self&); //purposely not implemented
224 void operator=(const Self&); //purposely not implemented
228 } // end namespace clitk