13 #ifndef mitkitkMaskImageFilter_h
14 #define mitkitkMaskImageFilter_h
18 #include "itkBinaryFunctorImageFilter.h"
19 #include "itkNumericTraits.h"
20 #include "itkVariableLengthVector.h"
32 template<
typename TInput,
typename TMask,
typename TOutput = TInput >
40 m_MaskingValue = NumericTraits< TMask >::ZeroValue();
41 InitializeOutsideValue(
static_cast<TOutput*
>(
nullptr ) );
51 return !( *
this != other );
54 inline TOutput
operator()(
const TInput & A,
const TMask & B)
const
56 if ( B == m_MaskingValue )
58 return static_cast< TOutput
>( A );
62 return m_OutsideValue;
69 m_OutsideValue = outsideValue;
75 return m_OutsideValue;
81 m_MaskingValue = maskingValue;
86 return m_MaskingValue;
91 template <
typename TPixelType >
92 void InitializeOutsideValue( TPixelType * )
94 this->m_OutsideValue = NumericTraits< TPixelType >::ZeroValue();
97 template <
typename TValue >
104 TOutput m_OutsideValue;
105 TMask m_MaskingValue;
136 template<
typename TInputImage,
typename TMaskImage,
typename TOutputImage = TInputImage >
139 BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
141 typename TInputImage::PixelType,
142 typename TMaskImage::PixelType,
143 typename TOutputImage::PixelType > >
149 typedef BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
151 typename TInputImage::PixelType,
152 typename TMaskImage::PixelType,
153 typename TOutputImage::PixelType >
164 BinaryFunctorImageFilter);
176 this->SetNthInput( 1,
const_cast< MaskImageType *
>( maskImage ) );
180 return static_cast<const MaskImageType*
>(this->ProcessObject::GetInput(1));
186 if ( this->GetOutsideValue() != outsideValue )
189 this->GetFunctor().SetOutsideValue(outsideValue);
195 return this->GetFunctor().GetOutsideValue();
201 if ( this->GetMaskingValue() != maskingValue )
204 this->GetFunctor().SetMaskingValue(maskingValue);
211 return this->GetFunctor().GetMaskingValue();
216 typedef typename TOutputImage::PixelType PixelType;
217 this->CheckOutsideValue(
static_cast<PixelType*
>(
nullptr) );
220 #ifdef ITK_USE_CONCEPT_CHECKING
222 itkConceptMacro( MaskEqualityComparableCheck,
223 ( Concept::EqualityComparable< typename TMaskImage::PixelType > ) );
224 itkConceptMacro( InputConvertibleToOutputCheck,
225 ( Concept::Convertible<
typename TInputImage::PixelType,
226 typename TOutputImage::PixelType > ) );
234 void PrintSelf(std::ostream & os, Indent indent)
const override
236 Superclass::PrintSelf(os, indent);
237 os << indent <<
"OutsideValue: " << this->GetOutsideValue() << std::endl;
242 void operator=(
const Self &);
244 template <
typename TPixelType >
245 void CheckOutsideValue(
const TPixelType * ) {}
247 template <
typename TValue >
248 void CheckOutsideValue(
const VariableLengthVector< TValue > * )
255 VariableLengthVector< TValue > currentValue =
256 this->GetFunctor().GetOutsideValue();
257 VariableLengthVector< TValue > zeroVector( currentValue.GetSize() );
258 zeroVector.Fill( NumericTraits< TValue >::ZeroValue() );
260 if ( currentValue == zeroVector )
262 zeroVector.SetSize( this->GetOutput()->GetVectorLength() );
263 zeroVector.Fill( NumericTraits< TValue >::ZeroValue() );
264 this->GetFunctor().SetOutsideValue( zeroVector );
266 else if ( this->GetFunctor().GetOutsideValue().GetSize() !=
267 this->GetOutput()->GetVectorLength() )
270 <<
"Number of components in OutsideValue: "
271 << this->GetFunctor().GetOutsideValue().GetSize()
272 <<
" is not the same as the "
273 <<
"number of components in the image: "
274 << this->GetOutput()->GetVectorLength());