ITK  5.3.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  * https://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 true;
49  }
50 
52 
53  inline TOutput
54  operator()(const TInput & A, const TMask & B) const
55  {
56  if (B != m_MaskingValue)
57  {
58  return m_OutsideValue;
59  }
60  else
61  {
62  return static_cast<TOutput>(A);
63  }
64  }
65 
67  void
68  SetOutsideValue(const TOutput & outsideValue)
69  {
70  m_OutsideValue = outsideValue;
71  }
72 
74  const TOutput &
76  {
77  return m_OutsideValue;
78  }
79 
81  void
82  SetMaskingValue(const TMask & maskingValue)
83  {
84  m_MaskingValue = maskingValue;
85  }
86 
88  const TMask &
90  {
91  return m_MaskingValue;
92  }
93 
94 private:
95  TOutput m_OutsideValue;
97 };
98 } // namespace Functor
99 
134 template <typename TInputImage, typename TMaskImage, typename TOutputImage = TInputImage>
135 class ITK_TEMPLATE_EXPORT MaskNegatedImageFilter
136  : public BinaryGeneratorImageFilter<TInputImage, TMaskImage, TOutputImage>
137 {
138 public:
139  ITK_DISALLOW_COPY_AND_MOVE(MaskNegatedImageFilter);
140 
144 
145  using FunctorType = Functor::
146  MaskNegatedInput<typename TInputImage::PixelType, typename TMaskImage::PixelType, typename TOutputImage::PixelType>;
149 
151  itkNewMacro(Self);
152 
155 
157  using MaskImageType = TMaskImage;
158 
160  void
161  SetOutsideValue(const typename TOutputImage::PixelType & outsideValue)
162  {
163  if (Math::NotExactlyEquals(this->GetOutsideValue(), outsideValue))
164  {
165  this->Modified();
166  this->GetFunctor().SetOutsideValue(outsideValue);
167  }
168  }
171  const typename TOutputImage::PixelType &
173  {
174  return this->GetFunctor().GetOutsideValue();
175  }
176 
178  void
179  SetMaskingValue(const typename TMaskImage::PixelType & maskingValue)
180  {
181  if (this->GetMaskingValue() != maskingValue)
182  {
183  this->GetFunctor().SetMaskingValue(maskingValue);
184  this->Modified();
185  }
186  }
190  const typename TMaskImage::PixelType &
192  {
193  return this->GetFunctor().GetMaskingValue();
194  }
195 
200  void
201  SetMaskImage(const MaskImageType * maskImage)
202  {
203  // Process object is not const-correct so the const casting is required.
204  this->SetNthInput(1, const_cast<MaskImageType *>(maskImage));
205  }
206 
207  const MaskImageType *
209  {
210  return static_cast<const MaskImageType *>(this->ProcessObject::GetInput(1));
211  }
212 
213 #ifdef ITK_USE_CONCEPT_CHECKING
214  // Begin concept checking
216  itkConceptMacro(InputConvertibleToOutputCheck,
218  // End concept checking
219 #endif
220 
221 protected:
222  MaskNegatedImageFilter() = default;
223  ~MaskNegatedImageFilter() override = default;
224 
225  void
226  PrintSelf(std::ostream & os, Indent indent) const override
227  {
228  Superclass::PrintSelf(os, indent);
229  os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
230  }
231 
232  void
234  {
235  this->SetFunctor(this->GetFunctor());
236  }
237 
238 private:
239  itkGetConstReferenceMacro(Functor, FunctorType);
240  FunctorType &
242  {
243  return m_Functor;
244  }
245 
247 };
248 } // end namespace itk
249 
250 #endif
itk::Functor::MaskNegatedInput::~MaskNegatedInput
~MaskNegatedInput()=default
itk::Functor::MaskNegatedInput::m_MaskingValue
TMask m_MaskingValue
Definition: itkMaskNegatedImageFilter.h:96
itk::MaskNegatedImageFilter::m_Functor
FunctorType m_Functor
Definition: itkMaskNegatedImageFilter.h:246
itk::MaskNegatedImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkMaskNegatedImageFilter.h:226
itk::Functor::MaskNegatedInput::operator()
TOutput operator()(const TInput &A, const TMask &B) const
Definition: itkMaskNegatedImageFilter.h:54
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:191
itk::MaskNegatedImageFilter::GetOutsideValue
const TOutputImage::PixelType & GetOutsideValue() const
Definition: itkMaskNegatedImageFilter.h:172
itk::Functor::MaskNegatedInput
Definition: itkMaskNegatedImageFilter.h:35
itk::MaskNegatedImageFilter::GetMaskImage
const MaskImageType * GetMaskImage()
Definition: itkMaskNegatedImageFilter.h:208
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:68
itk::Functor::MaskNegatedInput::GetMaskingValue
const TMask & GetMaskingValue() const
Definition: itkMaskNegatedImageFilter.h:89
itk::Functor::MaskNegatedInput::operator==
bool operator==(const MaskNegatedInput &) const
Definition: itkMaskNegatedImageFilter.h:46
itk::MaskNegatedImageFilter
Mask an image with the negation (or logical compliment) of a mask.
Definition: itkMaskNegatedImageFilter.h:135
itk::MaskNegatedImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: itkMaskNegatedImageFilter.h:233
itk::MaskNegatedImageFilter::SetOutsideValue
void SetOutsideValue(const typename TOutputImage::PixelType &outsideValue)
Definition: itkMaskNegatedImageFilter.h:161
FunctorType
Functor::Add2< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: itkAddImageFilter.h:96
itk::Functor::MaskNegatedInput::ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(MaskNegatedInput)
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:75
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
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::Concept::Convertible
Definition: itkConceptChecking.h:216
itkNumericTraits.h
itk::MaskNegatedImageFilter::MaskImageType
TMaskImage MaskImageType
Definition: itkMaskNegatedImageFilter.h:157
itk::MaskNegatedImageFilter::GetFunctor
FunctorType & GetFunctor()
Definition: itkMaskNegatedImageFilter.h:241
itk::Functor::MaskNegatedInput::SetMaskingValue
void SetMaskingValue(const TMask &maskingValue)
Definition: itkMaskNegatedImageFilter.h:82
itk::Functor::MaskNegatedInput::m_OutsideValue
TOutput m_OutsideValue
Definition: itkMaskNegatedImageFilter.h:95
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::MaskNegatedImageFilter::SetMaskImage
void SetMaskImage(const MaskImageType *maskImage)
Definition: itkMaskNegatedImageFilter.h:201
itk::MaskNegatedImageFilter::SetMaskingValue
void SetMaskingValue(const typename TMaskImage::PixelType &maskingValue)
Definition: itkMaskNegatedImageFilter.h:179