ITK  5.2.0
Insight Toolkit
itkMaskNegatedImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  ~MaskNegatedInput() = default;
45  bool
47  {
48  return false;
49  }
50 
51  bool
52  operator==(const MaskNegatedInput & other) const
53  {
54  return !(*this != other);
55  }
56 
57  inline TOutput
58  operator()(const TInput & A, const TMask & B) const
59  {
60  if (B != m_MaskingValue)
61  {
62  return m_OutsideValue;
63  }
64  else
65  {
66  return static_cast<TOutput>(A);
67  }
68  }
69 
71  void
72  SetOutsideValue(const TOutput & outsideValue)
73  {
74  m_OutsideValue = outsideValue;
75  }
76 
78  const TOutput &
80  {
81  return m_OutsideValue;
82  }
83 
85  void
86  SetMaskingValue(const TMask & maskingValue)
87  {
88  m_MaskingValue = maskingValue;
89  }
90 
92  const TMask &
94  {
95  return m_MaskingValue;
96  }
97 
98 private:
99  TOutput m_OutsideValue;
101 };
102 } // namespace Functor
103 
138 template <typename TInputImage, typename TMaskImage, typename TOutputImage = TInputImage>
139 class MaskNegatedImageFilter : public BinaryGeneratorImageFilter<TInputImage, TMaskImage, TOutputImage>
140 {
141 public:
142  ITK_DISALLOW_COPY_AND_MOVE(MaskNegatedImageFilter);
143 
147 
148  using FunctorType = Functor::
149  MaskNegatedInput<typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType>;
152 
154  itkNewMacro(Self);
155 
158 
160  using MaskImageType = TMaskImage;
161 
163  void
164  SetOutsideValue(const typename TOutputImage::PixelType & outsideValue)
165  {
166  if (Math::NotExactlyEquals(this->GetOutsideValue(), outsideValue))
167  {
168  this->Modified();
169  this->GetFunctor().SetOutsideValue(outsideValue);
170  }
171  }
173 
174  const typename TOutputImage::PixelType &
176  {
177  return this->GetFunctor().GetOutsideValue();
178  }
179 
181  void
182  SetMaskingValue(const typename TMaskImage::PixelType & maskingValue)
183  {
184  if (this->GetMaskingValue() != maskingValue)
185  {
186  this->GetFunctor().SetMaskingValue(maskingValue);
187  this->Modified();
188  }
189  }
191 
193  const typename TMaskImage::PixelType &
195  {
196  return this->GetFunctor().GetMaskingValue();
197  }
198 
203  void
204  SetMaskImage(const MaskImageType * maskImage)
205  {
206  // Process object is not const-correct so the const casting is required.
207  this->SetNthInput(1, const_cast<MaskImageType *>(maskImage));
208  }
209 
210  const MaskImageType *
212  {
213  return static_cast<const MaskImageType *>(this->ProcessObject::GetInput(1));
214  }
215 
216 #ifdef ITK_USE_CONCEPT_CHECKING
217  // Begin concept checking
219  itkConceptMacro(InputConvertibleToOutputCheck,
221  // End concept checking
222 #endif
223 
224 protected:
225  MaskNegatedImageFilter() = default;
226  ~MaskNegatedImageFilter() override = default;
227 
228  void
229  PrintSelf(std::ostream & os, Indent indent) const override
230  {
231  Superclass::PrintSelf(os, indent);
232  os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
233  }
234 
235  void
237  {
238  this->SetFunctor(this->GetFunctor());
239  }
240 
241 private:
242  itkGetConstReferenceMacro(Functor, FunctorType);
243  FunctorType &
245  {
246  return m_Functor;
247  }
248 
250 };
251 } // end namespace itk
252 
253 #endif
itk::Functor::MaskNegatedInput::~MaskNegatedInput
~MaskNegatedInput()=default
itk::MaskNegatedImageFilter::~MaskNegatedImageFilter
~MaskNegatedImageFilter() override=default
itk::Functor::MaskNegatedInput::m_MaskingValue
TMask m_MaskingValue
Definition: itkMaskNegatedImageFilter.h:100
itk::MaskNegatedImageFilter::m_Functor
FunctorType m_Functor
Definition: itkMaskNegatedImageFilter.h:249
itk::MaskNegatedImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkMaskNegatedImageFilter.h:229
itk::MaskNegatedImageFilter::GetFunctor
virtual const FunctorType & GetFunctor() const
itk::Functor::MaskNegatedInput::operator()
TOutput operator()(const TInput &A, const TMask &B) const
Definition: itkMaskNegatedImageFilter.h:58
itk::Functor::MaskNegatedInput::operator!=
bool operator!=(const MaskNegatedInput &) const
Definition: itkMaskNegatedImageFilter.h:46
itk::BinaryGeneratorImageFilter
Implements pixel-wise generic operation of two images, or of an image and a constant.
Definition: itkBinaryGeneratorImageFilter.h:56
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Math::NotExactlyEquals
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:733
itk::MaskNegatedImageFilter::GetMaskingValue
const TMaskImage::PixelType & GetMaskingValue() const
Definition: itkMaskNegatedImageFilter.h:194
itk::MaskNegatedImageFilter::GetOutsideValue
const TOutputImage::PixelType & GetOutsideValue() const
Definition: itkMaskNegatedImageFilter.h:175
itk::Functor::MaskNegatedInput
Definition: itkMaskNegatedImageFilter.h:35
itk::MaskNegatedImageFilter::GetMaskImage
const MaskImageType * GetMaskImage()
Definition: itkMaskNegatedImageFilter.h:211
itkBinaryGeneratorImageFilter.h
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::MaskNegatedInput::SetOutsideValue
void SetOutsideValue(const TOutput &outsideValue)
Definition: itkMaskNegatedImageFilter.h:72
itk::Functor::MaskNegatedInput::operator==
bool operator==(const MaskNegatedInput &other) const
Definition: itkMaskNegatedImageFilter.h:52
itk::Functor::MaskNegatedInput::GetMaskingValue
const TMask & GetMaskingValue() const
Definition: itkMaskNegatedImageFilter.h:93
itk::InPlaceImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::MaskNegatedImageFilter::FunctorType
Functor::MaskNegatedInput< typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: itkMaskNegatedImageFilter.h:149
itk::MaskNegatedImageFilter
Mask an image with the negation (or logical compliment) of a mask.
Definition: itkMaskNegatedImageFilter.h:139
itk::MaskNegatedImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: itkMaskNegatedImageFilter.h:236
itk::MaskNegatedImageFilter::SetOutsideValue
void SetOutsideValue(const typename TOutputImage::PixelType &outsideValue)
Definition: itkMaskNegatedImageFilter.h:164
itk::MaskNegatedImageFilter::MaskNegatedImageFilter
MaskNegatedImageFilter()=default
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::Functor::MaskNegatedInput< typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType >::AccumulatorType
typename NumericTraits< typename TInputImage::PixelType >::AccumulateType AccumulatorType
Definition: itkMaskNegatedImageFilter.h:38
itk::Functor::MaskNegatedInput::GetOutsideValue
const TOutput & GetOutsideValue() const
Definition: itkMaskNegatedImageFilter.h:79
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject::SetNthInput
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itkNumericTraits.h
itk::MaskNegatedImageFilter::MaskImageType
TMaskImage MaskImageType
Definition: itkMaskNegatedImageFilter.h:160
itk::MaskNegatedImageFilter::GetFunctor
FunctorType & GetFunctor()
Definition: itkMaskNegatedImageFilter.h:244
itk::Functor::MaskNegatedInput::SetMaskingValue
void SetMaskingValue(const TMask &maskingValue)
Definition: itkMaskNegatedImageFilter.h:86
itk::Functor::MaskNegatedInput::m_OutsideValue
TOutput m_OutsideValue
Definition: itkMaskNegatedImageFilter.h:99
itk::Object::Modified
virtual void Modified() const
itkMath.h
itk::ProcessObject::GetInput
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
itk::Concept::EqualityComparable
Definition: itkConceptChecking.h:306
itk::Functor::MaskNegatedInput::MaskNegatedInput
MaskNegatedInput()
Definition: itkMaskNegatedImageFilter.h:40
itk::BinaryGeneratorImageFilter< TInputImage, TMaskImage, TOutputImage >::SetFunctor
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Definition: itkBinaryGeneratorImageFilter.h:150
itk::MaskNegatedImageFilter::SetMaskImage
void SetMaskImage(const MaskImageType *maskImage)
Definition: itkMaskNegatedImageFilter.h:204
itk::MaskNegatedImageFilter::SetMaskingValue
void SetMaskingValue(const typename TMaskImage::PixelType &maskingValue)
Definition: itkMaskNegatedImageFilter.h:182