13 #ifndef mitkitkMaskImageFilter_h
14 #define mitkitkMaskImageFilter_h
18 #include <itkBinaryFunctorImageFilter.h>
19 #include <itkNumericTraits.h>
20 #include <itkVariableLengthVector.h>
31 template<
typename TInput,
typename TMask,
typename TOutput = TInput >
39 m_MaskingValue = NumericTraits< TMask >::ZeroValue();
40 InitializeOutsideValue(
static_cast<TOutput*
>(
nullptr ) );
50 return !( *
this != other );
53 inline TOutput
operator()(
const TInput & A,
const TMask & B)
const
55 if ( B == m_MaskingValue )
57 return static_cast< TOutput
>( A );
61 return m_OutsideValue;
68 m_OutsideValue = outsideValue;
74 return m_OutsideValue;
80 m_MaskingValue = maskingValue;
85 return m_MaskingValue;
90 template <
typename TPixelType >
91 void InitializeOutsideValue( TPixelType * )
93 this->m_OutsideValue = NumericTraits< TPixelType >::ZeroValue();
96 template <
typename TValue >
103 TOutput m_OutsideValue;
104 TMask m_MaskingValue;
132 template<
typename TInputImage,
typename TMaskImage,
typename TOutputImage = TInputImage >
135 BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
137 typename TInputImage::PixelType,
138 typename TMaskImage::PixelType,
139 typename TOutputImage::PixelType > >
145 typedef BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
147 typename TInputImage::PixelType,
148 typename TMaskImage::PixelType,
149 typename TOutputImage::PixelType >
160 BinaryFunctorImageFilter);
172 this->SetNthInput( 1,
const_cast< MaskImageType *
>( maskImage ) );
176 return static_cast<const MaskImageType*
>(this->ProcessObject::GetInput(1));
182 if ( this->GetOutsideValue() != outsideValue )
185 this->GetFunctor().SetOutsideValue(outsideValue);
191 return this->GetFunctor().GetOutsideValue();
197 if ( this->GetMaskingValue() != maskingValue )
200 this->GetFunctor().SetMaskingValue(maskingValue);
207 return this->GetFunctor().GetMaskingValue();
212 typedef typename TOutputImage::PixelType PixelType;
213 this->CheckOutsideValue(
static_cast<PixelType*
>(
nullptr) );
216 #ifdef ITK_USE_CONCEPT_CHECKING
218 itkConceptMacro( MaskEqualityComparableCheck,
219 ( Concept::EqualityComparable< typename TMaskImage::PixelType > ) );
220 itkConceptMacro( InputConvertibleToOutputCheck,
221 ( Concept::Convertible<
typename TInputImage::PixelType,
222 typename TOutputImage::PixelType > ) );
230 void PrintSelf(std::ostream & os, Indent indent)
const override
232 Superclass::PrintSelf(os, indent);
233 os << indent <<
"OutsideValue: " << this->GetOutsideValue() << std::endl;
238 void operator=(
const Self &);
240 template <
typename TPixelType >
241 void CheckOutsideValue(
const TPixelType * ) {}
243 template <
typename TValue >
244 void CheckOutsideValue(
const VariableLengthVector< TValue > * )
251 VariableLengthVector< TValue > currentValue =
252 this->GetFunctor().GetOutsideValue();
253 VariableLengthVector< TValue > zeroVector( currentValue.GetSize() );
254 zeroVector.Fill( NumericTraits< TValue >::ZeroValue() );
256 if ( currentValue == zeroVector )
258 zeroVector.SetSize( this->GetOutput()->GetVectorLength() );
259 zeroVector.Fill( NumericTraits< TValue >::ZeroValue() );
260 this->GetFunctor().SetOutsideValue( zeroVector );
262 else if ( this->GetFunctor().GetOutsideValue().GetSize() !=
263 this->GetOutput()->GetVectorLength() )
266 <<
"Number of components in OutsideValue: "
267 << this->GetFunctor().GetOutsideValue().GetSize()
268 <<
" is not the same as the "
269 <<
"number of components in the image: "
270 << this->GetOutput()->GetVectorLength());
#define MITKIMAGESTATISTICS_EXPORT
const TOutputImage::PixelType & GetOutsideValue() const
void BeforeThreadedGenerateData() override
BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage, Functor::MaskInput2< typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType > > Superclass
void SetMaskingValue(const typename TMaskImage::PixelType &maskingValue)
SmartPointer< const Self > ConstPointer
const TMaskImage::PixelType & GetMaskingValue() const
SmartPointer< Self > Pointer
void SetOutsideValue(const typename TOutputImage::PixelType &outsideValue)
~MaskImageFilter2() override
const MaskImageType * GetMaskImage()
void PrintSelf(std::ostream &os, Indent indent) const override
void SetMaskImage(const MaskImageType *maskImage)