ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMaskNegatedImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMaskNegatedImageFilter_h
19 #define itkMaskNegatedImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 #include "itkMath.h"
24 
25 namespace itk
26 {
27 namespace Functor
28 {
34 template< typename TInput, typename TMask, typename TOutput = TInput >
36 {
37 public:
39 
41  : m_OutsideValue(NumericTraits< TOutput >::ZeroValue())
42  , m_MaskingValue(NumericTraits< TMask >::ZeroValue())
43  {
44  }
45  ~MaskNegatedInput() = default;
46  bool operator!=(const MaskNegatedInput &) const
47  {
48  return false;
49  }
50 
51  bool operator==(const MaskNegatedInput & other) const
52  {
53  return !( *this != other );
54  }
55 
56  inline TOutput operator()(const TInput & A, const TMask & B) const
57  {
58  if ( B != m_MaskingValue )
59  {
60  return m_OutsideValue;
61  }
62  else
63  {
64  return static_cast< TOutput >( A );
65  }
66  }
67 
69  void SetOutsideValue(const TOutput & outsideValue)
70  {
71  m_OutsideValue = outsideValue;
72  }
73 
75  const TOutput & GetOutsideValue() const
76  {
77  return m_OutsideValue;
78  }
79 
81  void SetMaskingValue(const TMask & maskingValue)
82  {
83  m_MaskingValue = maskingValue;
84  }
85 
87  const TMask & GetMaskingValue() const
88  {
89  return m_MaskingValue;
90  }
91 private:
92  TOutput m_OutsideValue;
94 };
95 }
96 
131 template< typename TInputImage, typename TMaskImage, typename TOutputImage = TInputImage >
133  public
134  BinaryGeneratorImageFilter< TInputImage, TMaskImage, TOutputImage >
135 {
136 public:
137  ITK_DISALLOW_COPY_AND_ASSIGN(MaskNegatedImageFilter);
138 
142 
143  using FunctorType = Functor::MaskNegatedInput< typename TInputImage::PixelType,
144  typename TMaskImage::PixelType,
145  typename TOutputImage::PixelType >;
148 
150  itkNewMacro(Self);
151 
153  itkTypeMacro(MaskNegatedImageFilter,
155 
157  using MaskImageType = TMaskImage;
158 
160  void SetOutsideValue(const typename TOutputImage::PixelType & outsideValue)
161  {
162  if ( Math::NotExactlyEquals(this->GetOutsideValue(), outsideValue) )
163  {
164  this->Modified();
165  this->GetFunctor().SetOutsideValue(outsideValue);
166  }
167  }
169 
170  const typename TOutputImage::PixelType & GetOutsideValue() const
171  {
172  return this->GetFunctor().GetOutsideValue();
173  }
174 
176  void SetMaskingValue(const typename TMaskImage::PixelType & maskingValue)
177  {
178  if ( this->GetMaskingValue() != maskingValue )
179  {
180  this->GetFunctor().SetMaskingValue(maskingValue);
181  this->Modified();
182  }
183  }
185 
187  const typename TMaskImage::PixelType & GetMaskingValue() const
188  {
189  return this->GetFunctor().GetMaskingValue();
190  }
191 
196  void SetMaskImage(const MaskImageType *maskImage)
197  {
198  // Process object is not const-correct so the const casting is required.
199  this->SetNthInput( 1, const_cast< MaskImageType * >( maskImage ) );
200  }
201 
203  {
204  return static_cast<const MaskImageType*>(this->ProcessObject::GetInput(1));
205  }
206 
207 #ifdef ITK_USE_CONCEPT_CHECKING
208  // Begin concept checking
209  itkConceptMacro( MaskEqualityComparableCheck,
211  itkConceptMacro( InputConvertibleToOutputCheck,
212  ( Concept::Convertible< typename TInputImage::PixelType,
213  typename TOutputImage::PixelType > ) );
214  // End concept checking
215 #endif
216 
217 protected:
218  MaskNegatedImageFilter() = default;
219  ~MaskNegatedImageFilter() override = default;
220 
221  void PrintSelf(std::ostream & os, Indent indent) const override
222  {
223  Superclass::PrintSelf(os, indent);
224  os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
225  }
226 
228  {
229  this->SetFunctor(this->GetFunctor());
230  }
231 
232 private:
233  itkGetConstReferenceMacro(Functor, FunctorType);
235 
237 };
238 } // end namespace itk
239 
240 #endif
void SetOutsideValue(const typename TOutputImage::PixelType &outsideValue)
void PrintSelf(std::ostream &os, Indent indent) const override
Define numeric traits for std::vector.
void SetOutsideValue(const TOutput &outsideValue)
Mask an image with the negation (or logical compliment) of a mask.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
virtual const FunctorType & GetFunctor() const
const TOutputImage::PixelType & GetOutsideValue() const
Base class for all process objects that output image data.
void PrintSelf(std::ostream &os, Indent indent) const override
void SetMaskingValue(const TMask &maskingValue)
const TOutput & GetOutsideValue() const
bool operator==(const MaskNegatedInput &other) const
void SetMaskImage(const MaskImageType *maskImage)
const TMaskImage::PixelType & GetMaskingValue() const
~MaskNegatedImageFilter() override=default
const MaskImageType * GetMaskImage()
Implements pixel-wise generic operation of two images, or of an image and a constant.
TOutput operator()(const TInput &A, const TMask &B) const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
virtual void Modified() const
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
bool operator!=(const MaskNegatedInput &) const
Functor::MaskNegatedInput< typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType > FunctorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
#define itkConceptMacro(name, concept)
void SetMaskingValue(const typename TMaskImage::PixelType &maskingValue)